Linux build fixes

This commit is contained in:
Jack Andersen
2019-05-25 20:24:13 -10:00
parent 20862139b6
commit 9f94db6c82
83 changed files with 839 additions and 295 deletions

View File

@@ -2,6 +2,8 @@
#include <Common/Math/CTransform4f.h>
#include <Common/Math/MathUtil.h>
#include <cfloat>
CAnimation::CAnimation(CResourceEntry *pEntry /*= 0*/)
: CResource(pEntry)
, mDuration(0.f)

View File

@@ -5,6 +5,8 @@
#include <Common/Macros.h>
#include <Common/Math/MathUtil.h>
#include <cfloat>
// ************ CBone ************
CBone::CBone(CSkeleton *pSkel)
: mpSkeleton(pSkel)

View File

@@ -21,10 +21,6 @@ CGameArea::~CGameArea()
for (uint32 iSCLY = 0; iSCLY < mScriptLayers.size(); iSCLY++)
delete mScriptLayers[iSCLY];
for (uint32 iLyr = 0; iLyr < mLightLayers.size(); iLyr++)
for (uint32 iLight = 0; iLight < mLightLayers[iLyr].size(); iLight++)
delete mLightLayers[iLyr][iLight];
}
CDependencyTree* CGameArea::BuildDependencyTree() const

View File

@@ -53,7 +53,7 @@ class CGameArea : public CResource
// Collision
std::unique_ptr<CCollisionMeshGroup> mpCollision;
// Lights
std::vector<std::vector<CLight*>> mLightLayers;
std::vector<std::vector<CLight>> mLightLayers;
// Path Mesh
CAssetID mPathID;
// Portal Area
@@ -98,7 +98,7 @@ public:
inline CScriptLayer* ScriptLayer(uint32 Index) const { return mScriptLayers[Index]; }
inline uint32 NumLightLayers() const { return mLightLayers.size(); }
inline uint32 NumLights(uint32 LayerIndex) const { return (LayerIndex < mLightLayers.size() ? mLightLayers[LayerIndex].size() : 0); }
inline CLight* Light(uint32 LayerIndex, uint32 LightIndex) const { return mLightLayers[LayerIndex][LightIndex]; }
inline CLight* Light(uint32 LayerIndex, uint32 LightIndex) { return &mLightLayers[LayerIndex][LightIndex]; }
inline CAssetID PathID() const { return mPathID; }
inline CPoiToWorld* PoiToWorldMap() const { return mpPoiToWorldMap; }
inline CAssetID PortalAreaID() const { return mPortalAreaID; }

View File

