diff --git a/Core/CAreaAttributes.cpp b/Core/CAreaAttributes.cpp index d449bdde..6b0eb85b 100644 --- a/Core/CAreaAttributes.cpp +++ b/Core/CAreaAttributes.cpp @@ -45,9 +45,9 @@ CModel* CAreaAttributes::SkyModel() { case ePrime: case eEchoes: - return (CModel*) static_cast(pBaseStruct->PropertyByIndex(7))->Get(); + return (CModel*) static_cast(pBaseStruct->PropertyByIndex(7))->Get().RawPointer(); case eCorruption: - return (CModel*) static_cast(pBaseStruct->PropertyByIndex(8))->Get(); + return (CModel*) static_cast(pBaseStruct->PropertyByIndex(8))->Get().RawPointer(); default: return nullptr; } diff --git a/Core/CDrawUtil.cpp b/Core/CDrawUtil.cpp index ef974eeb..d2f788cd 100644 --- a/Core/CDrawUtil.cpp +++ b/Core/CDrawUtil.cpp @@ -15,19 +15,15 @@ CIndexBuffer CDrawUtil::mSquareIndices; CDynamicVertexBuffer CDrawUtil::mLineVertices; CIndexBuffer CDrawUtil::mLineIndices; -CModel *CDrawUtil::mpCubeModel; -CToken CDrawUtil::mCubeToken; +TResPtr CDrawUtil::mpCubeModel; CVertexBuffer CDrawUtil::mWireCubeVertices; CIndexBuffer CDrawUtil::mWireCubeIndices; -CModel *CDrawUtil::mpSphereModel; -CModel *CDrawUtil::mpDoubleSidedSphereModel; -CToken CDrawUtil::mSphereToken; -CToken CDrawUtil::mDoubleSidedSphereToken; +TResPtr CDrawUtil::mpSphereModel; +TResPtr CDrawUtil::mpDoubleSidedSphereModel; -CModel *CDrawUtil::mpWireSphereModel; -CToken CDrawUtil::mWireSphereToken; +TResPtr CDrawUtil::mpWireSphereModel; CShader *CDrawUtil::mpColorShader; CShader *CDrawUtil::mpColorShaderLighting; @@ -37,12 +33,10 @@ CShader *CDrawUtil::mpTextureShader; CShader *CDrawUtil::mpCollisionShader; CShader *CDrawUtil::mpTextShader; -CTexture *CDrawUtil::mpCheckerTexture; -CToken CDrawUtil::mCheckerTextureToken; +TResPtr CDrawUtil::mpCheckerTexture; -CTexture *CDrawUtil::mpLightTextures[4]; -CTexture *CDrawUtil::mpLightMasks[4]; -CToken CDrawUtil::mLightTextureTokens[8]; +TResPtr CDrawUtil::mpLightTextures[4]; +TResPtr CDrawUtil::mpLightMasks[4]; bool CDrawUtil::mDrawUtilInitialized = false; @@ -493,8 +487,7 @@ void CDrawUtil::InitLine() void CDrawUtil::InitCube() { Log::Write("Creating cube"); - mpCubeModel = (CModel*) gResCache.GetResource("../resources/Cube.cmdl"); - mCubeToken = CToken(mpCubeModel); + mpCubeModel = gResCache.GetResource("../resources/Cube.cmdl"); } void CDrawUtil::InitWireCube() @@ -532,17 +525,14 @@ void CDrawUtil::InitWireCube() void CDrawUtil::InitSphere() { Log::Write("Creating sphere"); - mpSphereModel = (CModel*) gResCache.GetResource("../resources/Sphere.cmdl"); - mpDoubleSidedSphereModel = (CModel*) gResCache.GetResource("../resources/SphereDoubleSided.cmdl"); - mSphereToken = CToken(mpSphereModel); - mDoubleSidedSphereToken = CToken(mpDoubleSidedSphereModel); + mpSphereModel = gResCache.GetResource("../resources/Sphere.cmdl"); + mpDoubleSidedSphereModel = gResCache.GetResource("../resources/SphereDoubleSided.cmdl"); } void CDrawUtil::InitWireSphere() { Log::Write("Creating wire sphere"); - mpWireSphereModel = (CModel*) gResCache.GetResource("../resources/WireSphere.cmdl"); - mWireSphereToken = CToken(mpWireSphereModel); + mpWireSphereModel = gResCache.GetResource("../resources/WireSphere.cmdl"); } void CDrawUtil::InitShaders() @@ -560,24 +550,17 @@ void CDrawUtil::InitShaders() void CDrawUtil::InitTextures() { Log::Write("Loading textures"); - mpCheckerTexture = (CTexture*) gResCache.GetResource("../resources/Checkerboard.txtr"); - mCheckerTextureToken = CToken(mpCheckerTexture); + mpCheckerTexture = gResCache.GetResource("../resources/Checkerboard.txtr"); - mpLightTextures[0] = (CTexture*) gResCache.GetResource("../resources/LightAmbient.txtr"); - mpLightTextures[1] = (CTexture*) gResCache.GetResource("../resources/LightDirectional.txtr"); - mpLightTextures[2] = (CTexture*) gResCache.GetResource("../resources/LightCustom.txtr"); - mpLightTextures[3] = (CTexture*) gResCache.GetResource("../resources/LightSpot.txtr"); + mpLightTextures[0] = gResCache.GetResource("../resources/LightAmbient.txtr"); + mpLightTextures[1] = gResCache.GetResource("../resources/LightDirectional.txtr"); + mpLightTextures[2] = gResCache.GetResource("../resources/LightCustom.txtr"); + mpLightTextures[3] = gResCache.GetResource("../resources/LightSpot.txtr"); - mpLightMasks[0] = (CTexture*) gResCache.GetResource("../resources/LightAmbientMask.txtr"); - mpLightMasks[1] = (CTexture*) gResCache.GetResource("../resources/LightDirectionalMask.txtr"); - mpLightMasks[2] = (CTexture*) gResCache.GetResource("../resources/LightCustomMask.txtr"); - mpLightMasks[3] = (CTexture*) gResCache.GetResource("../resources/LightSpotMask.txtr"); - - for (int i = 0; i < 4; i++) - { - mLightTextureTokens[i] = CToken(mpLightTextures[i]); - mLightTextureTokens[i+4] = CToken(mpLightMasks[i]); - } + mpLightMasks[0] = gResCache.GetResource("../resources/LightAmbientMask.txtr"); + mpLightMasks[1] = gResCache.GetResource("../resources/LightDirectionalMask.txtr"); + mpLightMasks[2] = gResCache.GetResource("../resources/LightCustomMask.txtr"); + mpLightMasks[3] = gResCache.GetResource("../resources/LightSpotMask.txtr"); } void CDrawUtil::Shutdown() @@ -585,9 +568,6 @@ void CDrawUtil::Shutdown() if (mDrawUtilInitialized) { Log::Write("Shutting down"); - mCubeToken = CToken(); - mSphereToken = CToken(); - mDoubleSidedSphereToken = CToken(); delete mpColorShader; delete mpColorShaderLighting; delete mpTextureShader; diff --git a/Core/CDrawUtil.h b/Core/CDrawUtil.h index 09d09131..5c7f4991 100644 --- a/Core/CDrawUtil.h +++ b/Core/CDrawUtil.h @@ -25,22 +25,18 @@ class CDrawUtil static CIndexBuffer mLineIndices; // Cube - static CModel *mpCubeModel; - static CToken mCubeToken; + static TResPtr mpCubeModel; // Wire Cube static CVertexBuffer mWireCubeVertices; static CIndexBuffer mWireCubeIndices; // Sphere - static CModel *mpSphereModel; - static CModel *mpDoubleSidedSphereModel; - static CToken mSphereToken; - static CToken mDoubleSidedSphereToken; + static TResPtr mpSphereModel; + static TResPtr mpDoubleSidedSphereModel; // Wire Sphere - static CModel *mpWireSphereModel; - static CToken mWireSphereToken; + static TResPtr mpWireSphereModel; // Shaders static CShader *mpColorShader; @@ -52,12 +48,10 @@ class CDrawUtil static CShader *mpTextShader; // Textures - static CTexture *mpCheckerTexture; - static CToken mCheckerTextureToken; + static TResPtr mpCheckerTexture; - static CTexture *mpLightTextures[4]; - static CTexture *mpLightMasks[4]; - static CToken mLightTextureTokens[8]; + static TResPtr mpLightTextures[4]; + static TResPtr mpLightMasks[4]; // Have all the above members been initialized? static bool mDrawUtilInitialized; diff --git a/Core/CSceneManager.cpp b/Core/CSceneManager.cpp index 2e3d4407..e9ed8a82 100644 --- a/Core/CSceneManager.cpp +++ b/Core/CSceneManager.cpp @@ -9,6 +9,7 @@ #include #include #include +#include /** * This class direly needs a rewrite @@ -97,7 +98,6 @@ void CSceneManager::SetActiveArea(CGameArea* _area) // Create nodes for new area mpArea = _area; - mAreaToken = CToken(mpArea); mpAreaRootNode = new CRootNode(this, mpSceneRootNode); if (mSplitTerrain) @@ -191,7 +191,6 @@ void CSceneManager::SetActiveArea(CGameArea* _area) void CSceneManager::SetActiveWorld(CWorld* _world) { mpWorld = _world; - mWorldToken = CToken(mpWorld); } void CSceneManager::ClearScene() @@ -209,9 +208,7 @@ void CSceneManager::ClearScene() mLightNodes.clear(); mpArea = nullptr; - mAreaToken.Unlock(); mpWorld = nullptr; - mWorldToken.Unlock(); mNodeCount = 0; } diff --git a/Core/CSceneManager.h b/Core/CSceneManager.h index 6b458bf5..15d173c8 100644 --- a/Core/CSceneManager.h +++ b/Core/CSceneManager.h @@ -32,10 +32,8 @@ class CSceneManager std::vector mLightNodes; CRootNode *mpSceneRootNode; - CGameArea *mpArea; - CWorld *mpWorld; - CToken mAreaToken; - CToken mWorldToken; + TResPtr mpArea; + TResPtr mpWorld; CRootNode *mpAreaRootNode; // Environment diff --git a/Core/CToken.cpp b/Core/CToken.cpp deleted file mode 100644 index 1302f88c..00000000 --- a/Core/CToken.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "CToken.h" - -CToken::CToken() -{ - mpRes = nullptr; - mLocked = false; -} - -CToken::CToken(CResource *pRes) -{ - mpRes = pRes; - mLocked = false; - Lock(); -} - -CToken::CToken(const CToken& Source) -{ - mLocked = false; - *this = Source; -} - -CToken::~CToken() -{ - Unlock(); -} - -void CToken::Lock() -{ - if (!mLocked) - { - if (mpRes) - { - mpRes->Lock(); - mLocked = true; - } - } -} - -void CToken::Unlock() -{ - if (mLocked) - { - mpRes->Release(); - mLocked = false; - } -} - -CToken& CToken::operator=(const CToken& Source) -{ - if (mLocked) Unlock(); - - mpRes = Source.mpRes; - Lock(); - return *this; -} diff --git a/Core/CToken.h b/Core/CToken.h deleted file mode 100644 index 5ea9ae40..00000000 --- a/Core/CToken.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef CTOKEN_H -#define CTOKEN_H - -#include - -class CToken -{ - CResource *mpRes; - bool mLocked; - -public: - CToken(); - CToken(CResource *pRes); - CToken(const CToken& Source); - ~CToken(); - void Lock(); - void Unlock(); - CToken& operator=(const CToken& Source); -}; - -#endif // CTOKEN_H diff --git a/Core/TResPtr.h b/Core/TResPtr.h new file mode 100644 index 00000000..d55198ec --- /dev/null +++ b/Core/TResPtr.h @@ -0,0 +1,91 @@ +#ifndef TRESPTR_H +#define TRESPTR_H + +#include + +template +class TResPtr +{ + ResType *mpRes; + +public: + TResPtr() + : mpRes(nullptr) {} + + TResPtr(void *pPtr) + : mpRes(nullptr) + { + *this = pPtr; + } + + TResPtr(const TResPtr& rkSource) + : mpRes(nullptr) + { + *this = rkSource; + } + + ~TResPtr() + { + if (mpRes) + mpRes->Release(); + } + + inline void Delete() + { + // use with caution! this function exists because not all resources are cached currently + delete mpRes; + mpRes = nullptr; + } + + inline ResType* RawPointer() const + { + return mpRes; + } + + inline operator ResType*() const + { + return mpRes; + } + + inline ResType& operator*() const + { + return *mpRes; + } + + inline ResType* operator->() const + { + return mpRes; + } + + TResPtr& operator=(void *pPtr) + { + // todo: this probably crashes if you try to pass a non-CResource-derived pointer. is there a safer way? + // dynamic cast may be slow, but it's the only way I can think of to do type-checking without making a + // zillion redundant static functions on every resource class + if (mpRes) + mpRes->Release(); + + CResource *pRes = (CResource*) pPtr; + mpRes = dynamic_cast((CResource*) pRes); + + if (mpRes) + mpRes->Lock(); + + return *this; + } + + TResPtr& operator=(const TResPtr& rkRight) + { + if (mpRes) + mpRes->Release(); + + mpRes = rkRight.mpRes; + + if (mpRes) + mpRes->Lock(); + + return *this; + } +}; + +#endif // TRESPTR_H diff --git a/PrimeWorldEditor.pro b/PrimeWorldEditor.pro index de7040bf..6d4c3e76 100644 --- a/PrimeWorldEditor.pro +++ b/PrimeWorldEditor.pro @@ -85,7 +85,6 @@ SOURCES += \ Common/CHashFNV1A.cpp \ UI/CModelEditorWindow.cpp \ Resource/CResource.cpp \ - Core/CToken.cpp \ Core/CRenderBucket.cpp \ Core/CDrawUtil.cpp \ UI/WTextureGLWidget.cpp \ @@ -245,7 +244,6 @@ HEADERS += \ Common/CHashFNV1A.h \ Core/ERenderOptions.h \ UI/CModelEditorWindow.h \ - Core/CToken.h \ Core/CRenderBucket.h \ Common/EMouseInputs.h \ Common/EKeyInputs.h \ @@ -332,7 +330,8 @@ HEADERS += \ Scene/script/CSpacePirateExtra.h \ Scene/script/CWaypointExtra.h \ Scene/script/CDoorExtra.h \ - Scene/script/CDamageableTriggerExtra.h + Scene/script/CDamageableTriggerExtra.h \ + Core/TResPtr.h FORMS += \ UI/CStartWindow.ui \ diff --git a/Resource/CAnimSet.h b/Resource/CAnimSet.h index 01831b30..cec0a902 100644 --- a/Resource/CAnimSet.h +++ b/Resource/CAnimSet.h @@ -2,7 +2,7 @@ #define CANIMSET_H #include -#include +#include #include #include "model/CModel.h" #include "CResource.h" @@ -15,10 +15,9 @@ class CAnimSet : public CResource struct SNode { TString name; - CModel *model; + TResPtr model; u32 skinID; u32 skelID; - CToken ModelToken; SNode() { model = nullptr; } }; diff --git a/Resource/CAnimationParameters.cpp b/Resource/CAnimationParameters.cpp index 5e7f24fd..9936ee52 100644 --- a/Resource/CAnimationParameters.cpp +++ b/Resource/CAnimationParameters.cpp @@ -32,7 +32,6 @@ CAnimationParameters::CAnimationParameters(CInputStream& SCLY, EGame game) mUnknown1 = SCLY.ReadLong(); mpCharSet = gResCache.GetResource(animSetID, "ANCS"); - mResToken = CToken(mpCharSet); } else if (game <= eCorruption) @@ -41,7 +40,6 @@ CAnimationParameters::CAnimationParameters(CInputStream& SCLY, EGame game) mUnknown1 = SCLY.ReadLong(); mpCharSet = gResCache.GetResource(charID, "CHAR"); - mResToken = CToken(mpCharSet); } else if (game == eReturns) @@ -62,7 +60,6 @@ CAnimationParameters::CAnimationParameters(CInputStream& SCLY, EGame game) mUnknown4 = SCLY.ReadLong(); mpCharSet = gResCache.GetResource(charID, "CHAR"); - mResToken = CToken(mpCharSet); } else if (mUnknown1 != 0x80) @@ -79,7 +76,7 @@ CModel* CAnimationParameters::GetCurrentModel(s32 nodeIndex) if (mpCharSet->Type() != eAnimSet) return nullptr; if (nodeIndex == -1) nodeIndex = mNodeIndex; - CAnimSet *pSet = static_cast(mpCharSet); + CAnimSet *pSet = static_cast(mpCharSet.RawPointer()); if (pSet->getNodeCount() <= (u32) nodeIndex) return nullptr; return pSet->getNodeModel(nodeIndex); } @@ -118,7 +115,6 @@ void CAnimationParameters::SetResource(CResource *pRes) if ((pRes->Type() == eAnimSet) || (pRes->Type() == eCharacter)) { mpCharSet = pRes; - mResToken = CToken(pRes); mNodeIndex = 0; } else diff --git a/Resource/CAnimationParameters.h b/Resource/CAnimationParameters.h index 764651e4..2182c6b8 100644 --- a/Resource/CAnimationParameters.h +++ b/Resource/CAnimationParameters.h @@ -3,14 +3,13 @@ #include "CResource.h" #include "model/CModel.h" -#include +#include #include "EFormatVersion.h" class CAnimationParameters { EGame mGame; - CResource *mpCharSet; - CToken mResToken; + TResPtr mpCharSet; u32 mNodeIndex; u32 mUnknown1; diff --git a/Resource/CCollisionMeshGroup.h b/Resource/CCollisionMeshGroup.h index f34687c5..4e294cfc 100644 --- a/Resource/CCollisionMeshGroup.h +++ b/Resource/CCollisionMeshGroup.h @@ -3,7 +3,7 @@ #include "CResource.h" #include "CCollisionMesh.h" -#include +#include #include class CCollisionMeshGroup : public CResource diff --git a/Resource/CFont.h b/Resource/CFont.h index d771a4fc..7a4b06b5 100644 --- a/Resource/CFont.h +++ b/Resource/CFont.h @@ -5,7 +5,7 @@ #include "CTexture.h" #include "model/CVertex.h" #include -#include +#include #include #include @@ -23,15 +23,14 @@ class CFont : public CResource 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(). - u32 mUnknown; // Value at offset 0x8. Not sure what this is. Including for experimentation purposes. - u32 mLineHeight; // Height of each line, in points - u32 mLineMargin; // Gap between lines, in points - this is added to the line height - u32 mVerticalOffset; // In points. This is used to reposition glyphs after the per-glyph vertical offset is applied - u32 mDefaultSize; // In points. - TString mFontName; // Self-explanatory - CTexture *mpFontTexture; // The texture used by this font - CToken mTextureToken; // Token for the font - u32 mTextureFormat; // Indicates which layers on the texture are for what - multiple glyph layers or fill/stroke + u32 mUnknown; // Value at offset 0x8. Not sure what this is. Including for experimentation purposes. + u32 mLineHeight; // Height of each line, in points + u32 mLineMargin; // Gap between lines, in points - this is added to the line height + u32 mVerticalOffset; // In points. This is used to reposition glyphs after the per-glyph vertical offset is applied + u32 mDefaultSize; // In points. + TString mFontName; // Self-explanatory + TResPtr mpFontTexture; // The texture used by this font + u32 mTextureFormat; // Indicates which layers on the texture are for what - multiple glyph layers or fill/stroke struct SGlyph { diff --git a/Resource/CGameArea.cpp b/Resource/CGameArea.cpp index 77837c1f..6a70d60f 100644 --- a/Resource/CGameArea.cpp +++ b/Resource/CGameArea.cpp @@ -1,4 +1,5 @@ #include "CGameArea.h" +#include "script/CScriptLayer.h" #include CGameArea::CGameArea() : CResource() diff --git a/Resource/CGameArea.h b/Resource/CGameArea.h index 0c4d06c5..7d9f158a 100644 --- a/Resource/CGameArea.h +++ b/Resource/CGameArea.h @@ -7,11 +7,13 @@ #include "model/CModel.h" #include "model/CStaticModel.h" #include "CResource.h" -#include "script/CScriptLayer.h" #include #include #include +class CScriptLayer; +class CScriptObject; + class CGameArea : public CResource { friend class CAreaLoader; diff --git a/Resource/CMaterial.cpp b/Resource/CMaterial.cpp index a1ce1415..2ff19abb 100644 --- a/Resource/CMaterial.cpp +++ b/Resource/CMaterial.cpp @@ -70,7 +70,6 @@ CMaterial* CMaterial::Clone() pOut->mEchoesUnknownA = mEchoesUnknownA; pOut->mEchoesUnknownB = mEchoesUnknownB; pOut->mpIndirectTexture = mpIndirectTexture; - pOut->mIndTextureToken = CToken(pOut->mpIndirectTexture); pOut->mPasses.resize(mPasses.size()); for (u32 iPass = 0; iPass < mPasses.size(); iPass++) diff --git a/Resource/CMaterial.h b/Resource/CMaterial.h index 059bb18c..3a7040ec 100644 --- a/Resource/CMaterial.h +++ b/Resource/CMaterial.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include @@ -58,16 +58,15 @@ private: bool mEnableBloom; // Bool that toggles bloom on or off. On by default on MP3 materials, off by default on MP1 materials. EGame mVersion; - EMaterialOptions mOptions; // See the EMaterialOptions enum above - EVertexDescription mVtxDesc; // Descriptor of vertex attributes used by this material - CColor mKonstColors[4]; // Konst color values for TEV - GLenum mBlendSrcFac; // Source blend factor - GLenum mBlendDstFac; // Dest blend factor - bool mLightingEnabled; // Color channel control flags; indicate whether lighting is enabled - u32 mEchoesUnknownA; // First unknown value introduced in Echoes. Included for cooking. - u32 mEchoesUnknownB; // Second unknown value introduced in Echoes. Included for cooking. - CTexture *mpIndirectTexture; // Optional texture used for the indirect stage for reflections - CToken mIndTextureToken; // Token for indirect texture + EMaterialOptions mOptions; // See the EMaterialOptions enum above + EVertexDescription mVtxDesc; // Descriptor of vertex attributes used by this material + CColor mKonstColors[4]; // Konst color values for TEV + GLenum mBlendSrcFac; // Source blend factor + GLenum mBlendDstFac; // Dest blend factor + bool mLightingEnabled; // Color channel control flags; indicate whether lighting is enabled + u32 mEchoesUnknownA; // First unknown value introduced in Echoes. Included for cooking. + u32 mEchoesUnknownB; // Second unknown value introduced in Echoes. Included for cooking. + TResPtr mpIndirectTexture; // Optional texture used for the indirect stage for reflections std::vector mPasses; diff --git a/Resource/CMaterialPass.cpp b/Resource/CMaterialPass.cpp index 4492b307..4e7e0d52 100644 --- a/Resource/CMaterialPass.cpp +++ b/Resource/CMaterialPass.cpp @@ -47,7 +47,6 @@ CMaterialPass* CMaterialPass::Clone(CMaterial *pParent) pOut->mRasSel = mRasSel; pOut->mTexCoordSource = mTexCoordSource; pOut->mpTexture = mpTexture; - pOut->mTexToken = CToken(pOut->mpTexture); pOut->mAnimMode = mAnimMode; for (u32 iParam = 0; iParam < 4; iParam++) pOut->mAnimParams[iParam] = mAnimParams[iParam]; @@ -280,7 +279,6 @@ void CMaterialPass::SetTexCoordSource(u32 Source) void CMaterialPass::SetTexture(CTexture *pTex) { mpTexture = pTex; - mTexToken = CToken(pTex); } void CMaterialPass::SetAnimMode(EUVAnimMode Mode) diff --git a/Resource/CMaterialPass.h b/Resource/CMaterialPass.h index 01b6c5b4..72050e5d 100644 --- a/Resource/CMaterialPass.h +++ b/Resource/CMaterialPass.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include "ETevEnums.h" @@ -36,8 +36,7 @@ private: ETevKSel mKAlphaSel; ETevRasSel mRasSel; u32 mTexCoordSource; // Should maybe be an enum but worried about conflicts with EVertexDescriptionn - CTexture *mpTexture; - CToken mTexToken; + TResPtr mpTexture; EUVAnimMode mAnimMode; float mAnimParams[4]; bool mEnabled; diff --git a/Resource/CScan.h b/Resource/CScan.h index 99c676e2..1380ab4c 100644 --- a/Resource/CScan.h +++ b/Resource/CScan.h @@ -4,7 +4,7 @@ #include "CResource.h" #include "CStringTable.h" #include "EFormatVersion.h" -#include +#include class CScan : public CResource { @@ -23,10 +23,8 @@ public: private: EGame mVersion; - CResource *mpFrame; - CStringTable *mpStringTable; - CToken mFrameToken; - CToken mStringToken; + TResPtr mpFrame; + TResPtr mpStringTable; bool mIsSlow; bool mIsImportant; ELogbookCategory mCategory; diff --git a/Resource/CWorld.cpp b/Resource/CWorld.cpp index 4d2f3d8d..74723c52 100644 --- a/Resource/CWorld.cpp +++ b/Resource/CWorld.cpp @@ -1,4 +1,5 @@ #include "CWorld.h" +#include "script/CScriptLayer.h" #include CWorld::CWorld() : CResource() diff --git a/Resource/CWorld.h b/Resource/CWorld.h index 15f22691..2ad78e84 100644 --- a/Resource/CWorld.h +++ b/Resource/CWorld.h @@ -14,12 +14,11 @@ class CWorld : public CResource // Instances of CResource pointers are placeholders for unimplemented resource types (eg CMapWorld) EGame mWorldVersion; - CStringTable *mpWorldName; - CStringTable *mpDarkWorldName; - CResource *mpSaveWorld; - CModel *mpDefaultSkybox; - CResource *mpMapWorld; - CToken mResTokens[5]; + TResPtr mpWorldName; + TResPtr mpDarkWorldName; + TResPtr mpSaveWorld; + TResPtr mpDefaultSkybox; + TResPtr mpMapWorld; u32 mUnknown1; u32 mUnknownAreas; @@ -44,12 +43,11 @@ class CWorld : public CResource struct SArea { TString InternalName; - CStringTable *pAreaName; + TResPtr pAreaName; CTransform4f Transform; CAABox AetherBox; u64 FileID; // Loading every single area as a CResource would be a very bad idea u64 AreaID; - CToken AreaNameToken; std::vector AttachedAreaIDs; std::vector Dependencies; diff --git a/Resource/cooker/CModelCooker.h b/Resource/cooker/CModelCooker.h index 1626d4f1..b4ea3775 100644 --- a/Resource/cooker/CModelCooker.h +++ b/Resource/cooker/CModelCooker.h @@ -7,7 +7,7 @@ class CModelCooker { - CModel *mpModel; + TResPtr mpModel; EGame mVersion; u32 mNumMatSets; u32 mNumSurfaces; diff --git a/Resource/cooker/CTextureEncoder.h b/Resource/cooker/CTextureEncoder.h index c738da1d..899eaf8b 100644 --- a/Resource/cooker/CTextureEncoder.h +++ b/Resource/cooker/CTextureEncoder.h @@ -2,13 +2,13 @@ #define CTEXTUREENCODER_H #include "../CTexture.h" +#include // Class contains basic functionality right now - only supports directly converting DXT1 to CMPR // More advanced functions (including actual encoding!) coming later class CTextureEncoder { - - CTexture *mpTexture; + TResPtr mpTexture; ETexelFormat mSourceFormat; ETexelFormat mOutputFormat; diff --git a/Resource/factory/CAnimSetLoader.cpp b/Resource/factory/CAnimSetLoader.cpp index 993e6880..0aacc9e1 100644 --- a/Resource/factory/CAnimSetLoader.cpp +++ b/Resource/factory/CAnimSetLoader.cpp @@ -14,8 +14,7 @@ CAnimSet* CAnimSetLoader::LoadCorruptionCHAR(CInputStream& CHAR) CAnimSet::SNode& node = set->nodes[0]; node.name = CHAR.ReadString(); - node.model = (CModel*) gResCache.GetResource(CHAR.ReadLongLong(), "CMDL"); - node.ModelToken = CToken(node.model); + node.model = gResCache.GetResource(CHAR.ReadLongLong(), "CMDL"); return set; } @@ -29,8 +28,7 @@ CAnimSet* CAnimSetLoader::LoadReturnsCHAR(CInputStream& CHAR) node.name = CHAR.ReadString(); CHAR.Seek(0x14, SEEK_CUR); CHAR.ReadString(); - node.model = (CModel*) gResCache.GetResource(CHAR.ReadLongLong(), "CMDL"); - node.ModelToken = CToken(node.model); + node.model = gResCache.GetResource(CHAR.ReadLongLong(), "CMDL"); return set; } @@ -100,10 +98,9 @@ CAnimSet* CAnimSetLoader::LoadANCS(CInputStream& ANCS) u16 unknown1 = ANCS.ReadShort(); if (n == 0) loader.mVersion = (unknown1 == 0xA) ? eEchoes : ePrime; // Best version indicator we know of unfortunately node->name = ANCS.ReadString(); - node->model = (CModel*) gResCache.GetResource(ANCS.ReadLong(), "CMDL"); + node->model = gResCache.GetResource(ANCS.ReadLong(), "CMDL"); node->skinID = ANCS.ReadLong(); node->skelID = ANCS.ReadLong(); - node->ModelToken = CToken(node->model); // Unfortunately that's all that's actually supported at the moment. Hope to expand later. // Since there's no size value I have to actually read the rest of the node to reach the next one diff --git a/Resource/factory/CAnimSetLoader.h b/Resource/factory/CAnimSetLoader.h index fa6938ea..4dd1f420 100644 --- a/Resource/factory/CAnimSetLoader.h +++ b/Resource/factory/CAnimSetLoader.h @@ -7,7 +7,7 @@ class CAnimSetLoader { - CAnimSet *set; + TResPtr set; CResCache *mpResCache; EGame mVersion; diff --git a/Resource/factory/CAreaLoader.cpp b/Resource/factory/CAreaLoader.cpp index 091d3b21..005f5936 100644 --- a/Resource/factory/CAreaLoader.cpp +++ b/Resource/factory/CAreaLoader.cpp @@ -593,7 +593,7 @@ CGameArea* CAreaLoader::LoadMREA(CInputStream& MREA) break; default: Log::FileError(MREA.GetSourceString(), "Unsupported MREA version: " + TString::HexString(version)); - delete Loader.mpArea; + Loader.mpArea.Delete(); return nullptr; } diff --git a/Resource/factory/CAreaLoader.h b/Resource/factory/CAreaLoader.h index 64760472..4f7e243a 100644 --- a/Resource/factory/CAreaLoader.h +++ b/Resource/factory/CAreaLoader.h @@ -6,13 +6,14 @@ #include "../EFormatVersion.h" #include "CBlockMgrIn.h" #include +#include class CAreaLoader { struct SCompressedCluster; // Area data - CGameArea *mpArea; + TResPtr mpArea; CInputStream *mpMREA; CBlockMgrIn *mBlockMgr; EGame mVersion; diff --git a/Resource/factory/CCollisionLoader.cpp b/Resource/factory/CCollisionLoader.cpp index fc02684d..cacf5708 100644 --- a/Resource/factory/CCollisionLoader.cpp +++ b/Resource/factory/CCollisionLoader.cpp @@ -178,7 +178,7 @@ CCollisionMeshGroup* CCollisionLoader::LoadDCLN(CInputStream &DCLN) if (deafbabe != 0xDEAFBABE) { Log::FileError(DCLN.GetSourceString(), DCLN.Tell() - 4, "Invalid collision magic: " + TString::HexString(deafbabe)); - delete loader.mpGroup; + loader.mpGroup.Delete(); return nullptr; } diff --git a/Resource/factory/CCollisionLoader.h b/Resource/factory/CCollisionLoader.h index 9225040e..b40214dc 100644 --- a/Resource/factory/CCollisionLoader.h +++ b/Resource/factory/CCollisionLoader.h @@ -7,7 +7,7 @@ class CCollisionLoader { - CCollisionMeshGroup *mpGroup; + TResPtr mpGroup; CCollisionMesh *mpMesh; EGame mVersion; std::vector mProperties; diff --git a/Resource/factory/CFontLoader.cpp b/Resource/factory/CFontLoader.cpp index bed27118..9ba11179 100644 --- a/Resource/factory/CFontLoader.cpp +++ b/Resource/factory/CFontLoader.cpp @@ -18,9 +18,8 @@ CFont* CFontLoader::LoadFont(CInputStream& FONT) mpFont->mDefaultSize = FONT.ReadLong(); mpFont->mFontName = FONT.ReadString(); - if (mVersion <= eEchoes) mpFont->mpFontTexture = (CTexture*) gResCache.GetResource(FONT.ReadLong(), "TXTR"); - else mpFont->mpFontTexture = (CTexture*) gResCache.GetResource(FONT.ReadLongLong(), "TXTR"); - mpFont->mTextureToken = CToken(mpFont->mpFontTexture); + if (mVersion <= eEchoes) mpFont->mpFontTexture = gResCache.GetResource(FONT.ReadLong(), "TXTR"); + else mpFont->mpFontTexture = gResCache.GetResource(FONT.ReadLongLong(), "TXTR"); mpFont->mTextureFormat = FONT.ReadLong(); u32 NumGlyphs = FONT.ReadLong(); diff --git a/Resource/factory/CFontLoader.h b/Resource/factory/CFontLoader.h index 57e92bfb..2ebab42d 100644 --- a/Resource/factory/CFontLoader.h +++ b/Resource/factory/CFontLoader.h @@ -7,7 +7,7 @@ class CFontLoader { - CFont *mpFont; + TResPtr mpFont; EGame mVersion; CFontLoader(); diff --git a/Resource/factory/CMaterialLoader.cpp b/Resource/factory/CMaterialLoader.cpp index df16153a..45914ef9 100644 --- a/Resource/factory/CMaterialLoader.cpp +++ b/Resource/factory/CMaterialLoader.cpp @@ -24,7 +24,7 @@ void CMaterialLoader::ReadPrimeMatSet() for (u32 iTex = 0; iTex < numTextures; iTex++) { u32 TextureID = mpFile->ReadLong(); - mTextures[iTex] = (CTexture*) gResCache.GetResource(TextureID, "TXTR"); + mTextures[iTex] = gResCache.GetResource(TextureID, "TXTR"); } // Materials @@ -137,14 +137,9 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial() u8 TexSel = mpFile->ReadByte(); if ((TexSel == 0xFF) || (TexSel >= mTextures.size())) - { pPass->mpTexture = nullptr; - } else - { pPass->mpTexture = mTextures[TextureIndices[TexSel]]; - pPass->mTexToken = CToken(pPass->mpTexture); - } TevCoordIndices[iTev] = mpFile->ReadByte(); } @@ -344,9 +339,7 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial() continue; } - CTexture *pTex = (CTexture*) gResCache.GetResource(TextureID, "TXTR"); - pPass->mpTexture = pTex; - pPass->mTexToken = CToken(pTex); + pPass->mpTexture = gResCache.GetResource(TextureID, "TXTR"); pPass->mTexCoordSource = 4 + (u8) mpFile->ReadLong(); u32 AnimSize = mpFile->ReadLong(); diff --git a/Resource/factory/CMaterialLoader.h b/Resource/factory/CMaterialLoader.h index 862c9d80..64700279 100644 --- a/Resource/factory/CMaterialLoader.h +++ b/Resource/factory/CMaterialLoader.h @@ -14,7 +14,7 @@ class CMaterialLoader CMaterialSet *mpSet; CInputStream *mpFile; EGame mVersion; - std::vector mTextures; + std::vector> mTextures; bool mHasOPAC; bool mHas0x400; diff --git a/Resource/factory/CModelLoader.h b/Resource/factory/CModelLoader.h index 08b9775e..ee02240d 100644 --- a/Resource/factory/CModelLoader.h +++ b/Resource/factory/CModelLoader.h @@ -23,7 +23,7 @@ public: }; private: - CModel *mpModel; + TResPtr mpModel; std::vector mMaterials; CBlockMgrIn *mpBlockMgr; CAABox mAABox; diff --git a/Resource/factory/CScanLoader.cpp b/Resource/factory/CScanLoader.cpp index 9f56e16b..42c31b5d 100644 --- a/Resource/factory/CScanLoader.cpp +++ b/Resource/factory/CScanLoader.cpp @@ -10,8 +10,7 @@ CScan* CScanLoader::LoadScanMP1(CInputStream &SCAN) { // Basic support at the moment - don't read animation/scan image data SCAN.Seek(0x4, SEEK_CUR); // Skip FRME ID - mpScan->mpStringTable = (CStringTable*) gResCache.GetResource(SCAN.ReadLong(), "STRG"); - mpScan->mStringToken = CToken(mpScan->mpStringTable); + mpScan->mpStringTable = gResCache.GetResource(SCAN.ReadLong(), "STRG"); mpScan->mIsSlow = (SCAN.ReadLong() != 0); mpScan->mCategory = (CScan::ELogbookCategory) SCAN.ReadLong(); mpScan->mIsImportant = (SCAN.ReadByte() == 1); @@ -85,8 +84,7 @@ void CScanLoader::LoadParamsMP2(CInputStream& SCAN) switch (PropertyID) { case 0x2F5B6423: - mpScan->mpStringTable = (CStringTable*) gResCache.GetResource(SCAN.ReadLong(), "STRG"); - mpScan->mStringToken = CToken(mpScan->mpStringTable); + mpScan->mpStringTable = gResCache.GetResource(SCAN.ReadLong(), "STRG"); break; case 0xC308A322: @@ -119,8 +117,7 @@ void CScanLoader::LoadParamsMP3(CInputStream& SCAN) switch (PropertyID) { case 0x2F5B6423: - mpScan->mpStringTable = (CStringTable*) gResCache.GetResource(SCAN.ReadLongLong(), "STRG"); - mpScan->mStringToken = CToken(mpScan->mpStringTable); + mpScan->mpStringTable = gResCache.GetResource(SCAN.ReadLongLong(), "STRG"); break; case 0xC308A322: diff --git a/Resource/factory/CScanLoader.h b/Resource/factory/CScanLoader.h index 9b88e6a3..d62ec8ac 100644 --- a/Resource/factory/CScanLoader.h +++ b/Resource/factory/CScanLoader.h @@ -6,7 +6,7 @@ class CScanLoader { - CScan *mpScan; + TResPtr mpScan; EGame mVersion; CScanLoader(); diff --git a/Resource/factory/CStringLoader.h b/Resource/factory/CStringLoader.h index ae1f6e46..9edc7546 100644 --- a/Resource/factory/CStringLoader.h +++ b/Resource/factory/CStringLoader.h @@ -4,10 +4,11 @@ #include "../CStringTable.h" #include "../EFormatVersion.h" #include +#include class CStringLoader { - CStringTable* mpStringTable; + TResPtr mpStringTable; EGame mVersion; CStringLoader(); diff --git a/Resource/factory/CWorldLoader.cpp b/Resource/factory/CWorldLoader.cpp index 5c819167..39191976 100644 --- a/Resource/factory/CWorldLoader.cpp +++ b/Resource/factory/CWorldLoader.cpp @@ -17,19 +17,19 @@ void CWorldLoader::LoadPrimeMLVL(CInputStream& MLVL) // Header if (mVersion < eCorruptionProto) { - mpWorld->mpWorldName = (CStringTable*) gResCache.GetResource(MLVL.ReadLong(), "STRG"); - if (mVersion == eEchoes) mpWorld->mpDarkWorldName = (CStringTable*) gResCache.GetResource(MLVL.ReadLong(), "STRG"); + mpWorld->mpWorldName = gResCache.GetResource(MLVL.ReadLong(), "STRG"); + if (mVersion == eEchoes) mpWorld->mpDarkWorldName = gResCache.GetResource(MLVL.ReadLong(), "STRG"); if (mVersion > ePrime) mpWorld->mUnknown1 = MLVL.ReadLong(); if (mVersion >= ePrime) mpWorld->mpSaveWorld = gResCache.GetResource(MLVL.ReadLong(), "SAVW"); - mpWorld->mpDefaultSkybox = (CModel*) gResCache.GetResource(MLVL.ReadLong(), "CMDL"); + mpWorld->mpDefaultSkybox = gResCache.GetResource(MLVL.ReadLong(), "CMDL"); } else { - mpWorld->mpWorldName = (CStringTable*) gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); + mpWorld->mpWorldName = gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); MLVL.Seek(0x4, SEEK_CUR); // Skipping unknown value mpWorld->mpSaveWorld = gResCache.GetResource(MLVL.ReadLongLong(), "SAVW"); - mpWorld->mpDefaultSkybox = (CModel*) gResCache.GetResource(MLVL.ReadLongLong(), "CMDL"); + mpWorld->mpDefaultSkybox = gResCache.GetResource(MLVL.ReadLongLong(), "CMDL"); } // Memory relays - only in MP1 @@ -60,11 +60,10 @@ void CWorldLoader::LoadPrimeMLVL(CInputStream& MLVL) CWorld::SArea *pArea = &mpWorld->mAreas[iArea]; if (mVersion < eCorruptionProto) - pArea->pAreaName = (CStringTable*) gResCache.GetResource(MLVL.ReadLong(), "STRG"); + pArea->pAreaName = gResCache.GetResource(MLVL.ReadLong(), "STRG"); else - pArea->pAreaName = (CStringTable*) gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); + pArea->pAreaName = gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); - pArea->AreaNameToken = CToken(pArea->pAreaName); pArea->Transform = CTransform4f(MLVL); pArea->AetherBox = CAABox(MLVL); @@ -217,16 +216,11 @@ void CWorldLoader::LoadPrimeMLVL(CInputStream& MLVL) // Last part of the file is layer name offsets, but we don't need it // todo: Layer ID support for MP3 - mpWorld->mResTokens[0] = CToken(mpWorld->mpWorldName); - mpWorld->mResTokens[1] = CToken(mpWorld->mpDarkWorldName); - mpWorld->mResTokens[2] = CToken(mpWorld->mpSaveWorld); - mpWorld->mResTokens[3] = CToken(mpWorld->mpDefaultSkybox); - mpWorld->mResTokens[4] = CToken(mpWorld->mpMapWorld); } void CWorldLoader::LoadReturnsMLVL(CInputStream& MLVL) { - mpWorld->mpWorldName = (CStringTable*) gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); + mpWorld->mpWorldName = gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); bool Check = (MLVL.ReadByte() != 0); if (Check) @@ -236,7 +230,7 @@ void CWorldLoader::LoadReturnsMLVL(CInputStream& MLVL) } mpWorld->mpSaveWorld = gResCache.GetResource(MLVL.ReadLongLong(), "SAVW"); - mpWorld->mpDefaultSkybox = (CModel*) gResCache.GetResource(MLVL.ReadLongLong(), "CMDL"); + mpWorld->mpDefaultSkybox = gResCache.GetResource(MLVL.ReadLongLong(), "CMDL"); // Areas u32 NumAreas = MLVL.ReadLong(); @@ -247,12 +241,11 @@ void CWorldLoader::LoadReturnsMLVL(CInputStream& MLVL) // Area header CWorld::SArea *pArea = &mpWorld->mAreas[iArea]; - pArea->pAreaName = (CStringTable*) gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); + pArea->pAreaName = gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); pArea->Transform = CTransform4f(MLVL); pArea->AetherBox = CAABox(MLVL); pArea->FileID = MLVL.ReadLongLong(); pArea->AreaID = MLVL.ReadLongLong(); - pArea->AreaNameToken = CToken(pArea->pAreaName); MLVL.Seek(0x4, SEEK_CUR); pArea->InternalName = MLVL.ReadString(); @@ -285,11 +278,6 @@ void CWorldLoader::LoadReturnsMLVL(CInputStream& MLVL) // Last part of the file is layer name offsets, but we don't need it // todo: Layer ID support - mpWorld->mResTokens[0] = CToken(mpWorld->mpWorldName); - mpWorld->mResTokens[1] = CToken(mpWorld->mpDarkWorldName); - mpWorld->mResTokens[2] = CToken(mpWorld->mpSaveWorld); - mpWorld->mResTokens[3] = CToken(mpWorld->mpDefaultSkybox); - mpWorld->mResTokens[4] = CToken(mpWorld->mpMapWorld); } CWorld* CWorldLoader::LoadMLVL(CInputStream& MLVL) diff --git a/Resource/factory/CWorldLoader.h b/Resource/factory/CWorldLoader.h index 18304d40..96090682 100644 --- a/Resource/factory/CWorldLoader.h +++ b/Resource/factory/CWorldLoader.h @@ -8,7 +8,7 @@ class CWorldLoader { - CWorld *mpWorld; + TResPtr mpWorld; EGame mVersion; CWorldLoader(); diff --git a/Resource/script/CProperty.h b/Resource/script/CProperty.h index 17aadc90..49f15b6c 100644 --- a/Resource/script/CProperty.h +++ b/Resource/script/CProperty.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include class CScriptTemplate; @@ -65,48 +65,11 @@ typedef __CProperty CFloatProperty; typedef __CProperty CStringProperty; typedef __CProperty CVector3Property; typedef __CProperty CColorProperty; -typedef __CProperty CFileProperty; +typedef __CProperty, eFileProperty> CFileProperty; typedef __CProperty CAnimParamsProperty; typedef __CProperty, eArrayProperty> CArrayProperty; typedef __CProperty, eUnknownProperty> CUnknownProperty; -/* - * Template specialization for CFileProperty to allow a token for resources - */ -template <> -class __CProperty : public CPropertyBase -{ - CResource *mValue; - CToken mToken; - -public: - __CProperty() { - mValue = nullptr; - } - - __CProperty(CResource* v) { - mValue = v; - mToken = CToken(v); - } - - ~__CProperty() {} - - inline EPropertyType Type() { return eFileProperty; } - inline CResource* Get() { return mValue; } - inline void Set(CResource *v) - { - if (mValue != v) - { - mValue = v; - mToken = CToken(v); - } - } - const TStringList& AllowedExtensions() - { - return static_cast(Template())->Extensions(); - } -}; - /* * CPropertyStruct is for defining structs of properties. */ diff --git a/Resource/script/CScriptObject.cpp b/Resource/script/CScriptObject.cpp index 0f701f7a..afdd9592 100644 --- a/Resource/script/CScriptObject.cpp +++ b/Resource/script/CScriptObject.cpp @@ -47,19 +47,16 @@ void CScriptObject::EvaluateProperties() void CScriptObject::EvaluateDisplayModel() { mpDisplayModel = mpTemplate->FindDisplayModel(mpProperties); - mModelToken = CToken(mpDisplayModel); } void CScriptObject::EvaluateBillboard() { mpBillboard = mpTemplate->FindBillboardTexture(mpProperties); - mBillboardToken = CToken(mpBillboard); } void CScriptObject::EvaluateCollisionModel() { mpCollision = mpTemplate->FindCollision(mpProperties); - mCollisionToken = CToken(mpCollision); } // ************ GETTERS ************ diff --git a/Resource/script/CScriptObject.h b/Resource/script/CScriptObject.h index 3fe4264f..17b53adf 100644 --- a/Resource/script/CScriptObject.h +++ b/Resource/script/CScriptObject.h @@ -7,8 +7,8 @@ #include "CScriptTemplate.h" #include "../model/CModel.h" #include "../CCollisionMeshGroup.h" +#include "../CGameArea.h" -class CGameArea; class CScriptLayer; class CScriptObject @@ -17,7 +17,7 @@ class CScriptObject friend class CAreaLoader; CScriptTemplate *mpTemplate; - CGameArea *mpArea; + TResPtr mpArea; CScriptLayer *mpLayer; u32 mInstanceID; @@ -31,12 +31,9 @@ class CScriptObject CVector3Property *mpScale; CBoolProperty *mpActive; CPropertyStruct *mpLightParameters; - CModel *mpDisplayModel; - CTexture *mpBillboard; - CCollisionMeshGroup *mpCollision; - CToken mModelToken; - CToken mBillboardToken; - CToken mCollisionToken; + TResPtr mpDisplayModel; + TResPtr mpBillboard; + TResPtr mpCollision; bool mHasInGameModel; EVolumeShape mVolumeShape; diff --git a/Scene/CCollisionNode.cpp b/Scene/CCollisionNode.cpp index 0065a1cf..cf20044e 100644 --- a/Scene/CCollisionNode.cpp +++ b/Scene/CCollisionNode.cpp @@ -54,5 +54,4 @@ SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*Ray*/, u32 / void CCollisionNode::SetCollision(CCollisionMeshGroup *pCollision) { mpCollision = pCollision; - mCollisionToken = CToken(pCollision); } diff --git a/Scene/CCollisionNode.h b/Scene/CCollisionNode.h index de781bec..0e1aa2d5 100644 --- a/Scene/CCollisionNode.h +++ b/Scene/CCollisionNode.h @@ -6,8 +6,7 @@ class CCollisionNode : public CSceneNode { - CCollisionMeshGroup *mpCollision; - CToken mCollisionToken; + TResPtr mpCollision; public: CCollisionNode(CSceneManager *pScene, CSceneNode *pParent = 0, CCollisionMeshGroup *pCollision = 0); diff --git a/Scene/CModelNode.cpp b/Scene/CModelNode.cpp index 64c2aca4..f13017b5 100644 --- a/Scene/CModelNode.cpp +++ b/Scene/CModelNode.cpp @@ -105,7 +105,6 @@ SRayIntersection CModelNode::RayNodeIntersectTest(const CRay &Ray, u32 AssetID, void CModelNode::SetModel(CModel *pModel) { mpModel = pModel; - mModelToken = CToken(pModel); mActiveMatSet = 0; if (pModel) diff --git a/Scene/CModelNode.h b/Scene/CModelNode.h index 2989e277..07075461 100644 --- a/Scene/CModelNode.h +++ b/Scene/CModelNode.h @@ -6,8 +6,7 @@ class CModelNode : public CSceneNode { - CModel *mpModel; - CToken mModelToken; + TResPtr mpModel; u32 mActiveMatSet; bool mLightingEnabled; bool mForceAlphaOn; diff --git a/Scene/CScriptNode.cpp b/Scene/CScriptNode.cpp index 7e902660..ee23ccf5 100644 --- a/Scene/CScriptNode.cpp +++ b/Scene/CScriptNode.cpp @@ -9,6 +9,7 @@ #include #include #include +#include CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObject *pObject) : CSceneNode(pScene, pParent) @@ -37,11 +38,7 @@ CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObje // Determine display assets mpActiveModel = mpInstance->GetDisplayModel(); - mModelToken = CToken(mpActiveModel); - mpBillboard = mpInstance->GetBillboard(); - mBillboardToken = CToken(mpBillboard); - mpCollisionNode->SetCollision(mpInstance->GetCollision()); // Create preview volume node @@ -51,19 +48,19 @@ CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObje if (mHasVolumePreview) { EVolumeShape shape = mpInstance->VolumeShape(); - CModel *pVolumeModel = nullptr; + TResPtr pVolumeModel = nullptr; if ((shape == eAxisAlignedBoxShape) || (shape == eBoxShape)) - pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeBox.cmdl"); + pVolumeModel = gResCache.GetResource("../resources/VolumeBox.cmdl"); else if (shape == eEllipsoidShape) - pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeSphere.cmdl"); + pVolumeModel = gResCache.GetResource("../resources/VolumeSphere.cmdl"); else if (shape == eCylinderShape) - pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeCylinder.cmdl"); + pVolumeModel = gResCache.GetResource("../resources/VolumeCylinder.cmdl"); else if (shape == eCylinderLargeShape) - pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeCylinderLarge.cmdl"); + pVolumeModel = gResCache.GetResource("../resources/VolumeCylinderLarge.cmdl"); if (pVolumeModel) { diff --git a/Scene/CScriptNode.h b/Scene/CScriptNode.h index a0ef1ac9..739e8654 100644 --- a/Scene/CScriptNode.h +++ b/Scene/CScriptNode.h @@ -12,10 +12,8 @@ class CScriptNode : public CSceneNode CScriptObject *mpInstance; class CScriptExtra *mpExtra; - CModel *mpActiveModel; - CTexture *mpBillboard; - CToken mModelToken; - CToken mBillboardToken; + TResPtr mpActiveModel; + TResPtr mpBillboard; CCollisionNode *mpCollisionNode; bool mHasValidPosition; diff --git a/Scene/script/CDamageableTriggerExtra.cpp b/Scene/script/CDamageableTriggerExtra.cpp index 031c895a..fe8e502d 100644 --- a/Scene/script/CDamageableTriggerExtra.cpp +++ b/Scene/script/CDamageableTriggerExtra.cpp @@ -167,13 +167,12 @@ void CDamageableTriggerExtra::PropertyModified(CPropertyBase *pProperty) { if (pProperty == mpTextureProps[iTex]) { - mpTextures[iTex] = (CTexture*) mpTextureProps[iTex]->Get(); + mpTextures[iTex] = mpTextureProps[iTex]->Get(); if (mpTextures[iTex] && mpTextures[iTex]->Type() != eTexture) mpTextures[iTex] = nullptr; mpMat->Pass(iTex)->SetTexture(mpTextures[iTex]); - mTextureTokens[iTex] = CToken(mpTextures[iTex]); break; } } diff --git a/Scene/script/CDamageableTriggerExtra.h b/Scene/script/CDamageableTriggerExtra.h index e1fcfb96..4a3c402b 100644 --- a/Scene/script/CDamageableTriggerExtra.h +++ b/Scene/script/CDamageableTriggerExtra.h @@ -23,8 +23,7 @@ class CDamageableTriggerExtra : public CScriptExtra CVector3f mPlaneSize; ERenderSide mRenderSide; - CTexture *mpTextures[3]; - CToken mTextureTokens[3]; + TResPtr mpTextures[3]; CMaterial *mpMat; CVector2f mCoordScale; diff --git a/Scene/script/CDoorExtra.cpp b/Scene/script/CDoorExtra.cpp index 3b74b2eb..acb7e5a7 100644 --- a/Scene/script/CDoorExtra.cpp +++ b/Scene/script/CDoorExtra.cpp @@ -25,20 +25,13 @@ void CDoorExtra::PropertyModified(CPropertyBase *pProperty) { if (pProperty == mpShieldModelProp) { - mpShieldModel = (CModel*) mpShieldModelProp->Get(); + mpShieldModel = mpShieldModelProp->Get(); - if (mpShieldModel && mpShieldModel->Type() == eModel) - { - mModelToken = CToken(mpShieldModel); + if (mpShieldModel) mLocalAABox = mpShieldModel->AABox(); - } else - { - mpShieldModel = nullptr; - mModelToken.Unlock(); mLocalAABox = CAABox::skInfinite; - } MarkTransformChanged(); } diff --git a/Scene/script/CDoorExtra.h b/Scene/script/CDoorExtra.h index 8b0e48f7..61c87565 100644 --- a/Scene/script/CDoorExtra.h +++ b/Scene/script/CDoorExtra.h @@ -8,9 +8,7 @@ class CDoorExtra : public CScriptExtra // Render colored door shield in MP2/3 CFileProperty *mpShieldModelProp; CColorProperty *mpShieldColorProp; - - CModel *mpShieldModel; - CToken mModelToken; + TResPtr mpShieldModel; public: explicit CDoorExtra(CScriptObject *pInstance, CSceneManager *pScene, CSceneNode *pParent = 0); diff --git a/Scene/script/CPointOfInterestExtra.cpp b/Scene/script/CPointOfInterestExtra.cpp index 54b45914..4ee03b19 100644 --- a/Scene/script/CPointOfInterestExtra.cpp +++ b/Scene/script/CPointOfInterestExtra.cpp @@ -42,18 +42,7 @@ CPointOfInterestExtra::CPointOfInterestExtra(CScriptObject *pInstance, CSceneMan void CPointOfInterestExtra::PropertyModified(CPropertyBase* pProperty) { if (mpScanProperty == pProperty) - { - mpScanData = (CScan*) mpScanProperty->Get(); - - if (mpScanData && mpScanData->Type() == eScan) - mScanToken = CToken(mpScanData); - - else - { - mpScanData = nullptr; - mScanToken.Unlock(); - } - } + mpScanData = mpScanProperty->Get(); } void CPointOfInterestExtra::ModifyTintColor(CColor& Color) diff --git a/Scene/script/CPointOfInterestExtra.h b/Scene/script/CPointOfInterestExtra.h index d519a70e..a4489bff 100644 --- a/Scene/script/CPointOfInterestExtra.h +++ b/Scene/script/CPointOfInterestExtra.h @@ -9,8 +9,7 @@ class CPointOfInterestExtra : public CScriptExtra { // Tint POI billboard orange/red depending on scan importance CFileProperty *mpScanProperty; - CScan *mpScanData; - CToken mScanToken; + TResPtr mpScanData; public: explicit CPointOfInterestExtra(CScriptObject *pInstance, CSceneManager *pScene, CSceneNode *pParent = 0); diff --git a/Scene/script/CWaypointExtra.cpp b/Scene/script/CWaypointExtra.cpp index 3092ee5b..0ceb8958 100644 --- a/Scene/script/CWaypointExtra.cpp +++ b/Scene/script/CWaypointExtra.cpp @@ -12,7 +12,7 @@ CWaypointExtra::CWaypointExtra(CScriptObject *pInstance, CSceneManager *pScene, CScriptNode *pScript = static_cast(pParent); CModel *pModel = pScript->ActiveModel(); - if ((pModel->GetMatSetCount() > 0) && (pModel->GetMatCount() > 0)) + if (pModel && (pModel->GetMatSetCount() > 0) && (pModel->GetMatCount() > 0)) { CMaterial *pMat = pModel->GetMaterialByIndex(0, 0); mColor = pMat->Konst(0); diff --git a/UI/CGizmo.cpp b/UI/CGizmo.cpp index a0f28c52..02e1de5b 100644 --- a/UI/CGizmo.cpp +++ b/UI/CGizmo.cpp @@ -625,32 +625,32 @@ void CGizmo::LoadModels() { Log::Write("Loading transform gizmo models"); - smTranslateModels[CGIZMO_TRANSLATE_X] = SModelPart(eX, true, false, (CModel*) gResCache.GetResource("../resources/editor/TranslateX.CMDL")); - smTranslateModels[CGIZMO_TRANSLATE_Y] = SModelPart(eY, true, false, (CModel*) gResCache.GetResource("../resources/editor/TranslateY.CMDL")); - smTranslateModels[CGIZMO_TRANSLATE_Z] = SModelPart(eZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/TranslateZ.CMDL")); - smTranslateModels[CGIZMO_TRANSLATE_LINES_XY] = SModelPart(eXY, true, false, (CModel*) gResCache.GetResource("../resources/editor/TranslateLinesXY.CMDL")); - smTranslateModels[CGIZMO_TRANSLATE_LINES_XZ] = SModelPart(eXZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/TranslateLinesXZ.CMDL")); - smTranslateModels[CGIZMO_TRANSLATE_LINES_YZ] = SModelPart(eYZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/TranslateLinesYZ.CMDL")); - smTranslateModels[CGIZMO_TRANSLATE_POLY_XY] = SModelPart(eXY, false, false, (CModel*) gResCache.GetResource("../resources/editor/TranslatePolyXY.CMDL")); - smTranslateModels[CGIZMO_TRANSLATE_POLY_XZ] = SModelPart(eXZ, false, false, (CModel*) gResCache.GetResource("../resources/editor/TranslatePolyXZ.CMDL")); - smTranslateModels[CGIZMO_TRANSLATE_POLY_YZ] = SModelPart(eYZ, false, false, (CModel*) gResCache.GetResource("../resources/editor/TranslatePolyYZ.CMDL")); + smTranslateModels[CGIZMO_TRANSLATE_X] = SModelPart(eX, true, false, gResCache.GetResource("../resources/editor/TranslateX.CMDL")); + smTranslateModels[CGIZMO_TRANSLATE_Y] = SModelPart(eY, true, false, gResCache.GetResource("../resources/editor/TranslateY.CMDL")); + smTranslateModels[CGIZMO_TRANSLATE_Z] = SModelPart(eZ, true, false, gResCache.GetResource("../resources/editor/TranslateZ.CMDL")); + smTranslateModels[CGIZMO_TRANSLATE_LINES_XY] = SModelPart(eXY, true, false, gResCache.GetResource("../resources/editor/TranslateLinesXY.CMDL")); + smTranslateModels[CGIZMO_TRANSLATE_LINES_XZ] = SModelPart(eXZ, true, false, gResCache.GetResource("../resources/editor/TranslateLinesXZ.CMDL")); + smTranslateModels[CGIZMO_TRANSLATE_LINES_YZ] = SModelPart(eYZ, true, false, gResCache.GetResource("../resources/editor/TranslateLinesYZ.CMDL")); + smTranslateModels[CGIZMO_TRANSLATE_POLY_XY] = SModelPart(eXY, false, false, gResCache.GetResource("../resources/editor/TranslatePolyXY.CMDL")); + smTranslateModels[CGIZMO_TRANSLATE_POLY_XZ] = SModelPart(eXZ, false, false, gResCache.GetResource("../resources/editor/TranslatePolyXZ.CMDL")); + smTranslateModels[CGIZMO_TRANSLATE_POLY_YZ] = SModelPart(eYZ, false, false, gResCache.GetResource("../resources/editor/TranslatePolyYZ.CMDL")); - smRotateModels[CGIZMO_ROTATE_OUTLINE] = SModelPart(eNone, true, true, (CModel*) gResCache.GetResource("../resources/editor/RotateClipOutline.CMDL")); - smRotateModels[CGIZMO_ROTATE_X] = SModelPart(eX, true, false, (CModel*) gResCache.GetResource("../resources/editor/RotateX.CMDL")); - smRotateModels[CGIZMO_ROTATE_Y] = SModelPart(eY, true, false, (CModel*) gResCache.GetResource("../resources/editor/RotateY.CMDL")); - smRotateModels[CGIZMO_ROTATE_Z] = SModelPart(eZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/RotateZ.CMDL")); - smRotateModels[CGIZMO_ROTATE_XYZ] = SModelPart(eXYZ, false, false, (CModel*) gResCache.GetResource("../resources/editor/RotateXYZ.CMDL")); + smRotateModels[CGIZMO_ROTATE_OUTLINE] = SModelPart(eNone, true, true, gResCache.GetResource("../resources/editor/RotateClipOutline.CMDL")); + smRotateModels[CGIZMO_ROTATE_X] = SModelPart(eX, true, false, gResCache.GetResource("../resources/editor/RotateX.CMDL")); + smRotateModels[CGIZMO_ROTATE_Y] = SModelPart(eY, true, false, gResCache.GetResource("../resources/editor/RotateY.CMDL")); + smRotateModels[CGIZMO_ROTATE_Z] = SModelPart(eZ, true, false, gResCache.GetResource("../resources/editor/RotateZ.CMDL")); + smRotateModels[CGIZMO_ROTATE_XYZ] = SModelPart(eXYZ, false, false, gResCache.GetResource("../resources/editor/RotateXYZ.CMDL")); - smScaleModels[CGIZMO_SCALE_X] = SModelPart(eX, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScaleX.CMDL")); - smScaleModels[CGIZMO_SCALE_Y] = SModelPart(eY, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScaleY.CMDL")); - smScaleModels[CGIZMO_SCALE_Z] = SModelPart(eZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScaleZ.CMDL")); - smScaleModels[CGIZMO_SCALE_LINES_XY] = SModelPart(eXY, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScaleLinesXY.CMDL")); - smScaleModels[CGIZMO_SCALE_LINES_XZ] = SModelPart(eXZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScaleLinesXZ.CMDL")); - smScaleModels[CGIZMO_SCALE_LINES_YZ] = SModelPart(eYZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScaleLinesYZ.CMDL")); - smScaleModels[CGIZMO_SCALE_POLY_XY] = SModelPart(eXY, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScalePolyXY.CMDL")); - smScaleModels[CGIZMO_SCALE_POLY_XZ] = SModelPart(eXZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScalePolyXZ.CMDL")); - smScaleModels[CGIZMO_SCALE_POLY_YZ] = SModelPart(eYZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScalePolyYZ.CMDL")); - smScaleModels[CGIZMO_SCALE_XYZ] = SModelPart(eXYZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScaleXYZ.CMDL")); + smScaleModels[CGIZMO_SCALE_X] = SModelPart(eX, true, false, gResCache.GetResource("../resources/editor/ScaleX.CMDL")); + smScaleModels[CGIZMO_SCALE_Y] = SModelPart(eY, true, false, gResCache.GetResource("../resources/editor/ScaleY.CMDL")); + smScaleModels[CGIZMO_SCALE_Z] = SModelPart(eZ, true, false, gResCache.GetResource("../resources/editor/ScaleZ.CMDL")); + smScaleModels[CGIZMO_SCALE_LINES_XY] = SModelPart(eXY, true, false, gResCache.GetResource("../resources/editor/ScaleLinesXY.CMDL")); + smScaleModels[CGIZMO_SCALE_LINES_XZ] = SModelPart(eXZ, true, false, gResCache.GetResource("../resources/editor/ScaleLinesXZ.CMDL")); + smScaleModels[CGIZMO_SCALE_LINES_YZ] = SModelPart(eYZ, true, false, gResCache.GetResource("../resources/editor/ScaleLinesYZ.CMDL")); + smScaleModels[CGIZMO_SCALE_POLY_XY] = SModelPart(eXY, true, false, gResCache.GetResource("../resources/editor/ScalePolyXY.CMDL")); + smScaleModels[CGIZMO_SCALE_POLY_XZ] = SModelPart(eXZ, true, false, gResCache.GetResource("../resources/editor/ScalePolyXZ.CMDL")); + smScaleModels[CGIZMO_SCALE_POLY_YZ] = SModelPart(eYZ, true, false, gResCache.GetResource("../resources/editor/ScalePolyYZ.CMDL")); + smScaleModels[CGIZMO_SCALE_XYZ] = SModelPart(eXYZ, true, false, gResCache.GetResource("../resources/editor/ScaleXYZ.CMDL")); smModelsLoaded = true; } diff --git a/UI/CGizmo.h b/UI/CGizmo.h index 63b3903d..147f643d 100644 --- a/UI/CGizmo.h +++ b/UI/CGizmo.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include @@ -104,12 +104,11 @@ private: EGizmoAxes modelAxes; bool enableRayCast; bool isBillboard; - CModel *pModel; - CToken modelToken; + TResPtr pModel; SModelPart() {} - SModelPart(EGizmoAxes axes, bool rayCastOn, bool billboard, CModel *_pModel) : - modelAxes(axes), enableRayCast(rayCastOn), isBillboard(billboard), pModel(_pModel), modelToken(_pModel) {} + SModelPart(EGizmoAxes axes, bool rayCastOn, bool billboard, TResPtr _pModel) : + modelAxes(axes), enableRayCast(rayCastOn), isBillboard(billboard), pModel(_pModel) {} }; SModelPart *mpCurrentParts; u32 mNumCurrentParts; diff --git a/UI/CModelEditorWindow.cpp b/UI/CModelEditorWindow.cpp index 5c3cfe39..c162ff57 100644 --- a/UI/CModelEditorWindow.cpp +++ b/UI/CModelEditorWindow.cpp @@ -154,7 +154,6 @@ void CModelEditorWindow::SetActiveModel(CModel *pModel) { mpCurrentModelNode->SetModel(pModel); mpCurrentModel = pModel; - mModelToken = CToken(pModel); ui->Viewport->Camera().SetOrbit(pModel->AABox()); u32 numVertices = (pModel ? pModel->GetVertexCount() : 0); @@ -569,7 +568,7 @@ void CModelEditorWindow::UpdateMaterial(QString Value) if (mIgnoreSignals) return; EModelEditorWidget Widget = (EModelEditorWidget) sender()->property("ModelEditorWidgetType").toInt(); - CTexture *pTex = (CTexture*) gResCache.GetResource(TO_TSTRING(Value)); + TResPtr pTex = gResCache.GetResource(TO_TSTRING(Value)); if (pTex->Type() != eTexture) pTex = nullptr; switch (Widget) @@ -712,7 +711,7 @@ void CModelEditorWindow::on_actionConvert_to_DDS_triggered() if (Input.isEmpty()) return; TString TexFilename = Input.toStdString(); - CTexture *Tex = (CTexture*) gResCache.GetResource(TexFilename); + TResPtr pTex = (CTexture*) gResCache.GetResource(TexFilename); TString OutName = TexFilename.GetFilePathWithoutExtension() + ".dds"; CFileOutStream Out(OutName.ToStdString(), IOUtil::LittleEndian); @@ -720,7 +719,7 @@ void CModelEditorWindow::on_actionConvert_to_DDS_triggered() else { - bool success = Tex->WriteDDS(Out); + bool success = pTex->WriteDDS(Out); if (!success) QMessageBox::warning(this, "Error", "Couldn't write output DDS!"); else QMessageBox::information(this, "Success", "Successfully converted to DDS!"); } @@ -731,7 +730,7 @@ void CModelEditorWindow::on_actionOpen_triggered() QString ModelFilename = QFileDialog::getOpenFileName(this, "Save model", "", "Retro Model (*.CMDL)"); if (ModelFilename.isEmpty()) return; - CModel *pModel = (CModel*) gResCache.GetResource(ModelFilename.toStdString()); + TResPtr pModel = gResCache.GetResource(ModelFilename.toStdString()); if (pModel) { SetActiveModel(pModel); diff --git a/UI/CModelEditorWindow.h b/UI/CModelEditorWindow.h index 270695eb..1dac4e36 100644 --- a/UI/CModelEditorWindow.h +++ b/UI/CModelEditorWindow.h @@ -23,8 +23,7 @@ class CModelEditorWindow : public QMainWindow Ui::CModelEditorWindow *ui; CSceneManager *mpScene; QString mOutputFilename; - CModel *mpCurrentModel; - CToken mModelToken; + TResPtr mpCurrentModel; CModelNode *mpCurrentModelNode; CMaterial *mpCurrentMat; CMaterialPass *mpCurrentPass; diff --git a/UI/CStartWindow.cpp b/UI/CStartWindow.cpp index 18caacf5..6a989394 100644 --- a/UI/CStartWindow.cpp +++ b/UI/CStartWindow.cpp @@ -32,8 +32,7 @@ void CStartWindow::on_actionOpen_MLVL_triggered() if (WorldFile.isEmpty()) return; gResCache.SetFolder(TString(WorldFile.toStdString()).GetFileDirectory()); - mpWorld = (CWorld*) gResCache.GetResource(WorldFile.toStdString()); - mWorldToken = CToken(mpWorld); + mpWorld = gResCache.GetResource(WorldFile.toStdString()); mpWorldEditor->close(); FillWorldUI(); @@ -156,7 +155,7 @@ void CStartWindow::on_AttachedAreasList_doubleClicked(const QModelIndex &index) void CStartWindow::on_LaunchWorldEditorButton_clicked() { u64 AreaID = mpWorld->GetAreaResourceID(mSelectedAreaIndex); - CGameArea *pArea = (CGameArea*) gResCache.GetResource(AreaID, "MREA"); + TResPtr pArea = gResCache.GetResource(AreaID, "MREA"); if (!pArea) { diff --git a/UI/CStartWindow.h b/UI/CStartWindow.h index 4aec578f..9e37c352 100644 --- a/UI/CStartWindow.h +++ b/UI/CStartWindow.h @@ -16,8 +16,7 @@ class CStartWindow : public QMainWindow Q_OBJECT Ui::CStartWindow *ui; - CWorld *mpWorld; - CToken mWorldToken; + TResPtr mpWorld; u32 mSelectedAreaIndex; CWorldEditor *mpWorldEditor; diff --git a/UI/CWorldEditor.cpp b/UI/CWorldEditor.cpp index 49f95022..4fce6746 100644 --- a/UI/CWorldEditor.cpp +++ b/UI/CWorldEditor.cpp @@ -107,9 +107,6 @@ void CWorldEditor::SetArea(CWorld *pWorld, CGameArea *pArea) // Load new area mpArea = pArea; mpWorld = pWorld; - mAreaToken = CToken(pArea); - mWorldToken = CToken(pWorld); - mScene.SetActiveWorld(pWorld); mScene.SetActiveArea(pArea); diff --git a/UI/CWorldEditor.h b/UI/CWorldEditor.h index ae8908b4..940070b1 100644 --- a/UI/CWorldEditor.h +++ b/UI/CWorldEditor.h @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -30,10 +30,8 @@ class CWorldEditor : public INodeEditor Q_OBJECT Ui::CWorldEditor *ui; - CWorld *mpWorld; - CGameArea *mpArea; - CToken mAreaToken; - CToken mWorldToken; + TResPtr mpWorld; + TResPtr mpArea; QTimer mRefreshTimer; public: diff --git a/UI/WPropertyEditor.cpp b/UI/WPropertyEditor.cpp index b8e07d1d..852d0c0d 100644 --- a/UI/WPropertyEditor.cpp +++ b/UI/WPropertyEditor.cpp @@ -7,6 +7,7 @@ #include "WVectorEditor.h" #include "WAnimParamsEditor.h" #include +#include #include #include @@ -254,10 +255,11 @@ void WPropertyEditor::CreateEditor() case eFileProperty: { CFileProperty *pFileCast = static_cast(mpProperty); + CFileTemplate *pFileTemp = static_cast(pFileCast->Template()); WResourceSelector *pResourceSelector = new WResourceSelector(this); pResourceSelector->AdjustPreviewToParent(true); - pResourceSelector->SetAllowedExtensions(pFileCast->AllowedExtensions()); + pResourceSelector->SetAllowedExtensions(pFileTemp->Extensions()); pResourceSelector->SetResource(pFileCast->Get()); mUI.EditorWidget = pResourceSelector; @@ -431,8 +433,9 @@ void WPropertyEditor::UpdateEditor() case eFileProperty: { CFileProperty *pFileCast = static_cast(mpProperty); + CFileTemplate *pFileTemp = static_cast(pFileCast->Template()); WResourceSelector *pResourceSelector = static_cast(mUI.EditorWidget); - pResourceSelector->SetAllowedExtensions(pFileCast->AllowedExtensions()); + pResourceSelector->SetAllowedExtensions(pFileTemp->Extensions()); pResourceSelector->SetResource(pFileCast->Get()); break; } diff --git a/UI/WResourceSelector.cpp b/UI/WResourceSelector.cpp index ffdc20ba..3645d9ae 100644 --- a/UI/WResourceSelector.cpp +++ b/UI/WResourceSelector.cpp @@ -134,7 +134,6 @@ bool WResourceSelector::IsPreviewPanelEnabled() void WResourceSelector::SetResource(CResource *pRes) { mpResource = pRes; - mResToken = CToken(pRes); if (pRes) { @@ -261,7 +260,6 @@ void WResourceSelector::Export() void WResourceSelector::LoadResource(const QString& ResPath) { mpResource = nullptr; - mResToken.Unlock(); TString pathStr = ResPath.toStdString(); TString ext = pathStr.GetFileExtension(); @@ -271,7 +269,6 @@ void WResourceSelector::LoadResource(const QString& ResPath) if ((ext != "MREA") && (ext != "MLVL")) { mpResource = gResCache.GetResource(pathStr); - mResToken = CToken(mpResource); mResourceValid = (mpResource != nullptr); if (mPreviewPanelValid) mpPreviewPanel->SetResource(mpResource); diff --git a/UI/WResourceSelector.h b/UI/WResourceSelector.h index 2ae8296f..89783392 100644 --- a/UI/WResourceSelector.h +++ b/UI/WResourceSelector.h @@ -3,7 +3,7 @@ #include "IPreviewPanel.h" #include -#include +#include #include #include @@ -29,8 +29,7 @@ class WResourceSelector : public QWidget bool mAdjustPreviewToParent; // Resource - CResource *mpResource; - CToken mResToken; + TResPtr mpResource; bool mResourceValid; // UI diff --git a/UI/WTextureGLWidget.cpp b/UI/WTextureGLWidget.cpp index 8028591e..d2d9be9a 100644 --- a/UI/WTextureGLWidget.cpp +++ b/UI/WTextureGLWidget.cpp @@ -77,7 +77,6 @@ void WTextureGLWidget::resizeGL(int w, int h) void WTextureGLWidget::SetTexture(CTexture *pTex) { mpTexture = pTex; - mTexToken = CToken(pTex); if (pTex) mTexAspectRatio = (float) pTex->Width() / (float) pTex->Height(); else mTexAspectRatio = 0.f; diff --git a/UI/WTextureGLWidget.h b/UI/WTextureGLWidget.h index 9bd9d5cb..11de7adc 100644 --- a/UI/WTextureGLWidget.h +++ b/UI/WTextureGLWidget.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -15,8 +15,7 @@ class WTextureGLWidget : public QOpenGLWidget Q_OBJECT float mAspectRatio; - CTexture *mpTexture; - CToken mTexToken; + TResPtr mpTexture; float mTexAspectRatio; CTransform4f mTexTransform; CVector2f mCheckerCoords[4]; diff --git a/UI/WorldEditor/CLayerEditor.cpp b/UI/WorldEditor/CLayerEditor.cpp index 3596779e..221bf248 100644 --- a/UI/WorldEditor/CLayerEditor.cpp +++ b/UI/WorldEditor/CLayerEditor.cpp @@ -1,6 +1,7 @@ #include "CLayerEditor.h" #include "ui_CLayerEditor.h" #include "../UICommon.h" +#include CLayerEditor::CLayerEditor(QWidget *parent) : QDialog(parent), diff --git a/UI/WorldEditor/CLayerEditor.h b/UI/WorldEditor/CLayerEditor.h index cab33f0a..e84e3f7c 100644 --- a/UI/WorldEditor/CLayerEditor.h +++ b/UI/WorldEditor/CLayerEditor.h @@ -11,7 +11,7 @@ class CLayerEditor; class CLayerEditor : public QDialog { Q_OBJECT - CGameArea *mpArea; + TResPtr mpArea; CLayerModel *mpModel; CScriptLayer *mpCurrentLayer; diff --git a/UI/WorldEditor/CLayerModel.cpp b/UI/WorldEditor/CLayerModel.cpp index 09685562..a5f43d54 100644 --- a/UI/WorldEditor/CLayerModel.cpp +++ b/UI/WorldEditor/CLayerModel.cpp @@ -1,5 +1,6 @@ #include "CLayerModel.h" #include "../UICommon.h" +#include CLayerModel::CLayerModel(QObject *pParent) : QAbstractListModel(pParent) { diff --git a/UI/WorldEditor/CLayerModel.h b/UI/WorldEditor/CLayerModel.h index bb9c3870..f1937186 100644 --- a/UI/WorldEditor/CLayerModel.h +++ b/UI/WorldEditor/CLayerModel.h @@ -6,7 +6,7 @@ class CLayerModel : public QAbstractListModel { - CGameArea *mpArea; + TResPtr mpArea; bool mHasGenerateLayer; public: diff --git a/UI/WorldEditor/CLayersInstanceModel.h b/UI/WorldEditor/CLayersInstanceModel.h index 7bba66ca..b8353219 100644 --- a/UI/WorldEditor/CLayersInstanceModel.h +++ b/UI/WorldEditor/CLayersInstanceModel.h @@ -24,7 +24,7 @@ public: private: CWorldEditor *mpEditor; CSceneManager *mpScene; - CGameArea *mpArea; + TResPtr mpArea; public: explicit CLayersInstanceModel(QObject *pParent = 0); diff --git a/UI/WorldEditor/CTypesInstanceModel.cpp b/UI/WorldEditor/CTypesInstanceModel.cpp index dd54c5b1..bb0bde86 100644 --- a/UI/WorldEditor/CTypesInstanceModel.cpp +++ b/UI/WorldEditor/CTypesInstanceModel.cpp @@ -1,5 +1,6 @@ #include "CTypesInstanceModel.h" #include "../UICommon.h" +#include #include #include #include diff --git a/UI/WorldEditor/CTypesInstanceModel.h b/UI/WorldEditor/CTypesInstanceModel.h index eb731562..fd150283 100644 --- a/UI/WorldEditor/CTypesInstanceModel.h +++ b/UI/WorldEditor/CTypesInstanceModel.h @@ -30,7 +30,7 @@ public: private: CWorldEditor *mpEditor; CSceneManager *mpScene; - CGameArea *mpArea; + TResPtr mpArea; CMasterTemplate *mpCurrentMaster; EInstanceModelType mModelType; QList mTemplateList; diff --git a/UI/WorldEditor/WInstancesTab.cpp b/UI/WorldEditor/WInstancesTab.cpp index a72ad53c..45661790 100644 --- a/UI/WorldEditor/WInstancesTab.cpp +++ b/UI/WorldEditor/WInstancesTab.cpp @@ -3,6 +3,7 @@ #include "../CWorldEditor.h" #include +#include WInstancesTab::WInstancesTab(QWidget *parent) : QWidget(parent),