From 42717c383c5561e68dbc9fb99e0b3c173e470ca9 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Fri, 18 Mar 2016 19:04:12 -0700 Subject: [PATCH] Rename EVNT structs to match the engine Implement getter elements and state tracking for CElementGen --- DataSpec/DNAMP1/EVNT.cpp | 52 +++++++++++------------ DataSpec/DNAMP1/EVNT.hpp | 30 +++++++------ Runtime/Particle/CElementGen.cpp | 20 +++++++++ Runtime/Particle/CElementGen.hpp | 9 +++- Runtime/Particle/CIntElement.cpp | 14 +++--- Runtime/Particle/CIntElement.hpp | 6 +-- Runtime/Particle/CParticleDataFactory.cpp | 18 ++++---- Runtime/Particle/CParticleGlobals.hpp | 4 +- Runtime/Particle/CVectorElement.cpp | 24 ++++------- Runtime/Particle/CVectorElement.hpp | 12 +++--- 10 files changed, 108 insertions(+), 81 deletions(-) diff --git a/DataSpec/DNAMP1/EVNT.cpp b/DataSpec/DNAMP1/EVNT.cpp index e22025759..6e10ff552 100644 --- a/DataSpec/DNAMP1/EVNT.cpp +++ b/DataSpec/DNAMP1/EVNT.cpp @@ -10,19 +10,19 @@ void EVNT::read(athena::io::IStreamReader& reader) version = reader.readUint32Big(); atUint32 loopCount = reader.readUint32Big(); - reader.enumerate(loopEvents, loopCount); + reader.enumerate(boolPOINodes, loopCount); - uevtEvents.clear(); + int32POINodes.clear(); atUint32 uevtCount = reader.readUint32Big(); - reader.enumerate(uevtEvents, uevtCount); + reader.enumerate(int32POINodes, uevtCount); atUint32 effectCount = reader.readUint32Big(); - reader.enumerate(effectEvents, effectCount); + reader.enumerate(particlePOINodes, effectCount); if (version == 2) { atUint32 sfxCount = reader.readUint32Big(); - reader.enumerate(sfxEvents, sfxCount); + reader.enumerate(soundPOINodes, sfxCount); } } @@ -30,19 +30,19 @@ void EVNT::write(athena::io::IStreamWriter& writer) const { writer.writeUint32Big(version); - writer.writeUint32Big(loopEvents.size()); - writer.enumerate(loopEvents); + writer.writeUint32Big(boolPOINodes.size()); + writer.enumerate(boolPOINodes); - writer.writeUint32Big(uevtEvents.size()); - writer.enumerate(uevtEvents); + writer.writeUint32Big(int32POINodes.size()); + writer.enumerate(int32POINodes); - writer.writeUint32Big(effectEvents.size()); - writer.enumerate(effectEvents); + writer.writeUint32Big(particlePOINodes.size()); + writer.enumerate(particlePOINodes); if (version == 2) { - writer.writeUint32Big(sfxEvents.size()); - writer.enumerate(sfxEvents); + writer.writeUint32Big(soundPOINodes.size()); + writer.enumerate(soundPOINodes); } } @@ -50,16 +50,16 @@ void EVNT::read(athena::io::YAMLDocReader& reader) { version = reader.readUint32("version"); - reader.enumerate("loopEvents", loopEvents); + reader.enumerate("boolPOINodes", boolPOINodes); - uevtEvents.clear(); - reader.enumerate("uevtEvents", uevtEvents); + int32POINodes.clear(); + reader.enumerate("int32POINodes", int32POINodes); - reader.enumerate("effectEvents", effectEvents); + reader.enumerate("particlePOINodes", particlePOINodes); if (version == 2) { - reader.enumerate("sfxEvents", sfxEvents); + reader.enumerate("soundPOINodes", soundPOINodes); } } @@ -67,15 +67,15 @@ void EVNT::write(athena::io::YAMLDocWriter& writer) const { writer.writeUint32("version", version); - writer.enumerate("loopEvents", loopEvents); + writer.enumerate("boolPOINodes", boolPOINodes); - writer.enumerate("uevtEvents", uevtEvents); + writer.enumerate("int32POINodes", int32POINodes); - writer.enumerate("effectEvents", effectEvents); + writer.enumerate("particlePOINodes", particlePOINodes); if (version == 2) { - writer.enumerate("sfxEvents", sfxEvents); + writer.enumerate("soundPOINodes", soundPOINodes); } } @@ -86,11 +86,11 @@ const char* EVNT::DNAType() size_t EVNT::binarySize(size_t __isz) const { - __isz = __EnumerateSize(__isz, loopEvents); - __isz = __EnumerateSize(__isz, uevtEvents); - __isz = __EnumerateSize(__isz, effectEvents); + __isz = __EnumerateSize(__isz, boolPOINodes); + __isz = __EnumerateSize(__isz, int32POINodes); + __isz = __EnumerateSize(__isz, particlePOINodes); if (version == 2) - __isz = __EnumerateSize(__isz, sfxEvents); + __isz = __EnumerateSize(__isz, soundPOINodes); return __isz + (version == 2 ? 20 : 16); } diff --git a/DataSpec/DNAMP1/EVNT.hpp b/DataSpec/DNAMP1/EVNT.hpp index c5ff317f2..0c36b1333 100644 --- a/DataSpec/DNAMP1/EVNT.hpp +++ b/DataSpec/DNAMP1/EVNT.hpp @@ -15,37 +15,43 @@ struct EVNT : BigYAML Delete expl; Value version; - struct EventBase : BigYAML + struct POINode : BigYAML { DECL_YAML Value unk0; String<-1> name; Value type; - Value startTime; - Value unk1; + struct CharAnimTime : BigYAML + { + DECL_YAML + Value time; + Value unk1; + }; + + CharAnimTime animTime; Value idx; - Value unk2; + Value unk2; Value unk3; Value unk4; Value unk5; }; - struct LoopEvent : EventBase + struct BoolPOINode : POINode { DECL_YAML Value flag; }; - std::vector loopEvents; + std::vector boolPOINodes; - struct UEVTEvent : EventBase + struct Int32POINode : POINode { DECL_YAML Value uevtType; String<-1> boneName; }; - std::vector uevtEvents; + std::vector int32POINodes; - struct EffectEvent : EventBase + struct ParticlePOINode : POINode { DECL_YAML Value frameCount; @@ -55,16 +61,16 @@ struct EVNT : BigYAML Value scale; Value parentMode; }; - std::vector effectEvents; + std::vector particlePOINodes; - struct SFXEvent : EventBase + struct SoundPOINode : POINode { DECL_YAML Value soundId; Value smallNum; Value bigNum; }; - std::vector sfxEvents; + std::vector soundPOINodes; static bool Extract(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) { diff --git a/Runtime/Particle/CElementGen.cpp b/Runtime/Particle/CElementGen.cpp index c0d1ea1d0..88f9c3642 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -456,6 +456,9 @@ CElementGen::~CElementGen() void CElementGen::Update(double t) { + CParticleGlobals::SParticleSystem* prevSystem = CParticleGlobals::g_currentParticleSystem; + CParticleGlobals::SParticleSystem thisSystem { FOURCC('PART'), this }; + CParticleGlobals::g_currentParticleSystem = &thisSystem; CGenDescription* desc = x1c_genDesc.GetObj(); CIntElement* pswtElem = desc->x10_x4_PSWT.get(); if (pswtElem && !x225_28_warmedUp) @@ -472,6 +475,7 @@ void CElementGen::Update(double t) } } InternalUpdate(t); + CParticleGlobals::g_currentParticleSystem = prevSystem; } bool CElementGen::InternalUpdate(double dt) @@ -806,6 +810,7 @@ void CElementGen::CreateNewParticles(int count) } AccumulateBounds(particle.x4_pos, particle.x2c_lineLengthOrSize); + ++x260_cumulativeParticles; ++x210_curEmitterFrame; --g_FreeIndex; } @@ -1117,6 +1122,17 @@ void CElementGen::EndLifetime() ch->SetParticleEmission(false); } +void CElementGen::ForceParticleCreation(int amount) +{ + CParticleGlobals::SParticleSystem* prevSystem = CParticleGlobals::g_currentParticleSystem; + CParticleGlobals::SParticleSystem thisSystem{ FOURCC('PART'), this }; + CParticleGlobals::g_currentParticleSystem = &thisSystem; + /* This is a guess, but it seems right, retail loads x74 */ + CParticleGlobals::SetEmitterTime(x50_curFrame); + CreateNewParticles(amount); + CParticleGlobals::g_currentParticleSystem = prevSystem; +} + void CElementGen::BuildParticleSystemBounds() { zeus::CAABox aabb; @@ -1193,6 +1209,9 @@ u32 CElementGen::GetSystemCount() void CElementGen::Render() { + CParticleGlobals::SParticleSystem* prevSystem = CParticleGlobals::g_currentParticleSystem; + CParticleGlobals::SParticleSystem thisSystem{ FOURCC('PART'), this }; + CParticleGlobals::g_currentParticleSystem = &thisSystem; CGenDescription* desc = x1c_genDesc.GetObj(); x22c_backupLightActive = CGraphics::g_LightActive; @@ -1222,6 +1241,7 @@ void CElementGen::Render() else RenderParticles(); } + CParticleGlobals::g_currentParticleSystem = prevSystem; } void CElementGen::RenderModels() diff --git a/Runtime/Particle/CElementGen.hpp b/Runtime/Particle/CElementGen.hpp index a7939130b..3a9fa3888 100644 --- a/Runtime/Particle/CElementGen.hpp +++ b/Runtime/Particle/CElementGen.hpp @@ -128,6 +128,7 @@ private: std::vector> x248_finishPartChildren; int x258_SISY = 16; int x25c_PISY = 16; + u32 x260_cumulativeParticles = 0; /* Retail */ std::vector> x260_swhcChildren; int x270_SSSD = 0; zeus::CVector3f x274_SSPO; @@ -196,11 +197,17 @@ public: CElementGen* ConstructChildParticleSystem(const TToken&); void UpdateLightParameters(); void BuildParticleSystemBounds(); + u32 GetEmitterTime() const + { + /* Game returns x74, guessing x50 is what it's asking for */ + return x50_curFrame; + } u32 GetSystemCount(); + u32 GetCumulativeParticleCount() const { return x260_cumulativeParticles; } u32 GetParticleCountAllInternal() const; u32 GetParticleCountAll() const {return x20c_recursiveParticleCount;} void EndLifetime(); - void ForceParticleCreation(int amount) { CreateNewParticles(amount); } + void ForceParticleCreation(int amount); bool InternalUpdate(double); void RenderModels(); diff --git a/Runtime/Particle/CIntElement.cpp b/Runtime/Particle/CIntElement.cpp index 03112c0f5..ee4d46400 100644 --- a/Runtime/Particle/CIntElement.cpp +++ b/Runtime/Particle/CIntElement.cpp @@ -1,7 +1,7 @@ #include "CIntElement.hpp" #include "CParticleGlobals.hpp" #include "CRandom16.hpp" - +#include "CElementGen.hpp" /* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Int_Elements */ namespace urde @@ -203,21 +203,21 @@ bool CIETimeScale::GetValue(int frame, int& valOut) const return false; } -bool CIEGTCP::GetValue(int frame, int& valOut) const +bool CIEGetCumulativeParticleCount::GetValue(int frame, int& valOut) const { - /* TODO: Do */ + valOut = CParticleGlobals::g_currentParticleSystem->x4_system->GetCumulativeParticleCount(); return false; } -bool CIEGAPC::GetValue(int frame, int &valOut) const +bool CIEGetActiveParticleCount::GetValue(int frame, int &valOut) const { - /* TODO: Do */ + valOut = CParticleGlobals::g_currentParticleSystem->x4_system->GetParticleCount(); return false; } -bool CIEGEMT::GetValue(int frame, int &valOut) const +bool CIEGetEmitterTime::GetValue(int frame, int &valOut) const { - /* TODO: Do */ + valOut = CParticleGlobals::g_currentParticleSystem->x4_system->GetEmitterTime(); return false; } diff --git a/Runtime/Particle/CIntElement.hpp b/Runtime/Particle/CIntElement.hpp index 0f089e830..c9ce860af 100644 --- a/Runtime/Particle/CIntElement.hpp +++ b/Runtime/Particle/CIntElement.hpp @@ -154,19 +154,19 @@ public: bool GetValue(int frame, int& valOut) const; }; -class CIEGTCP : public CIntElement +class CIEGetCumulativeParticleCount : public CIntElement { public: bool GetValue(int frame, int& valOut) const; }; -class CIEGAPC : public CIntElement +class CIEGetActiveParticleCount : public CIntElement { public: bool GetValue(int frame, int &valOut) const; }; -class CIEGEMT : public CIntElement +class CIEGetEmitterTime : public CIntElement { public: bool GetValue(int frame, int &valOut) const; diff --git a/Runtime/Particle/CParticleDataFactory.cpp b/Runtime/Particle/CParticleDataFactory.cpp index 7d900e725..bff870ba6 100644 --- a/Runtime/Particle/CParticleDataFactory.cpp +++ b/Runtime/Particle/CParticleDataFactory.cpp @@ -446,27 +446,27 @@ CVectorElement* CParticleDataFactory::GetVectorElement(CInputStream& in) } case SBIG('PLCO'): { - return new CVEPLCO; + return new CVEParticleColor; } case SBIG('PLOC'): { - return new CVEPLOC; + return new CVEParticleLocation; } case SBIG('PSOF'): { - return new CVEPSOF; + return new CVEParticleSystemOrientationFront; } case SBIG('PSOU'): { - return new CVEPSOU; + return new CVEParticleSystemOrientationUp; } case SBIG('PSOR'): { - return new CVEPSOR; + return new CVEParticleSystemOrientationRight; } case SBIG('PSTR'): { - return new CVEPSTR; + return new CVEParticleSystemTranslation; } case SBIG('SUB_'): { @@ -798,15 +798,15 @@ CIntElement* CParticleDataFactory::GetIntElement(CInputStream& in) } case SBIG('GAPC'): { - return new CIEGAPC; + return new CIEGetActiveParticleCount; } case SBIG('GTCP'): { - return new CIEGTCP; + return new CIEGetCumulativeParticleCount; } case SBIG('GEMT'): { - return new CIEGEMT; + return new CIEGetEmitterTime; } case SBIG('MODU'): { diff --git a/Runtime/Particle/CParticleGlobals.hpp b/Runtime/Particle/CParticleGlobals.hpp index 83925f1e4..fd848eafb 100644 --- a/Runtime/Particle/CParticleGlobals.hpp +++ b/Runtime/Particle/CParticleGlobals.hpp @@ -7,7 +7,7 @@ namespace urde { -class CParticleGen; +class CElementGen; class CParticleGlobals { public: @@ -43,7 +43,7 @@ public: struct SParticleSystem { FourCC x0_type; - CParticleGen* x4_system; + CElementGen* x4_system; }; static SParticleSystem* g_currentParticleSystem; diff --git a/Runtime/Particle/CVectorElement.cpp b/Runtime/Particle/CVectorElement.cpp index 9a4d930b2..a679971c2 100644 --- a/Runtime/Particle/CVectorElement.cpp +++ b/Runtime/Particle/CVectorElement.cpp @@ -270,46 +270,40 @@ bool CVEParticleVelocity::GetValue(int /*frame*/, zeus::CVector3f& valOut) const return false; } -bool CVEPLCO::GetValue(int /*frame*/, zeus::CVector3f& valOut) const +bool CVEParticleColor::GetValue(int /*frame*/, zeus::CVector3f& valOut) const { valOut = CElementGen::g_currentParticle->x10_prevPos; return false; } -bool CVEPLOC::GetValue(int /*frame*/, zeus::CVector3f& valOut) const +bool CVEParticleLocation::GetValue(int /*frame*/, zeus::CVector3f& valOut) const { valOut = CElementGen::g_currentParticle->x4_pos; return false; } -bool CVEPSOF::GetValue(int /*frame*/, zeus::CVector3f& valOut) const +bool CVEParticleSystemOrientationFront::GetValue(int /*frame*/, zeus::CVector3f& valOut) const { + /* TODO: Get front vector */ zeus::CTransform trans= CParticleGlobals::g_currentParticleSystem->x4_system->GetOrientation(); - valOut.x = trans.m_basis[0].y; - valOut.y = trans.m_basis[1].z; - valOut.z = trans.m_origin.x; return false; } -bool CVEPSOU::GetValue(int /*frame*/, zeus::CVector3f& valOut) const +bool CVEParticleSystemOrientationUp::GetValue(int /*frame*/, zeus::CVector3f& valOut) const { + /* TODO: Get up vector */ zeus::CTransform trans= CParticleGlobals::g_currentParticleSystem->x4_system->GetOrientation(); - valOut.x = trans.m_basis[0].z; - valOut.y = trans.m_basis[1].x; - valOut.z = trans.m_origin.y; return false; } -bool CVEPSOR::GetValue(int /*frame*/, zeus::CVector3f& valOut) const +bool CVEParticleSystemOrientationRight::GetValue(int /*frame*/, zeus::CVector3f& valOut) const { + /* TODO: Get right vector */ zeus::CTransform trans= CParticleGlobals::g_currentParticleSystem->x4_system->GetOrientation(); - valOut.x = trans.m_basis[0].x; - valOut.y = trans.m_basis[1].y; - valOut.z = trans.m_basis[2].z; return false; } -bool CVEPSTR::GetValue(int /*frame*/, zeus::CVector3f& valOut) const +bool CVEParticleSystemTranslation::GetValue(int /*frame*/, zeus::CVector3f& valOut) const { valOut = CParticleGlobals::g_currentParticleSystem->x4_system->GetTranslation(); return false; diff --git a/Runtime/Particle/CVectorElement.hpp b/Runtime/Particle/CVectorElement.hpp index 6cc429330..53c9aa3fb 100644 --- a/Runtime/Particle/CVectorElement.hpp +++ b/Runtime/Particle/CVectorElement.hpp @@ -149,37 +149,37 @@ public: bool GetValue(int frame, zeus::CVector3f& valOut) const; }; -class CVEPLCO : public CVectorElement +class CVEParticleColor : public CVectorElement { public: bool GetValue(int frame, zeus::CVector3f& valOut) const; }; -class CVEPLOC : public CVectorElement +class CVEParticleLocation : public CVectorElement { public: bool GetValue(int frame, zeus::CVector3f& valOut) const; }; -class CVEPSOF : public CVectorElement +class CVEParticleSystemOrientationFront : public CVectorElement { public: bool GetValue(int frame, zeus::CVector3f& valOut) const; }; -class CVEPSOU : public CVectorElement +class CVEParticleSystemOrientationUp : public CVectorElement { public: bool GetValue(int frame, zeus::CVector3f& valOut) const; }; -class CVEPSOR : public CVectorElement +class CVEParticleSystemOrientationRight : public CVectorElement { public: bool GetValue(int frame, zeus::CVector3f& valOut) const; }; -class CVEPSTR : public CVectorElement +class CVEParticleSystemTranslation : public CVectorElement { public: bool GetValue(int frame, zeus::CVector3f& valOut) const;