diff --git a/Runtime/MP1/World/CMetroidPrimeEssence.cpp b/Runtime/MP1/World/CMetroidPrimeEssence.cpp index 8728e0dae..e90e8a1fd 100644 --- a/Runtime/MP1/World/CMetroidPrimeEssence.cpp +++ b/Runtime/MP1/World/CMetroidPrimeEssence.cpp @@ -203,7 +203,8 @@ void CMetroidPrimeEssence::DoUserAnimEvent(CStateManager& mgr, const CInt32POINo } case EUserEventType::BeginAction: { SShockWaveData data(x660_, x698_, 2.f, x664_, x70c_); - data.SetSpeedIncrease(180.f); + // TODO: Need to fix CElementGen accessing null ParticleAccessParameters + // data.SetSpeedIncrease(180.f); DropShockwave(mgr, data); ShakeCamera(mgr, 1.f); return; diff --git a/Runtime/Particle/CElementGen.cpp b/Runtime/Particle/CElementGen.cpp index 468f7cf30..05fbd00c6 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -83,6 +83,7 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie if (CIntElement* mbspElem = desc->x48_x34_MBSP.get()) mbspElem->GetValue(x74_curFrame, x270_MBSP); + m_maxMBSP = x270_MBSP; if (CModVectorElement* elem = desc->x7c_x68_VEL1.get()) { x280_VELSources[0] = elem; @@ -151,11 +152,13 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie if (CIntElement* maxpElem = desc->x28_x1c_MAXP.get()) { maxpElem->GetValue(x74_curFrame, x90_MAXP); + m_maxMAXP = maxpElem->GetMaxValue(); } - x30_particles.reserve(x90_MAXP); + m_maxMAXP = std::min(m_maxMAXP, 256); + x30_particles.reserve(m_maxMAXP); if (x2c_orientType == EModelOrientationType::One) - x50_parentMatrices.resize(x90_MAXP); + x50_parentMatrices.resize(m_maxMAXP); x26c_31_LINE = desc->x44_24_x30_24_LINE; x26d_24_FXLL = desc->x44_25_x30_25_FXLL; @@ -202,14 +205,14 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie boo::ObjToken tex; if (texr) tex = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - int maxVerts = x90_MAXP; + int maxVerts = (m_maxMAXP == 0 ? 256 : m_maxMAXP); m_lineRenderer.reset( new CLineRenderer(CLineRenderer::EPrimitiveMode::Lines, maxVerts * 2, tex, x26c_26_AAPH, x26c_28_zTest)); } else { m_shaderClass = CElementGenShaders::GetShaderClass(*this); } - size_t maxInsts = x26c_30_MBLR ? (x270_MBSP * x90_MAXP) : x90_MAXP; + size_t maxInsts = x26c_30_MBLR ? (m_maxMBSP * m_maxMAXP) : m_maxMAXP; maxInsts = (maxInsts == 0 ? 256 : maxInsts); CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { @@ -271,6 +274,7 @@ bool CElementGen::InternalUpdate(double dt) { if (x26c_30_MBLR && dt > 0.0) { if (CIntElement* mbspElem = desc->x48_x34_MBSP.get()) mbspElem->GetValue(x74_curFrame, x270_MBSP); + x270_MBSP = std::min(x270_MBSP, m_maxMBSP); } int frameUpdateCount = 0; @@ -339,7 +343,12 @@ void CElementGen::AccumulateBounds(const zeus::CVector3f& pos, float size) { } void CElementGen::UpdateAdvanceAccessParameters(u32 activeParticleCount, s32 particleFrame) { - CGenDescription* desc = x28_loadedGenDesc; + if (activeParticleCount >= x60_advValues.size()) { + CParticleGlobals::instance()->m_particleAccessParameters = nullptr; + return; + } + + CGenDescription* desc = x1c_genDesc.GetObj(); std::array& arr = x60_advValues[activeParticleCount]; CParticleGlobals::instance()->m_particleAccessParameters = &arr; @@ -395,7 +404,10 @@ void CElementGen::UpdateExistingParticles() { x25c_activeParticleCount = 0; CParticleGlobals::instance()->SetEmitterTime(x74_curFrame); - CParticleGlobals::instance()->m_particleAccessParameters = nullptr; + if (x25c_activeParticleCount < x60_advValues.size()) + CParticleGlobals::instance()->m_particleAccessParameters = &x60_advValues[x25c_activeParticleCount]; + else + CParticleGlobals::instance()->m_particleAccessParameters = nullptr; for (auto it = x30_particles.begin(); it != x30_particles.end();) { CParticle& particle = *it; @@ -486,14 +498,13 @@ void CElementGen::CreateNewParticles(int count) { CGlobalRandom gr(x27c_randState); x30_particles.reserve(x90_MAXP); if (x26d_28_enableADV && x60_advValues.empty()) - x60_advValues.resize(x90_MAXP); + x60_advValues.resize(m_maxMAXP); CParticleGlobals::instance()->m_particleAccessParameters = nullptr; for (int i = 0; i < count; ++i) { CParticle& particle = x30_particles.emplace_back(); ++g_ParticleAliveCount; - u32 particleCount = x30_particles.size() - 1; ++x25c_activeParticleCount; ++x260_cumulativeParticles; if (x2c_orientType == EModelOrientationType::One) { @@ -507,16 +518,14 @@ void CElementGen::CreateNewParticles(int count) { CParticleGlobals::instance()->SetParticleLifetime(particle.x0_endFrame); CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(0); g_currentParticle = &particle; - if (x26d_28_enableADV) { - UpdateAdvanceAccessParameters(particleCount, 0); - } + if (x26d_28_enableADV) + UpdateAdvanceAccessParameters(x30_particles.size() - 1, 0); particle.x0_endFrame += x74_curFrame; - if (CColorElement* colr = desc->x30_x24_COLR.get()) { + if (CColorElement* colr = desc->x30_x24_COLR.get()) colr->GetValue(0, particle.x34_color); - } else { + else particle.x34_color = zeus::skWhite; - } if (CEmitterElement* emtr = desc->x40_x2c_EMTR.get()) { emtr->GetValue(x74_curFrame, particle.x4_pos, particle.x1c_vel); @@ -831,13 +840,12 @@ void CElementGen::Render(const CActorLights* actorLights) { } void CElementGen::RenderModels(const CActorLights* actorLights) { - CParticleGlobals::instance()->m_particleAccessParameters = nullptr; + CGenDescription* desc = x1c_genDesc.GetObj(); + if (x26d_26_modelsUseLights) CGraphics::SetLightState(x274_backupLightActive); CGlobalRandom gr(x27c_randState); - CGenDescription* desc = x1c_genDesc.GetObj(); - SUVElementSet uvs = {0.f, 0.f, 1.f, 1.f}; CUVElement* texr = desc->x54_x40_TEXR.get(); CTexture* cachedTex = nullptr; @@ -940,10 +948,10 @@ void CElementGen::RenderModels(const CActorLights* actorLights) { CParticleGlobals::instance()->SetParticleLifetime(particle.x0_endFrame - particle.x28_startFrame); int partFrame = x74_curFrame - particle.x28_startFrame - 1; CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(partFrame); - if (x26d_28_enableADV) { + if (i < x60_advValues.size()) CParticleGlobals::instance()->m_particleAccessParameters = &x60_advValues[i]; - } - + else + CParticleGlobals::instance()->m_particleAccessParameters = nullptr; CVectorElement* pmop = desc->x6c_x58_PMOP.get(); if (pmop) pmop->GetValue(partFrame, pmopVec); diff --git a/Runtime/Particle/CElementGen.hpp b/Runtime/Particle/CElementGen.hpp index 1230e493f..892133f04 100644 --- a/Runtime/Particle/CElementGen.hpp +++ b/Runtime/Particle/CElementGen.hpp @@ -65,6 +65,7 @@ private: bool x88_particleEmission = true; float x8c_generatorRemainder = 0.f; int x90_MAXP = 0; + int m_maxMAXP = 256; u16 x94_randomSeed = g_GlobalSeed; float x98_generatorRate = 1.f; std::array x9c_externalVars{}; @@ -100,6 +101,7 @@ private: bool x26d_27_enableOPTS : 1; bool x26d_28_enableADV : 1 = false; int x270_MBSP = 0; + int m_maxMBSP = 0; ERglLightBits x274_backupLightActive = ERglLightBits::None; std::array x278_hasVMD{}; CRandom16 x27c_randState; @@ -223,6 +225,7 @@ public: static void SetMoveRedToAlphaBuffer(bool move); s32 GetMaxParticles() const { return x90_MAXP; } + s32 GetMaxMaxParticles() const { return m_maxMAXP; } std::vector const& GetParticles() const { return x30_particles; } std::vector &GetParticles() { return x30_particles; } diff --git a/Runtime/Weapon/CNewFlameThrower.cpp b/Runtime/Weapon/CNewFlameThrower.cpp index 8a34ae858..ef430c030 100644 --- a/Runtime/Weapon/CNewFlameThrower.cpp +++ b/Runtime/Weapon/CNewFlameThrower.cpp @@ -368,6 +368,15 @@ void CNewFlameThrower::UpdateFx(const zeus::CTransform& xf, float dt, CStateMana float tmp = std::clamp(unk.magnitude() * 30.f, 1.f, x37c_26_runningSlowish ? 2.f : 4.f); x3b4_numSmokeParticlesSpawned = std::max(static_cast(round(tmp)), x3b4_numSmokeParticlesSpawned - 1); + // INSERT + if ((x35c_mainSmokeGen->GetParticles().size() + x3b4_numSmokeParticlesSpawned) > + x35c_mainSmokeGen->GetMaxMaxParticles()) { + x3b4_numSmokeParticlesSpawned = x3b4_numSmokeParticlesSpawned - + ((x35c_mainSmokeGen->GetParticles().size() + x3b4_numSmokeParticlesSpawned) - + x35c_mainSmokeGen->GetMaxMaxParticles()); + } + // END INSERT + // This limit shouldn't be needed, m_maxMAXP should be removed? x35c_mainSmokeGen->SetTranslation(swoosh_1.xc_translation); x35c_mainSmokeGen->SetOrientation(swoosh_1.x38_orientation);