metaforce/Runtime/Particle/CElementGen.hpp

248 lines
7.9 KiB
C++
Raw Normal View History

2016-04-13 06:07:23 +00:00
#ifndef __URDE_CELEMENTGEN_HPP__
#define __URDE_CELEMENTGEN_HPP__
2015-08-17 23:46:41 +00:00
2016-02-11 22:38:25 +00:00
#include "RetroTypes.hpp"
2016-03-04 23:04:53 +00:00
#include "zeus/CTransform.hpp"
#include "zeus/CVector3f.hpp"
#include "zeus/CColor.hpp"
#include "zeus/CAABox.hpp"
2016-02-08 05:10:17 +00:00
#include "CToken.hpp"
2016-03-04 23:04:53 +00:00
#include "Graphics/CLight.hpp"
#include "Graphics/CGraphics.hpp"
2016-02-09 22:52:33 +00:00
#include "CRandom16.hpp"
2016-02-13 05:49:59 +00:00
#include "CParticleGen.hpp"
2016-02-15 04:00:26 +00:00
#include "CElementGenShaders.hpp"
#include "Graphics/CLineRenderer.hpp"
2015-08-21 00:06:39 +00:00
2016-03-04 23:04:53 +00:00
namespace urde
2015-08-17 23:46:41 +00:00
{
2016-02-08 03:31:05 +00:00
class CWarp;
class CLight;
class IGenDescription;
2016-02-08 05:10:17 +00:00
class CGenDescription;
2016-02-11 22:38:25 +00:00
class CParticleSwoosh;
class CParticleElectric;
2015-08-17 23:46:41 +00:00
2016-02-13 05:49:59 +00:00
class CElementGen : public CParticleGen
2015-08-17 23:46:41 +00:00
{
2016-02-08 05:10:17 +00:00
public:
enum class EModelOrientationType
{
2016-02-09 22:52:33 +00:00
Normal,
One
2016-02-08 05:10:17 +00:00
};
enum class EOptionalSystemFlags
2016-02-09 22:52:33 +00:00
{
None,
One,
Two
};
enum class LightType
{
None = 0,
Custom = 1,
Directional = 2,
Spot = 3
};
2016-02-09 22:52:33 +00:00
class CParticleListItem
2016-02-08 05:10:17 +00:00
{
2016-02-11 02:36:21 +00:00
friend class CElementGen;
s16 x0_partIdx;
2016-03-04 23:04:53 +00:00
zeus::CVector3f x4_viewPoint;
2016-02-10 02:00:28 +00:00
public:
2016-02-11 02:36:21 +00:00
CParticleListItem(s16 idx)
: x0_partIdx(idx)
{
++g_ParticleAliveCount;
}
~CParticleListItem()
{
--g_ParticleAliveCount;
}
2016-02-10 02:00:28 +00:00
};
2016-02-25 06:23:35 +00:00
struct CParticle
2016-02-10 02:00:28 +00:00
{
2016-02-11 02:36:21 +00:00
int x0_endFrame = 0;
2016-03-04 23:04:53 +00:00
zeus::CVector3f x4_pos;
zeus::CVector3f x10_prevPos;
zeus::CVector3f x1c_vel;
2016-02-11 02:36:21 +00:00
int x28_startFrame = 0;
float x2c_lineLengthOrSize = 0.f;
float x30_lineWidthOrRota = 0.f;
2016-03-04 23:04:53 +00:00
zeus::CColor x34_color = {0.f, 0.f, 0.f, 1.f};
2016-02-08 05:10:17 +00:00
};
2016-02-25 06:23:35 +00:00
static CParticle* g_currentParticle;
2016-02-15 04:00:26 +00:00
private:
friend class CElementGenShaders;
2016-02-13 05:49:59 +00:00
TLockedToken<CGenDescription> x1c_genDesc;
2016-02-08 05:10:17 +00:00
EModelOrientationType x28_orientType;
2016-02-09 22:52:33 +00:00
std::vector<CParticleListItem> x2c_particleLists;
2016-03-04 23:04:53 +00:00
std::vector<zeus::CMatrix3f> x3c_parentMatrices;
u32 x4c_internalStartFrame = 0;
2016-02-10 02:00:28 +00:00
u32 x50_curFrame = 0;
double x58_curSeconds = 0.f;
float x60_timeDeltaScale;
2016-02-11 22:38:25 +00:00
u32 x64_prevFrame = -1;
2016-02-08 05:10:17 +00:00
bool x68_particleEmission = true;
2016-02-11 02:36:21 +00:00
float x6c_generatorRemainder = 0.f;
2016-02-09 22:52:33 +00:00
int x70_MAXP = 0;
u16 x74_randomSeed = 99;
2016-02-08 05:10:17 +00:00
float x78_generatorRate = 1.f;
2016-03-04 23:04:53 +00:00
zeus::CVector3f x7c_translation;
zeus::CVector3f x88_globalTranslation;
zeus::CVector3f x94_POFS;
zeus::CVector3f xa0_globalScale = {1.f, 1.f, 1.f};
zeus::CTransform xac_globalScaleTransform = zeus::CTransform::Identity();
zeus::CTransform xdc_globalScaleTransformInverse = zeus::CTransform::Identity();
zeus::CVector3f x10c_localScale = {1.f, 1.f, 1.f};
zeus::CTransform x118_localScaleTransform = zeus::CTransform::Identity();
zeus::CTransform x148_localScaleTransformInverse = zeus::CTransform::Identity();
zeus::CTransform x178_orientation = zeus::CTransform::Identity();
zeus::CTransform x1a8_orientationInverse = zeus::CTransform::Identity();
zeus::CTransform x1d8_globalOrientation = zeus::CTransform::Identity();
2016-02-11 02:36:21 +00:00
u32 x208_activeParticleCount = 0;
2016-02-11 22:38:25 +00:00
u32 x20c_recursiveParticleCount = 0;
2016-02-11 02:36:21 +00:00
u32 x210_curEmitterFrame = 0;
2016-02-18 04:44:06 +00:00
int x214_PSLT = 90;//0x7fffff;
2016-03-04 23:04:53 +00:00
zeus::CVector3f x218_PSIV;
bool x224_24_translationDirty = false;
2016-02-09 22:52:33 +00:00
bool x224_25_LIT_;
bool x224_26_AAPH;
bool x224_27_ZBUF;
2016-02-16 05:50:41 +00:00
bool x224_28_zTest = false;
2016-02-09 22:52:33 +00:00
bool x224_29_MBLR;
bool x224_30_VMD1;
bool x224_31_VMD2;
2016-02-11 02:36:21 +00:00
bool x225_24_VMD3;
bool x225_25_VMD4;
2016-02-09 22:52:33 +00:00
bool x225_26_LINE;
bool x225_27_FXLL;
2016-02-10 02:00:28 +00:00
bool x225_28_warmedUp = false;
2016-02-13 00:57:09 +00:00
bool x225_29_modelsUseLights = false;
bool x226_enableOPTS;
2016-02-15 04:00:26 +00:00
int x228_MBSP = 0; int m_maxMBSP = 0;
2016-03-15 04:55:57 +00:00
ERglLightBits x22c_backupLightActive = ERglLightBits::None;
2016-02-11 02:36:21 +00:00
CRandom16 x230_randState;
2016-02-11 22:38:25 +00:00
std::vector<std::unique_ptr<CElementGen>> x234_activePartChildren;
2016-02-09 22:52:33 +00:00
int x244_CSSD = 0;
2016-02-11 22:38:25 +00:00
std::vector<std::unique_ptr<CElementGen>> x248_finishPartChildren;
2016-02-09 22:52:33 +00:00
int x258_SISY = 16;
int x25c_PISY = 16;
u32 x260_cumulativeParticles = 0; /* Retail */
2016-02-11 22:38:25 +00:00
std::vector<std::unique_ptr<CParticleSwoosh>> x260_swhcChildren;
2016-02-09 22:52:33 +00:00
int x270_SSSD = 0;
2016-03-04 23:04:53 +00:00
zeus::CVector3f x274_SSPO;
2016-02-11 22:38:25 +00:00
std::vector<std::unique_ptr<CParticleElectric>> x280_elscChildren;
2016-02-09 22:52:33 +00:00
int x290_SESD = 0;
2016-03-04 23:04:53 +00:00
zeus::CVector3f x294_SEPO;
2016-02-09 22:52:33 +00:00
float x2a0 = 0.f;
float x2a4 = 0.f;
2016-03-04 23:04:53 +00:00
zeus::CVector3f x2a8_aabbMin;
zeus::CVector3f x2b4_aabbMax;
2016-02-11 02:36:21 +00:00
float x2c0_maxSize = 0.f;
2016-03-04 23:04:53 +00:00
zeus::CAABox x2c4_systemBounds = zeus::CAABox::skInvertedBox;
LightType x2dc_lightType;
2016-03-04 23:04:53 +00:00
zeus::CColor x2e0_LCLR = zeus::CColor::skWhite;
2016-02-11 22:38:25 +00:00
float x2e4_LINT = 1.f;
2016-03-04 23:04:53 +00:00
zeus::CVector3f x2e8_LOFF;
zeus::CVector3f x2f4_LDIR = {1.f, 0.f, 0.f};
2016-02-09 22:52:33 +00:00
EFalloffType x300_falloffType = EFalloffType::Linear;
2016-02-11 22:38:25 +00:00
float x304_LFOR = 1.f;
float x308_LSLA = 45.f;
2016-03-04 23:04:53 +00:00
zeus::CColor x30c_moduColor = {1.f, 1.f, 1.f, 1.f};
2016-02-09 22:52:33 +00:00
std::unique_ptr<CLineRenderer> m_lineRenderer;
2016-02-15 04:00:26 +00:00
CElementGenShaders::EShaderClass m_shaderClass;
2016-03-04 23:04:53 +00:00
void AccumulateBounds(zeus::CVector3f& pos, float size);
2016-02-11 02:36:21 +00:00
2015-08-18 05:54:43 +00:00
public:
2016-02-08 05:10:17 +00:00
CElementGen(const TToken<CGenDescription>& gen, EModelOrientationType orientType, EOptionalSystemFlags flags);
2016-02-13 05:49:59 +00:00
~CElementGen();
2016-02-08 05:10:17 +00:00
2016-02-15 04:00:26 +00:00
boo::GraphicsDataToken m_gfxToken;
boo::IShaderDataBinding* m_normalDataBind = nullptr;
boo::IShaderDataBinding* m_redToAlphaDataBind = nullptr;
boo::IGraphicsBufferD* m_instBuf = nullptr;
boo::IGraphicsBufferD* m_uniformBuf = nullptr;
CGenDescription* GetDesc() {return x1c_genDesc.GetObj();}
2016-02-13 05:49:59 +00:00
static s32 g_FreeIndex;
static bool g_StaticListInitialized;
static int g_ParticleAliveCount;
static int g_ParticleSystemAliveCount;
static bool g_MoveRedToAlphaBuffer;
static void Initialize();
2016-02-16 19:42:24 +00:00
static void Shutdown();
void SetGeneratorRateScalar(float scalar)
{
if (scalar >= 0.0f)
x78_generatorRate = scalar;
else
x78_generatorRate = 0.0f;
2016-02-11 22:38:25 +00:00
for (std::unique_ptr<CElementGen>& child : x234_activePartChildren)
2016-02-09 22:52:33 +00:00
child->SetGeneratorRateScalar(x78_generatorRate);
2016-02-11 22:38:25 +00:00
for (std::unique_ptr<CElementGen>& child : x248_finishPartChildren)
2016-02-09 22:52:33 +00:00
child->SetGeneratorRateScalar(x78_generatorRate);
}
2016-02-10 02:00:28 +00:00
void UpdateExistingParticles();
void CreateNewParticles(int);
void UpdatePSTranslationAndOrientation();
void UpdateChildParticleSystems(double);
2016-02-11 06:58:33 +00:00
CElementGen* ConstructChildParticleSystem(const TToken<CGenDescription>&);
2016-02-10 02:00:28 +00:00
void UpdateLightParameters();
void BuildParticleSystemBounds();
u32 GetEmitterTime() const
{
/* Game returns x74, guessing x50 is what it's asking for */
return x50_curFrame;
}
2016-02-11 19:18:14 +00:00
u32 GetSystemCount();
u32 GetCumulativeParticleCount() const { return x260_cumulativeParticles; }
2016-02-11 22:38:25 +00:00
u32 GetParticleCountAllInternal() const;
u32 GetParticleCountAll() const {return x20c_recursiveParticleCount;}
2016-02-26 03:31:00 +00:00
void EndLifetime();
void ForceParticleCreation(int amount);
2016-02-08 03:31:05 +00:00
2016-02-13 05:49:59 +00:00
bool InternalUpdate(double);
2016-02-12 02:36:34 +00:00
void RenderModels();
void RenderLines();
void RenderParticles();
2016-02-13 00:57:09 +00:00
void RenderParticlesIndirectTexture();
2016-02-12 02:36:34 +00:00
2016-02-13 05:49:59 +00:00
void Update(double);
void Render();
2016-03-04 23:04:53 +00:00
void SetOrientation(const zeus::CTransform&);
void SetTranslation(const zeus::CVector3f&);
void SetGlobalOrientation(const zeus::CTransform&);
void SetGlobalTranslation(const zeus::CVector3f&);
void SetGlobalScale(const zeus::CVector3f&);
void SetLocalScale(const zeus::CVector3f&);
2016-02-13 05:49:59 +00:00
void SetParticleEmission(bool);
2016-03-04 23:04:53 +00:00
void SetModulationColor(const zeus::CColor&);
const zeus::CTransform& GetOrientation() const;
const zeus::CVector3f& GetTranslation() const;
const zeus::CTransform& GetGlobalOrientation() const;
const zeus::CVector3f& GetGlobalTranslation() const;
const zeus::CVector3f& GetGlobalScale() const;
const zeus::CColor& GetModulationColor() const;
2016-02-13 05:49:59 +00:00
bool IsSystemDeletable() const;
2017-01-21 06:03:37 +00:00
rstl::optional_object<zeus::CAABox> GetBounds() const;
2016-02-13 05:49:59 +00:00
u32 GetParticleCount() const;
bool SystemHasLight() const;
CLight GetLight() const;
bool GetParticleEmission() const;
void DestroyParticles();
2016-02-18 04:44:06 +00:00
void Reset();
2015-08-17 23:46:41 +00:00
};
2016-02-09 22:52:33 +00:00
ENABLE_BITWISE_ENUM(CElementGen::EOptionalSystemFlags)
2015-08-17 23:46:41 +00:00
}
2016-04-13 06:07:23 +00:00
#endif // __URDE_CELEMENTGEN_HPP__