2016-02-07 23:59:05 +00:00
|
|
|
#include "CColorElement.hpp"
|
2016-02-25 06:23:35 +00:00
|
|
|
#include "CElementGen.hpp"
|
2016-02-07 23:59:05 +00:00
|
|
|
#include "CParticleGlobals.hpp"
|
|
|
|
#include "CRandom16.hpp"
|
2016-03-04 23:04:53 +00:00
|
|
|
#include "zeus/Math.hpp"
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2016-02-28 06:55:05 +00:00
|
|
|
/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Color_Elements */
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
CCEKeyframeEmitter::CCEKeyframeEmitter(CInputStream& in)
|
|
|
|
{
|
|
|
|
x4_percent = in.readUint32Big();
|
|
|
|
x8_unk1 = in.readUint32Big();
|
|
|
|
xc_loop = in.readBool();
|
|
|
|
xd_unk2 = in.readBool();
|
|
|
|
x10_loopEnd = in.readUint32Big();
|
|
|
|
x14_loopStart = in.readUint32Big();
|
|
|
|
|
|
|
|
u32 count = in.readUint32Big();
|
|
|
|
x18_keys.reserve(count);
|
|
|
|
for (u32 i=0 ; i<count ; ++i)
|
|
|
|
x18_keys.push_back(in.readVec4fBig());
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CCEKeyframeEmitter::GetValue(int frame, zeus::CColor& valOut) const
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
|
|
|
if (!x4_percent)
|
|
|
|
{
|
2016-02-09 22:52:33 +00:00
|
|
|
int emitterTime = CParticleGlobals::g_EmitterTime;
|
2016-02-07 23:59:05 +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;
|
|
|
|
}
|
|
|
|
valOut = x18_keys[calcKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-09 22:52:33 +00:00
|
|
|
int ltPerc = CParticleGlobals::g_ParticleLifetimePercentage;
|
|
|
|
float ltPercRem = CParticleGlobals::g_ParticleLifetimePercentageRemainder;
|
2016-02-07 23:59:05 +00:00
|
|
|
if (ltPerc == 100)
|
|
|
|
valOut = x18_keys[100];
|
|
|
|
else
|
|
|
|
valOut = ltPercRem * x18_keys[ltPerc+1] + (1.0f - ltPercRem) * x18_keys[ltPerc];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CCEConstant::GetValue(int frame, zeus::CColor& valOut) const
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
|
|
|
float a, b, c, d;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
xc_c->GetValue(frame, c);
|
|
|
|
x10_d->GetValue(frame, d);
|
2016-03-04 23:04:53 +00:00
|
|
|
valOut = zeus::CColor(a, b, c, d);
|
2016-02-07 23:59:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CCEFastConstant::GetValue(int frame, zeus::CColor& valOut) const
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
|
|
|
valOut = x4_val;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CCETimeChain::GetValue(int frame, zeus::CColor& valOut) const
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
|
|
|
int v;
|
|
|
|
xc_swFrame->GetValue(frame, v);
|
|
|
|
if (frame >= v)
|
|
|
|
return x8_b->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
return x4_a->GetValue(frame, valOut);
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CCEFadeEnd::GetValue(int frame, zeus::CColor& valOut) const
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
|
|
|
float c;
|
|
|
|
xc_startFrame->GetValue(frame, c);
|
|
|
|
|
|
|
|
if (frame < c)
|
|
|
|
{
|
|
|
|
x4_a->GetValue(frame, valOut);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
float d;
|
|
|
|
x10_endFrame->GetValue(frame, d);
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CColor colA;
|
|
|
|
zeus::CColor colB;
|
2016-02-07 23:59:05 +00:00
|
|
|
x4_a->GetValue(frame, colA);
|
|
|
|
x8_b->GetValue(frame, colB);
|
|
|
|
|
|
|
|
float t = (frame - c) / (d - c);
|
2016-03-04 23:04:53 +00:00
|
|
|
valOut = zeus::CColor::lerp(colA, colB, t);
|
2016-02-07 23:59:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CCEFade::GetValue(int frame, zeus::CColor& valOut) const
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
|
|
|
float c;
|
2016-02-29 03:03:11 +00:00
|
|
|
xc_endFrame->GetValue(frame, c);
|
2016-02-07 23:59:05 +00:00
|
|
|
|
|
|
|
float t = frame / c;
|
|
|
|
if (t > 1.f)
|
|
|
|
{
|
|
|
|
x8_b->GetValue(frame, valOut);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CColor colA;
|
|
|
|
zeus::CColor colB;
|
2016-02-07 23:59:05 +00:00
|
|
|
x4_a->GetValue(frame, colA);
|
|
|
|
x8_b->GetValue(frame, colB);
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
valOut = zeus::CColor::lerp(colA, colB, t);
|
2016-02-07 23:59:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CCEPulse::GetValue(int frame, zeus::CColor& valOut) const
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
|
|
|
int a, b;
|
|
|
|
x4_aDuration->GetValue(frame, a);
|
|
|
|
x8_bDuration->GetValue(frame, b);
|
2016-03-04 23:04:53 +00:00
|
|
|
int cv = zeus::max(1, a + b + 1);
|
2016-02-07 23:59:05 +00:00
|
|
|
|
|
|
|
if (b >= 1)
|
|
|
|
{
|
|
|
|
int cv2 = frame % cv;
|
|
|
|
if (cv2 >= a)
|
|
|
|
x10_bVal->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
xc_aVal->GetValue(frame, valOut);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xc_aVal->GetValue(frame, valOut);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CCEParticleColor::GetValue(int /*frame*/, zeus::CColor& colorOut) const
|
2016-02-12 06:06:17 +00:00
|
|
|
{
|
2016-02-25 06:23:35 +00:00
|
|
|
colorOut = CElementGen::g_currentParticle->x34_color;
|
2016-02-12 07:14:21 +00:00
|
|
|
return false;
|
2016-02-12 06:06:17 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 23:59:05 +00:00
|
|
|
}
|