mirror of https://github.com/AxioDL/metaforce.git
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:
parent
c4ecf972f5
commit
7430b70b73
|
@ -700,21 +700,23 @@ std::unique_ptr<CIntElement> CParticleDataFactory::GetIntElement(CInputStream& i
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
CGenDescription* CParticleDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) {
|
||||
std::unique_ptr<CGenDescription> CParticleDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) {
|
||||
std::vector<CAssetId> tracker;
|
||||
tracker.reserve(8);
|
||||
return CreateGeneratorDescription(in, tracker, 0, resPool);
|
||||
}
|
||||
|
||||
CGenDescription* CParticleDataFactory::CreateGeneratorDescription(CInputStream& in, std::vector<CAssetId>& tracker,
|
||||
CAssetId resId, CSimplePool* resPool) {
|
||||
std::unique_ptr<CGenDescription> CParticleDataFactory::CreateGeneratorDescription(CInputStream& in,
|
||||
std::vector<CAssetId>& tracker,
|
||||
CAssetId resId,
|
||||
CSimplePool* resPool) {
|
||||
if (std::count(tracker.cbegin(), tracker.cend(), resId) == 0) {
|
||||
tracker.push_back(resId);
|
||||
FourCC cid = GetClassID(in);
|
||||
if (cid == FOURCC('GPSM')) {
|
||||
CGenDescription* ret = new CGenDescription;
|
||||
CreateGPSM(ret, in, tracker, resPool);
|
||||
LoadGPSMTokens(ret);
|
||||
auto ret = std::make_unique<CGenDescription>();
|
||||
CreateGPSM(ret.get(), in, tracker, resPool);
|
||||
LoadGPSMTokens(ret.get());
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -1027,9 +1029,8 @@ void CParticleDataFactory::LoadGPSMTokens(CGenDescription* desc) {
|
|||
|
||||
CFactoryFnReturn FParticleFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
||||
CObjectReference* selfRef) {
|
||||
CSimplePool* sp = vparms.GetOwnedObj<CSimplePool*>();
|
||||
return TToken<CGenDescription>::GetIObjObjectFor(
|
||||
std::unique_ptr<CGenDescription>(CParticleDataFactory::GetGeneratorDesc(in, sp)));
|
||||
auto* const sp = vparms.GetOwnedObj<CSimplePool*>();
|
||||
return TToken<CGenDescription>::GetIObjObjectFor(CParticleDataFactory::GetGeneratorDesc(in, sp));
|
||||
}
|
||||
|
||||
} // namespace urde
|
||||
|
|
|
@ -86,14 +86,14 @@ class CParticleDataFactory {
|
|||
static s32 GetInt(CInputStream& in);
|
||||
static bool GetBool(CInputStream& in);
|
||||
static FourCC GetClassID(CInputStream& in);
|
||||
static CGenDescription* CreateGeneratorDescription(CInputStream& in, std::vector<CAssetId>& tracker, CAssetId resId,
|
||||
CSimplePool* resPool);
|
||||
static std::unique_ptr<CGenDescription> CreateGeneratorDescription(CInputStream& in, std::vector<CAssetId>& tracker,
|
||||
CAssetId resId, CSimplePool* resPool);
|
||||
static bool CreateGPSM(CGenDescription* fillDesc, CInputStream& in, std::vector<CAssetId>& tracker,
|
||||
CSimplePool* resPool);
|
||||
static void LoadGPSMTokens(CGenDescription* desc);
|
||||
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue