CParticleDataFactory: Use unique_ptr where applicable

Same behavior, but makes the functions a little safer in terms of memory
management.
This commit is contained in:
Lioncash 2019-10-11 15:13:02 -04:00
parent c4ecf972f5
commit 7430b70b73
2 changed files with 13 additions and 12 deletions

View File

@ -700,21 +700,23 @@ std::unique_ptr<CIntElement> CParticleDataFactory::GetIntElement(CInputStream& i
return nullptr; return nullptr;
} }
CGenDescription* CParticleDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) { std::unique_ptr<CGenDescription> CParticleDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) {
std::vector<CAssetId> tracker; std::vector<CAssetId> tracker;
tracker.reserve(8); tracker.reserve(8);
return CreateGeneratorDescription(in, tracker, 0, resPool); return CreateGeneratorDescription(in, tracker, 0, resPool);
} }
CGenDescription* CParticleDataFactory::CreateGeneratorDescription(CInputStream& in, std::vector<CAssetId>& tracker, std::unique_ptr<CGenDescription> CParticleDataFactory::CreateGeneratorDescription(CInputStream& in,
CAssetId resId, CSimplePool* resPool) { std::vector<CAssetId>& tracker,
CAssetId resId,
CSimplePool* resPool) {
if (std::count(tracker.cbegin(), tracker.cend(), resId) == 0) { if (std::count(tracker.cbegin(), tracker.cend(), resId) == 0) {
tracker.push_back(resId); tracker.push_back(resId);
FourCC cid = GetClassID(in); FourCC cid = GetClassID(in);
if (cid == FOURCC('GPSM')) { if (cid == FOURCC('GPSM')) {
CGenDescription* ret = new CGenDescription; auto ret = std::make_unique<CGenDescription>();
CreateGPSM(ret, in, tracker, resPool); CreateGPSM(ret.get(), in, tracker, resPool);
LoadGPSMTokens(ret); LoadGPSMTokens(ret.get());
return ret; return ret;
} }
} }
@ -1027,9 +1029,8 @@ void CParticleDataFactory::LoadGPSMTokens(CGenDescription* desc) {
CFactoryFnReturn FParticleFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CFactoryFnReturn FParticleFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
CObjectReference* selfRef) { CObjectReference* selfRef) {
CSimplePool* sp = vparms.GetOwnedObj<CSimplePool*>(); auto* const sp = vparms.GetOwnedObj<CSimplePool*>();
return TToken<CGenDescription>::GetIObjObjectFor( return TToken<CGenDescription>::GetIObjObjectFor(CParticleDataFactory::GetGeneratorDesc(in, sp));
std::unique_ptr<CGenDescription>(CParticleDataFactory::GetGeneratorDesc(in, sp)));
} }
} // namespace urde } // namespace urde

View File

@ -86,14 +86,14 @@ class CParticleDataFactory {
static s32 GetInt(CInputStream& in); static s32 GetInt(CInputStream& in);
static bool GetBool(CInputStream& in); static bool GetBool(CInputStream& in);
static FourCC GetClassID(CInputStream& in); static FourCC GetClassID(CInputStream& in);
static CGenDescription* CreateGeneratorDescription(CInputStream& in, std::vector<CAssetId>& tracker, CAssetId resId, static std::unique_ptr<CGenDescription> CreateGeneratorDescription(CInputStream& in, std::vector<CAssetId>& tracker,
CSimplePool* resPool); CAssetId resId, CSimplePool* resPool);
static bool CreateGPSM(CGenDescription* fillDesc, CInputStream& in, std::vector<CAssetId>& tracker, static bool CreateGPSM(CGenDescription* fillDesc, CInputStream& in, std::vector<CAssetId>& tracker,
CSimplePool* resPool); CSimplePool* resPool);
static void LoadGPSMTokens(CGenDescription* desc); static void LoadGPSMTokens(CGenDescription* desc);
public: public:
static CGenDescription* GetGeneratorDesc(CInputStream& in, CSimplePool* resPool); static std::unique_ptr<CGenDescription> GetGeneratorDesc(CInputStream& in, CSimplePool* resPool);
}; };
CFactoryFnReturn FParticleFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms, CFactoryFnReturn FParticleFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,