metaforce/Runtime/Particle/CDecalDataFactory.cpp

136 lines
3.8 KiB
C++
Raw Normal View History

#include "Runtime/Particle/CDecalDataFactory.hpp"
#include "Runtime/CRandom16.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/Graphics/CModel.hpp"
#include "Runtime/Particle/CGenDescription.hpp"
#include "Runtime/Particle/CElectricDescription.hpp"
#include "Runtime/Particle/CParticleDataFactory.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::CDecalDataFactory");
2016-02-23 10:34:19 +00:00
using CPF = CParticleDataFactory;
2018-12-08 05:30:43 +00:00
CDecalDescription* CDecalDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) {
return CreateGeneratorDescription(in, resPool);
2016-02-23 10:34:19 +00:00
}
2018-12-08 05:30:43 +00:00
CDecalDescription* CDecalDataFactory::CreateGeneratorDescription(CInputStream& in, CSimplePool* resPool) {
FourCC clsId = CPF::GetClassID(in);
if (clsId == FOURCC('DPSM')) {
CDecalDescription* desc = new CDecalDescription;
if (CreateDPSM(desc, in, resPool))
return desc;
else
delete desc;
}
return nullptr;
2016-02-23 02:08:13 +00:00
}
2018-12-08 05:30:43 +00:00
bool CDecalDataFactory::CreateDPSM(CDecalDescription* desc, CInputStream& in, CSimplePool* resPool) {
CRandom16 rand;
CGlobalRandom gr{rand};
FourCC clsId = CPF::GetClassID(in);
2016-02-23 10:34:19 +00:00
2018-12-08 05:30:43 +00:00
while (clsId != SBIG('_END')) {
bool loadFirstDesc = false;
2019-07-20 04:27:21 +00:00
switch (clsId.toUint32()) {
2018-12-08 05:30:43 +00:00
case SBIG('1SZE'):
2016-02-23 10:34:19 +00:00
case SBIG('1LFT'):
2018-12-08 05:30:43 +00:00
case SBIG('1ROT'):
case SBIG('1OFF'):
case SBIG('1CLR'):
case SBIG('1TEX'):
case SBIG('1ADD'):
loadFirstDesc = true;
2019-02-18 05:47:46 +00:00
[[fallthrough]];
2016-02-23 10:34:19 +00:00
case SBIG('2LFT'):
case SBIG('2SZE'):
case SBIG('2ROT'):
case SBIG('2OFF'):
case SBIG('2CLR'):
case SBIG('2TEX'):
case SBIG('2ADD'):
2018-12-08 05:30:43 +00:00
if (loadFirstDesc)
GetQuadDecalInfo(in, resPool, clsId, desc->x0_Quads[0]);
else
GetQuadDecalInfo(in, resPool, clsId, desc->x0_Quads[1]);
break;
case SBIG('DMDL'):
desc->x38_DMDL = CPF::GetModel(in, resPool);
break;
case SBIG('DLFT'):
desc->x48_DLFT = CPF::GetIntElement(in);
break;
case SBIG('DMOP'):
desc->x4c_DMOP = CPF::GetVectorElement(in);
break;
case SBIG('DMRT'):
desc->x50_DMRT = CPF::GetVectorElement(in);
break;
case SBIG('DMSC'):
desc->x54_DMSC = CPF::GetVectorElement(in);
break;
case SBIG('DMCL'):
desc->x58_DMCL = CPF::GetColorElement(in);
break;
case SBIG('DMAB'):
desc->x5c_24_DMAB = CPF::GetBool(in);
break;
case SBIG('DMOO'):
desc->x5c_25_DMOO = CPF::GetBool(in);
break;
default: {
2019-07-20 04:27:21 +00:00
Log.report(logvisor::Fatal, fmt("Unknown DPSC class {} @{}"), clsId, in.position());
2018-12-08 05:30:43 +00:00
return false;
}
2016-02-23 10:34:19 +00:00
}
2018-12-08 05:30:43 +00:00
clsId = CPF::GetClassID(in);
}
return true;
2016-02-23 10:34:19 +00:00
}
2018-12-08 05:30:43 +00:00
void CDecalDataFactory::GetQuadDecalInfo(CInputStream& in, CSimplePool* resPool, FourCC clsId, SQuadDescr& quad) {
2019-07-20 04:27:21 +00:00
switch (clsId.toUint32()) {
2018-12-08 05:30:43 +00:00
case SBIG('1LFT'):
case SBIG('2LFT'):
quad.x0_LFT = CPF::GetIntElement(in);
break;
case SBIG('1SZE'):
case SBIG('2SZE'):
quad.x4_SZE = CPF::GetRealElement(in);
break;
case SBIG('1ROT'):
case SBIG('2ROT'):
quad.x8_ROT = CPF::GetRealElement(in);
break;
case SBIG('1OFF'):
case SBIG('2OFF'):
quad.xc_OFF = CPF::GetVectorElement(in);
break;
case SBIG('1CLR'):
case SBIG('2CLR'):
quad.x10_CLR = CPF::GetColorElement(in);
break;
case SBIG('1TEX'):
case SBIG('2TEX'):
quad.x14_TEX = CPF::GetTextureElement(in, resPool);
break;
case SBIG('1ADD'):
case SBIG('2ADD'):
quad.x18_ADD = CPF::GetBool(in);
break;
}
2016-02-10 22:54:47 +00:00
}
2018-12-08 05:30:43 +00:00
CFactoryFnReturn FDecalDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
CObjectReference*) {
CSimplePool* sp = vparms.GetOwnedObj<CSimplePool*>();
return TToken<CDecalDescription>::GetIObjObjectFor(
std::unique_ptr<CDecalDescription>(CDecalDataFactory::GetGeneratorDesc(in, sp)));
2016-02-10 22:54:47 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde