metaforce/Runtime/Particle/CParticleElectricDataFactor...

131 lines
4.0 KiB
C++
Raw Normal View History

#include "Runtime/Particle/CParticleElectricDataFactory.hpp"
#include "Runtime/CRandom16.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/CToken.hpp"
#include "Runtime/Graphics/CModel.hpp"
#include "Runtime/Particle/CElectricDescription.hpp"
#include "Runtime/Particle/CGenDescription.hpp"
#include "Runtime/Particle/CSwooshDescription.hpp"
2016-02-10 22:54:47 +00:00
2018-12-08 05:30:43 +00:00
namespace urde {
2016-03-04 23:04:53 +00:00
static logvisor::Module Log("urde::CParticleElectricDataFactory");
2016-02-10 22:54:47 +00:00
2016-02-13 06:25:29 +00:00
using CPF = CParticleDataFactory;
2018-12-08 05:30:43 +00:00
CElectricDescription* CParticleElectricDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) {
return CreateElectricDescription(in, resPool);
2016-02-10 22:54:47 +00:00
}
2018-12-08 05:30:43 +00:00
CElectricDescription* CParticleElectricDataFactory::CreateElectricDescription(CInputStream& in, CSimplePool* resPool) {
FourCC cid = CPF::GetClassID(in);
if (cid == FOURCC('ELSM')) {
CElectricDescription* desc = new CElectricDescription;
CreateELSM(desc, in, resPool);
LoadELSMTokens(desc);
return desc;
}
2016-02-13 06:25:29 +00:00
2018-12-08 05:30:43 +00:00
return nullptr;
2016-02-10 22:54:47 +00:00
}
2018-12-08 05:30:43 +00:00
bool CParticleElectricDataFactory::CreateELSM(CElectricDescription* desc, CInputStream& in, CSimplePool* resPool) {
CRandom16 rand;
CGlobalRandom gr{rand};
2016-02-15 08:23:50 +00:00
2018-12-08 05:30:43 +00:00
FourCC clsId = CPF::GetClassID(in);
while (clsId != SBIG('_END')) {
2019-07-20 04:27:21 +00:00
switch (clsId.toUint32()) {
2018-12-08 05:30:43 +00:00
case SBIG('LIFE'):
desc->x0_LIFE = CPF::GetIntElement(in);
break;
case SBIG('SLIF'):
desc->x4_SLIF = CPF::GetIntElement(in);
break;
case SBIG('GRAT'):
desc->x8_GRAT = CPF::GetRealElement(in);
break;
case SBIG('SCNT'):
desc->xc_SCNT = CPF::GetIntElement(in);
break;
case SBIG('SSEG'):
desc->x10_SSEG = CPF::GetIntElement(in);
break;
case SBIG('COLR'):
desc->x14_COLR = CPF::GetColorElement(in);
break;
case SBIG('IEMT'):
desc->x18_IEMT = CPF::GetEmitterElement(in);
break;
case SBIG('FEMT'):
desc->x1c_FEMT = CPF::GetEmitterElement(in);
break;
case SBIG('AMPL'):
desc->x20_AMPL = CPF::GetRealElement(in);
break;
case SBIG('AMPD'):
desc->x24_AMPD = CPF::GetRealElement(in);
break;
case SBIG('LWD1'):
desc->x28_LWD1 = CPF::GetRealElement(in);
break;
case SBIG('LWD2'):
desc->x2c_LWD2 = CPF::GetRealElement(in);
break;
case SBIG('LWD3'):
desc->x30_LWD3 = CPF::GetRealElement(in);
break;
case SBIG('LCL1'):
desc->x34_LCL1 = CPF::GetColorElement(in);
break;
case SBIG('LCL2'):
desc->x38_LCL2 = CPF::GetColorElement(in);
break;
case SBIG('LCL3'):
desc->x3c_LCL3 = CPF::GetColorElement(in);
break;
case SBIG('SSWH'):
desc->x40_SSWH = CPF::GetSwooshGeneratorDesc(in, resPool);
break;
case SBIG('GPSM'): {
std::vector<CAssetId> tracker;
tracker.reserve(8);
desc->x50_GPSM = CPF::GetChildGeneratorDesc(in, resPool, tracker);
break;
}
case SBIG('EPSM'): {
std::vector<CAssetId> tracker;
tracker.reserve(8);
desc->x60_EPSM = CPF::GetChildGeneratorDesc(in, resPool, tracker);
break;
}
case SBIG('ZERY'):
desc->x70_ZERY = CPF::GetBool(in);
break;
default: {
2019-07-20 04:27:21 +00:00
Log.report(logvisor::Fatal, fmt("Unknown ELSM class {} @{}"), clsId, in.position());
2018-12-08 05:30:43 +00:00
return false;
2016-02-13 06:25:29 +00:00
}
2018-12-08 05:30:43 +00:00
}
clsId = CPF::GetClassID(in);
}
return true;
2016-02-13 06:25:29 +00:00
}
2018-12-08 05:30:43 +00:00
void CParticleElectricDataFactory::LoadELSMTokens(CElectricDescription* desc) {
if (desc->x40_SSWH.m_found)
desc->x40_SSWH.m_swoosh = desc->x40_SSWH.m_token.GetObj();
if (desc->x50_GPSM.m_found)
desc->x50_GPSM.m_gen = desc->x50_GPSM.m_token.GetObj();
if (desc->x60_EPSM.m_found)
desc->x60_EPSM.m_gen = desc->x60_EPSM.m_token.GetObj();
2016-02-15 08:23:50 +00:00
}
2017-02-13 21:29:00 +00:00
CFactoryFnReturn FParticleElectricDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
2018-12-08 05:30:43 +00:00
CObjectReference*) {
CSimplePool* sp = vparms.GetOwnedObj<CSimplePool*>();
return TToken<CElectricDescription>::GetIObjObjectFor(
std::unique_ptr<CElectricDescription>(CParticleElectricDataFactory::GetGeneratorDesc(in, sp)));
2016-02-10 22:54:47 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde