metaforce/Runtime/Particle/CParticleElectricDataFactor...

143 lines
4.5 KiB
C++
Raw Normal View History

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