CDamageableTriggerExtra: Make use of unique_ptr

Safer lifetime management.
This commit is contained in:
Lioncash 2020-06-19 00:28:22 -04:00
parent 81560138c0
commit 3dd325f708
2 changed files with 4 additions and 6 deletions

View File

@ -31,15 +31,12 @@ CDamageableTriggerExtra::CDamageableTriggerExtra(CScriptObject *pInstance, CScen
} }
} }
CDamageableTriggerExtra::~CDamageableTriggerExtra() CDamageableTriggerExtra::~CDamageableTriggerExtra() = default;
{
delete mpMat;
}
void CDamageableTriggerExtra::CreateMaterial() void CDamageableTriggerExtra::CreateMaterial()
{ {
ASSERT(!mpMat); ASSERT(!mpMat);
mpMat = new CMaterial(mGame, EVertexAttribute::Position | EVertexAttribute::Normal | EVertexAttribute::Tex0); mpMat = std::make_unique<CMaterial>(mGame, EVertexAttribute::Position | EVertexAttribute::Normal | EVertexAttribute::Tex0);
// Most values/TEV setup were found from the executable + from graphics debuggers // Most values/TEV setup were found from the executable + from graphics debuggers
// Animation parameters are estimates from eyeballing the values ingame // Animation parameters are estimates from eyeballing the values ingame

View File

@ -3,6 +3,7 @@
#include "CScriptExtra.h" #include "CScriptExtra.h"
#include <array> #include <array>
#include <memory>
class CDamageableTriggerExtra : public CScriptExtra class CDamageableTriggerExtra : public CScriptExtra
{ {
@ -24,7 +25,7 @@ private:
TEnumRef<ERenderSide> mRenderSide; TEnumRef<ERenderSide> mRenderSide;
std::array<CAssetRef, 3> mTextureAssets; std::array<CAssetRef, 3> mTextureAssets;
CMaterial* mpMat = nullptr; std::unique_ptr<CMaterial> mpMat;
std::array<CTexture*, 3> mpTextures{}; std::array<CTexture*, 3> mpTextures{};
CVector2f mCoordScale; CVector2f mCoordScale;