mirror of https://github.com/AxioDL/metaforce.git
CParticleSwooshDataFactory: Make GetGeneratorDesc() return a unique_ptr
Same behavior, but with safer memory management.
This commit is contained in:
parent
93121c38f7
commit
59bbbdf41c
|
@ -12,19 +12,22 @@ static logvisor::Module Log("urde::CParticleSwooshDataFactory");
|
||||||
|
|
||||||
using CPF = CParticleDataFactory;
|
using CPF = CParticleDataFactory;
|
||||||
|
|
||||||
CSwooshDescription* CParticleSwooshDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) {
|
std::unique_ptr<CSwooshDescription> CParticleSwooshDataFactory::GetGeneratorDesc(CInputStream& in,
|
||||||
|
CSimplePool* resPool) {
|
||||||
return CreateGeneratorDescription(in, resPool);
|
return CreateGeneratorDescription(in, resPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSwooshDescription* CParticleSwooshDataFactory::CreateGeneratorDescription(CInputStream& in, CSimplePool* resPool) {
|
std::unique_ptr<CSwooshDescription> CParticleSwooshDataFactory::CreateGeneratorDescription(CInputStream& in,
|
||||||
FourCC clsId = CPF::GetClassID(in);
|
CSimplePool* resPool) {
|
||||||
|
const FourCC clsId = CPF::GetClassID(in);
|
||||||
|
|
||||||
if (clsId == FOURCC('SWSH')) {
|
if (clsId == FOURCC('SWSH')) {
|
||||||
CSwooshDescription* desc = new CSwooshDescription;
|
auto desc = std::make_unique<CSwooshDescription>();
|
||||||
if (CreateWPSM(desc, in, resPool))
|
if (CreateWPSM(desc.get(), in, resPool)) {
|
||||||
return desc;
|
return desc;
|
||||||
else
|
|
||||||
delete desc;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +135,6 @@ bool CParticleSwooshDataFactory::CreateWPSM(CSwooshDescription* desc, CInputStre
|
||||||
CFactoryFnReturn FParticleSwooshDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
CFactoryFnReturn FParticleSwooshDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
||||||
CObjectReference*) {
|
CObjectReference*) {
|
||||||
CSimplePool* sp = vparms.GetOwnedObj<CSimplePool*>();
|
CSimplePool* sp = vparms.GetOwnedObj<CSimplePool*>();
|
||||||
return TToken<CSwooshDescription>::GetIObjObjectFor(
|
return TToken<CSwooshDescription>::GetIObjObjectFor(CParticleSwooshDataFactory::GetGeneratorDesc(in, sp));
|
||||||
std::unique_ptr<CSwooshDescription>(CParticleSwooshDataFactory::GetGeneratorDesc(in, sp)));
|
|
||||||
}
|
}
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "Runtime/CFactoryMgr.hpp"
|
#include "Runtime/CFactoryMgr.hpp"
|
||||||
#include "Runtime/CToken.hpp"
|
#include "Runtime/CToken.hpp"
|
||||||
#include "Runtime/IOStreams.hpp"
|
#include "Runtime/IOStreams.hpp"
|
||||||
|
@ -10,11 +12,11 @@ namespace urde {
|
||||||
class CSwooshDescription;
|
class CSwooshDescription;
|
||||||
class CSimplePool;
|
class CSimplePool;
|
||||||
class CParticleSwooshDataFactory {
|
class CParticleSwooshDataFactory {
|
||||||
static CSwooshDescription* CreateGeneratorDescription(CInputStream& in, CSimplePool* resPool);
|
static std::unique_ptr<CSwooshDescription> CreateGeneratorDescription(CInputStream& in, CSimplePool* resPool);
|
||||||
static bool CreateWPSM(CSwooshDescription* desc, CInputStream& in, CSimplePool* resPool);
|
static bool CreateWPSM(CSwooshDescription* desc, CInputStream& in, CSimplePool* resPool);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CSwooshDescription* GetGeneratorDesc(CInputStream& in, CSimplePool* resPool);
|
static std::unique_ptr<CSwooshDescription> GetGeneratorDesc(CInputStream& in, CSimplePool* resPool);
|
||||||
};
|
};
|
||||||
|
|
||||||
CFactoryFnReturn FParticleSwooshDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
CFactoryFnReturn FParticleSwooshDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
||||||
|
|
Loading…
Reference in New Issue