2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Particle/CColorElement.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CRandom16.hpp"
|
|
|
|
#include "Runtime/Particle/CElementGen.hpp"
|
|
|
|
#include "Runtime/Particle/CGenDescription.hpp"
|
|
|
|
#include "Runtime/Particle/CParticleGlobals.hpp"
|
|
|
|
|
|
|
|
#include <zeus/Math.hpp>
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2019-12-03 08:47:05 +00:00
|
|
|
/* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Color_Elements */
|
2016-02-28 06:55:05 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
CCEKeyframeEmitter::CCEKeyframeEmitter(CInputStream& in) {
|
2022-02-18 07:37:54 +00:00
|
|
|
x4_percent = in.ReadLong();
|
|
|
|
x8_unk1 = in.ReadLong();
|
|
|
|
xc_loop = in.ReadBool();
|
|
|
|
xd_unk2 = in.ReadBool();
|
|
|
|
x10_loopEnd = in.ReadLong();
|
|
|
|
x14_loopStart = in.ReadLong();
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2022-02-18 07:37:54 +00:00
|
|
|
const u32 count = in.ReadLong();
|
2018-12-08 05:30:43 +00:00
|
|
|
x18_keys.reserve(count);
|
2020-03-21 04:12:13 +00:00
|
|
|
for (u32 i = 0; i < count; ++i) {
|
2022-02-18 07:37:54 +00:00
|
|
|
x18_keys.emplace_back(in.Get<zeus::CColor>());
|
2020-03-21 04:12:13 +00:00
|
|
|
}
|
2016-02-07 23:59:05 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 04:54:08 +00:00
|
|
|
bool CCEKeyframeEmitter::GetValue([[maybe_unused]] int frame, zeus::CColor& valOut) const {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!x4_percent) {
|
2019-12-03 08:47:05 +00:00
|
|
|
int emitterTime = CParticleGlobals::instance()->m_EmitterTime;
|
2018-12-08 05:30:43 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int v1 = x10_loopEnd - 1;
|
|
|
|
if (v1 < emitterTime)
|
|
|
|
calcKey = v1;
|
2016-02-07 23:59:05 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
valOut = x18_keys[calcKey];
|
|
|
|
} else {
|
2019-12-03 08:47:05 +00:00
|
|
|
int ltPerc = CParticleGlobals::instance()->m_ParticleLifetimePercentage;
|
|
|
|
float ltPercRem = CParticleGlobals::instance()->m_ParticleLifetimePercentageRemainder;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (ltPerc == 100)
|
|
|
|
valOut = x18_keys[100];
|
2016-02-07 23:59:05 +00:00
|
|
|
else
|
2018-12-08 05:30:43 +00:00
|
|
|
valOut = ltPercRem * x18_keys[ltPerc + 1] + (1.0f - ltPercRem) * x18_keys[ltPerc];
|
|
|
|
}
|
|
|
|
return false;
|
2016-02-07 23:59:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCEConstant::GetValue(int frame, zeus::CColor& valOut) const {
|
|
|
|
float r, g, b, a;
|
|
|
|
x4_r->GetValue(frame, r);
|
|
|
|
x8_g->GetValue(frame, g);
|
|
|
|
xc_b->GetValue(frame, b);
|
|
|
|
x10_a->GetValue(frame, a);
|
|
|
|
valOut = zeus::CColor(r, g, b, a);
|
|
|
|
return false;
|
2016-02-07 23:59:05 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 04:54:08 +00:00
|
|
|
bool CCEFastConstant::GetValue([[maybe_unused]] int frame, zeus::CColor& valOut) const {
|
2018-12-08 05:30:43 +00:00
|
|
|
valOut = x4_val;
|
|
|
|
return false;
|
2016-02-07 23:59:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCETimeChain::GetValue(int frame, zeus::CColor& valOut) const {
|
|
|
|
int v;
|
|
|
|
xc_swFrame->GetValue(frame, v);
|
2022-10-29 15:05:11 +00:00
|
|
|
if (frame < v) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return x4_a->GetValue(frame, valOut);
|
2022-10-29 15:05:11 +00:00
|
|
|
} else {
|
|
|
|
return x8_b->GetValue(frame - v, valOut);
|
|
|
|
}
|
2016-02-07 23:59:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCEFadeEnd::GetValue(int frame, zeus::CColor& valOut) const {
|
|
|
|
float c;
|
|
|
|
xc_startFrame->GetValue(frame, c);
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (frame < c) {
|
|
|
|
x4_a->GetValue(frame, valOut);
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float d;
|
|
|
|
x10_endFrame->GetValue(frame, d);
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CColor colA;
|
|
|
|
zeus::CColor colB;
|
|
|
|
x4_a->GetValue(frame, colA);
|
|
|
|
x8_b->GetValue(frame, colB);
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float t = (frame - c) / (d - c);
|
|
|
|
valOut = zeus::CColor::lerp(colA, colB, t);
|
|
|
|
return false;
|
2016-02-07 23:59:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCEFade::GetValue(int frame, zeus::CColor& valOut) const {
|
|
|
|
float c;
|
|
|
|
xc_endFrame->GetValue(frame, c);
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float t = frame / c;
|
|
|
|
if (t > 1.f) {
|
|
|
|
x8_b->GetValue(frame, valOut);
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CColor colA;
|
|
|
|
zeus::CColor colB;
|
|
|
|
x4_a->GetValue(frame, colA);
|
|
|
|
x8_b->GetValue(frame, colB);
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
valOut = zeus::CColor::lerp(colA, colB, t);
|
|
|
|
return false;
|
2016-02-07 23:59:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCEPulse::GetValue(int frame, zeus::CColor& valOut) const {
|
|
|
|
int a, b;
|
|
|
|
x4_aDuration->GetValue(frame, a);
|
|
|
|
x8_bDuration->GetValue(frame, b);
|
2020-04-12 09:31:00 +00:00
|
|
|
int cv = a + b + 1;
|
|
|
|
if (cv < 0) {
|
|
|
|
cv = 1;
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-12 09:31:00 +00:00
|
|
|
if (b < 1 || frame % cv <= a) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xc_aVal->GetValue(frame, valOut);
|
2020-04-12 09:31:00 +00:00
|
|
|
} else {
|
|
|
|
x10_bVal->GetValue(frame, valOut);
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-07 23:59:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCEParticleColor::GetValue(int /*frame*/, zeus::CColor& colorOut) const {
|
|
|
|
colorOut = CElementGen::g_currentParticle->x34_color;
|
|
|
|
return false;
|
2016-02-12 06:06:17 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|