metaforce/Runtime/Particle/CDecalDataFactory.cpp

135 lines
3.7 KiB
C++
Raw Normal View History

2016-02-10 22:54:47 +00:00
#include "CDecalDataFactory.hpp"
2016-02-24 20:53:26 +00:00
#include "CGenDescription.hpp"
#include "CSwooshDescription.hpp"
#include "CElectricDescription.hpp"
2016-02-23 10:34:19 +00:00
#include "CParticleDataFactory.hpp"
2016-03-04 23:04:53 +00:00
#include "Graphics/CModel.hpp"
2016-02-10 22:54:47 +00:00
#include "CSimplePool.hpp"
2016-02-23 10:34:19 +00:00
#include "CRandom16.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;
switch (clsId) {
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;
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: {
uint32_t clsName = clsId.toUint32();
Log.report(logvisor::Fatal, "Unknown DPSC class %.4s @%" PRIi64, &clsName, in.position());
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) {
switch (clsId) {
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