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 eEchoes:
return (CModel*) static_cast<CFileProperty*>(pBaseStruct->PropertyByIndex(7))->Get();
return (CModel*) static_cast<CFileProperty*>(pBaseStruct->PropertyByIndex(7))->Get().RawPointer();
case eCorruption:
return (CModel*) static_cast<CFileProperty*>(pBaseStruct->PropertyByIndex(8))->Get();
return (CModel*) static_cast<CFileProperty*>(pBaseStruct->PropertyByIndex(8))->Get().RawPointer();
default:
return nullptr;
}

View File

@ -15,19 +15,15 @@ CIndexBuffer CDrawUtil::mSquareIndices;
CDynamicVertexBuffer CDrawUtil::mLineVertices;
CIndexBuffer CDrawUtil::mLineIndices;
CModel *CDrawUtil::mpCubeModel;
CToken CDrawUtil::mCubeToken;
TResPtr<CModel> CDrawUtil::mpCubeModel;
CVertexBuffer CDrawUtil::mWireCubeVertices;
CIndexBuffer CDrawUtil::mWireCubeIndices;
CModel *CDrawUtil::mpSphereModel;
CModel *CDrawUtil::mpDoubleSidedSphereModel;
CToken CDrawUtil::mSphereToken;
CToken CDrawUtil::mDoubleSidedSphereToken;
TResPtr<CModel> CDrawUtil::mpSphereModel;
TResPtr<CModel> CDrawUtil::mpDoubleSidedSphereModel;
CModel *CDrawUtil::mpWireSphereModel;
CToken CDrawUtil::mWireSphereToken;
TResPtr<CModel> 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<CTexture> CDrawUtil::mpCheckerTexture;
CTexture *CDrawUtil::mpLightTextures[4];
CTexture *CDrawUtil::mpLightMasks[4];
CToken CDrawUtil::mLightTextureTokens[8];
TResPtr<CTexture> CDrawUtil::mpLightTextures[4];
TResPtr<CTexture> 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;

View File

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

View File

@ -9,6 +9,7 @@
#include <Core/CGraphics.h>
#include <Core/CResCache.h>
#include <FileIO/CFileInStream.h>
#include <Resource/script/CScriptLayer.h>
/**
* 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;
}

View File

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

View File

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

View File

@ -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<CAnimSet*>(mpCharSet);
CAnimSet *pSet = static_cast<CAnimSet*>(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

View File

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

View File

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

View File

@ -5,7 +5,7 @@
#include "CTexture.h"
#include "model/CVertex.h"
#include <Common/types.h>
#include <Core/CToken.h>
#include <Core/TResPtr.h>
#include <OpenGL/CDynamicVertexBuffer.h>
#include <OpenGL/CIndexBuffer.h>
@ -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<CTexture> 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
{

View File

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

View File

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

View File

@ -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++)

View File

@ -8,7 +8,7 @@
#include <Common/CColor.h>
#include <Common/EnumUtil.h>
#include <Common/types.h>
#include <Core/CToken.h>
#include <Core/TResPtr.h>
#include <Core/ERenderOptions.h>
#include <FileIO/CInputStream.h>
#include <OpenGL/CShader.h>
@ -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<CTexture> mpIndirectTexture; // Optional texture used for the indirect stage for reflections
std::vector<CMaterialPass*> mPasses;

View File

@ -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)

View File

@ -3,7 +3,7 @@
#include <Common/CFourCC.h>
#include <Common/CHashFNV1A.h>
#include <Core/CToken.h>
#include <Core/TResPtr.h>
#include <Core/ERenderOptions.h>
#include <Resource/CTexture.h>
#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<CTexture> mpTexture;
EUVAnimMode mAnimMode;
float mAnimParams[4];
bool mEnabled;

View File

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

View File

@ -1,4 +1,5 @@
#include "CWorld.h"
#include "script/CScriptLayer.h"
#include <Core/CResCache.h>
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)
EGame mWorldVersion;
CStringTable *mpWorldName;
CStringTable *mpDarkWorldName;
CResource *mpSaveWorld;
CModel *mpDefaultSkybox;
CResource *mpMapWorld;
CToken mResTokens[5];
TResPtr<CStringTable> mpWorldName;
TResPtr<CStringTable> mpDarkWorldName;
TResPtr<CResource> mpSaveWorld;
TResPtr<CModel> mpDefaultSkybox;
TResPtr<CResource> mpMapWorld;
u32 mUnknown1;
u32 mUnknownAreas;
@ -44,12 +43,11 @@ class CWorld : public CResource
struct SArea
{
TString InternalName;
CStringTable *pAreaName;
TResPtr<CStringTable> 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<u16> AttachedAreaIDs;
std::vector<SDependency> Dependencies;

View File

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

View File

@ -2,13 +2,13 @@
#define CTEXTUREENCODER_H
#include "../CTexture.h"
#include <Core/TResPtr.h>
// 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<CTexture> mpTexture;
ETexelFormat mSourceFormat;
ETexelFormat mOutputFormat;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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();

View File

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

View File

@ -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();

View File

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

View File

@ -23,7 +23,7 @@ public:
};
private:
CModel *mpModel;
TResPtr<CModel> mpModel;
std::vector<CMaterialSet*> mMaterials;
CBlockMgrIn *mpBlockMgr;
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
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:

View File

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

View File

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

View File

@ -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)

View File

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

View File

@ -13,7 +13,7 @@
#include <Common/CColor.h>
#include <Common/CVector3f.h>
#include <Common/TString.h>
#include <Core/CToken.h>
#include <Core/TResPtr.h>
#include <list>
class CScriptTemplate;
@ -65,48 +65,11 @@ typedef __CProperty<float, eFloatProperty> CFloatProperty;
typedef __CProperty<TString, eStringProperty> CStringProperty;
typedef __CProperty<CVector3f, eVector3Property> CVector3Property;
typedef __CProperty<CColor, eColorProperty> CColorProperty;
typedef __CProperty<CResource*, eFileProperty> CFileProperty;
typedef __CProperty<TResPtr<CResource>, eFileProperty> CFileProperty;
typedef __CProperty<CAnimationParameters, eAnimParamsProperty> CAnimParamsProperty;
typedef __CProperty<std::vector<u8>, eArrayProperty> CArrayProperty;
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.
*/

View File

@ -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 ************

View File

@ -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<CGameArea> 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<CModel> mpDisplayModel;
TResPtr<CTexture> mpBillboard;
TResPtr<CCollisionMeshGroup> mpCollision;
bool mHasInGameModel;
EVolumeShape mVolumeShape;

View File

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

View File

@ -6,8 +6,7 @@
class CCollisionNode : public CSceneNode
{
CCollisionMeshGroup *mpCollision;
CToken mCollisionToken;
TResPtr<CCollisionMeshGroup> mpCollision;
public:
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)
{
mpModel = pModel;
mModelToken = CToken(pModel);
mActiveMatSet = 0;
if (pModel)

View File

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

View File

@ -9,6 +9,7 @@
#include <Core/CResCache.h>
#include <Core/CSceneManager.h>
#include <Resource/script/CMasterTemplate.h>
#include <Resource/script/CScriptLayer.h>
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<CModel> 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)
{

View File

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

View File

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

View File

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

View File

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

View File

@ -8,9 +8,7 @@ class CDoorExtra : public CScriptExtra
// Render colored door shield in MP2/3
CFileProperty *mpShieldModelProp;
CColorProperty *mpShieldColorProp;
CModel *mpShieldModel;
CToken mModelToken;
TResPtr<CModel> mpShieldModel;
public:
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)
{
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)

View File

@ -9,8 +9,7 @@ class CPointOfInterestExtra : public CScriptExtra
{
// Tint POI billboard orange/red depending on scan importance
CFileProperty *mpScanProperty;
CScan *mpScanData;
CToken mScanToken;
TResPtr<CScan> mpScanData;
public:
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);
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);

View File

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

View File

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

View File

@ -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<CTexture> 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<CTexture> 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<CModel> pModel = gResCache.GetResource(ModelFilename.toStdString());
if (pModel)
{
SetActiveModel(pModel);

View File

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

View File

@ -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<CGameArea> pArea = gResCache.GetResource(AreaID, "MREA");
if (!pArea)
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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