From 93eca39a31cd82b8f479ff8f93389103ac69265a Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sun, 9 Oct 2022 12:42:53 -0400 Subject: [PATCH] CIntEmitter: Updates from matching decomp --- Runtime/Particle/CIntElement.cpp | 91 +++++++++++++++++++------------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/Runtime/Particle/CIntElement.cpp b/Runtime/Particle/CIntElement.cpp index 4bc4c7a62..95fcfaeb0 100644 --- a/Runtime/Particle/CIntElement.cpp +++ b/Runtime/Particle/CIntElement.cpp @@ -26,41 +26,40 @@ CIEKeyframeEmitter::CIEKeyframeEmitter(CInputStream& in) { } bool CIEKeyframeEmitter::GetValue([[maybe_unused]] int frame, int& valOut) const { - if (!x4_percent) { + if (x4_percent == 0) { int emitterTime = CParticleGlobals::instance()->m_EmitterTime; - int calcKey = emitterTime; if (xc_loop) { if (emitterTime >= x10_loopEnd) { - int v1 = emitterTime - x14_loopStart; - int v2 = x10_loopEnd - x14_loopStart; - calcKey = v1 % v2; - calcKey += x14_loopStart; + emitterTime -= x14_loopStart; + emitterTime = emitterTime % (x10_loopEnd - x14_loopStart); + emitterTime += x14_loopStart; } + valOut = x18_keys[emitterTime]; } else { - int v1 = x10_loopEnd - 1; - if (v1 < emitterTime) - calcKey = v1; + emitterTime = std::min(emitterTime, x10_loopEnd - 1); + valOut = x18_keys[emitterTime]; } - valOut = x18_keys[calcKey]; + return false; } else { int ltPerc = CParticleGlobals::instance()->m_ParticleLifetimePercentage; - float ltPercRem = CParticleGlobals::instance()->m_ParticleLifetimePercentageRemainder; - if (ltPerc == 100) - valOut = x18_keys[100]; - else - valOut = ltPercRem * x18_keys[ltPerc + 1] + (1.0f - ltPercRem) * x18_keys[ltPerc]; + if (ltPerc == 100) { + valOut = x18_keys[ltPerc]; + } else { + float ltPercRem = CParticleGlobals::instance()->m_ParticleLifetimePercentageRemainder; + float lerp = (1.0f - ltPercRem) * x18_keys[ltPerc] + ltPercRem * x18_keys[ltPerc + 1]; + valOut = static_cast(lerp); + } + return false; } - return false; } int CIEKeyframeEmitter::GetMaxValue() const { return *std::max_element(x18_keys.cbegin(), x18_keys.cend()); } bool CIEDeath::GetValue(int frame, int& valOut) const { - x4_a->GetValue(frame, valOut); int b; + x4_a->GetValue(frame, valOut); x8_b->GetValue(frame, b); - /* Not 100% sure about this, originally some kinda branchless comparison */ - return frame > b; + return frame >= b; } int CIEDeath::GetMaxValue() const { return x4_a->GetMaxValue(); } @@ -70,8 +69,12 @@ bool CIEClamp::GetValue(int frame, int& valOut) const { x4_min->GetValue(frame, a); x8_max->GetValue(frame, b); xc_val->GetValue(frame, valOut); - - valOut = std::clamp(valOut, a, b); + if (valOut > b) { + valOut = b; + } + if (valOut < a) { + valOut = a; + } return false; } @@ -86,10 +89,11 @@ int CIEClamp::GetMaxValue() const { bool CIETimeChain::GetValue(int frame, int& valOut) const { int v; xc_swFrame->GetValue(frame, v); - if (frame >= v) - return x8_b->GetValue(frame, valOut); - else + if (frame < v) { return x4_a->GetValue(frame, valOut); + } else { + return x8_b->GetValue(frame - v, valOut); + } } int CIETimeChain::GetMaxValue() const { return std::max(x8_b->GetMaxValue(), x4_a->GetMaxValue()); } @@ -116,19 +120,22 @@ bool CIEConstant::GetValue([[maybe_unused]] int frame, int& valOut) const { int CIEConstant::GetMaxValue() const { return x4_val; } bool CIEImpulse::GetValue(int frame, int& valOut) const { - if (frame == 0) + if (frame == 0) { x4_a->GetValue(frame, valOut); - else + } else { valOut = 0; + } return false; } int CIEImpulse::GetMaxValue() const { return x4_a->GetMaxValue(); } bool CIELifetimePercent::GetValue(int frame, int& valOut) const { - int a; + int a = 0; x4_percentVal->GetValue(frame, a); - a = std::max(0, a); + if (a < 0) { + a = 0; + } valOut = (a / 100.0f) * CParticleGlobals::instance()->m_ParticleLifetimeReal + 0.5f; return false; } @@ -161,10 +168,14 @@ bool CIEPulse::GetValue(int frame, int& valOut) const { cv = 1; } - if (b < 1 || frame % cv <= a) { - xc_aVal->GetValue(frame, valOut); + if (b >= 1) { + if (frame % cv > a) { + x10_bVal->GetValue(frame, valOut); + } else { + xc_aVal->GetValue(frame, valOut); + } } else { - x10_bVal->GetValue(frame, valOut); + xc_aVal->GetValue(frame, valOut); } return false; } @@ -182,17 +193,19 @@ bool CIEMultiply::GetValue(int frame, int& valOut) const { int CIEMultiply::GetMaxValue() const { return x4_a->GetMaxValue() * x8_b->GetMaxValue(); } bool CIESampleAndHold::GetValue(int frame, int& valOut) const { + bool ret; if (x8_nextSampleFrame < frame) { int b, c; xc_waitFramesMin->GetValue(frame, b); x10_waitFramesMax->GetValue(frame, c); x8_nextSampleFrame = CRandom16::GetRandomNumber()->Range(b, c) + frame; - x4_sampleSource->GetValue(frame, valOut); + ret = x4_sampleSource->GetValue(frame, valOut); x14_holdVal = valOut; } else { valOut = x14_holdVal; + ret = false; } - return false; + return ret; } int CIESampleAndHold::GetMaxValue() const { return x4_sampleSource->GetMaxValue(); } @@ -201,10 +214,11 @@ bool CIERandom::GetValue(int frame, int& valOut) const { int a, b; x4_min->GetValue(frame, a); x8_max->GetValue(frame, b); - if (a > 0) + if (a > 0) { valOut = CRandom16::GetRandomNumber()->Range(a, b); - else + } else { valOut = CRandom16::GetRandomNumber()->Next(); + } return false; } @@ -218,7 +232,7 @@ int CIERandom::GetMaxValue() const { bool CIETimeScale::GetValue(int frame, int& valOut) const { float a; x4_a->GetValue(frame, a); - valOut = float(frame) * a; + valOut = static_cast< float >(frame) * a; return false; } @@ -249,10 +263,11 @@ bool CIEModulo::GetValue(int frame, int& valOut) const { int a, b; x4_a->GetValue(frame, a); x8_b->GetValue(frame, b); - if (b != 0) + if (b != 0) { valOut = a % b; - else + } else { valOut = a; + } return false; }