CIntEmitter: Updates from matching decomp

This commit is contained in:
Luke Street 2022-10-09 12:42:53 -04:00
parent 1758ea076d
commit 93eca39a31
1 changed files with 53 additions and 38 deletions

View File

@ -26,41 +26,40 @@ CIEKeyframeEmitter::CIEKeyframeEmitter(CInputStream& in) {
} }
bool CIEKeyframeEmitter::GetValue([[maybe_unused]] int frame, int& valOut) const { bool CIEKeyframeEmitter::GetValue([[maybe_unused]] int frame, int& valOut) const {
if (!x4_percent) { if (x4_percent == 0) {
int emitterTime = CParticleGlobals::instance()->m_EmitterTime; int emitterTime = CParticleGlobals::instance()->m_EmitterTime;
int calcKey = emitterTime;
if (xc_loop) { if (xc_loop) {
if (emitterTime >= x10_loopEnd) { if (emitterTime >= x10_loopEnd) {
int v1 = emitterTime - x14_loopStart; emitterTime -= x14_loopStart;
int v2 = x10_loopEnd - x14_loopStart; emitterTime = emitterTime % (x10_loopEnd - x14_loopStart);
calcKey = v1 % v2; emitterTime += x14_loopStart;
calcKey += x14_loopStart;
} }
valOut = x18_keys[emitterTime];
} else { } else {
int v1 = x10_loopEnd - 1; emitterTime = std::min<int>(emitterTime, x10_loopEnd - 1);
if (v1 < emitterTime) valOut = x18_keys[emitterTime];
calcKey = v1;
} }
valOut = x18_keys[calcKey]; return false;
} else { } else {
int ltPerc = CParticleGlobals::instance()->m_ParticleLifetimePercentage; int ltPerc = CParticleGlobals::instance()->m_ParticleLifetimePercentage;
float ltPercRem = CParticleGlobals::instance()->m_ParticleLifetimePercentageRemainder; if (ltPerc == 100) {
if (ltPerc == 100) valOut = x18_keys[ltPerc];
valOut = x18_keys[100]; } else {
else float ltPercRem = CParticleGlobals::instance()->m_ParticleLifetimePercentageRemainder;
valOut = ltPercRem * x18_keys[ltPerc + 1] + (1.0f - ltPercRem) * x18_keys[ltPerc]; float lerp = (1.0f - ltPercRem) * x18_keys[ltPerc] + ltPercRem * x18_keys[ltPerc + 1];
valOut = static_cast<int>(lerp);
}
return false;
} }
return false;
} }
int CIEKeyframeEmitter::GetMaxValue() const { return *std::max_element(x18_keys.cbegin(), x18_keys.cend()); } int CIEKeyframeEmitter::GetMaxValue() const { return *std::max_element(x18_keys.cbegin(), x18_keys.cend()); }
bool CIEDeath::GetValue(int frame, int& valOut) const { bool CIEDeath::GetValue(int frame, int& valOut) const {
x4_a->GetValue(frame, valOut);
int b; int b;
x4_a->GetValue(frame, valOut);
x8_b->GetValue(frame, b); 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(); } 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); x4_min->GetValue(frame, a);
x8_max->GetValue(frame, b); x8_max->GetValue(frame, b);
xc_val->GetValue(frame, valOut); xc_val->GetValue(frame, valOut);
if (valOut > b) {
valOut = std::clamp(valOut, a, b); valOut = b;
}
if (valOut < a) {
valOut = a;
}
return false; return false;
} }
@ -86,10 +89,11 @@ int CIEClamp::GetMaxValue() const {
bool CIETimeChain::GetValue(int frame, int& valOut) const { bool CIETimeChain::GetValue(int frame, int& valOut) const {
int v; int v;
xc_swFrame->GetValue(frame, v); xc_swFrame->GetValue(frame, v);
if (frame >= v) if (frame < v) {
return x8_b->GetValue(frame, valOut);
else
return x4_a->GetValue(frame, valOut); 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()); } 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; } int CIEConstant::GetMaxValue() const { return x4_val; }
bool CIEImpulse::GetValue(int frame, int& valOut) const { bool CIEImpulse::GetValue(int frame, int& valOut) const {
if (frame == 0) if (frame == 0) {
x4_a->GetValue(frame, valOut); x4_a->GetValue(frame, valOut);
else } else {
valOut = 0; valOut = 0;
}
return false; return false;
} }
int CIEImpulse::GetMaxValue() const { return x4_a->GetMaxValue(); } int CIEImpulse::GetMaxValue() const { return x4_a->GetMaxValue(); }
bool CIELifetimePercent::GetValue(int frame, int& valOut) const { bool CIELifetimePercent::GetValue(int frame, int& valOut) const {
int a; int a = 0;
x4_percentVal->GetValue(frame, a); 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; valOut = (a / 100.0f) * CParticleGlobals::instance()->m_ParticleLifetimeReal + 0.5f;
return false; return false;
} }
@ -161,10 +168,14 @@ bool CIEPulse::GetValue(int frame, int& valOut) const {
cv = 1; cv = 1;
} }
if (b < 1 || frame % cv <= a) { if (b >= 1) {
xc_aVal->GetValue(frame, valOut); if (frame % cv > a) {
x10_bVal->GetValue(frame, valOut);
} else {
xc_aVal->GetValue(frame, valOut);
}
} else { } else {
x10_bVal->GetValue(frame, valOut); xc_aVal->GetValue(frame, valOut);
} }
return false; 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(); } int CIEMultiply::GetMaxValue() const { return x4_a->GetMaxValue() * x8_b->GetMaxValue(); }
bool CIESampleAndHold::GetValue(int frame, int& valOut) const { bool CIESampleAndHold::GetValue(int frame, int& valOut) const {
bool ret;
if (x8_nextSampleFrame < frame) { if (x8_nextSampleFrame < frame) {
int b, c; int b, c;
xc_waitFramesMin->GetValue(frame, b); xc_waitFramesMin->GetValue(frame, b);
x10_waitFramesMax->GetValue(frame, c); x10_waitFramesMax->GetValue(frame, c);
x8_nextSampleFrame = CRandom16::GetRandomNumber()->Range(b, c) + frame; x8_nextSampleFrame = CRandom16::GetRandomNumber()->Range(b, c) + frame;
x4_sampleSource->GetValue(frame, valOut); ret = x4_sampleSource->GetValue(frame, valOut);
x14_holdVal = valOut; x14_holdVal = valOut;
} else { } else {
valOut = x14_holdVal; valOut = x14_holdVal;
ret = false;
} }
return false; return ret;
} }
int CIESampleAndHold::GetMaxValue() const { return x4_sampleSource->GetMaxValue(); } int CIESampleAndHold::GetMaxValue() const { return x4_sampleSource->GetMaxValue(); }
@ -201,10 +214,11 @@ bool CIERandom::GetValue(int frame, int& valOut) const {
int a, b; int a, b;
x4_min->GetValue(frame, a); x4_min->GetValue(frame, a);
x8_max->GetValue(frame, b); x8_max->GetValue(frame, b);
if (a > 0) if (a > 0) {
valOut = CRandom16::GetRandomNumber()->Range(a, b); valOut = CRandom16::GetRandomNumber()->Range(a, b);
else } else {
valOut = CRandom16::GetRandomNumber()->Next(); valOut = CRandom16::GetRandomNumber()->Next();
}
return false; return false;
} }
@ -218,7 +232,7 @@ int CIERandom::GetMaxValue() const {
bool CIETimeScale::GetValue(int frame, int& valOut) const { bool CIETimeScale::GetValue(int frame, int& valOut) const {
float a; float a;
x4_a->GetValue(frame, a); x4_a->GetValue(frame, a);
valOut = float(frame) * a; valOut = static_cast< float >(frame) * a;
return false; return false;
} }
@ -249,10 +263,11 @@ bool CIEModulo::GetValue(int frame, int& valOut) const {
int a, b; int a, b;
x4_a->GetValue(frame, a); x4_a->GetValue(frame, a);
x8_b->GetValue(frame, b); x8_b->GetValue(frame, b);
if (b != 0) if (b != 0) {
valOut = a % b; valOut = a % b;
else } else {
valOut = a; valOut = a;
}
return false; return false;
} }