metaforce/Runtime/Particle/CDecalDataFactory.cpp

147 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{99};
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)
GetQuadDecalInfo(in, resPool, clsId, desc->x0_Quad);
else
GetQuadDecalInfo(in, resPool, clsId, desc->x1c_Quad);
break;
case SBIG('DMDL'):
desc->x38_DMDL = CPF::GetModel(in, resPool);
break;
2016-03-29 00:07:38 +00:00
case SBIG('DLFT'):
desc->x48_DLFT.reset(CPF::GetIntElement(in));
2016-02-23 10:34:19 +00:00
break;
case SBIG('DMOP'):
desc->x4c_DMOP.reset(CPF::GetVectorElement(in));
break;
case SBIG('DMRT'):
desc->x50_DMRT.reset(CPF::GetVectorElement(in));
break;
case SBIG('DMSC'):
desc->x54_DMSC.reset(CPF::GetVectorElement(in));
break;
case SBIG('DMCL'):
desc->x58_DMCL.reset(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();
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;
}
2016-08-04 22:24:28 +00:00
void CDecalDataFactory::GetQuadDecalInfo(CInputStream& in, CSimplePool* resPool, FourCC clsId,
CDecalDescription::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.reset(CPF::GetIntElement(in));
break;
case SBIG('1SZE'):
case SBIG('2SZE'):
quad.x4_SZE.reset(CPF::GetRealElement(in));
break;
case SBIG('1ROT'):
case SBIG('2ROT'):
quad.x8_ROT.reset(CPF::GetRealElement(in));
break;
case SBIG('1OFF'):
case SBIG('2OFF'):
quad.xc_OFF.reset(CPF::GetVectorElement(in));
break;
case SBIG('1CLR'):
case SBIG('2CLR'):
quad.x10_CLR.reset(CPF::GetColorElement(in));
break;
case SBIG('1TEX'):
case SBIG('2TEX'):
quad.x14_TEX.reset(CPF::GetTextureElement(in, resPool));
break;
case SBIG('1ADD'):
case SBIG('2ADD'):
quad.x18_ADD = CPF::GetBool(in);
break;
}
}
2016-03-31 00:38:03 +00:00
CFactoryFnReturn FDecalDataFactory(const SObjectTag &tag, CInputStream &in, const CVParamTransfer &vparms)
2016-02-10 22:54:47 +00:00
{
2016-12-23 06:41:39 +00:00
CSimplePool* sp = vparms.GetOwnedObj<CSimplePool*>();
2016-02-10 22:54:47 +00:00
return TToken<CDecalDescription>::GetIObjObjectFor(std::unique_ptr<CDecalDescription>(CDecalDataFactory::GetGeneratorDesc(in, sp)));
}
2016-02-23 02:08:13 +00:00
2016-02-10 22:54:47 +00:00
}