metaforce/Runtime/Particle/CDecalDataFactory.cpp

146 lines
4.1 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
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::CDecalDataFactory");
2016-02-23 10:34:19 +00:00
using CPF = CParticleDataFactory;
2016-02-23 02:08:13 +00:00
CDecalDescription* CDecalDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool)
{
2016-02-23 10:34:19 +00:00
return CreateGeneratorDescription(in, resPool);
}
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;
}
2016-02-23 02:08:13 +00:00
return nullptr;
}
2016-02-23 10:34:19 +00:00
bool CDecalDataFactory::CreateDPSM(CDecalDescription* desc, CInputStream& in, CSimplePool* resPool)
{
CRandom16 rand;
2016-02-23 10:34:19 +00:00
CGlobalRandom gr{rand};
FourCC clsId = CPF::GetClassID(in);
2016-02-24 20:53:26 +00:00
while (clsId != SBIG('_END'))
2016-02-23 10:34:19 +00:00
{
bool loadFirstDesc = false;
2016-02-24 20:53:26 +00:00
switch (clsId)
2016-02-23 10:34:19 +00:00
{
case SBIG('1SZE'):
case SBIG('1LFT'):
case SBIG('1ROT'):
case SBIG('1OFF'):
case SBIG('1CLR'):
case SBIG('1TEX'):
case SBIG('1ADD'):
loadFirstDesc = true;
case SBIG('2LFT'):
case SBIG('2SZE'):
case SBIG('2ROT'):
case SBIG('2OFF'):
case SBIG('2CLR'):
case SBIG('2TEX'):
case SBIG('2ADD'):
if (loadFirstDesc)
2018-03-17 03:41:01 +00:00
GetQuadDecalInfo(in, resPool, clsId, desc->x0_Quads[0]);
2016-02-23 10:34:19 +00:00
else
2018-03-17 03:41:01 +00:00
GetQuadDecalInfo(in, resPool, clsId, desc->x0_Quads[1]);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('DMDL'):
desc->x38_DMDL = CPF::GetModel(in, resPool);
2017-02-13 21:29:00 +00:00
break;
2016-03-29 00:07:38 +00:00
case SBIG('DLFT'):
desc->x48_DLFT = CPF::GetIntElement(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('DMOP'):
desc->x4c_DMOP = CPF::GetVectorElement(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('DMRT'):
desc->x50_DMRT = CPF::GetVectorElement(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('DMSC'):
desc->x54_DMSC = CPF::GetVectorElement(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('DMCL'):
desc->x58_DMCL = CPF::GetColorElement(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('DMAB'):
desc->x5c_24_DMAB = CPF::GetBool(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('DMOO'):
desc->x5c_25_DMOO = CPF::GetBool(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
default:
{
uint32_t clsName = clsId.toUint32();
2016-03-04 23:04:53 +00:00
Log.report(logvisor::Fatal, "Unknown DPSC class %.4s @%" PRIi64, &clsName, in.position());
2016-02-23 10:34:19 +00:00
return false;
}
}
clsId = CPF::GetClassID(in);
}
return true;
}
2018-03-17 03:41:01 +00:00
void CDecalDataFactory::GetQuadDecalInfo(CInputStream& in, CSimplePool* resPool, FourCC clsId, SQuadDescr& quad)
2016-02-23 10:34:19 +00:00
{
2016-02-24 20:53:26 +00:00
switch (clsId)
2016-02-23 10:34:19 +00:00
{
case SBIG('1LFT'):
case SBIG('2LFT'):
quad.x0_LFT = CPF::GetIntElement(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('1SZE'):
case SBIG('2SZE'):
quad.x4_SZE = CPF::GetRealElement(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('1ROT'):
case SBIG('2ROT'):
quad.x8_ROT = CPF::GetRealElement(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('1OFF'):
case SBIG('2OFF'):
quad.xc_OFF = CPF::GetVectorElement(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('1CLR'):
case SBIG('2CLR'):
quad.x10_CLR = CPF::GetColorElement(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('1TEX'):
case SBIG('2TEX'):
quad.x14_TEX = CPF::GetTextureElement(in, resPool);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
case SBIG('1ADD'):
case SBIG('2ADD'):
quad.x18_ADD = CPF::GetBool(in);
2017-02-13 21:29:00 +00:00
break;
2016-02-23 10:34:19 +00:00
}
}
2017-02-13 21:29:00 +00:00
CFactoryFnReturn FDecalDataFactory(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<CDecalDescription>::GetIObjObjectFor(
std::unique_ptr<CDecalDescription>(CDecalDataFactory::GetGeneratorDesc(in, sp)));
2016-02-10 22:54:47 +00:00
}
}