2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Particle/CDecalDataFactory.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CRandom16.hpp"
|
|
|
|
#include "Runtime/CSimplePool.hpp"
|
|
|
|
#include "Runtime/Graphics/CModel.hpp"
|
|
|
|
#include "Runtime/Particle/CParticleDataFactory.hpp"
|
2016-02-10 22:54:47 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
|
|
|
static logvisor::Module Log("metaforce::CDecalDataFactory");
|
2016-02-23 10:34:19 +00:00
|
|
|
|
|
|
|
using CPF = CParticleDataFactory;
|
2020-03-12 18:45:20 +00:00
|
|
|
std::unique_ptr<CDecalDescription> CDecalDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return CreateGeneratorDescription(in, resPool);
|
2016-02-23 10:34:19 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 18:45:20 +00:00
|
|
|
std::unique_ptr<CDecalDescription> CDecalDataFactory::CreateGeneratorDescription(CInputStream& in,
|
|
|
|
CSimplePool* resPool) {
|
|
|
|
const FourCC clsId = CPF::GetClassID(in);
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (clsId == FOURCC('DPSM')) {
|
2020-03-12 18:45:20 +00:00
|
|
|
auto desc = std::make_unique<CDecalDescription>();
|
|
|
|
if (CreateDPSM(desc.get(), in, resPool)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return desc;
|
2020-03-12 18:45:20 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-03-12 18:45:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
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: {
|
2022-02-18 07:37:54 +00:00
|
|
|
Log.report(logvisor::Fatal, FMT_STRING("Unknown DPSC class {} @{}"), clsId, in.GetReadPosition());
|
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*>();
|
2020-03-12 18:45:20 +00:00
|
|
|
return TToken<CDecalDescription>::GetIObjObjectFor(CDecalDataFactory::GetGeneratorDesc(in, sp));
|
2016-02-10 22:54:47 +00:00
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|