Replaced CToken with TResPtr

This commit is contained in:
parax0 2015-12-13 13:52:17 -07:00
parent b4855e37ed
commit 394953434d
78 changed files with 283 additions and 420 deletions

View File

@ -45,9 +45,9 @@ CModel* CAreaAttributes::SkyModel()
{ {
case ePrime: case ePrime:
case eEchoes: case eEchoes:
return (CModel*) static_cast<CFileProperty*>(pBaseStruct->PropertyByIndex(7))->Get(); return (CModel*) static_cast<CFileProperty*>(pBaseStruct->PropertyByIndex(7))->Get().RawPointer();
case eCorruption: case eCorruption:
return (CModel*) static_cast<CFileProperty*>(pBaseStruct->PropertyByIndex(8))->Get(); return (CModel*) static_cast<CFileProperty*>(pBaseStruct->PropertyByIndex(8))->Get().RawPointer();
default: default:
return nullptr; return nullptr;
} }

View File

@ -15,19 +15,15 @@ CIndexBuffer CDrawUtil::mSquareIndices;
CDynamicVertexBuffer CDrawUtil::mLineVertices; CDynamicVertexBuffer CDrawUtil::mLineVertices;
CIndexBuffer CDrawUtil::mLineIndices; CIndexBuffer CDrawUtil::mLineIndices;
CModel *CDrawUtil::mpCubeModel; TResPtr<CModel> CDrawUtil::mpCubeModel;
CToken CDrawUtil::mCubeToken;
CVertexBuffer CDrawUtil::mWireCubeVertices; CVertexBuffer CDrawUtil::mWireCubeVertices;
CIndexBuffer CDrawUtil::mWireCubeIndices; CIndexBuffer CDrawUtil::mWireCubeIndices;
CModel *CDrawUtil::mpSphereModel; TResPtr<CModel> CDrawUtil::mpSphereModel;
CModel *CDrawUtil::mpDoubleSidedSphereModel; TResPtr<CModel> CDrawUtil::mpDoubleSidedSphereModel;
CToken CDrawUtil::mSphereToken;
CToken CDrawUtil::mDoubleSidedSphereToken;
CModel *CDrawUtil::mpWireSphereModel; TResPtr<CModel> CDrawUtil::mpWireSphereModel;
CToken CDrawUtil::mWireSphereToken;
CShader *CDrawUtil::mpColorShader; CShader *CDrawUtil::mpColorShader;
CShader *CDrawUtil::mpColorShaderLighting; CShader *CDrawUtil::mpColorShaderLighting;
@ -37,12 +33,10 @@ CShader *CDrawUtil::mpTextureShader;
CShader *CDrawUtil::mpCollisionShader; CShader *CDrawUtil::mpCollisionShader;
CShader *CDrawUtil::mpTextShader; CShader *CDrawUtil::mpTextShader;
CTexture *CDrawUtil::mpCheckerTexture; TResPtr<CTexture> CDrawUtil::mpCheckerTexture;
CToken CDrawUtil::mCheckerTextureToken;
CTexture *CDrawUtil::mpLightTextures[4]; TResPtr<CTexture> CDrawUtil::mpLightTextures[4];
CTexture *CDrawUtil::mpLightMasks[4]; TResPtr<CTexture> CDrawUtil::mpLightMasks[4];
CToken CDrawUtil::mLightTextureTokens[8];
bool CDrawUtil::mDrawUtilInitialized = false; bool CDrawUtil::mDrawUtilInitialized = false;
@ -493,8 +487,7 @@ void CDrawUtil::InitLine()
void CDrawUtil::InitCube() void CDrawUtil::InitCube()
{ {
Log::Write("Creating cube"); Log::Write("Creating cube");
mpCubeModel = (CModel*) gResCache.GetResource("../resources/Cube.cmdl"); mpCubeModel = gResCache.GetResource("../resources/Cube.cmdl");
mCubeToken = CToken(mpCubeModel);
} }
void CDrawUtil::InitWireCube() void CDrawUtil::InitWireCube()
@ -532,17 +525,14 @@ void CDrawUtil::InitWireCube()
void CDrawUtil::InitSphere() void CDrawUtil::InitSphere()
{ {
Log::Write("Creating sphere"); Log::Write("Creating sphere");
mpSphereModel = (CModel*) gResCache.GetResource("../resources/Sphere.cmdl"); mpSphereModel = gResCache.GetResource("../resources/Sphere.cmdl");
mpDoubleSidedSphereModel = (CModel*) gResCache.GetResource("../resources/SphereDoubleSided.cmdl"); mpDoubleSidedSphereModel = gResCache.GetResource("../resources/SphereDoubleSided.cmdl");
mSphereToken = CToken(mpSphereModel);
mDoubleSidedSphereToken = CToken(mpDoubleSidedSphereModel);
} }
void CDrawUtil::InitWireSphere() void CDrawUtil::InitWireSphere()
{ {
Log::Write("Creating wire sphere"); Log::Write("Creating wire sphere");
mpWireSphereModel = (CModel*) gResCache.GetResource("../resources/WireSphere.cmdl"); mpWireSphereModel = gResCache.GetResource("../resources/WireSphere.cmdl");
mWireSphereToken = CToken(mpWireSphereModel);
} }
void CDrawUtil::InitShaders() void CDrawUtil::InitShaders()
@ -560,24 +550,17 @@ void CDrawUtil::InitShaders()
void CDrawUtil::InitTextures() void CDrawUtil::InitTextures()
{ {
Log::Write("Loading textures"); Log::Write("Loading textures");
mpCheckerTexture = (CTexture*) gResCache.GetResource("../resources/Checkerboard.txtr"); mpCheckerTexture = gResCache.GetResource("../resources/Checkerboard.txtr");
mCheckerTextureToken = CToken(mpCheckerTexture);
mpLightTextures[0] = (CTexture*) gResCache.GetResource("../resources/LightAmbient.txtr"); mpLightTextures[0] = gResCache.GetResource("../resources/LightAmbient.txtr");
mpLightTextures[1] = (CTexture*) gResCache.GetResource("../resources/LightDirectional.txtr"); mpLightTextures[1] = gResCache.GetResource("../resources/LightDirectional.txtr");
mpLightTextures[2] = (CTexture*) gResCache.GetResource("../resources/LightCustom.txtr"); mpLightTextures[2] = gResCache.GetResource("../resources/LightCustom.txtr");
mpLightTextures[3] = (CTexture*) gResCache.GetResource("../resources/LightSpot.txtr"); mpLightTextures[3] = gResCache.GetResource("../resources/LightSpot.txtr");
mpLightMasks[0] = (CTexture*) gResCache.GetResource("../resources/LightAmbientMask.txtr"); mpLightMasks[0] = gResCache.GetResource("../resources/LightAmbientMask.txtr");
mpLightMasks[1] = (CTexture*) gResCache.GetResource("../resources/LightDirectionalMask.txtr"); mpLightMasks[1] = gResCache.GetResource("../resources/LightDirectionalMask.txtr");
mpLightMasks[2] = (CTexture*) gResCache.GetResource("../resources/LightCustomMask.txtr"); mpLightMasks[2] = gResCache.GetResource("../resources/LightCustomMask.txtr");
mpLightMasks[3] = (CTexture*) gResCache.GetResource("../resources/LightSpotMask.txtr"); mpLightMasks[3] = gResCache.GetResource("../resources/LightSpotMask.txtr");
for (int i = 0; i < 4; i++)
{
mLightTextureTokens[i] = CToken(mpLightTextures[i]);
mLightTextureTokens[i+4] = CToken(mpLightMasks[i]);
}
} }
void CDrawUtil::Shutdown() void CDrawUtil::Shutdown()
@ -585,9 +568,6 @@ void CDrawUtil::Shutdown()
if (mDrawUtilInitialized) if (mDrawUtilInitialized)
{ {
Log::Write("Shutting down"); Log::Write("Shutting down");
mCubeToken = CToken();
mSphereToken = CToken();
mDoubleSidedSphereToken = CToken();
delete mpColorShader; delete mpColorShader;
delete mpColorShaderLighting; delete mpColorShaderLighting;
delete mpTextureShader; delete mpTextureShader;

View File

@ -25,22 +25,18 @@ class CDrawUtil
static CIndexBuffer mLineIndices; static CIndexBuffer mLineIndices;
// Cube // Cube
static CModel *mpCubeModel; static TResPtr<CModel> mpCubeModel;
static CToken mCubeToken;
// Wire Cube // Wire Cube
static CVertexBuffer mWireCubeVertices; static CVertexBuffer mWireCubeVertices;
static CIndexBuffer mWireCubeIndices; static CIndexBuffer mWireCubeIndices;
// Sphere // Sphere
static CModel *mpSphereModel; static TResPtr<CModel> mpSphereModel;
static CModel *mpDoubleSidedSphereModel; static TResPtr<CModel> mpDoubleSidedSphereModel;
static CToken mSphereToken;
static CToken mDoubleSidedSphereToken;
// Wire Sphere // Wire Sphere
static CModel *mpWireSphereModel; static TResPtr<CModel> mpWireSphereModel;
static CToken mWireSphereToken;
// Shaders // Shaders
static CShader *mpColorShader; static CShader *mpColorShader;
@ -52,12 +48,10 @@ class CDrawUtil
static CShader *mpTextShader; static CShader *mpTextShader;
// Textures // Textures
static CTexture *mpCheckerTexture; static TResPtr<CTexture> mpCheckerTexture;
static CToken mCheckerTextureToken;
static CTexture *mpLightTextures[4]; static TResPtr<CTexture> mpLightTextures[4];
static CTexture *mpLightMasks[4]; static TResPtr<CTexture> mpLightMasks[4];
static CToken mLightTextureTokens[8];
// Have all the above members been initialized? // Have all the above members been initialized?
static bool mDrawUtilInitialized; static bool mDrawUtilInitialized;

View File

@ -9,6 +9,7 @@
#include <Core/CGraphics.h> #include <Core/CGraphics.h>
#include <Core/CResCache.h> #include <Core/CResCache.h>
#include <FileIO/CFileInStream.h> #include <FileIO/CFileInStream.h>
#include <Resource/script/CScriptLayer.h>
/** /**
* This class direly needs a rewrite * This class direly needs a rewrite
@ -97,7 +98,6 @@ void CSceneManager::SetActiveArea(CGameArea* _area)
// Create nodes for new area // Create nodes for new area
mpArea = _area; mpArea = _area;
mAreaToken = CToken(mpArea);
mpAreaRootNode = new CRootNode(this, mpSceneRootNode); mpAreaRootNode = new CRootNode(this, mpSceneRootNode);
if (mSplitTerrain) if (mSplitTerrain)
@ -191,7 +191,6 @@ void CSceneManager::SetActiveArea(CGameArea* _area)
void CSceneManager::SetActiveWorld(CWorld* _world) void CSceneManager::SetActiveWorld(CWorld* _world)
{ {
mpWorld = _world; mpWorld = _world;
mWorldToken = CToken(mpWorld);
} }
void CSceneManager::ClearScene() void CSceneManager::ClearScene()
@ -209,9 +208,7 @@ void CSceneManager::ClearScene()
mLightNodes.clear(); mLightNodes.clear();
mpArea = nullptr; mpArea = nullptr;
mAreaToken.Unlock();
mpWorld = nullptr; mpWorld = nullptr;
mWorldToken.Unlock();
mNodeCount = 0; mNodeCount = 0;
} }

View File

@ -32,10 +32,8 @@ class CSceneManager
std::vector<CLightNode*> mLightNodes; std::vector<CLightNode*> mLightNodes;
CRootNode *mpSceneRootNode; CRootNode *mpSceneRootNode;
CGameArea *mpArea; TResPtr<CGameArea> mpArea;
CWorld *mpWorld; TResPtr<CWorld> mpWorld;
CToken mAreaToken;
CToken mWorldToken;
CRootNode *mpAreaRootNode; CRootNode *mpAreaRootNode;
// Environment // Environment

View File

@ -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;
}

View File

@ -1,21 +0,0 @@
#ifndef CTOKEN_H
#define CTOKEN_H
#include <Resource/CResource.h>
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

91
Core/TResPtr.h Normal file
View File

@ -0,0 +1,91 @@
#ifndef TRESPTR_H
#define TRESPTR_H
#include <Resource/CResource.h>
template <typename ResType>
class TResPtr
{
ResType *mpRes;
public:
TResPtr()
: mpRes(nullptr) {}
TResPtr(void *pPtr)
: mpRes(nullptr)
{
*this = pPtr;
}
TResPtr(const TResPtr<ResType>& 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<ResType>& 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<ResType*>((CResource*) pRes);
if (mpRes)
mpRes->Lock();
return *this;
}
TResPtr<ResType>& operator=(const TResPtr<ResType>& rkRight)
{
if (mpRes)
mpRes->Release();
mpRes = rkRight.mpRes;
if (mpRes)
mpRes->Lock();
return *this;
}
};
#endif // TRESPTR_H

View File

@ -85,7 +85,6 @@ SOURCES += \
Common/CHashFNV1A.cpp \ Common/CHashFNV1A.cpp \
UI/CModelEditorWindow.cpp \ UI/CModelEditorWindow.cpp \
Resource/CResource.cpp \ Resource/CResource.cpp \
Core/CToken.cpp \
Core/CRenderBucket.cpp \ Core/CRenderBucket.cpp \
Core/CDrawUtil.cpp \ Core/CDrawUtil.cpp \
UI/WTextureGLWidget.cpp \ UI/WTextureGLWidget.cpp \
@ -245,7 +244,6 @@ HEADERS += \
Common/CHashFNV1A.h \ Common/CHashFNV1A.h \
Core/ERenderOptions.h \ Core/ERenderOptions.h \
UI/CModelEditorWindow.h \ UI/CModelEditorWindow.h \
Core/CToken.h \
Core/CRenderBucket.h \ Core/CRenderBucket.h \
Common/EMouseInputs.h \ Common/EMouseInputs.h \
Common/EKeyInputs.h \ Common/EKeyInputs.h \
@ -332,7 +330,8 @@ HEADERS += \
Scene/script/CSpacePirateExtra.h \ Scene/script/CSpacePirateExtra.h \
Scene/script/CWaypointExtra.h \ Scene/script/CWaypointExtra.h \
Scene/script/CDoorExtra.h \ Scene/script/CDoorExtra.h \
Scene/script/CDamageableTriggerExtra.h Scene/script/CDamageableTriggerExtra.h \
Core/TResPtr.h
FORMS += \ FORMS += \
UI/CStartWindow.ui \ UI/CStartWindow.ui \

View File

@ -2,7 +2,7 @@
#define CANIMSET_H #define CANIMSET_H
#include <Common/types.h> #include <Common/types.h>
#include <Core/CToken.h> #include <Core/TResPtr.h>
#include <vector> #include <vector>
#include "model/CModel.h" #include "model/CModel.h"
#include "CResource.h" #include "CResource.h"
@ -15,10 +15,9 @@ class CAnimSet : public CResource
struct SNode struct SNode
{ {
TString name; TString name;
CModel *model; TResPtr<CModel> model;
u32 skinID; u32 skinID;
u32 skelID; u32 skelID;
CToken ModelToken;
SNode() { model = nullptr; } SNode() { model = nullptr; }
}; };

View File

@ -32,7 +32,6 @@ CAnimationParameters::CAnimationParameters(CInputStream& SCLY, EGame game)
mUnknown1 = SCLY.ReadLong(); mUnknown1 = SCLY.ReadLong();
mpCharSet = gResCache.GetResource(animSetID, "ANCS"); mpCharSet = gResCache.GetResource(animSetID, "ANCS");
mResToken = CToken(mpCharSet);
} }
else if (game <= eCorruption) else if (game <= eCorruption)
@ -41,7 +40,6 @@ CAnimationParameters::CAnimationParameters(CInputStream& SCLY, EGame game)
mUnknown1 = SCLY.ReadLong(); mUnknown1 = SCLY.ReadLong();
mpCharSet = gResCache.GetResource(charID, "CHAR"); mpCharSet = gResCache.GetResource(charID, "CHAR");
mResToken = CToken(mpCharSet);
} }
else if (game == eReturns) else if (game == eReturns)
@ -62,7 +60,6 @@ CAnimationParameters::CAnimationParameters(CInputStream& SCLY, EGame game)
mUnknown4 = SCLY.ReadLong(); mUnknown4 = SCLY.ReadLong();
mpCharSet = gResCache.GetResource(charID, "CHAR"); mpCharSet = gResCache.GetResource(charID, "CHAR");
mResToken = CToken(mpCharSet);
} }
else if (mUnknown1 != 0x80) else if (mUnknown1 != 0x80)
@ -79,7 +76,7 @@ CModel* CAnimationParameters::GetCurrentModel(s32 nodeIndex)
if (mpCharSet->Type() != eAnimSet) return nullptr; if (mpCharSet->Type() != eAnimSet) return nullptr;
if (nodeIndex == -1) nodeIndex = mNodeIndex; if (nodeIndex == -1) nodeIndex = mNodeIndex;
CAnimSet *pSet = static_cast<CAnimSet*>(mpCharSet); CAnimSet *pSet = static_cast<CAnimSet*>(mpCharSet.RawPointer());
if (pSet->getNodeCount() <= (u32) nodeIndex) return nullptr; if (pSet->getNodeCount() <= (u32) nodeIndex) return nullptr;
return pSet->getNodeModel(nodeIndex); return pSet->getNodeModel(nodeIndex);
} }
@ -118,7 +115,6 @@ void CAnimationParameters::SetResource(CResource *pRes)
if ((pRes->Type() == eAnimSet) || (pRes->Type() == eCharacter)) if ((pRes->Type() == eAnimSet) || (pRes->Type() == eCharacter))
{ {
mpCharSet = pRes; mpCharSet = pRes;
mResToken = CToken(pRes);
mNodeIndex = 0; mNodeIndex = 0;
} }
else else

View File

@ -3,14 +3,13 @@
#include "CResource.h" #include "CResource.h"
#include "model/CModel.h" #include "model/CModel.h"
#include <Core/CToken.h> #include <Core/TResPtr.h>
#include "EFormatVersion.h" #include "EFormatVersion.h"
class CAnimationParameters class CAnimationParameters
{ {
EGame mGame; EGame mGame;
CResource *mpCharSet; TResPtr<CResource> mpCharSet;
CToken mResToken;
u32 mNodeIndex; u32 mNodeIndex;
u32 mUnknown1; u32 mUnknown1;

View File

@ -3,7 +3,7 @@
#include "CResource.h" #include "CResource.h"
#include "CCollisionMesh.h" #include "CCollisionMesh.h"
#include <Core/CToken.h> #include <Core/TResPtr.h>
#include <vector> #include <vector>
class CCollisionMeshGroup : public CResource class CCollisionMeshGroup : public CResource

View File

@ -5,7 +5,7 @@
#include "CTexture.h" #include "CTexture.h"
#include "model/CVertex.h" #include "model/CVertex.h"
#include <Common/types.h> #include <Common/types.h>
#include <Core/CToken.h> #include <Core/TResPtr.h>
#include <OpenGL/CDynamicVertexBuffer.h> #include <OpenGL/CDynamicVertexBuffer.h>
#include <OpenGL/CIndexBuffer.h> #include <OpenGL/CIndexBuffer.h>
@ -29,8 +29,7 @@ class CFont : public CResource
u32 mVerticalOffset; // In points. This is used to reposition glyphs after the per-glyph vertical offset is applied u32 mVerticalOffset; // In points. This is used to reposition glyphs after the per-glyph vertical offset is applied
u32 mDefaultSize; // In points. u32 mDefaultSize; // In points.
TString mFontName; // Self-explanatory TString mFontName; // Self-explanatory
CTexture *mpFontTexture; // The texture used by this font TResPtr<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 mTextureFormat; // Indicates which layers on the texture are for what - multiple glyph layers or fill/stroke
struct SGlyph struct SGlyph

View File

@ -1,4 +1,5 @@
#include "CGameArea.h" #include "CGameArea.h"
#include "script/CScriptLayer.h"
#include <Core/CRenderer.h> #include <Core/CRenderer.h>
CGameArea::CGameArea() : CResource() CGameArea::CGameArea() : CResource()

View File

@ -7,11 +7,13 @@
#include "model/CModel.h" #include "model/CModel.h"
#include "model/CStaticModel.h" #include "model/CStaticModel.h"
#include "CResource.h" #include "CResource.h"
#include "script/CScriptLayer.h"
#include <Common/types.h> #include <Common/types.h>
#include <Common/CTransform4f.h> #include <Common/CTransform4f.h>
#include <unordered_map> #include <unordered_map>
class CScriptLayer;
class CScriptObject;
class CGameArea : public CResource class CGameArea : public CResource
{ {
friend class CAreaLoader; friend class CAreaLoader;

View File

@ -70,7 +70,6 @@ CMaterial* CMaterial::Clone()
pOut->mEchoesUnknownA = mEchoesUnknownA; pOut->mEchoesUnknownA = mEchoesUnknownA;
pOut->mEchoesUnknownB = mEchoesUnknownB; pOut->mEchoesUnknownB = mEchoesUnknownB;
pOut->mpIndirectTexture = mpIndirectTexture; pOut->mpIndirectTexture = mpIndirectTexture;
pOut->mIndTextureToken = CToken(pOut->mpIndirectTexture);
pOut->mPasses.resize(mPasses.size()); pOut->mPasses.resize(mPasses.size());
for (u32 iPass = 0; iPass < mPasses.size(); iPass++) for (u32 iPass = 0; iPass < mPasses.size(); iPass++)

View File

@ -8,7 +8,7 @@
#include <Common/CColor.h> #include <Common/CColor.h>
#include <Common/EnumUtil.h> #include <Common/EnumUtil.h>
#include <Common/types.h> #include <Common/types.h>
#include <Core/CToken.h> #include <Core/TResPtr.h>
#include <Core/ERenderOptions.h> #include <Core/ERenderOptions.h>
#include <FileIO/CInputStream.h> #include <FileIO/CInputStream.h>
#include <OpenGL/CShader.h> #include <OpenGL/CShader.h>
@ -66,8 +66,7 @@ private:
bool mLightingEnabled; // Color channel control flags; indicate whether lighting is enabled bool mLightingEnabled; // Color channel control flags; indicate whether lighting is enabled
u32 mEchoesUnknownA; // First unknown value introduced in Echoes. Included for cooking. u32 mEchoesUnknownA; // First unknown value introduced in Echoes. Included for cooking.
u32 mEchoesUnknownB; // Second 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 TResPtr<CTexture> mpIndirectTexture; // Optional texture used for the indirect stage for reflections
CToken mIndTextureToken; // Token for indirect texture
std::vector<CMaterialPass*> mPasses; std::vector<CMaterialPass*> mPasses;

View File

@ -47,7 +47,6 @@ CMaterialPass* CMaterialPass::Clone(CMaterial *pParent)
pOut->mRasSel = mRasSel; pOut->mRasSel = mRasSel;
pOut->mTexCoordSource = mTexCoordSource; pOut->mTexCoordSource = mTexCoordSource;
pOut->mpTexture = mpTexture; pOut->mpTexture = mpTexture;
pOut->mTexToken = CToken(pOut->mpTexture);
pOut->mAnimMode = mAnimMode; pOut->mAnimMode = mAnimMode;
for (u32 iParam = 0; iParam < 4; iParam++) for (u32 iParam = 0; iParam < 4; iParam++)
pOut->mAnimParams[iParam] = mAnimParams[iParam]; pOut->mAnimParams[iParam] = mAnimParams[iParam];
@ -280,7 +279,6 @@ void CMaterialPass::SetTexCoordSource(u32 Source)
void CMaterialPass::SetTexture(CTexture *pTex) void CMaterialPass::SetTexture(CTexture *pTex)
{ {
mpTexture = pTex; mpTexture = pTex;
mTexToken = CToken(pTex);
} }
void CMaterialPass::SetAnimMode(EUVAnimMode Mode) void CMaterialPass::SetAnimMode(EUVAnimMode Mode)

View File

@ -3,7 +3,7 @@
#include <Common/CFourCC.h> #include <Common/CFourCC.h>
#include <Common/CHashFNV1A.h> #include <Common/CHashFNV1A.h>
#include <Core/CToken.h> #include <Core/TResPtr.h>
#include <Core/ERenderOptions.h> #include <Core/ERenderOptions.h>
#include <Resource/CTexture.h> #include <Resource/CTexture.h>
#include "ETevEnums.h" #include "ETevEnums.h"
@ -36,8 +36,7 @@ private:
ETevKSel mKAlphaSel; ETevKSel mKAlphaSel;
ETevRasSel mRasSel; ETevRasSel mRasSel;
u32 mTexCoordSource; // Should maybe be an enum but worried about conflicts with EVertexDescriptionn u32 mTexCoordSource; // Should maybe be an enum but worried about conflicts with EVertexDescriptionn
CTexture *mpTexture; TResPtr<CTexture> mpTexture;
CToken mTexToken;
EUVAnimMode mAnimMode; EUVAnimMode mAnimMode;
float mAnimParams[4]; float mAnimParams[4];
bool mEnabled; bool mEnabled;

View File

@ -4,7 +4,7 @@
#include "CResource.h" #include "CResource.h"
#include "CStringTable.h" #include "CStringTable.h"
#include "EFormatVersion.h" #include "EFormatVersion.h"
#include <Core/CToken.h> #include <Core/TResPtr.h>
class CScan : public CResource class CScan : public CResource
{ {
@ -23,10 +23,8 @@ public:
private: private:
EGame mVersion; EGame mVersion;
CResource *mpFrame; TResPtr<CResource> mpFrame;
CStringTable *mpStringTable; TResPtr<CStringTable> mpStringTable;
CToken mFrameToken;
CToken mStringToken;
bool mIsSlow; bool mIsSlow;
bool mIsImportant; bool mIsImportant;
ELogbookCategory mCategory; ELogbookCategory mCategory;

View File

@ -1,4 +1,5 @@
#include "CWorld.h" #include "CWorld.h"
#include "script/CScriptLayer.h"
#include <Core/CResCache.h> #include <Core/CResCache.h>
CWorld::CWorld() : CResource() CWorld::CWorld() : CResource()

View File

@ -14,12 +14,11 @@ class CWorld : public CResource
// Instances of CResource pointers are placeholders for unimplemented resource types (eg CMapWorld) // Instances of CResource pointers are placeholders for unimplemented resource types (eg CMapWorld)
EGame mWorldVersion; EGame mWorldVersion;
CStringTable *mpWorldName; TResPtr<CStringTable> mpWorldName;
CStringTable *mpDarkWorldName; TResPtr<CStringTable> mpDarkWorldName;
CResource *mpSaveWorld; TResPtr<CResource> mpSaveWorld;
CModel *mpDefaultSkybox; TResPtr<CModel> mpDefaultSkybox;
CResource *mpMapWorld; TResPtr<CResource> mpMapWorld;
CToken mResTokens[5];
u32 mUnknown1; u32 mUnknown1;
u32 mUnknownAreas; u32 mUnknownAreas;
@ -44,12 +43,11 @@ class CWorld : public CResource
struct SArea struct SArea
{ {
TString InternalName; TString InternalName;
CStringTable *pAreaName; TResPtr<CStringTable> pAreaName;
CTransform4f Transform; CTransform4f Transform;
CAABox AetherBox; CAABox AetherBox;
u64 FileID; // Loading every single area as a CResource would be a very bad idea u64 FileID; // Loading every single area as a CResource would be a very bad idea
u64 AreaID; u64 AreaID;
CToken AreaNameToken;
std::vector<u16> AttachedAreaIDs; std::vector<u16> AttachedAreaIDs;
std::vector<SDependency> Dependencies; std::vector<SDependency> Dependencies;

View File

@ -7,7 +7,7 @@
class CModelCooker class CModelCooker
{ {
CModel *mpModel; TResPtr<CModel> mpModel;
EGame mVersion; EGame mVersion;
u32 mNumMatSets; u32 mNumMatSets;
u32 mNumSurfaces; u32 mNumSurfaces;

View File

@ -2,13 +2,13 @@
#define CTEXTUREENCODER_H #define CTEXTUREENCODER_H
#include "../CTexture.h" #include "../CTexture.h"
#include <Core/TResPtr.h>
// Class contains basic functionality right now - only supports directly converting DXT1 to CMPR // Class contains basic functionality right now - only supports directly converting DXT1 to CMPR
// More advanced functions (including actual encoding!) coming later // More advanced functions (including actual encoding!) coming later
class CTextureEncoder class CTextureEncoder
{ {
TResPtr<CTexture> mpTexture;
CTexture *mpTexture;
ETexelFormat mSourceFormat; ETexelFormat mSourceFormat;
ETexelFormat mOutputFormat; ETexelFormat mOutputFormat;

View File

@ -14,8 +14,7 @@ CAnimSet* CAnimSetLoader::LoadCorruptionCHAR(CInputStream& CHAR)
CAnimSet::SNode& node = set->nodes[0]; CAnimSet::SNode& node = set->nodes[0];
node.name = CHAR.ReadString(); node.name = CHAR.ReadString();
node.model = (CModel*) gResCache.GetResource(CHAR.ReadLongLong(), "CMDL"); node.model = gResCache.GetResource(CHAR.ReadLongLong(), "CMDL");
node.ModelToken = CToken(node.model);
return set; return set;
} }
@ -29,8 +28,7 @@ CAnimSet* CAnimSetLoader::LoadReturnsCHAR(CInputStream& CHAR)
node.name = CHAR.ReadString(); node.name = CHAR.ReadString();
CHAR.Seek(0x14, SEEK_CUR); CHAR.Seek(0x14, SEEK_CUR);
CHAR.ReadString(); CHAR.ReadString();
node.model = (CModel*) gResCache.GetResource(CHAR.ReadLongLong(), "CMDL"); node.model = gResCache.GetResource(CHAR.ReadLongLong(), "CMDL");
node.ModelToken = CToken(node.model);
return set; return set;
} }
@ -100,10 +98,9 @@ CAnimSet* CAnimSetLoader::LoadANCS(CInputStream& ANCS)
u16 unknown1 = ANCS.ReadShort(); u16 unknown1 = ANCS.ReadShort();
if (n == 0) loader.mVersion = (unknown1 == 0xA) ? eEchoes : ePrime; // Best version indicator we know of unfortunately if (n == 0) loader.mVersion = (unknown1 == 0xA) ? eEchoes : ePrime; // Best version indicator we know of unfortunately
node->name = ANCS.ReadString(); node->name = ANCS.ReadString();
node->model = (CModel*) gResCache.GetResource(ANCS.ReadLong(), "CMDL"); node->model = gResCache.GetResource(ANCS.ReadLong(), "CMDL");
node->skinID = ANCS.ReadLong(); node->skinID = ANCS.ReadLong();
node->skelID = 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. // 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 // Since there's no size value I have to actually read the rest of the node to reach the next one

View File

@ -7,7 +7,7 @@
class CAnimSetLoader class CAnimSetLoader
{ {
CAnimSet *set; TResPtr<CAnimSet> set;
CResCache *mpResCache; CResCache *mpResCache;
EGame mVersion; EGame mVersion;

View File

@ -593,7 +593,7 @@ CGameArea* CAreaLoader::LoadMREA(CInputStream& MREA)
break; break;
default: default:
Log::FileError(MREA.GetSourceString(), "Unsupported MREA version: " + TString::HexString(version)); Log::FileError(MREA.GetSourceString(), "Unsupported MREA version: " + TString::HexString(version));
delete Loader.mpArea; Loader.mpArea.Delete();
return nullptr; return nullptr;
} }

View File

@ -6,13 +6,14 @@
#include "../EFormatVersion.h" #include "../EFormatVersion.h"
#include "CBlockMgrIn.h" #include "CBlockMgrIn.h"
#include <Core/CResCache.h> #include <Core/CResCache.h>
#include <Resource/script/SConnection.h>
class CAreaLoader class CAreaLoader
{ {
struct SCompressedCluster; struct SCompressedCluster;
// Area data // Area data
CGameArea *mpArea; TResPtr<CGameArea> mpArea;
CInputStream *mpMREA; CInputStream *mpMREA;
CBlockMgrIn *mBlockMgr; CBlockMgrIn *mBlockMgr;
EGame mVersion; EGame mVersion;

View File

@ -178,7 +178,7 @@ CCollisionMeshGroup* CCollisionLoader::LoadDCLN(CInputStream &DCLN)
if (deafbabe != 0xDEAFBABE) if (deafbabe != 0xDEAFBABE)
{ {
Log::FileError(DCLN.GetSourceString(), DCLN.Tell() - 4, "Invalid collision magic: " + TString::HexString(deafbabe)); Log::FileError(DCLN.GetSourceString(), DCLN.Tell() - 4, "Invalid collision magic: " + TString::HexString(deafbabe));
delete loader.mpGroup; loader.mpGroup.Delete();
return nullptr; return nullptr;
} }

View File

@ -7,7 +7,7 @@
class CCollisionLoader class CCollisionLoader
{ {
CCollisionMeshGroup *mpGroup; TResPtr<CCollisionMeshGroup> mpGroup;
CCollisionMesh *mpMesh; CCollisionMesh *mpMesh;
EGame mVersion; EGame mVersion;
std::vector<CCollisionMesh::SCollisionProperties> mProperties; std::vector<CCollisionMesh::SCollisionProperties> mProperties;

View File

@ -18,9 +18,8 @@ CFont* CFontLoader::LoadFont(CInputStream& FONT)
mpFont->mDefaultSize = FONT.ReadLong(); mpFont->mDefaultSize = FONT.ReadLong();
mpFont->mFontName = FONT.ReadString(); mpFont->mFontName = FONT.ReadString();
if (mVersion <= eEchoes) mpFont->mpFontTexture = (CTexture*) gResCache.GetResource(FONT.ReadLong(), "TXTR"); if (mVersion <= eEchoes) mpFont->mpFontTexture = gResCache.GetResource(FONT.ReadLong(), "TXTR");
else mpFont->mpFontTexture = (CTexture*) gResCache.GetResource(FONT.ReadLongLong(), "TXTR"); else mpFont->mpFontTexture = gResCache.GetResource(FONT.ReadLongLong(), "TXTR");
mpFont->mTextureToken = CToken(mpFont->mpFontTexture);
mpFont->mTextureFormat = FONT.ReadLong(); mpFont->mTextureFormat = FONT.ReadLong();
u32 NumGlyphs = FONT.ReadLong(); u32 NumGlyphs = FONT.ReadLong();

View File

@ -7,7 +7,7 @@
class CFontLoader class CFontLoader
{ {
CFont *mpFont; TResPtr<CFont> mpFont;
EGame mVersion; EGame mVersion;
CFontLoader(); CFontLoader();

View File

@ -24,7 +24,7 @@ void CMaterialLoader::ReadPrimeMatSet()
for (u32 iTex = 0; iTex < numTextures; iTex++) for (u32 iTex = 0; iTex < numTextures; iTex++)
{ {
u32 TextureID = mpFile->ReadLong(); u32 TextureID = mpFile->ReadLong();
mTextures[iTex] = (CTexture*) gResCache.GetResource(TextureID, "TXTR"); mTextures[iTex] = gResCache.GetResource(TextureID, "TXTR");
} }
// Materials // Materials
@ -137,14 +137,9 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
u8 TexSel = mpFile->ReadByte(); u8 TexSel = mpFile->ReadByte();
if ((TexSel == 0xFF) || (TexSel >= mTextures.size())) if ((TexSel == 0xFF) || (TexSel >= mTextures.size()))
{
pPass->mpTexture = nullptr; pPass->mpTexture = nullptr;
}
else else
{
pPass->mpTexture = mTextures[TextureIndices[TexSel]]; pPass->mpTexture = mTextures[TextureIndices[TexSel]];
pPass->mTexToken = CToken(pPass->mpTexture);
}
TevCoordIndices[iTev] = mpFile->ReadByte(); TevCoordIndices[iTev] = mpFile->ReadByte();
} }
@ -344,9 +339,7 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial()
continue; continue;
} }
CTexture *pTex = (CTexture*) gResCache.GetResource(TextureID, "TXTR"); pPass->mpTexture = gResCache.GetResource(TextureID, "TXTR");
pPass->mpTexture = pTex;
pPass->mTexToken = CToken(pTex);
pPass->mTexCoordSource = 4 + (u8) mpFile->ReadLong(); pPass->mTexCoordSource = 4 + (u8) mpFile->ReadLong();
u32 AnimSize = mpFile->ReadLong(); u32 AnimSize = mpFile->ReadLong();

View File

@ -14,7 +14,7 @@ class CMaterialLoader
CMaterialSet *mpSet; CMaterialSet *mpSet;
CInputStream *mpFile; CInputStream *mpFile;
EGame mVersion; EGame mVersion;
std::vector<CTexture*> mTextures; std::vector<TResPtr<CTexture>> mTextures;
bool mHasOPAC; bool mHasOPAC;
bool mHas0x400; bool mHas0x400;

View File

@ -23,7 +23,7 @@ public:
}; };
private: private:
CModel *mpModel; TResPtr<CModel> mpModel;
std::vector<CMaterialSet*> mMaterials; std::vector<CMaterialSet*> mMaterials;
CBlockMgrIn *mpBlockMgr; CBlockMgrIn *mpBlockMgr;
CAABox mAABox; CAABox mAABox;

View File

@ -10,8 +10,7 @@ CScan* CScanLoader::LoadScanMP1(CInputStream &SCAN)
{ {
// Basic support at the moment - don't read animation/scan image data // Basic support at the moment - don't read animation/scan image data
SCAN.Seek(0x4, SEEK_CUR); // Skip FRME ID SCAN.Seek(0x4, SEEK_CUR); // Skip FRME ID
mpScan->mpStringTable = (CStringTable*) gResCache.GetResource(SCAN.ReadLong(), "STRG"); mpScan->mpStringTable = gResCache.GetResource(SCAN.ReadLong(), "STRG");
mpScan->mStringToken = CToken(mpScan->mpStringTable);
mpScan->mIsSlow = (SCAN.ReadLong() != 0); mpScan->mIsSlow = (SCAN.ReadLong() != 0);
mpScan->mCategory = (CScan::ELogbookCategory) SCAN.ReadLong(); mpScan->mCategory = (CScan::ELogbookCategory) SCAN.ReadLong();
mpScan->mIsImportant = (SCAN.ReadByte() == 1); mpScan->mIsImportant = (SCAN.ReadByte() == 1);
@ -85,8 +84,7 @@ void CScanLoader::LoadParamsMP2(CInputStream& SCAN)
switch (PropertyID) switch (PropertyID)
{ {
case 0x2F5B6423: case 0x2F5B6423:
mpScan->mpStringTable = (CStringTable*) gResCache.GetResource(SCAN.ReadLong(), "STRG"); mpScan->mpStringTable = gResCache.GetResource(SCAN.ReadLong(), "STRG");
mpScan->mStringToken = CToken(mpScan->mpStringTable);
break; break;
case 0xC308A322: case 0xC308A322:
@ -119,8 +117,7 @@ void CScanLoader::LoadParamsMP3(CInputStream& SCAN)
switch (PropertyID) switch (PropertyID)
{ {
case 0x2F5B6423: case 0x2F5B6423:
mpScan->mpStringTable = (CStringTable*) gResCache.GetResource(SCAN.ReadLongLong(), "STRG"); mpScan->mpStringTable = gResCache.GetResource(SCAN.ReadLongLong(), "STRG");
mpScan->mStringToken = CToken(mpScan->mpStringTable);
break; break;
case 0xC308A322: case 0xC308A322:

View File

@ -6,7 +6,7 @@
class CScanLoader class CScanLoader
{ {
CScan *mpScan; TResPtr<CScan> mpScan;
EGame mVersion; EGame mVersion;
CScanLoader(); CScanLoader();

View File

@ -4,10 +4,11 @@
#include "../CStringTable.h" #include "../CStringTable.h"
#include "../EFormatVersion.h" #include "../EFormatVersion.h"
#include <Core/CResCache.h> #include <Core/CResCache.h>
#include <Core/TResPtr.h>
class CStringLoader class CStringLoader
{ {
CStringTable* mpStringTable; TResPtr<CStringTable> mpStringTable;
EGame mVersion; EGame mVersion;
CStringLoader(); CStringLoader();

View File

@ -17,19 +17,19 @@ void CWorldLoader::LoadPrimeMLVL(CInputStream& MLVL)
// Header // Header
if (mVersion < eCorruptionProto) if (mVersion < eCorruptionProto)
{ {
mpWorld->mpWorldName = (CStringTable*) gResCache.GetResource(MLVL.ReadLong(), "STRG"); mpWorld->mpWorldName = gResCache.GetResource(MLVL.ReadLong(), "STRG");
if (mVersion == eEchoes) mpWorld->mpDarkWorldName = (CStringTable*) 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->mUnknown1 = MLVL.ReadLong();
if (mVersion >= ePrime) mpWorld->mpSaveWorld = gResCache.GetResource(MLVL.ReadLong(), "SAVW"); 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 else
{ {
mpWorld->mpWorldName = (CStringTable*) gResCache.GetResource(MLVL.ReadLongLong(), "STRG"); mpWorld->mpWorldName = gResCache.GetResource(MLVL.ReadLongLong(), "STRG");
MLVL.Seek(0x4, SEEK_CUR); // Skipping unknown value MLVL.Seek(0x4, SEEK_CUR); // Skipping unknown value
mpWorld->mpSaveWorld = gResCache.GetResource(MLVL.ReadLongLong(), "SAVW"); 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 // Memory relays - only in MP1
@ -60,11 +60,10 @@ void CWorldLoader::LoadPrimeMLVL(CInputStream& MLVL)
CWorld::SArea *pArea = &mpWorld->mAreas[iArea]; CWorld::SArea *pArea = &mpWorld->mAreas[iArea];
if (mVersion < eCorruptionProto) if (mVersion < eCorruptionProto)
pArea->pAreaName = (CStringTable*) gResCache.GetResource(MLVL.ReadLong(), "STRG"); pArea->pAreaName = gResCache.GetResource(MLVL.ReadLong(), "STRG");
else 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->Transform = CTransform4f(MLVL);
pArea->AetherBox = CAABox(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 // Last part of the file is layer name offsets, but we don't need it
// todo: Layer ID support for MP3 // 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) 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); bool Check = (MLVL.ReadByte() != 0);
if (Check) if (Check)
@ -236,7 +230,7 @@ void CWorldLoader::LoadReturnsMLVL(CInputStream& MLVL)
} }
mpWorld->mpSaveWorld = gResCache.GetResource(MLVL.ReadLongLong(), "SAVW"); mpWorld->mpSaveWorld = gResCache.GetResource(MLVL.ReadLongLong(), "SAVW");
mpWorld->mpDefaultSkybox = (CModel*) gResCache.GetResource(MLVL.ReadLongLong(), "CMDL"); mpWorld->mpDefaultSkybox = gResCache.GetResource(MLVL.ReadLongLong(), "CMDL");
// Areas // Areas
u32 NumAreas = MLVL.ReadLong(); u32 NumAreas = MLVL.ReadLong();
@ -247,12 +241,11 @@ void CWorldLoader::LoadReturnsMLVL(CInputStream& MLVL)
// Area header // Area header
CWorld::SArea *pArea = &mpWorld->mAreas[iArea]; 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->Transform = CTransform4f(MLVL);
pArea->AetherBox = CAABox(MLVL); pArea->AetherBox = CAABox(MLVL);
pArea->FileID = MLVL.ReadLongLong(); pArea->FileID = MLVL.ReadLongLong();
pArea->AreaID = MLVL.ReadLongLong(); pArea->AreaID = MLVL.ReadLongLong();
pArea->AreaNameToken = CToken(pArea->pAreaName);
MLVL.Seek(0x4, SEEK_CUR); MLVL.Seek(0x4, SEEK_CUR);
pArea->InternalName = MLVL.ReadString(); 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 // Last part of the file is layer name offsets, but we don't need it
// todo: Layer ID support // 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) CWorld* CWorldLoader::LoadMLVL(CInputStream& MLVL)

View File

@ -8,7 +8,7 @@
class CWorldLoader class CWorldLoader
{ {
CWorld *mpWorld; TResPtr<CWorld> mpWorld;
EGame mVersion; EGame mVersion;
CWorldLoader(); CWorldLoader();

View File

@ -13,7 +13,7 @@
#include <Common/CColor.h> #include <Common/CColor.h>
#include <Common/CVector3f.h> #include <Common/CVector3f.h>
#include <Common/TString.h> #include <Common/TString.h>
#include <Core/CToken.h> #include <Core/TResPtr.h>
#include <list> #include <list>
class CScriptTemplate; class CScriptTemplate;
@ -65,48 +65,11 @@ typedef __CProperty<float, eFloatProperty> CFloatProperty;
typedef __CProperty<TString, eStringProperty> CStringProperty; typedef __CProperty<TString, eStringProperty> CStringProperty;
typedef __CProperty<CVector3f, eVector3Property> CVector3Property; typedef __CProperty<CVector3f, eVector3Property> CVector3Property;
typedef __CProperty<CColor, eColorProperty> CColorProperty; typedef __CProperty<CColor, eColorProperty> CColorProperty;
typedef __CProperty<CResource*, eFileProperty> CFileProperty; typedef __CProperty<TResPtr<CResource>, eFileProperty> CFileProperty;
typedef __CProperty<CAnimationParameters, eAnimParamsProperty> CAnimParamsProperty; typedef __CProperty<CAnimationParameters, eAnimParamsProperty> CAnimParamsProperty;
typedef __CProperty<std::vector<u8>, eArrayProperty> CArrayProperty; typedef __CProperty<std::vector<u8>, eArrayProperty> CArrayProperty;
typedef __CProperty<std::vector<u8>, eUnknownProperty> CUnknownProperty; typedef __CProperty<std::vector<u8>, eUnknownProperty> CUnknownProperty;
/*
* Template specialization for CFileProperty to allow a token for resources
*/
template <>
class __CProperty<CResource*, eFileProperty> : public CPropertyBase
{
CResource *mValue;
CToken mToken;
public:
__CProperty<CResource*, eFileProperty>() {
mValue = nullptr;
}
__CProperty<CResource*, eFileProperty>(CResource* v) {
mValue = v;
mToken = CToken(v);
}
~__CProperty<CResource*, eFileProperty>() {}
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<CFileTemplate*>(Template())->Extensions();
}
};
/* /*
* CPropertyStruct is for defining structs of properties. * CPropertyStruct is for defining structs of properties.
*/ */

View File

@ -47,19 +47,16 @@ void CScriptObject::EvaluateProperties()
void CScriptObject::EvaluateDisplayModel() void CScriptObject::EvaluateDisplayModel()
{ {
mpDisplayModel = mpTemplate->FindDisplayModel(mpProperties); mpDisplayModel = mpTemplate->FindDisplayModel(mpProperties);
mModelToken = CToken(mpDisplayModel);
} }
void CScriptObject::EvaluateBillboard() void CScriptObject::EvaluateBillboard()
{ {
mpBillboard = mpTemplate->FindBillboardTexture(mpProperties); mpBillboard = mpTemplate->FindBillboardTexture(mpProperties);
mBillboardToken = CToken(mpBillboard);
} }
void CScriptObject::EvaluateCollisionModel() void CScriptObject::EvaluateCollisionModel()
{ {
mpCollision = mpTemplate->FindCollision(mpProperties); mpCollision = mpTemplate->FindCollision(mpProperties);
mCollisionToken = CToken(mpCollision);
} }
// ************ GETTERS ************ // ************ GETTERS ************

View File

@ -7,8 +7,8 @@
#include "CScriptTemplate.h" #include "CScriptTemplate.h"
#include "../model/CModel.h" #include "../model/CModel.h"
#include "../CCollisionMeshGroup.h" #include "../CCollisionMeshGroup.h"
#include "../CGameArea.h"
class CGameArea;
class CScriptLayer; class CScriptLayer;
class CScriptObject class CScriptObject
@ -17,7 +17,7 @@ class CScriptObject
friend class CAreaLoader; friend class CAreaLoader;
CScriptTemplate *mpTemplate; CScriptTemplate *mpTemplate;
CGameArea *mpArea; TResPtr<CGameArea> mpArea;
CScriptLayer *mpLayer; CScriptLayer *mpLayer;
u32 mInstanceID; u32 mInstanceID;
@ -31,12 +31,9 @@ class CScriptObject
CVector3Property *mpScale; CVector3Property *mpScale;
CBoolProperty *mpActive; CBoolProperty *mpActive;
CPropertyStruct *mpLightParameters; CPropertyStruct *mpLightParameters;
CModel *mpDisplayModel; TResPtr<CModel> mpDisplayModel;
CTexture *mpBillboard; TResPtr<CTexture> mpBillboard;
CCollisionMeshGroup *mpCollision; TResPtr<CCollisionMeshGroup> mpCollision;
CToken mModelToken;
CToken mBillboardToken;
CToken mCollisionToken;
bool mHasInGameModel; bool mHasInGameModel;
EVolumeShape mVolumeShape; EVolumeShape mVolumeShape;

View File

@ -54,5 +54,4 @@ SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*Ray*/, u32 /
void CCollisionNode::SetCollision(CCollisionMeshGroup *pCollision) void CCollisionNode::SetCollision(CCollisionMeshGroup *pCollision)
{ {
mpCollision = pCollision; mpCollision = pCollision;
mCollisionToken = CToken(pCollision);
} }

View File

@ -6,8 +6,7 @@
class CCollisionNode : public CSceneNode class CCollisionNode : public CSceneNode
{ {
CCollisionMeshGroup *mpCollision; TResPtr<CCollisionMeshGroup> mpCollision;
CToken mCollisionToken;
public: public:
CCollisionNode(CSceneManager *pScene, CSceneNode *pParent = 0, CCollisionMeshGroup *pCollision = 0); CCollisionNode(CSceneManager *pScene, CSceneNode *pParent = 0, CCollisionMeshGroup *pCollision = 0);

View File

@ -105,7 +105,6 @@ SRayIntersection CModelNode::RayNodeIntersectTest(const CRay &Ray, u32 AssetID,
void CModelNode::SetModel(CModel *pModel) void CModelNode::SetModel(CModel *pModel)
{ {
mpModel = pModel; mpModel = pModel;
mModelToken = CToken(pModel);
mActiveMatSet = 0; mActiveMatSet = 0;
if (pModel) if (pModel)

View File

@ -6,8 +6,7 @@
class CModelNode : public CSceneNode class CModelNode : public CSceneNode
{ {
CModel *mpModel; TResPtr<CModel> mpModel;
CToken mModelToken;
u32 mActiveMatSet; u32 mActiveMatSet;
bool mLightingEnabled; bool mLightingEnabled;
bool mForceAlphaOn; bool mForceAlphaOn;

View File

@ -9,6 +9,7 @@
#include <Core/CResCache.h> #include <Core/CResCache.h>
#include <Core/CSceneManager.h> #include <Core/CSceneManager.h>
#include <Resource/script/CMasterTemplate.h> #include <Resource/script/CMasterTemplate.h>
#include <Resource/script/CScriptLayer.h>
CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObject *pObject) CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObject *pObject)
: CSceneNode(pScene, pParent) : CSceneNode(pScene, pParent)
@ -37,11 +38,7 @@ CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObje
// Determine display assets // Determine display assets
mpActiveModel = mpInstance->GetDisplayModel(); mpActiveModel = mpInstance->GetDisplayModel();
mModelToken = CToken(mpActiveModel);
mpBillboard = mpInstance->GetBillboard(); mpBillboard = mpInstance->GetBillboard();
mBillboardToken = CToken(mpBillboard);
mpCollisionNode->SetCollision(mpInstance->GetCollision()); mpCollisionNode->SetCollision(mpInstance->GetCollision());
// Create preview volume node // Create preview volume node
@ -51,19 +48,19 @@ CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObje
if (mHasVolumePreview) if (mHasVolumePreview)
{ {
EVolumeShape shape = mpInstance->VolumeShape(); EVolumeShape shape = mpInstance->VolumeShape();
CModel *pVolumeModel = nullptr; TResPtr<CModel> pVolumeModel = nullptr;
if ((shape == eAxisAlignedBoxShape) || (shape == eBoxShape)) if ((shape == eAxisAlignedBoxShape) || (shape == eBoxShape))
pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeBox.cmdl"); pVolumeModel = gResCache.GetResource("../resources/VolumeBox.cmdl");
else if (shape == eEllipsoidShape) else if (shape == eEllipsoidShape)
pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeSphere.cmdl"); pVolumeModel = gResCache.GetResource("../resources/VolumeSphere.cmdl");
else if (shape == eCylinderShape) else if (shape == eCylinderShape)
pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeCylinder.cmdl"); pVolumeModel = gResCache.GetResource("../resources/VolumeCylinder.cmdl");
else if (shape == eCylinderLargeShape) else if (shape == eCylinderLargeShape)
pVolumeModel = (CModel*) gResCache.GetResource("../resources/VolumeCylinderLarge.cmdl"); pVolumeModel = gResCache.GetResource("../resources/VolumeCylinderLarge.cmdl");
if (pVolumeModel) if (pVolumeModel)
{ {

View File

@ -12,10 +12,8 @@ class CScriptNode : public CSceneNode
CScriptObject *mpInstance; CScriptObject *mpInstance;
class CScriptExtra *mpExtra; class CScriptExtra *mpExtra;
CModel *mpActiveModel; TResPtr<CModel> mpActiveModel;
CTexture *mpBillboard; TResPtr<CTexture> mpBillboard;
CToken mModelToken;
CToken mBillboardToken;
CCollisionNode *mpCollisionNode; CCollisionNode *mpCollisionNode;
bool mHasValidPosition; bool mHasValidPosition;

View File

@ -167,13 +167,12 @@ void CDamageableTriggerExtra::PropertyModified(CPropertyBase *pProperty)
{ {
if (pProperty == mpTextureProps[iTex]) if (pProperty == mpTextureProps[iTex])
{ {
mpTextures[iTex] = (CTexture*) mpTextureProps[iTex]->Get(); mpTextures[iTex] = mpTextureProps[iTex]->Get();
if (mpTextures[iTex] && mpTextures[iTex]->Type() != eTexture) if (mpTextures[iTex] && mpTextures[iTex]->Type() != eTexture)
mpTextures[iTex] = nullptr; mpTextures[iTex] = nullptr;
mpMat->Pass(iTex)->SetTexture(mpTextures[iTex]); mpMat->Pass(iTex)->SetTexture(mpTextures[iTex]);
mTextureTokens[iTex] = CToken(mpTextures[iTex]);
break; break;
} }
} }

View File

@ -23,8 +23,7 @@ class CDamageableTriggerExtra : public CScriptExtra
CVector3f mPlaneSize; CVector3f mPlaneSize;
ERenderSide mRenderSide; ERenderSide mRenderSide;
CTexture *mpTextures[3]; TResPtr<CTexture> mpTextures[3];
CToken mTextureTokens[3];
CMaterial *mpMat; CMaterial *mpMat;
CVector2f mCoordScale; CVector2f mCoordScale;

View File

@ -25,20 +25,13 @@ void CDoorExtra::PropertyModified(CPropertyBase *pProperty)
{ {
if (pProperty == mpShieldModelProp) if (pProperty == mpShieldModelProp)
{ {
mpShieldModel = (CModel*) mpShieldModelProp->Get(); mpShieldModel = mpShieldModelProp->Get();
if (mpShieldModel && mpShieldModel->Type() == eModel) if (mpShieldModel)
{
mModelToken = CToken(mpShieldModel);
mLocalAABox = mpShieldModel->AABox(); mLocalAABox = mpShieldModel->AABox();
}
else else
{
mpShieldModel = nullptr;
mModelToken.Unlock();
mLocalAABox = CAABox::skInfinite; mLocalAABox = CAABox::skInfinite;
}
MarkTransformChanged(); MarkTransformChanged();
} }

View File

@ -8,9 +8,7 @@ class CDoorExtra : public CScriptExtra
// Render colored door shield in MP2/3 // Render colored door shield in MP2/3
CFileProperty *mpShieldModelProp; CFileProperty *mpShieldModelProp;
CColorProperty *mpShieldColorProp; CColorProperty *mpShieldColorProp;
TResPtr<CModel> mpShieldModel;
CModel *mpShieldModel;
CToken mModelToken;
public: public:
explicit CDoorExtra(CScriptObject *pInstance, CSceneManager *pScene, CSceneNode *pParent = 0); explicit CDoorExtra(CScriptObject *pInstance, CSceneManager *pScene, CSceneNode *pParent = 0);

View File

@ -42,18 +42,7 @@ CPointOfInterestExtra::CPointOfInterestExtra(CScriptObject *pInstance, CSceneMan
void CPointOfInterestExtra::PropertyModified(CPropertyBase* pProperty) void CPointOfInterestExtra::PropertyModified(CPropertyBase* pProperty)
{ {
if (mpScanProperty == pProperty) if (mpScanProperty == pProperty)
{ mpScanData = mpScanProperty->Get();
mpScanData = (CScan*) mpScanProperty->Get();
if (mpScanData && mpScanData->Type() == eScan)
mScanToken = CToken(mpScanData);
else
{
mpScanData = nullptr;
mScanToken.Unlock();
}
}
} }
void CPointOfInterestExtra::ModifyTintColor(CColor& Color) void CPointOfInterestExtra::ModifyTintColor(CColor& Color)

View File

@ -9,8 +9,7 @@ class CPointOfInterestExtra : public CScriptExtra
{ {
// Tint POI billboard orange/red depending on scan importance // Tint POI billboard orange/red depending on scan importance
CFileProperty *mpScanProperty; CFileProperty *mpScanProperty;
CScan *mpScanData; TResPtr<CScan> mpScanData;
CToken mScanToken;
public: public:
explicit CPointOfInterestExtra(CScriptObject *pInstance, CSceneManager *pScene, CSceneNode *pParent = 0); explicit CPointOfInterestExtra(CScriptObject *pInstance, CSceneManager *pScene, CSceneNode *pParent = 0);

View File

@ -12,7 +12,7 @@ CWaypointExtra::CWaypointExtra(CScriptObject *pInstance, CSceneManager *pScene,
CScriptNode *pScript = static_cast<CScriptNode*>(pParent); CScriptNode *pScript = static_cast<CScriptNode*>(pParent);
CModel *pModel = pScript->ActiveModel(); 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); CMaterial *pMat = pModel->GetMaterialByIndex(0, 0);
mColor = pMat->Konst(0); mColor = pMat->Konst(0);

View File

@ -625,32 +625,32 @@ void CGizmo::LoadModels()
{ {
Log::Write("Loading transform gizmo models"); Log::Write("Loading transform gizmo models");
smTranslateModels[CGIZMO_TRANSLATE_X] = SModelPart(eX, true, false, (CModel*) gResCache.GetResource("../resources/editor/TranslateX.CMDL")); smTranslateModels[CGIZMO_TRANSLATE_X] = SModelPart(eX, true, false, gResCache.GetResource("../resources/editor/TranslateX.CMDL"));
smTranslateModels[CGIZMO_TRANSLATE_Y] = SModelPart(eY, true, false, (CModel*) gResCache.GetResource("../resources/editor/TranslateY.CMDL")); smTranslateModels[CGIZMO_TRANSLATE_Y] = SModelPart(eY, true, false, gResCache.GetResource("../resources/editor/TranslateY.CMDL"));
smTranslateModels[CGIZMO_TRANSLATE_Z] = SModelPart(eZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/TranslateZ.CMDL")); smTranslateModels[CGIZMO_TRANSLATE_Z] = SModelPart(eZ, true, false, 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_XY] = SModelPart(eXY, true, false, 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_XZ] = SModelPart(eXZ, true, false, 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_LINES_YZ] = SModelPart(eYZ, true, false, 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_XY] = SModelPart(eXY, false, false, 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_XZ] = SModelPart(eXZ, false, false, 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_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_OUTLINE] = SModelPart(eNone, true, true, gResCache.GetResource("../resources/editor/RotateClipOutline.CMDL"));
smRotateModels[CGIZMO_ROTATE_X] = SModelPart(eX, true, false, (CModel*) gResCache.GetResource("../resources/editor/RotateX.CMDL")); smRotateModels[CGIZMO_ROTATE_X] = SModelPart(eX, true, false, gResCache.GetResource("../resources/editor/RotateX.CMDL"));
smRotateModels[CGIZMO_ROTATE_Y] = SModelPart(eY, true, false, (CModel*) gResCache.GetResource("../resources/editor/RotateY.CMDL")); smRotateModels[CGIZMO_ROTATE_Y] = SModelPart(eY, true, false, gResCache.GetResource("../resources/editor/RotateY.CMDL"));
smRotateModels[CGIZMO_ROTATE_Z] = SModelPart(eZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/RotateZ.CMDL")); smRotateModels[CGIZMO_ROTATE_Z] = SModelPart(eZ, true, false, gResCache.GetResource("../resources/editor/RotateZ.CMDL"));
smRotateModels[CGIZMO_ROTATE_XYZ] = SModelPart(eXYZ, false, false, (CModel*) gResCache.GetResource("../resources/editor/RotateXYZ.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_X] = SModelPart(eX, true, false, gResCache.GetResource("../resources/editor/ScaleX.CMDL"));
smScaleModels[CGIZMO_SCALE_Y] = SModelPart(eY, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScaleY.CMDL")); smScaleModels[CGIZMO_SCALE_Y] = SModelPart(eY, true, false, gResCache.GetResource("../resources/editor/ScaleY.CMDL"));
smScaleModels[CGIZMO_SCALE_Z] = SModelPart(eZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScaleZ.CMDL")); smScaleModels[CGIZMO_SCALE_Z] = SModelPart(eZ, true, false, 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_XY] = SModelPart(eXY, true, false, 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_XZ] = SModelPart(eXZ, true, false, 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_LINES_YZ] = SModelPart(eYZ, true, false, 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_XY] = SModelPart(eXY, true, false, 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_XZ] = SModelPart(eXZ, true, false, 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_POLY_YZ] = SModelPart(eYZ, true, false, gResCache.GetResource("../resources/editor/ScalePolyYZ.CMDL"));
smScaleModels[CGIZMO_SCALE_XYZ] = SModelPart(eXYZ, true, false, (CModel*) gResCache.GetResource("../resources/editor/ScaleXYZ.CMDL")); smScaleModels[CGIZMO_SCALE_XYZ] = SModelPart(eXYZ, true, false, gResCache.GetResource("../resources/editor/ScaleXYZ.CMDL"));
smModelsLoaded = true; smModelsLoaded = true;
} }

View File

@ -7,7 +7,7 @@
#include <Common/EnumUtil.h> #include <Common/EnumUtil.h>
#include <Common/ETransformSpace.h> #include <Common/ETransformSpace.h>
#include <Core/CCamera.h> #include <Core/CCamera.h>
#include <Core/CToken.h> #include <Core/TResPtr.h>
#include <Core/IRenderable.h> #include <Core/IRenderable.h>
#include <Resource/model/CModel.h> #include <Resource/model/CModel.h>
@ -104,12 +104,11 @@ private:
EGizmoAxes modelAxes; EGizmoAxes modelAxes;
bool enableRayCast; bool enableRayCast;
bool isBillboard; bool isBillboard;
CModel *pModel; TResPtr<CModel> pModel;
CToken modelToken;
SModelPart() {} SModelPart() {}
SModelPart(EGizmoAxes axes, bool rayCastOn, bool billboard, CModel *_pModel) : SModelPart(EGizmoAxes axes, bool rayCastOn, bool billboard, TResPtr<CModel> _pModel) :
modelAxes(axes), enableRayCast(rayCastOn), isBillboard(billboard), pModel(_pModel), modelToken(_pModel) {} modelAxes(axes), enableRayCast(rayCastOn), isBillboard(billboard), pModel(_pModel) {}
}; };
SModelPart *mpCurrentParts; SModelPart *mpCurrentParts;
u32 mNumCurrentParts; u32 mNumCurrentParts;

View File

@ -154,7 +154,6 @@ void CModelEditorWindow::SetActiveModel(CModel *pModel)
{ {
mpCurrentModelNode->SetModel(pModel); mpCurrentModelNode->SetModel(pModel);
mpCurrentModel = pModel; mpCurrentModel = pModel;
mModelToken = CToken(pModel);
ui->Viewport->Camera().SetOrbit(pModel->AABox()); ui->Viewport->Camera().SetOrbit(pModel->AABox());
u32 numVertices = (pModel ? pModel->GetVertexCount() : 0); u32 numVertices = (pModel ? pModel->GetVertexCount() : 0);
@ -569,7 +568,7 @@ void CModelEditorWindow::UpdateMaterial(QString Value)
if (mIgnoreSignals) return; if (mIgnoreSignals) return;
EModelEditorWidget Widget = (EModelEditorWidget) sender()->property("ModelEditorWidgetType").toInt(); EModelEditorWidget Widget = (EModelEditorWidget) sender()->property("ModelEditorWidgetType").toInt();
CTexture *pTex = (CTexture*) gResCache.GetResource(TO_TSTRING(Value)); TResPtr<CTexture> pTex = gResCache.GetResource(TO_TSTRING(Value));
if (pTex->Type() != eTexture) pTex = nullptr; if (pTex->Type() != eTexture) pTex = nullptr;
switch (Widget) switch (Widget)
@ -712,7 +711,7 @@ void CModelEditorWindow::on_actionConvert_to_DDS_triggered()
if (Input.isEmpty()) return; if (Input.isEmpty()) return;
TString TexFilename = Input.toStdString(); TString TexFilename = Input.toStdString();
CTexture *Tex = (CTexture*) gResCache.GetResource(TexFilename); TResPtr<CTexture> pTex = (CTexture*) gResCache.GetResource(TexFilename);
TString OutName = TexFilename.GetFilePathWithoutExtension() + ".dds"; TString OutName = TexFilename.GetFilePathWithoutExtension() + ".dds";
CFileOutStream Out(OutName.ToStdString(), IOUtil::LittleEndian); CFileOutStream Out(OutName.ToStdString(), IOUtil::LittleEndian);
@ -720,7 +719,7 @@ void CModelEditorWindow::on_actionConvert_to_DDS_triggered()
else else
{ {
bool success = Tex->WriteDDS(Out); bool success = pTex->WriteDDS(Out);
if (!success) QMessageBox::warning(this, "Error", "Couldn't write output DDS!"); if (!success) QMessageBox::warning(this, "Error", "Couldn't write output DDS!");
else QMessageBox::information(this, "Success", "Successfully converted to 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)"); QString ModelFilename = QFileDialog::getOpenFileName(this, "Save model", "", "Retro Model (*.CMDL)");
if (ModelFilename.isEmpty()) return; if (ModelFilename.isEmpty()) return;
CModel *pModel = (CModel*) gResCache.GetResource(ModelFilename.toStdString()); TResPtr<CModel> pModel = gResCache.GetResource(ModelFilename.toStdString());
if (pModel) if (pModel)
{ {
SetActiveModel(pModel); SetActiveModel(pModel);

View File

@ -23,8 +23,7 @@ class CModelEditorWindow : public QMainWindow
Ui::CModelEditorWindow *ui; Ui::CModelEditorWindow *ui;
CSceneManager *mpScene; CSceneManager *mpScene;
QString mOutputFilename; QString mOutputFilename;
CModel *mpCurrentModel; TResPtr<CModel> mpCurrentModel;
CToken mModelToken;
CModelNode *mpCurrentModelNode; CModelNode *mpCurrentModelNode;
CMaterial *mpCurrentMat; CMaterial *mpCurrentMat;
CMaterialPass *mpCurrentPass; CMaterialPass *mpCurrentPass;

View File

@ -32,8 +32,7 @@ void CStartWindow::on_actionOpen_MLVL_triggered()
if (WorldFile.isEmpty()) return; if (WorldFile.isEmpty()) return;
gResCache.SetFolder(TString(WorldFile.toStdString()).GetFileDirectory()); gResCache.SetFolder(TString(WorldFile.toStdString()).GetFileDirectory());
mpWorld = (CWorld*) gResCache.GetResource(WorldFile.toStdString()); mpWorld = gResCache.GetResource(WorldFile.toStdString());
mWorldToken = CToken(mpWorld);
mpWorldEditor->close(); mpWorldEditor->close();
FillWorldUI(); FillWorldUI();
@ -156,7 +155,7 @@ void CStartWindow::on_AttachedAreasList_doubleClicked(const QModelIndex &index)
void CStartWindow::on_LaunchWorldEditorButton_clicked() void CStartWindow::on_LaunchWorldEditorButton_clicked()
{ {
u64 AreaID = mpWorld->GetAreaResourceID(mSelectedAreaIndex); u64 AreaID = mpWorld->GetAreaResourceID(mSelectedAreaIndex);
CGameArea *pArea = (CGameArea*) gResCache.GetResource(AreaID, "MREA"); TResPtr<CGameArea> pArea = gResCache.GetResource(AreaID, "MREA");
if (!pArea) if (!pArea)
{ {

View File

@ -16,8 +16,7 @@ class CStartWindow : public QMainWindow
Q_OBJECT Q_OBJECT
Ui::CStartWindow *ui; Ui::CStartWindow *ui;
CWorld *mpWorld; TResPtr<CWorld> mpWorld;
CToken mWorldToken;
u32 mSelectedAreaIndex; u32 mSelectedAreaIndex;
CWorldEditor *mpWorldEditor; CWorldEditor *mpWorldEditor;

View File

@ -107,9 +107,6 @@ void CWorldEditor::SetArea(CWorld *pWorld, CGameArea *pArea)
// Load new area // Load new area
mpArea = pArea; mpArea = pArea;
mpWorld = pWorld; mpWorld = pWorld;
mAreaToken = CToken(pArea);
mWorldToken = CToken(pWorld);
mScene.SetActiveWorld(pWorld); mScene.SetActiveWorld(pWorld);
mScene.SetActiveArea(pArea); mScene.SetActiveArea(pArea);

View File

@ -17,7 +17,7 @@
#include <Common/ETransformSpace.h> #include <Common/ETransformSpace.h>
#include <Core/CRenderer.h> #include <Core/CRenderer.h>
#include <Core/CSceneManager.h> #include <Core/CSceneManager.h>
#include <Core/CToken.h> #include <Core/TResPtr.h>
#include <Resource/CGameArea.h> #include <Resource/CGameArea.h>
#include <Resource/CWorld.h> #include <Resource/CWorld.h>
@ -30,10 +30,8 @@ class CWorldEditor : public INodeEditor
Q_OBJECT Q_OBJECT
Ui::CWorldEditor *ui; Ui::CWorldEditor *ui;
CWorld *mpWorld; TResPtr<CWorld> mpWorld;
CGameArea *mpArea; TResPtr<CGameArea> mpArea;
CToken mAreaToken;
CToken mWorldToken;
QTimer mRefreshTimer; QTimer mRefreshTimer;
public: public:

View File

@ -7,6 +7,7 @@
#include "WVectorEditor.h" #include "WVectorEditor.h"
#include "WAnimParamsEditor.h" #include "WAnimParamsEditor.h"
#include <Resource/CAnimSet.h> #include <Resource/CAnimSet.h>
#include <Resource/script/CScriptLayer.h>
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox> #include <QComboBox>
@ -254,10 +255,11 @@ void WPropertyEditor::CreateEditor()
case eFileProperty: case eFileProperty:
{ {
CFileProperty *pFileCast = static_cast<CFileProperty*>(mpProperty); CFileProperty *pFileCast = static_cast<CFileProperty*>(mpProperty);
CFileTemplate *pFileTemp = static_cast<CFileTemplate*>(pFileCast->Template());
WResourceSelector *pResourceSelector = new WResourceSelector(this); WResourceSelector *pResourceSelector = new WResourceSelector(this);
pResourceSelector->AdjustPreviewToParent(true); pResourceSelector->AdjustPreviewToParent(true);
pResourceSelector->SetAllowedExtensions(pFileCast->AllowedExtensions()); pResourceSelector->SetAllowedExtensions(pFileTemp->Extensions());
pResourceSelector->SetResource(pFileCast->Get()); pResourceSelector->SetResource(pFileCast->Get());
mUI.EditorWidget = pResourceSelector; mUI.EditorWidget = pResourceSelector;
@ -431,8 +433,9 @@ void WPropertyEditor::UpdateEditor()
case eFileProperty: case eFileProperty:
{ {
CFileProperty *pFileCast = static_cast<CFileProperty*>(mpProperty); CFileProperty *pFileCast = static_cast<CFileProperty*>(mpProperty);
CFileTemplate *pFileTemp = static_cast<CFileTemplate*>(pFileCast->Template());
WResourceSelector *pResourceSelector = static_cast<WResourceSelector*>(mUI.EditorWidget); WResourceSelector *pResourceSelector = static_cast<WResourceSelector*>(mUI.EditorWidget);
pResourceSelector->SetAllowedExtensions(pFileCast->AllowedExtensions()); pResourceSelector->SetAllowedExtensions(pFileTemp->Extensions());
pResourceSelector->SetResource(pFileCast->Get()); pResourceSelector->SetResource(pFileCast->Get());
break; break;
} }

View File

@ -134,7 +134,6 @@ bool WResourceSelector::IsPreviewPanelEnabled()
void WResourceSelector::SetResource(CResource *pRes) void WResourceSelector::SetResource(CResource *pRes)
{ {
mpResource = pRes; mpResource = pRes;
mResToken = CToken(pRes);
if (pRes) if (pRes)
{ {
@ -261,7 +260,6 @@ void WResourceSelector::Export()
void WResourceSelector::LoadResource(const QString& ResPath) void WResourceSelector::LoadResource(const QString& ResPath)
{ {
mpResource = nullptr; mpResource = nullptr;
mResToken.Unlock();
TString pathStr = ResPath.toStdString(); TString pathStr = ResPath.toStdString();
TString ext = pathStr.GetFileExtension(); TString ext = pathStr.GetFileExtension();
@ -271,7 +269,6 @@ void WResourceSelector::LoadResource(const QString& ResPath)
if ((ext != "MREA") && (ext != "MLVL")) if ((ext != "MREA") && (ext != "MLVL"))
{ {
mpResource = gResCache.GetResource(pathStr); mpResource = gResCache.GetResource(pathStr);
mResToken = CToken(mpResource);
mResourceValid = (mpResource != nullptr); mResourceValid = (mpResource != nullptr);
if (mPreviewPanelValid) mpPreviewPanel->SetResource(mpResource); if (mPreviewPanelValid) mpPreviewPanel->SetResource(mpResource);

View File

@ -3,7 +3,7 @@
#include "IPreviewPanel.h" #include "IPreviewPanel.h"
#include <Common/CFourCC.h> #include <Common/CFourCC.h>
#include <Core/CToken.h> #include <Core/TResPtr.h>
#include <Resource/EResType.h> #include <Resource/EResType.h>
#include <QLabel> #include <QLabel>
@ -29,8 +29,7 @@ class WResourceSelector : public QWidget
bool mAdjustPreviewToParent; bool mAdjustPreviewToParent;
// Resource // Resource
CResource *mpResource; TResPtr<CResource> mpResource;
CToken mResToken;
bool mResourceValid; bool mResourceValid;
// UI // UI

View File

@ -77,7 +77,6 @@ void WTextureGLWidget::resizeGL(int w, int h)
void WTextureGLWidget::SetTexture(CTexture *pTex) void WTextureGLWidget::SetTexture(CTexture *pTex)
{ {
mpTexture = pTex; mpTexture = pTex;
mTexToken = CToken(pTex);
if (pTex) mTexAspectRatio = (float) pTex->Width() / (float) pTex->Height(); if (pTex) mTexAspectRatio = (float) pTex->Width() / (float) pTex->Height();
else mTexAspectRatio = 0.f; else mTexAspectRatio = 0.f;

View File

@ -6,7 +6,7 @@
#include <Common/CTransform4f.h> #include <Common/CTransform4f.h>
#include <Common/CVector2f.h> #include <Common/CVector2f.h>
#include <Core/CToken.h> #include <Core/TResPtr.h>
#include <Resource/CTexture.h> #include <Resource/CTexture.h>
#include <QTimer> #include <QTimer>
@ -15,8 +15,7 @@ class WTextureGLWidget : public QOpenGLWidget
Q_OBJECT Q_OBJECT
float mAspectRatio; float mAspectRatio;
CTexture *mpTexture; TResPtr<CTexture> mpTexture;
CToken mTexToken;
float mTexAspectRatio; float mTexAspectRatio;
CTransform4f mTexTransform; CTransform4f mTexTransform;
CVector2f mCheckerCoords[4]; CVector2f mCheckerCoords[4];

View File

@ -1,6 +1,7 @@
#include "CLayerEditor.h" #include "CLayerEditor.h"
#include "ui_CLayerEditor.h" #include "ui_CLayerEditor.h"
#include "../UICommon.h" #include "../UICommon.h"
#include <Resource/script/CScriptLayer.h>
CLayerEditor::CLayerEditor(QWidget *parent) : CLayerEditor::CLayerEditor(QWidget *parent) :
QDialog(parent), QDialog(parent),

View File

@ -11,7 +11,7 @@ class CLayerEditor;
class CLayerEditor : public QDialog class CLayerEditor : public QDialog
{ {
Q_OBJECT Q_OBJECT
CGameArea *mpArea; TResPtr<CGameArea> mpArea;
CLayerModel *mpModel; CLayerModel *mpModel;
CScriptLayer *mpCurrentLayer; CScriptLayer *mpCurrentLayer;

View File

@ -1,5 +1,6 @@
#include "CLayerModel.h" #include "CLayerModel.h"
#include "../UICommon.h" #include "../UICommon.h"
#include <Resource/script/CScriptLayer.h>
CLayerModel::CLayerModel(QObject *pParent) : QAbstractListModel(pParent) CLayerModel::CLayerModel(QObject *pParent) : QAbstractListModel(pParent)
{ {

View File

@ -6,7 +6,7 @@
class CLayerModel : public QAbstractListModel class CLayerModel : public QAbstractListModel
{ {
CGameArea *mpArea; TResPtr<CGameArea> mpArea;
bool mHasGenerateLayer; bool mHasGenerateLayer;
public: public:

View File

@ -24,7 +24,7 @@ public:
private: private:
CWorldEditor *mpEditor; CWorldEditor *mpEditor;
CSceneManager *mpScene; CSceneManager *mpScene;
CGameArea *mpArea; TResPtr<CGameArea> mpArea;
public: public:
explicit CLayersInstanceModel(QObject *pParent = 0); explicit CLayersInstanceModel(QObject *pParent = 0);

View File

@ -1,5 +1,6 @@
#include "CTypesInstanceModel.h" #include "CTypesInstanceModel.h"
#include "../UICommon.h" #include "../UICommon.h"
#include <Resource/script/CScriptLayer.h>
#include <Scene/CScriptNode.h> #include <Scene/CScriptNode.h>
#include <QApplication> #include <QApplication>
#include <QIcon> #include <QIcon>

View File

@ -30,7 +30,7 @@ public:
private: private:
CWorldEditor *mpEditor; CWorldEditor *mpEditor;
CSceneManager *mpScene; CSceneManager *mpScene;
CGameArea *mpArea; TResPtr<CGameArea> mpArea;
CMasterTemplate *mpCurrentMaster; CMasterTemplate *mpCurrentMaster;
EInstanceModelType mModelType; EInstanceModelType mModelType;
QList<CScriptTemplate*> mTemplateList; QList<CScriptTemplate*> mTemplateList;

View File

@ -3,6 +3,7 @@
#include "../CWorldEditor.h" #include "../CWorldEditor.h"
#include <Core/CSceneManager.h> #include <Core/CSceneManager.h>
#include <Resource/script/CScriptLayer.h>
WInstancesTab::WInstancesTab(QWidget *parent) : WInstancesTab::WInstancesTab(QWidget *parent) :
QWidget(parent), QWidget(parent),