From c7ca8dc3a746c0f4c7ccbc3ce5c701f35b707cf2 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sat, 11 Apr 2020 00:39:49 -0400 Subject: [PATCH] Runtime/Particle: Replace bitfield unions with constructor initializers --- Runtime/Particle/CDecal.cpp | 2 +- Runtime/Particle/CDecal.hpp | 22 +++------ Runtime/Particle/CDecalDescription.hpp | 11 ++--- Runtime/Particle/CElementGen.cpp | 19 ++++++-- Runtime/Particle/CElementGen.hpp | 33 +++++-------- Runtime/Particle/CGenDescription.hpp | 63 +++++++++++++++---------- Runtime/Particle/CParticleElectric.cpp | 11 +++-- Runtime/Particle/CParticleElectric.hpp | 18 +++---- Runtime/Particle/CParticleSwoosh.cpp | 12 ++++- Runtime/Particle/CParticleSwoosh.hpp | 24 ++++------ Runtime/Particle/CSwooshDescription.hpp | 40 +++++++++------- 11 files changed, 134 insertions(+), 121 deletions(-) diff --git a/Runtime/Particle/CDecal.cpp b/Runtime/Particle/CDecal.cpp index c18156852..a5c3d41b8 100644 --- a/Runtime/Particle/CDecal.cpp +++ b/Runtime/Particle/CDecal.cpp @@ -9,7 +9,7 @@ CRandom16 CDecal::sDecalRandom; bool CDecal::sMoveRedToAlphaBuffer = false; CDecal::CDecal(const TToken& desc, const zeus::CTransform& xf) -: x0_description(desc), xc_transform(xf) { +: x0_description(desc), xc_transform(xf), x5c_29_modelInvalid(false) { CGlobalRandom gr(sDecalRandom); CDecalDescription& desco = *x0_description; diff --git a/Runtime/Particle/CDecal.hpp b/Runtime/Particle/CDecal.hpp index 224658da1..6417e052e 100644 --- a/Runtime/Particle/CDecal.hpp +++ b/Runtime/Particle/CDecal.hpp @@ -13,17 +13,12 @@ namespace urde { struct SQuadDescr; struct CQuadDecal { - union { - struct { - bool x0_24_invalid : 1; - }; - u32 _dummy = 0; - }; + bool x0_24_invalid : 1; s32 x4_lifetime = 0; float x8_rotation = 0.f; const SQuadDescr* m_desc = nullptr; - CQuadDecal() = default; - CQuadDecal(s32 i, float f) : x4_lifetime(i), x8_rotation(f) { x0_24_invalid = true; } + CQuadDecal() : x0_24_invalid(true) {} + CQuadDecal(s32 i, float f) : x0_24_invalid(true), x4_lifetime(i), x8_rotation(f) {} boo::ObjToken m_instBuf; boo::ObjToken m_uniformBuf; @@ -41,14 +36,9 @@ class CDecal { std::array x3c_decalQuads; s32 x54_modelLifetime = 0; s32 x58_frameIdx = 0; - union { - struct { - bool x5c_31_quad1Invalid : 1; - bool x5c_30_quad2Invalid : 1; - bool x5c_29_modelInvalid : 1; - }; - u32 x5c_dummy = 0; - }; + bool x5c_31_quad1Invalid : 1; + bool x5c_30_quad2Invalid : 1; + bool x5c_29_modelInvalid : 1; zeus::CVector3f x60_rotation; bool InitQuad(CQuadDecal& quad, const SQuadDescr& desc); diff --git a/Runtime/Particle/CDecalDescription.hpp b/Runtime/Particle/CDecalDescription.hpp index ff1d74afa..7d0038a2e 100644 --- a/Runtime/Particle/CDecalDescription.hpp +++ b/Runtime/Particle/CDecalDescription.hpp @@ -23,6 +23,8 @@ struct SQuadDescr { class CDecalDescription { public: + CDecalDescription() : x5c_24_DMAB(false), x5c_25_DMOO(false) {} + SQuadDescr x0_Quads[2]; SParticleModel x38_DMDL; std::unique_ptr x48_DLFT; @@ -30,13 +32,8 @@ public: std::unique_ptr x50_DMRT; std::unique_ptr x54_DMSC; std::unique_ptr x58_DMCL; - union { - struct { - bool x5c_24_DMAB : 1; - bool x5c_25_DMOO : 1; - }; - u32 dummy = 0; - }; + bool x5c_24_DMAB : 1; + bool x5c_25_DMOO : 1; }; } // namespace urde diff --git a/Runtime/Particle/CElementGen.cpp b/Runtime/Particle/CElementGen.cpp index 1353886a9..479d44e56 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -54,12 +54,25 @@ void CElementGen::Initialize() { void CElementGen::Shutdown() { CElementGenShaders::Shutdown(); } CElementGen::CElementGen(TToken gen, EModelOrientationType orientType, EOptionalSystemFlags flags) -: x1c_genDesc(std::move(gen)), x2c_orientType(orientType), x27c_randState(x94_randomSeed) { +: x1c_genDesc(std::move(gen)) +, x2c_orientType(orientType) +, x26c_24_translationDirty(false) +, x26c_25_LIT_(false) +, x26c_26_AAPH(false) +, x26c_27_ZBUF(false) +, x26c_28_zTest(false) +, x26c_29_ORNT(false) +, x26c_30_MBLR(false) +, x26c_31_LINE(false) +, x26d_24_FXLL(false) +, x26d_25_warmedUp(false) +, x26d_26_modelsUseLights(false) +, x26d_27_enableOPTS(True(flags & EOptionalSystemFlags::Two)) +, x26d_28_enableADV(false) +, x27c_randState(x94_randomSeed) { CGenDescription* desc = x1c_genDesc.GetObj(); x28_loadedGenDesc = desc; - x26d_27_enableOPTS = True(flags & EOptionalSystemFlags::Two); - if (desc->x54_x40_TEXR) desc->x54_x40_TEXR->GetValueTexture(0).GetObj(); if (desc->x58_x44_TIND) diff --git a/Runtime/Particle/CElementGen.hpp b/Runtime/Particle/CElementGen.hpp index 26ec47598..6e585539a 100644 --- a/Runtime/Particle/CElementGen.hpp +++ b/Runtime/Particle/CElementGen.hpp @@ -87,26 +87,19 @@ private: u32 x260_cumulativeParticles = 0; u32 x264_recursiveParticleCount = 0; int x268_PSLT; - - union { - struct { - bool x26c_24_translationDirty : 1; - bool x26c_25_LIT_ : 1; - bool x26c_26_AAPH : 1; - bool x26c_27_ZBUF : 1; - bool x26c_28_zTest : 1; - bool x26c_29_ORNT : 1; - bool x26c_30_MBLR : 1; - bool x26c_31_LINE : 1; - bool x26d_24_FXLL : 1; - bool x26d_25_warmedUp : 1; - bool x26d_26_modelsUseLights : 1; - bool x26d_27_enableOPTS : 1; - bool x26d_28_enableADV : 1; - }; - u32 _dummy = 0; - }; - + bool x26c_24_translationDirty : 1; + bool x26c_25_LIT_ : 1; + bool x26c_26_AAPH : 1; + bool x26c_27_ZBUF : 1; + bool x26c_28_zTest : 1; + bool x26c_29_ORNT : 1; + bool x26c_30_MBLR : 1; + bool x26c_31_LINE : 1; + bool x26d_24_FXLL : 1; + bool x26d_25_warmedUp : 1; + bool x26d_26_modelsUseLights : 1; + bool x26d_27_enableOPTS : 1; + bool x26d_28_enableADV : 1; int x270_MBSP = 0; int m_maxMBSP = 0; ERglLightBits x274_backupLightActive = ERglLightBits::None; diff --git a/Runtime/Particle/CGenDescription.hpp b/Runtime/Particle/CGenDescription.hpp index bde4b376d..5661d62c4 100644 --- a/Runtime/Particle/CGenDescription.hpp +++ b/Runtime/Particle/CGenDescription.hpp @@ -39,30 +39,25 @@ public: // std::unique_ptr x38_ILOC; // std::unique_ptr x3c_IVEC; std::unique_ptr x40_x2c_EMTR; - union { - struct { - bool x44_28_x30_28_SORT : 1; - bool x44_30_x31_24_MBLR : 1; - bool x44_24_x30_24_LINE : 1; - bool x44_29_x30_29_LIT_ : 1; - bool x44_26_x30_26_AAPH : 1; - bool x44_27_x30_27_ZBUF : 1; - bool x44_25_x30_25_FXLL : 1; - bool x44_31_x31_25_PMAB : 1; - bool x45_29_x31_31_VMD4 : 1; - bool x45_28_x31_30_VMD3 : 1; - bool x45_27_x31_29_VMD2 : 1; - bool x45_26_x31_28_VMD1 : 1; - bool x45_31_x32_25_OPTS : 1; - bool x45_24_x31_26_PMUS : 1; - bool x45_25_x31_27_PMOO : 1; - bool x45_30_x32_24_CIND : 1; - /* 0-00 additions */ - bool x30_30_ORNT : 1; - bool x30_31_RSOP : 1; - }; - u32 dummy1 = 0; - }; + bool x44_28_x30_28_SORT : 1; + bool x44_30_x31_24_MBLR : 1; + bool x44_24_x30_24_LINE : 1; + bool x44_29_x30_29_LIT_ : 1; + bool x44_26_x30_26_AAPH : 1; + bool x44_27_x30_27_ZBUF : 1; + bool x44_25_x30_25_FXLL : 1; + bool x44_31_x31_25_PMAB : 1; + bool x45_29_x31_31_VMD4 : 1; + bool x45_28_x31_30_VMD3 : 1; + bool x45_27_x31_29_VMD2 : 1; + bool x45_26_x31_28_VMD1 : 1; + bool x45_31_x32_25_OPTS : 1; + bool x45_24_x31_26_PMUS : 1; + bool x45_25_x31_27_PMOO : 1; + bool x45_30_x32_24_CIND : 1; + /* 0-00 additions */ + bool x30_30_ORNT : 1; + bool x30_31_RSOP : 1; std::unique_ptr x48_x34_MBSP; std::unique_ptr x4c_x38_SIZE; std::unique_ptr x50_x3c_ROTA; @@ -112,7 +107,25 @@ public: /* Custom additions */ std::unique_ptr m_bevelGradient; /* FourCC BGCL */ - CGenDescription() { x45_25_x31_27_PMOO = true; } + CGenDescription() + : x44_28_x30_28_SORT(false) + , x44_30_x31_24_MBLR(false) + , x44_24_x30_24_LINE(false) + , x44_29_x30_29_LIT_(false) + , x44_26_x30_26_AAPH(false) + , x44_27_x30_27_ZBUF(false) + , x44_25_x30_25_FXLL(false) + , x44_31_x31_25_PMAB(false) + , x45_29_x31_31_VMD4(false) + , x45_28_x31_30_VMD3(false) + , x45_27_x31_29_VMD2(false) + , x45_26_x31_28_VMD1(false) + , x45_31_x32_25_OPTS(false) + , x45_24_x31_26_PMUS(false) + , x45_25_x31_27_PMOO(true) + , x45_30_x32_24_CIND(false) + , x30_30_ORNT(false) + , x30_31_RSOP(false) {} }; } // namespace urde diff --git a/Runtime/Particle/CParticleElectric.cpp b/Runtime/Particle/CParticleElectric.cpp index 355b8aaaa..679f6a773 100644 --- a/Runtime/Particle/CParticleElectric.cpp +++ b/Runtime/Particle/CParticleElectric.cpp @@ -19,11 +19,16 @@ namespace urde { u16 CParticleElectric::g_GlobalSeed = 99; CParticleElectric::CParticleElectric(const TToken& token) -: x1c_elecDesc(token), x14c_randState(g_GlobalSeed++) { +: x1c_elecDesc(token) +, x14c_randState(g_GlobalSeed++) +, x450_24_emitting(true) +, x450_25_haveGPSM(false) +, x450_26_haveEPSM(false) +, x450_27_haveSSWH(false) +, x450_28_haveLWD(false) +, x450_29_transformDirty(true) { x1bc_allocated.resize(32); - x450_24_emitting = true; - x450_29_transformDirty = true; CElectricDescription* desc = x1c_elecDesc.GetObj(); if (CIntElement* sseg = desc->x10_SSEG.get()) diff --git a/Runtime/Particle/CParticleElectric.hpp b/Runtime/Particle/CParticleElectric.hpp index 880ec2be3..d69e66f86 100644 --- a/Runtime/Particle/CParticleElectric.hpp +++ b/Runtime/Particle/CParticleElectric.hpp @@ -85,22 +85,16 @@ private: std::vector x420_calculatedVerts; std::vector x430_fractalMags; std::vector x440_fractalOffsets; + bool x450_24_emitting : 1; + bool x450_25_haveGPSM : 1; + bool x450_26_haveEPSM : 1; + bool x450_27_haveSSWH : 1; + bool x450_28_haveLWD : 1; + bool x450_29_transformDirty : 1; size_t m_nextLineRenderer = 0; std::vector> m_lineRenderers; - union { - struct { - bool x450_24_emitting : 1; - bool x450_25_haveGPSM : 1; - bool x450_26_haveEPSM : 1; - bool x450_27_haveSSWH : 1; - bool x450_28_haveLWD : 1; - bool x450_29_transformDirty : 1; - }; - u32 dummy = 0; - }; - void SetupLineGXMaterial(); void DrawLineStrip(const std::vector& verts, float width, const zeus::CColor& color); void RenderLines(); diff --git a/Runtime/Particle/CParticleSwoosh.cpp b/Runtime/Particle/CParticleSwoosh.cpp index 6ab26b711..2017a328d 100644 --- a/Runtime/Particle/CParticleSwoosh.cpp +++ b/Runtime/Particle/CParticleSwoosh.cpp @@ -16,8 +16,16 @@ CParticleSwoosh::CParticleSwoosh(const TToken& desc, int len , x1c0_rand(x1c_desc->x45_26_CRND ? std::chrono::duration_cast( std::chrono::steady_clock::now().time_since_epoch()) .count() - : 99) { - x1d0_24_emitting = true; + : 99) +, x1d0_24_emitting(true) +, x1d0_25_AALP(false) +, x1d0_26_forceOneUpdate(false) +, x1d0_27_renderGaps(false) +, x1d0_28_LLRD(false) +, x1d0_29_VLS1(false) +, x1d0_30_VLS2(false) +, x1d0_31_constantTex(false) +, x1d1_24_constantUv(false) { ++g_ParticleSystemAliveCount; if (leng > 0) diff --git a/Runtime/Particle/CParticleSwoosh.hpp b/Runtime/Particle/CParticleSwoosh.hpp index ed421eeca..e913e1ec8 100644 --- a/Runtime/Particle/CParticleSwoosh.hpp +++ b/Runtime/Particle/CParticleSwoosh.hpp @@ -83,21 +83,15 @@ class CParticleSwoosh : public CParticleGen { float x1c4_ = 0.f; float x1c8_ = 0.f; float x1cc_TSPN; - - union { - struct { - bool x1d0_24_emitting : 1; - bool x1d0_25_AALP : 1; - bool x1d0_26_forceOneUpdate : 1; - bool x1d0_27_renderGaps : 1; - bool x1d0_28_LLRD : 1; - bool x1d0_29_VLS1 : 1; - bool x1d0_30_VLS2 : 1; - bool x1d0_31_constantTex : 1; - bool x1d1_24_constantUv : 1; - }; - u32 _dummy = 0; - }; + bool x1d0_24_emitting : 1; + bool x1d0_25_AALP : 1; + bool x1d0_26_forceOneUpdate : 1; + bool x1d0_27_renderGaps : 1; + bool x1d0_28_LLRD : 1; + bool x1d0_29_VLS1 : 1; + bool x1d0_30_VLS2 : 1; + bool x1d0_31_constantTex : 1; + bool x1d1_24_constantUv : 1; SUVElementSet x1d4_uvs = {}; CTexture* x1e4_tex = nullptr; diff --git a/Runtime/Particle/CSwooshDescription.hpp b/Runtime/Particle/CSwooshDescription.hpp index 084ac1971..67217d80f 100644 --- a/Runtime/Particle/CSwooshDescription.hpp +++ b/Runtime/Particle/CSwooshDescription.hpp @@ -31,23 +31,29 @@ public: std::unique_ptr x38_SPLN; std::unique_ptr x3c_TEXR; std::unique_ptr x40_TSPN; - union { - struct { - bool x44_24_LLRD : 1; - bool x44_25_CROS : 1; - bool x44_26_VLS1 : 1; - bool x44_27_VLS2 : 1; - bool x44_28_SROT : 1; - bool x44_29_WIRE : 1; - bool x44_30_TEXW : 1; - bool x44_31_AALP : 1; - bool x45_24_ZBUF : 1; - bool x45_25_ORNT : 1; - bool x45_26_CRND : 1; - }; - u32 dummy = 0; - }; + bool x44_24_LLRD : 1; + bool x44_25_CROS : 1; + bool x44_26_VLS1 : 1; + bool x44_27_VLS2 : 1; + bool x44_28_SROT : 1; + bool x44_29_WIRE : 1; + bool x44_30_TEXW : 1; + bool x44_31_AALP : 1; + bool x45_24_ZBUF : 1; + bool x45_25_ORNT : 1; + bool x45_26_CRND : 1; - CSwooshDescription() { x44_25_CROS = true; } + CSwooshDescription() + : x44_24_LLRD(false) + , x44_25_CROS(true) + , x44_26_VLS1(false) + , x44_27_VLS2(false) + , x44_28_SROT(false) + , x44_29_WIRE(false) + , x44_30_TEXW(false) + , x44_31_AALP(false) + , x45_24_ZBUF(false) + , x45_25_ORNT(false) + , x45_26_CRND(false) {} }; } // namespace urde