@@ -3,7 +3,7 @@
#include "Core/Render/CDrawUtil.h"
#include "Core/Render/CRenderer.h"
CDynamicVertexBuffer CFont::smGlyphVertices;
std::optional<CDynamicVertexBuffer> CFont::smGlyphVertices;
CIndexBuffer CFont::smGlyphIndices;
bool CFont::smBuffersInitialized = false;
@@ -43,7 +43,7 @@ CVector2f CFont::RenderString(const TString& rkString, CRenderer* /*pRenderer*/,
GLuint ColorLoc = pTextShader->GetUniformLocation("FontColor");
GLuint LayerLoc = pTextShader->GetUniformLocation("RGBALayer");
mpFontTexture->Bind(0);
smGlyphVertices.Bind();
smGlyphVertices->Bind();
glDisable(GL_DEPTH_TEST);
// Initialize some more stuff before we start the character loop
@@ -116,7 +116,7 @@ CVector2f CFont::RenderString(const TString& rkString, CRenderer* /*pRenderer*/,
// Load shader uniforms, buffer texture
glUniformMatrix4fv(ModelMtxLoc, 1, GL_FALSE, (GLfloat*) &GlyphTransform);
smGlyphVertices.BufferAttrib(EVertexAttribute::Tex0, &pGlyph->TexCoords);
smGlyphVertices->BufferAttrib(EVertexAttribute::Tex0, &pGlyph->TexCoords);
// Draw fill
glUniform1i(LayerLoc, GlyphLayer);
@@ -148,8 +148,9 @@ CVector2f CFont::RenderString(const TString& rkString, CRenderer* /*pRenderer*/,
void CFont::InitBuffers()
{
smGlyphVertices.SetActiveAttribs(EVertexAttribute::Position | EVertexAttribute::Tex0);
smGlyphVertices.SetVertexCount(4);
smGlyphVertices.emplace();
smGlyphVertices->SetActiveAttribs(EVertexAttribute::Position | EVertexAttribute::Tex0);
smGlyphVertices->SetVertexCount(4);
CVector3f Vertices[4] = {
CVector3f( 0.f, 0.f, 0.f),
@@ -157,7 +158,7 @@ void CFont::InitBuffers()
CVector3f( 0.f, -2.f, 0.f),
CVector3f( 2.f, -2.f, 0.f)
};
smGlyphVertices.BufferAttrib(EVertexAttribute::Position, Vertices);
smGlyphVertices->BufferAttrib(EVertexAttribute::Position, Vertices);
CVector2f TexCoords[4] = {
CVector2f(0.f, 0.f),
@@ -165,7 +166,7 @@ void CFont::InitBuffers()
CVector2f(0.f, 1.f),
CVector2f(1.f, 1.f)
};
smGlyphVertices.BufferAttrib(EVertexAttribute::Tex0, TexCoords);
smGlyphVertices->BufferAttrib(EVertexAttribute::Tex0, TexCoords);
smGlyphIndices.Reserve(4);
smGlyphIndices.AddIndex(0);
@@ -176,3 +177,12 @@ void CFont::InitBuffers()
smBuffersInitialized = true;
}
void CFont::ShutdownBuffers()
{
if (smBuffersInitialized)
{
smGlyphVertices = std::nullopt;
smBuffersInitialized = false;
}
}

View File

@@ -9,6 +9,7 @@
#include "Core/OpenGL/CIndexBuffer.h"
#include <Common/BasicTypes.h>
#include <optional>
#include <string>
#include <unordered_map>
@@ -20,9 +21,9 @@ class CFont : public CResource
{
DECLARE_RESOURCE_TYPE(Font)
friend class CFontLoader;
static CDynamicVertexBuffer smGlyphVertices; // This is the vertex buffer used to draw glyphs. It has two attributes - Pos and Tex0. Tex0 should be updated for each glyph.
static CIndexBuffer smGlyphIndices; // This is the index buffer used to draw glyphs. It uses a triangle strip.
static bool smBuffersInitialized; // This bool indicates whether the vertex/index buffer have been initialized. Checked at the start of RenderString().
static std::optional<CDynamicVertexBuffer> smGlyphVertices; // This is the vertex buffer used to draw glyphs. It has two attributes - Pos and Tex0. Tex0 should be updated for each glyph.
static CIndexBuffer smGlyphIndices; // This is the index buffer used to draw glyphs. It uses a triangle strip.
static bool smBuffersInitialized; // This bool indicates whether the vertex/index buffer have been initialized. Checked at the start of RenderString().
uint32 mUnknown; // Value at offset 0x8. Not sure what this is. Including for experimentation purposes.
uint32 mLineHeight; // Height of each line, in points
@@ -70,7 +71,8 @@ public:
inline TString FontName() const { return mFontName; }
inline CTexture* Texture() const { return mpFontTexture; }
private:
void InitBuffers();
static void InitBuffers();
static void ShutdownBuffers();
};
#endif // CFONT_H

View File

@@ -216,56 +216,56 @@ void CLight::Load() const
}
// ************ STATIC ************
CLight* CLight::BuildLocalAmbient(const CVector3f& rkPosition, const CColor& rkColor)
CLight CLight::BuildLocalAmbient(const CVector3f& rkPosition, const CColor& rkColor)
{
CLight *pLight = new CLight;
pLight->mType = ELightType::LocalAmbient;
pLight->mPosition = rkPosition;
pLight->mDirection = skDefaultLightDir;
pLight->mColor = rkColor;
pLight->mSpotCutoff = 0.f;
CLight pLight;
pLight.mType = ELightType::LocalAmbient;
pLight.mPosition = rkPosition;
pLight.mDirection = skDefaultLightDir;
pLight.mColor = rkColor;
pLight.mSpotCutoff = 0.f;
return pLight;
}
CLight* CLight::BuildDirectional(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor)
CLight CLight::BuildDirectional(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor)
{
CLight *pLight = new CLight;
pLight->mType = ELightType::Directional;
pLight->mPosition = rkPosition;
pLight->mDirection = rkDirection;
pLight->mColor = rkColor;
pLight->mSpotCutoff = 0.f;
CLight pLight;
pLight.mType = ELightType::Directional;
pLight.mPosition = rkPosition;
pLight.mDirection = rkDirection;
pLight.mColor = rkColor;
pLight.mSpotCutoff = 0.f;
return pLight;
}
CLight* CLight::BuildSpot(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float Cutoff)
CLight CLight::BuildSpot(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float Cutoff)
{
CLight *pLight = new CLight;
pLight->mType = ELightType::Spot;
pLight->mPosition = rkPosition;
pLight->mDirection = -rkDirection.Normalized();
pLight->mColor = rkColor;
pLight->mSpotCutoff = Cutoff * 0.5f;
pLight->mAngleAttenCoefficients = pLight->CalculateSpotAngleAtten();
CLight pLight;
pLight.mType = ELightType::Spot;
pLight.mPosition = rkPosition;
pLight.mDirection = -rkDirection.Normalized();
pLight.mColor = rkColor;
pLight.mSpotCutoff = Cutoff * 0.5f;
pLight.mAngleAttenCoefficients = pLight.CalculateSpotAngleAtten();
return pLight;
}
CLight* CLight::BuildCustom(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor,
float DistAttenA, float DistAttenB, float DistAttenC,
float AngleAttenA, float AngleAttenB, float AngleAttenC)
CLight CLight::BuildCustom(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor,
float DistAttenA, float DistAttenB, float DistAttenC,
float AngleAttenA, float AngleAttenB, float AngleAttenC)
{
CLight *pLight = new CLight;
pLight->mType = ELightType::Custom;
pLight->mPosition = rkPosition;
pLight->mDirection = rkDirection;
pLight->mColor = rkColor;
pLight->mSpotCutoff = 0.f;
pLight->mDistAttenCoefficients.X = DistAttenA;
pLight->mDistAttenCoefficients.Y = DistAttenB;
pLight->mDistAttenCoefficients.Z = DistAttenC;
pLight->mAngleAttenCoefficients.X = AngleAttenA;
pLight->mAngleAttenCoefficients.Y = AngleAttenB;
pLight->mAngleAttenCoefficients.Z = AngleAttenC * AngleAttenC;
CLight pLight;
pLight.mType = ELightType::Custom;
pLight.mPosition = rkPosition;
pLight.mDirection = rkDirection;
pLight.mColor = rkColor;
pLight.mSpotCutoff = 0.f;
pLight.mDistAttenCoefficients.X = DistAttenA;
pLight.mDistAttenCoefficients.Y = DistAttenB;
pLight.mDistAttenCoefficients.Z = DistAttenC;
pLight.mAngleAttenCoefficients.X = AngleAttenA;
pLight.mAngleAttenCoefficients.Y = AngleAttenB;
pLight.mAngleAttenCoefficients.Z = AngleAttenC * AngleAttenC;
return pLight;
}

View File

@@ -69,10 +69,10 @@ public:
void Load() const;
// Static
static CLight* BuildLocalAmbient(const CVector3f& rkPosition, const CColor& rkColor);
static CLight* BuildDirectional(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor);
static CLight* BuildSpot(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float Cutoff);
static CLight* BuildCustom(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor,
static CLight BuildLocalAmbient(const CVector3f& rkPosition, const CColor& rkColor);
static CLight BuildDirectional(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor);
static CLight BuildSpot(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor, float Cutoff);
static CLight BuildCustom(const CVector3f& rkPosition, const CVector3f& rkDirection, const CColor& rkColor,
float DistAttenA, float DistAttenB, float DistAttenC,
float AngleAttenA, float AngleAttenB, float AngleAttenC);

View File

@@ -40,11 +40,13 @@ class CMaterial
friend class CMaterialLoader;
friend class CMaterialCooker;
public:
enum class EShaderStatus
{
NoShader, ShaderExists, ShaderFailed
};
private:
// Statics
static uint64 sCurrentMaterial; // The hash for the currently bound material
static CColor sCurrentTint; // The tint for the currently bound material

View File

@@ -2,7 +2,7 @@
#include <Common/Macros.h>
#include <algorithm>
std::unordered_map<EResourceType, CResTypeInfo*> CResTypeInfo::smTypeMap;
std::unordered_map<EResourceType, std::unique_ptr<CResTypeInfo>> CResTypeInfo::smTypeMap;
CResTypeInfo::CResTypeInfo(EResourceType Type, const TString& rkTypeName, const TString& rkRetroExtension)
: mType(Type)
@@ -15,7 +15,7 @@ CResTypeInfo::CResTypeInfo(EResourceType Type, const TString& rkTypeName, const
#if !PUBLIC_RELEASE
ASSERT(smTypeMap.find(Type) == smTypeMap.end());
#endif
smTypeMap[Type] = this;
smTypeMap[Type] = std::unique_ptr<CResTypeInfo>(this);
}
bool CResTypeInfo::IsInGame(EGame Game) const
@@ -48,7 +48,7 @@ void CResTypeInfo::GetAllTypesInGame(EGame Game, std::list<CResTypeInfo*>& rOut)
{
for (auto Iter = smTypeMap.begin(); Iter != smTypeMap.end(); Iter++)
{
CResTypeInfo *pType = Iter->second;
CResTypeInfo *pType = Iter->second.get();
if (pType->IsInGame(Game))
rOut.push_back(pType);
@@ -78,7 +78,7 @@ CResTypeInfo* CResTypeInfo::TypeForCookedExtension(EGame Game, CFourCC Ext)
// Not cached - do a slow lookup
for (auto Iter = smTypeMap.begin(); Iter != smTypeMap.end(); Iter++)
{
CResTypeInfo *pType = Iter->second;
CResTypeInfo *pType = Iter->second.get();
if (pType->CookedExtension(Game) == Ext)
{
@@ -98,6 +98,12 @@ CResTypeInfo* CResTypeInfo::TypeForCookedExtension(EGame Game, CFourCC Ext)
return nullptr;
}
CResTypeInfo* CResTypeInfo::FindTypeInfo(EResourceType Type)
{
auto Iter = smTypeMap.find(Type);
return (Iter == smTypeMap.end() ? nullptr : Iter->second.get());
}
// ************ SERIALIZATION ************
void Serialize(IArchive& rArc, CResTypeInfo*& rpType)
{

View File

@@ -25,11 +25,12 @@ class CResTypeInfo
bool mCanHaveDependencies;
bool mCanBeCreated;
static std::unordered_map<EResourceType, CResTypeInfo*> smTypeMap;
static std::unordered_map<EResourceType, std::unique_ptr<CResTypeInfo>> smTypeMap;
// Private Methods
CResTypeInfo(EResourceType Type, const TString& rkTypeName, const TString& rkRetroExtension);
~CResTypeInfo() {}
~CResTypeInfo() = default;
friend class std::default_delete<CResTypeInfo>;
// Public Methods
public:
@@ -47,11 +48,7 @@ public:
static void GetAllTypesInGame(EGame Game, std::list<CResTypeInfo*>& rOut);
static CResTypeInfo* TypeForCookedExtension(EGame, CFourCC Ext);
inline static CResTypeInfo* FindTypeInfo(EResourceType Type)
{
auto Iter = smTypeMap.find(Type);
return (Iter == smTypeMap.end() ? nullptr : Iter->second);
}
static CResTypeInfo* FindTypeInfo(EResourceType Type);
private:
// Creation

View File

@@ -1,4 +1,5 @@
#include "CTexture.h"
#include <cmath>
CTexture::CTexture(CResourceEntry *pEntry /*= 0*/)
: CResource(pEntry)
@@ -143,7 +144,7 @@ float CTexture::ReadTexelAlpha(const CVector2f& rkTexCoord)
// todo: support texel formats other than DXT1
// DXT1 is definitely the most complicated one anyway; try reusing CTextureDecoder functions for other formats
uint32 TexelX = (uint32) ((mWidth - 1) * rkTexCoord.X);
uint32 TexelY = (uint32) ((mHeight - 1) * (1.f - fmodf(rkTexCoord.Y, 1.f)));
uint32 TexelY = (uint32) ((mHeight - 1) * (1.f - std::fmod(rkTexCoord.Y, 1.f)));
if (mTexelFormat == ETexelFormat::DXT1 && mBufferExists)
{

View File

@@ -1,5 +1,6 @@
#include "CCollisionRenderData.h"
#include <Core/Render/CDrawUtil.h>
#include <algorithm>
/** Build from collision data */
void CCollisionRenderData::BuildRenderData(const SCollisionIndexData& kIndexData)

View File

@@ -99,6 +99,7 @@ enum class EUVAnimMode
ConvolutedModeA = 0x7,
ConvolutedModeB = 0x8,
SimpleMode = 0xA,
Eleven = 0xB,
NoUVAnim = -1
};

View File

@@ -8,6 +8,7 @@
#include <Common/CFourCC.h>
#include <cfloat>
#include <iostream>
CAreaLoader::CAreaLoader()
@@ -151,7 +152,7 @@ void CAreaLoader::ReadSCLYPrime()
CFourCC SCGN = mpMREA->ReadFourCC();
if (SCGN != FOURCC('SCGN'))
errorf("%s [0x%X]: Invalid SCGN magic: %s", *mpMREA->GetSourceString(), mpMREA->Tell() - 4, SCGN.ToString());
errorf("%s [0x%X]: Invalid SCGN magic: %s", *mpMREA->GetSourceString(), mpMREA->Tell() - 4, *SCGN.ToString());
else
{
@@ -191,7 +192,7 @@ void CAreaLoader::ReadLightsPrime()
mpMREA->Seek(0x4, SEEK_CUR);
// Relevant data is read - now we process and form a CLight out of it
CLight *pLight;
CLight pLight;
CColor LightColor = CColor(Color.X, Color.Y, Color.Z, 0.f);
if (Multiplier < FLT_EPSILON)
@@ -225,7 +226,7 @@ void CAreaLoader::ReadLightsPrime()
float DistAttenA = (FalloffType == 0) ? (2.f / Multiplier) : 0.f;
float DistAttenB = (FalloffType == 1) ? (250.f / Multiplier) : 0.f;
float DistAttenC = (FalloffType == 2) ? (25000.f / Multiplier) : 0.f;
pLight->SetDistAtten(DistAttenA, DistAttenB, DistAttenC);
pLight.SetDistAtten(DistAttenA, DistAttenB, DistAttenC);
}
// Custom
@@ -240,7 +241,7 @@ void CAreaLoader::ReadLightsPrime()
1.f, 0.f, 0.f);
}
pLight->SetLayer(iLyr);
pLight.SetLayer(iLyr);
mpArea->mLightLayers[iLyr][iLight] = pLight;
}
}
@@ -493,7 +494,7 @@ void CAreaLoader::ReadLightsCorruption()
mpMREA->Seek(0x18, SEEK_CUR);
// Relevant data is read - now we process and form a CLight out of it
CLight *pLight;
CLight pLight;
if (Multiplier < FLT_EPSILON)
Multiplier = FLT_EPSILON;
@@ -518,7 +519,7 @@ void CAreaLoader::ReadLightsCorruption()
float DistAttenA = (FalloffType == 0) ? (2.f / Multiplier) : 0.f;
float DistAttenB = (FalloffType == 1) ? (250.f / Multiplier) : 0.f;
float DistAttenC = (FalloffType == 2) ? (25000.f / Multiplier) : 0.f;
pLight->SetDistAtten(DistAttenA, DistAttenB, DistAttenC);
pLight.SetDistAtten(DistAttenA, DistAttenB, DistAttenC);
}
// Custom
@@ -533,7 +534,7 @@ void CAreaLoader::ReadLightsCorruption()
1.f, 0.f, 0.f);
}
pLight->SetLayer(iLayer);
pLight.SetLayer(iLayer);
mpArea->mLightLayers[iLayer][iLight] = pLight;
}
}

View File

@@ -379,28 +379,28 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial()
switch (pPass->mAnimMode)
{
case 3: // Rotation
case 7: // ???
case EUVAnimMode::UVRotation: // Rotation
case EUVAnimMode::ConvolutedModeA: // ???
pPass->mAnimParams[0] = mpFile->ReadFloat();
pPass->mAnimParams[1] = mpFile->ReadFloat();
break;
case 2: // UV Scroll
case 4: // U Scroll
case 5: // V Scroll
case EUVAnimMode::UVScroll: // UV Scroll
case EUVAnimMode::HFilmstrip: // U Scroll
case EUVAnimMode::VFilmstrip: // V Scroll
pPass->mAnimParams[0] = mpFile->ReadFloat();
pPass->mAnimParams[1] = mpFile->ReadFloat();
pPass->mAnimParams[2] = mpFile->ReadFloat();
pPass->mAnimParams[3] = mpFile->ReadFloat();
break;
case 0: // Inverse ModelView Matrix
case 1: // Inverse ModelView Matrix Translated
case 6: // Model Matrix
case 10: // Yet-to-be-named
case EUVAnimMode::InverseMV: // Inverse ModelView Matrix
case EUVAnimMode::InverseMVTranslated: // Inverse ModelView Matrix Translated
case EUVAnimMode::ModelMatrix: // Model Matrix
case EUVAnimMode::SimpleMode: // Yet-to-be-named
break;
// Unknown/unsupported animation type
case 8:
case 11:
case EUVAnimMode::ConvolutedModeB:
case EUVAnimMode::Eleven:
break;
default:
errorf("%s [0x%X]: Unsupported animation mode encountered: %d", *mpFile->GetSourceString(), mpFile->Tell() - 8, pPass->mAnimMode);

View File

@@ -111,19 +111,6 @@ EGame CScriptTemplate::Game() const
return mpGame->Game();
}
// ************ PROPERTY FETCHING ************
template<class PropType>
PropType* TFetchProperty(CStructProperty* pProperties, const TIDString& rkID)
{
if (rkID.IsEmpty()) return nullptr;
IProperty *pProp = pProperties->ChildByIDString(rkID);
if (pProp && (pProp->Type() == PropEnum))
return static_cast<PropType*>(pProp)->ValuePtr();
else
return nullptr;
}
EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj)
{
if (pObj->Template() != this)

View File

@@ -52,7 +52,6 @@ public:
ScaleEnabled, ScaleDisabled, ScaleVolume
};
private:
struct SEditorAsset
{
enum class EAssetType {
@@ -75,6 +74,7 @@ private:
}
};
private:
std::vector<TString> mModules;
std::unique_ptr<CStructProperty> mpProperties;
std::vector<SEditorAsset> mAssets;

