Add DSPC factory

This commit is contained in:
Phillip Stephens 2016-02-23 02:34:19 -08:00
parent 0c5a28f03c
commit 88cbb2b659
4 changed files with 164 additions and 4 deletions

View File

@ -1,14 +1,138 @@
#include "CDecalDataFactory.hpp"
#include "CDecalDescription.hpp"
#include "CParticleDataFactory.hpp"
#include "CSimplePool.hpp"
#include "CRandom16.hpp"
namespace pshag
{
static LogVisor::LogModule Log("pshag::CDecalDataFactory");
using CPF = CParticleDataFactory;
CDecalDescription* CDecalDataFactory::GetGeneratorDesc(CInputStream& in, CSimplePool* resPool)
{
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;
}
return nullptr;
}
bool CDecalDataFactory::CreateDPSM(CDecalDescription* desc, CInputStream& in, CSimplePool* resPool)
{
CRandom16 rand{99};
CGlobalRandom gr{rand};
FourCC clsId = CPF::GetClassID(in);
while(clsId != SBIG('_END'))
{
bool loadFirstDesc = false;
switch(clsId)
{
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;
case SBIG('DFLT'):
desc->x48_DFLT.reset(CPF::GetIntElement(in));
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();
Log.report(LogVisor::FatalError, "Unknown DPSC class %.4s @%" PRIi64, &clsName, in.position());
return false;
}
}
clsId = CPF::GetClassID(in);
}
return true;
}
void CDecalDataFactory::GetQuadDecalInfo(CInputStream& in, CSimplePool* resPool, FourCC clsId, SQuadDescr& quad)
{
switch(clsId)
{
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;
}
}
std::unique_ptr<IObj> FDecalDataFactory(const SObjectTag &tag, CInputStream &in, const CVParamTransfer &vparms)
{
CSimplePool* sp = static_cast<CSimplePool*>(static_cast<TObjOwnerParam<IObjectStore*>*>(vparms.GetObj())->GetParam());

View File

@ -9,15 +9,17 @@
namespace pshag
{
struct SQuadDescr;
class CDecalDescription;
class CSimplePool;
class CDecalDataFactory
{
static bool CreateDPSM(CDecalDescription* desc,CInputStream& in,CSimplePool* resPool);
static CDecalDescription* CreateGeneratorDescription(CInputStream& in, CSimplePool* resPool);
static void GetQuadDecalInfo(CInputStream& in, CSimplePool* resPool, FourCC clsId, SQuadDescr& quad);
public:
static CDecalDescription* GetGeneratorDesc(CInputStream& in,CSimplePool* resPool);
static CDecalDescription* CreateGeneratorDescription(CInputStream& in, CSimplePool* resPool);
static bool CreateDPSM(CDecalDescription* desc,CInputStream& in,CSimplePool* resPool);
};
std::unique_ptr<IObj> FDecalDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms);

View File

@ -1,10 +1,42 @@
#ifndef __PSHAG_CDECALDESCRIPTION_HPP__
#define __PSHAG_CDECALDESCRIPTION_HPP__
#include "CRealElement.hpp"
#include "CIntElement.hpp"
#include "CVectorElement.hpp"
#include "CColorElement.hpp"
#include "CUVElement.hpp"
#include "CParticleDataFactory.hpp"
namespace pshag
{
struct SQuadDescr
{
std::unique_ptr<CIntElement> x0_LFT;
std::unique_ptr<CRealElement> x4_SZE;
std::unique_ptr<CRealElement> x8_ROT;
std::unique_ptr<CVectorElement> xc_OFF;
std::unique_ptr<CColorElement> x10_CLR;
std::unique_ptr<CUVElement> x14_TEX;
bool x18_ADD = false;
};
class CDecalDescription
{
public:
SQuadDescr x0_Quad;
SQuadDescr x1c_Quad;
SParticleModel x38_DMDL;
std::unique_ptr<CIntElement> x48_DFLT;
std::unique_ptr<CVectorElement> x4c_DMOP;
std::unique_ptr<CVectorElement> x50_DMRT;
std::unique_ptr<CVectorElement> x54_DMSC;
std::unique_ptr<CColorElement> x58_DMCL;
union
{
struct { bool x5c_24_DMAB : 1; bool x5c_25_DMOO : 1;};
u8 dummy = 0;
};
};
}

View File

@ -23,8 +23,10 @@ CSwooshDescription*CParticleSwooshDataFactory::CreateGeneratorDescription(CInput
if (clsId == FOURCC('SWSH'))
{
CSwooshDescription* desc = new CSwooshDescription;
CreateWPSM(desc, in, resPool);
return desc;
if (CreateWPSM(desc, in, resPool))
return desc;
else
delete desc;
}
return nullptr;
}