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 {
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<int>(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<int>(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;
}