mirror of https://github.com/AxioDL/metaforce.git
CDecalDataFactory: Make GetGeneratorDesc() return a unique_ptr
Same behavior, but with safer memory management.
This commit is contained in:
parent
1f42b9be93
commit
05bccae70e
|
@ -12,19 +12,21 @@ namespace urde {
|
||||||
static logvisor::Module Log("urde::CDecalDataFactory");
|
static logvisor::Module Log("urde::CDecalDataFactory");
|
||||||
|
|
||||||
using CPF = CParticleDataFactory;
|
using CPF = CParticleDataFactory;
|
||||||
CDecalDescription* CDecalDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) {
|
std::unique_ptr<CDecalDescription> CDecalDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) {
|
||||||
return CreateGeneratorDescription(in, resPool);
|
return CreateGeneratorDescription(in, resPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
CDecalDescription* CDecalDataFactory::CreateGeneratorDescription(CInputStream& in, CSimplePool* resPool) {
|
std::unique_ptr<CDecalDescription> CDecalDataFactory::CreateGeneratorDescription(CInputStream& in,
|
||||||
FourCC clsId = CPF::GetClassID(in);
|
CSimplePool* resPool) {
|
||||||
|
const FourCC clsId = CPF::GetClassID(in);
|
||||||
|
|
||||||
if (clsId == FOURCC('DPSM')) {
|
if (clsId == FOURCC('DPSM')) {
|
||||||
CDecalDescription* desc = new CDecalDescription;
|
auto desc = std::make_unique<CDecalDescription>();
|
||||||
if (CreateDPSM(desc, in, resPool))
|
if (CreateDPSM(desc.get(), in, resPool)) {
|
||||||
return desc;
|
return desc;
|
||||||
else
|
}
|
||||||
delete desc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +131,6 @@ void CDecalDataFactory::GetQuadDecalInfo(CInputStream& in, CSimplePool* resPool,
|
||||||
CFactoryFnReturn FDecalDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
CFactoryFnReturn FDecalDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
||||||
CObjectReference*) {
|
CObjectReference*) {
|
||||||
CSimplePool* sp = vparms.GetOwnedObj<CSimplePool*>();
|
CSimplePool* sp = vparms.GetOwnedObj<CSimplePool*>();
|
||||||
return TToken<CDecalDescription>::GetIObjObjectFor(
|
return TToken<CDecalDescription>::GetIObjObjectFor(CDecalDataFactory::GetGeneratorDesc(in, sp));
|
||||||
std::unique_ptr<CDecalDescription>(CDecalDataFactory::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/IObj.hpp"
|
#include "Runtime/IObj.hpp"
|
||||||
|
@ -12,11 +14,11 @@ class CSimplePool;
|
||||||
|
|
||||||
class CDecalDataFactory {
|
class CDecalDataFactory {
|
||||||
static bool CreateDPSM(CDecalDescription* desc, CInputStream& in, CSimplePool* resPool);
|
static bool CreateDPSM(CDecalDescription* desc, CInputStream& in, CSimplePool* resPool);
|
||||||
static CDecalDescription* CreateGeneratorDescription(CInputStream& in, CSimplePool* resPool);
|
static std::unique_ptr<CDecalDescription> CreateGeneratorDescription(CInputStream& in, CSimplePool* resPool);
|
||||||
static void GetQuadDecalInfo(CInputStream& in, CSimplePool* resPool, FourCC clsId, SQuadDescr& quad);
|
static void GetQuadDecalInfo(CInputStream& in, CSimplePool* resPool, FourCC clsId, SQuadDescr& quad);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CDecalDescription* GetGeneratorDesc(CInputStream& in, CSimplePool* resPool);
|
static std::unique_ptr<CDecalDescription> GetGeneratorDesc(CInputStream& in, CSimplePool* resPool);
|
||||||
};
|
};
|
||||||
|
|
||||||
CFactoryFnReturn FDecalDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
CFactoryFnReturn FDecalDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
|
||||||
|
|
Loading…
Reference in New Issue