View File

@@ -5,7 +5,7 @@ namespace NGameList
{
/** Path for the templates directory */
const TString gkTemplatesDir = "../templates/";
const TString gkTemplatesDir = "templates/";
/** Path to the game list file */
const TString gkGameListPath = gkTemplatesDir + "GameList.xml";
@@ -33,7 +33,7 @@ struct SGameInfo
}
}
};
SGameInfo gGameList[EGame::Max];
SGameInfo gGameList[int(EGame::Max)];
/** Whether the game list has been loaded */
bool gLoadedGameList = false;
@@ -88,7 +88,7 @@ void LoadGameList()
ASSERT(!gLoadedGameList);
debugf("Loading game list");
CXMLReader Reader(gkGameListPath);
CXMLReader Reader(gDataDir + gkGameListPath);
ASSERT(Reader.IsValid());
SerializeGameList(Reader);
@@ -101,7 +101,7 @@ void SaveGameList()
ASSERT(gLoadedGameList);
debugf("Saving game list");
CXMLWriter Writer(gkGameListPath, "GameList");
CXMLWriter Writer(gDataDir + gkGameListPath, "GameList");
ASSERT(Writer.IsValid());
SerializeGameList(Writer);
@@ -151,7 +151,7 @@ CGameTemplate* GetGameTemplate(EGame Game)
// Load the game template, if it hasn't been loaded yet.
if (!GameInfo.pTemplate && !GameInfo.Name.IsEmpty())
{
TString GamePath = gkTemplatesDir + GameInfo.TemplatePath;
TString GamePath = gDataDir + gkTemplatesDir + GameInfo.TemplatePath;
GameInfo.pTemplate = std::make_unique<CGameTemplate>();
GameInfo.pTemplate->Load(GamePath);
}

View File

@@ -8,8 +8,8 @@ namespace NPropertyMap
{
/** Path to the property map file */
const char* gpkLegacyMapPath = "../templates/PropertyMapLegacy.xml";
const char* gpkMapPath = "../templates/PropertyMap.xml";
const char* gpkLegacyMapPath = "templates/PropertyMapLegacy.xml";
const char* gpkMapPath = "templates/PropertyMap.xml";
/** Whether to do name lookups from the legacy map */
const bool gkUseLegacyMapForNameLookups = false;
@@ -150,13 +150,13 @@ void LoadMap()
if ( gkUseLegacyMapForNameLookups )
{
CXMLReader Reader(gpkLegacyMapPath);
CXMLReader Reader(gDataDir + gpkLegacyMapPath);
ASSERT(Reader.IsValid());
Reader << SerialParameter("PropertyMap", gLegacyNameMap, SH_HexDisplay);
}
else
{
CXMLReader Reader(gpkMapPath);
CXMLReader Reader(gDataDir + gpkMapPath);
ASSERT(Reader.IsValid());
Reader << SerialParameter("PropertyMap", gNameMap, SH_HexDisplay);
@@ -198,7 +198,7 @@ void SaveMap(bool Force /*= false*/)
{
if( gkUseLegacyMapForUpdates )
{
CXMLWriter Writer(gpkLegacyMapPath, "PropertyMap");
CXMLWriter Writer(gDataDir + gpkLegacyMapPath, "PropertyMap");
ASSERT(Writer.IsValid());
Writer << SerialParameter("PropertyMap", gLegacyNameMap, SH_HexDisplay);
}
@@ -219,7 +219,7 @@ void SaveMap(bool Force /*= false*/)
}
// Perform the actual save
CXMLWriter Writer(gpkMapPath, "PropertyMap");
CXMLWriter Writer(gDataDir + gpkMapPath, "PropertyMap");
ASSERT(Writer.IsValid());
Writer << SerialParameter("PropertyMap", gNameMap, SH_HexDisplay);
}

View File

@@ -11,7 +11,7 @@ class CAssetProperty : public TSerializeableTypedProperty<CAssetID, EPropertyTyp
CResTypeFilter mTypeFilter;
protected:
CAssetProperty::CAssetProperty(EGame Game)
CAssetProperty(EGame Game)
: TSerializeableTypedProperty(Game)
{
mDefaultValue = CAssetID::InvalidID( mGame );

View File

@@ -13,6 +13,7 @@
template<EPropertyType TypeEnum>
class TEnumPropertyBase : public TSerializeableTypedProperty<int32, TypeEnum>
{
using base = TSerializeableTypedProperty<int32, TypeEnum>;
friend class IProperty;
struct SEnumValue
@@ -47,17 +48,17 @@ class TEnumPropertyBase : public TSerializeableTypedProperty<int32, TypeEnum>
protected:
/** Constructor */
TEnumPropertyBase(EGame Game)
: TSerializeableTypedProperty(Game)
: base(Game)
, mOverrideTypeName(false)
{}
public:
virtual const char* HashableTypeName() const
{
if (mpArchetype)
return mpArchetype->HashableTypeName();
if (base::mpArchetype)
return base::mpArchetype->HashableTypeName();
else if (mOverrideTypeName)
return *mName;
return *base::mName;
else if (TypeEnum == EPropertyType::Enum)
return "enum";
else
@@ -67,15 +68,15 @@ public:
virtual void Serialize(IArchive& rArc)
{
// Skip TSerializeableTypedProperty, serialize default value ourselves so we can set SH_HexDisplay
TTypedProperty::Serialize(rArc);
TTypedProperty<int32, TypeEnum>::Serialize(rArc);
// Serialize default value
TEnumPropertyBase* pArchetype = static_cast<TEnumPropertyBase*>(mpArchetype);
TEnumPropertyBase* pArchetype = static_cast<TEnumPropertyBase*>(base::mpArchetype);
uint32 DefaultValueFlags = SH_Optional | (TypeEnum == EPropertyType::Enum ? SH_HexDisplay : 0);
rArc << SerialParameter("DefaultValue", mDefaultValue, DefaultValueFlags, pArchetype ? pArchetype->mDefaultValue : 0);
rArc << SerialParameter("DefaultValue", base::mDefaultValue, DefaultValueFlags, pArchetype ? pArchetype->mDefaultValue : 0);
// Only serialize type name override for root archetypes.
if (!mpArchetype)
if (!base::mpArchetype)
{
rArc << SerialParameter("OverrideTypeName", mOverrideTypeName, SH_Optional, false);
}
@@ -88,19 +89,19 @@ public:
virtual void SerializeValue(void* pData, IArchive& Arc) const
{
Arc.SerializePrimitive( (uint32&) ValueRef(pData), 0 );
Arc.SerializePrimitive( (uint32&) base::ValueRef(pData), 0 );
}
virtual void InitFromArchetype(IProperty* pOther)
{
TTypedProperty::InitFromArchetype(pOther);
base::InitFromArchetype(pOther);
TEnumPropertyBase* pOtherEnum = static_cast<TEnumPropertyBase*>(pOther);
mValues = pOtherEnum->mValues;
}
virtual TString ValueAsString(void* pData) const
{
return TString::FromInt32( Value(pData), 0, 10 );
return TString::FromInt32( base::Value(pData), 0, 10 );
}
void AddValue(TString ValueName, uint32 ValueID)
@@ -137,21 +138,21 @@ public:
bool HasValidValue(void* pPropertyData)
{
if (mValues.empty()) return true;
int ID = ValueRef(pPropertyData);
int ID = base::ValueRef(pPropertyData);
uint32 Index = ValueIndex(ID);
return Index >= 0 && Index < mValues.size();
}
bool OverridesTypeName() const
{
return mpArchetype ? TPropCast<TEnumPropertyBase>(mpArchetype)->OverridesTypeName() : mOverrideTypeName;
return base::mpArchetype ? TPropCast<TEnumPropertyBase>(base::mpArchetype)->OverridesTypeName() : mOverrideTypeName;
}
void SetOverrideTypeName(bool Override)
{
if (mpArchetype)
if (base::mpArchetype)
{
TEnumPropertyBase* pArchetype = TPropCast<TEnumPropertyBase>(RootArchetype());
TEnumPropertyBase* pArchetype = TPropCast<TEnumPropertyBase>(base::RootArchetype());
pArchetype->SetOverrideTypeName(Override);
}
else
@@ -159,7 +160,7 @@ public:
if (mOverrideTypeName != Override)
{
mOverrideTypeName = Override;
MarkDirty();
base::MarkDirty();
}
}
}

View File

@@ -22,7 +22,7 @@ void CPropertyNameGenerator::Warmup()
mWords.clear();
// Load the word list from the file
FILE* pListFile = fopen("../resources/WordList.txt", "r");
FILE* pListFile = fopen(*(gDataDir + "resources/WordList.txt"), "r");
ASSERT(pListFile);
while (!feof(pListFile))

View File

@@ -10,6 +10,8 @@
#include "Core/Resource/Script/NGameList.h"
#include "Core/Resource/Script/NPropertyMap.h"
#include <cfloat>
/** IProperty */
IProperty::IProperty(EGame Game)
: mpParent( nullptr )
@@ -311,7 +313,7 @@ TString IProperty::GetTemplateFileName()
pTemplateRoot = pTemplateRoot->RootParent();
// Now that we have the base property of our template, we can return the file path.
static const uint32 kChopAmount = strlen("../templates/");
static const uint32 kChopAmount = strlen(*(gDataDir + "templates/"));
if (pTemplateRoot->ScriptTemplate())
{

View File

@@ -419,29 +419,30 @@ public:
template<typename PropType, EPropertyType PropEnum>
class TSerializeableTypedProperty : public TTypedProperty<PropType, PropEnum>
{
using base = TTypedProperty<PropType, PropEnum>;
protected:
TSerializeableTypedProperty(EGame Game)
: TTypedProperty(Game)
: base(Game)
{}
public:
virtual void Serialize(IArchive& rArc)
{
TTypedProperty::Serialize(rArc);
TSerializeableTypedProperty* pArchetype = static_cast<TSerializeableTypedProperty*>(mpArchetype);
base::Serialize(rArc);
TSerializeableTypedProperty* pArchetype = static_cast<TSerializeableTypedProperty*>(base::mpArchetype);
// Determine if default value should be serialized as optional.
// All MP1 properties should be optional. For MP2 and on, we set optional
// on property types that don't have default values in the game executable.
bool MakeOptional = false;
if (Game() <= EGame::Prime || pArchetype != nullptr)
if (base::Game() <= EGame::Prime || pArchetype != nullptr)
{
MakeOptional = true;
}
else
{
switch (Type())
switch (base::Type())
{
case EPropertyType::String:
case EPropertyType::Asset:
@@ -457,17 +458,18 @@ public:
// Branch here to avoid constructing a default value if we don't need to.
if (MakeOptional)
rArc << SerialParameter("DefaultValue", mDefaultValue, SH_Optional, pArchetype ? pArchetype->mDefaultValue : GetSerializationDefaultValue());
rArc << SerialParameter("DefaultValue", base::mDefaultValue, SH_Optional,
pArchetype ? pArchetype->mDefaultValue : GetSerializationDefaultValue());
else
rArc << SerialParameter("DefaultValue", mDefaultValue);
rArc << SerialParameter("DefaultValue", base::mDefaultValue);
}
virtual bool ShouldSerialize() const
{
TTypedProperty* pArchetype = static_cast<TTypedProperty*>(mpArchetype);
base* pArchetype = static_cast<base*>(base::mpArchetype);
return TTypedProperty::ShouldSerialize() ||
!(mDefaultValue == pArchetype->DefaultValue());
return base::ShouldSerialize() ||
!(base::mDefaultValue == pArchetype->DefaultValue());
}
/** Return default value for serialization - can be customized per type */
@@ -480,6 +482,7 @@ public:
template<typename PropType, EPropertyType PropEnum>
class TNumericalProperty : public TSerializeableTypedProperty<PropType, PropEnum>
{
using base = TSerializeableTypedProperty<PropType, PropEnum>;
friend class IProperty;
friend class CTemplateLoader;
@@ -488,7 +491,7 @@ protected:
PropType mMaxValue;
TNumericalProperty(EGame Game)
: TSerializeableTypedProperty(Game)
: base(Game)
, mMinValue( -1 )
, mMaxValue( -1 )
{}
@@ -496,8 +499,8 @@ protected:
public:
virtual void Serialize(IArchive& rArc)
{
TSerializeableTypedProperty::Serialize(rArc);
TNumericalProperty* pArchetype = static_cast<TNumericalProperty*>(mpArchetype);
base::Serialize(rArc);
TNumericalProperty* pArchetype = static_cast<TNumericalProperty*>(base::mpArchetype);
rArc << SerialParameter("Min", mMinValue, SH_Optional, pArchetype ? pArchetype->mMinValue : (PropType) -1)
<< SerialParameter("Max", mMaxValue, SH_Optional, pArchetype ? pArchetype->mMaxValue : (PropType) -1);
@@ -505,15 +508,15 @@ public:
virtual bool ShouldSerialize() const
{
TNumericalProperty* pArchetype = static_cast<TNumericalProperty*>(mpArchetype);
return TSerializeableTypedProperty::ShouldSerialize() ||
TNumericalProperty* pArchetype = static_cast<TNumericalProperty*>(base::mpArchetype);
return base::ShouldSerialize() ||
mMinValue != pArchetype->mMinValue ||
mMaxValue != pArchetype->mMaxValue;
}
virtual void InitFromArchetype(IProperty* pOther)
{
TSerializeableTypedProperty::InitFromArchetype(pOther);
base::InitFromArchetype(pOther);
TNumericalProperty* pCastOther = static_cast<TNumericalProperty*>(pOther);
mMinValue = pCastOther->mMinValue;
mMaxValue = pCastOther->mMaxValue;
@@ -521,11 +524,11 @@ public:
virtual void PropertyValueChanged(void* pPropertyData)
{
TSerializeableTypedProperty::PropertyValueChanged(pPropertyData);
base::PropertyValueChanged(pPropertyData);
if (mMinValue >= 0 && mMaxValue >= 0)
{
PropType& rValue = ValueRef(pPropertyData);
PropType& rValue = base::ValueRef(pPropertyData);
rValue = Math::Clamp(mMinValue, mMaxValue, rValue);
}
}

View File

@@ -23,7 +23,7 @@
#include "CVectorProperty.h"
/** TPropertyRef: Embeds a reference to a property on a specific object */
template<class PropertyClass, typename ValueType = PropertyClass::ValueType>
template<class PropertyClass, typename ValueType = typename PropertyClass::ValueType>
class TPropertyRef
{
/** Property data being referenced */
@@ -96,17 +96,18 @@ typedef TPropertyRef<CArrayProperty> CArrayRef;
template<typename ValueType>
class TEnumRef : public TPropertyRef<CEnumProperty, ValueType>
{
using base = TPropertyRef<CEnumProperty, ValueType>;
public:
TEnumRef()
: TPropertyRef()
: base()
{}
TEnumRef(void* pInData, IProperty* pInProperty)
: TPropertyRef(pInData, pInProperty)
: base(pInData, pInProperty)
{}
TEnumRef(void* pInData, CEnumProperty* pInProperty)
: TPropertyRef(pInData, pInProperty)
: base(pInData, pInProperty)
{}
};