2016-02-05 08:34:14 +00:00
|
|
|
#include "CRealElement.hpp"
|
|
|
|
#include "CParticleGlobals.hpp"
|
2016-02-06 07:31:53 +00:00
|
|
|
#include "CRandom16.hpp"
|
2016-02-28 06:55:05 +00:00
|
|
|
#include "CElementGen.hpp"
|
2016-03-30 20:44:19 +00:00
|
|
|
#include "Graphics/CTexture.hpp"
|
2016-03-04 23:04:53 +00:00
|
|
|
#include "zeus/Math.hpp"
|
2016-04-03 05:25:34 +00:00
|
|
|
#include "CGenDescription.hpp"
|
2016-02-05 08:34:14 +00:00
|
|
|
|
2016-02-28 06:55:05 +00:00
|
|
|
/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Real_Elements */
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2016-02-05 08:34:14 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
CREKeyframeEmitter::CREKeyframeEmitter(CInputStream& in)
|
|
|
|
{
|
|
|
|
x4_percent = in.readUint32Big();
|
2016-02-05 09:56:21 +00:00
|
|
|
x8_unk1 = in.readUint32Big();
|
2016-02-05 09:52:20 +00:00
|
|
|
xc_loop = in.readBool();
|
2016-02-05 09:56:21 +00:00
|
|
|
xd_unk2 = in.readBool();
|
2016-02-05 09:52:20 +00:00
|
|
|
x10_loopEnd = in.readUint32Big();
|
|
|
|
x14_loopStart = in.readUint32Big();
|
2016-02-05 08:34:14 +00:00
|
|
|
|
|
|
|
u32 count = in.readUint32Big();
|
|
|
|
x18_keys.reserve(count);
|
|
|
|
for (u32 i=0 ; i<count ; ++i)
|
|
|
|
x18_keys.push_back(in.readFloatBig());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREKeyframeEmitter::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
if (!x4_percent)
|
|
|
|
{
|
2016-02-09 22:52:33 +00:00
|
|
|
int emitterTime = CParticleGlobals::g_EmitterTime;
|
2016-02-05 08:34:14 +00:00
|
|
|
int calcKey = emitterTime;
|
2016-02-05 09:52:20 +00:00
|
|
|
if (xc_loop)
|
2016-02-05 08:34:14 +00:00
|
|
|
{
|
2016-02-05 09:52:20 +00:00
|
|
|
if (emitterTime >= x10_loopEnd)
|
2016-02-05 08:34:14 +00:00
|
|
|
{
|
2016-02-05 09:52:20 +00:00
|
|
|
int v1 = emitterTime - x14_loopStart;
|
|
|
|
int v2 = x10_loopEnd - x14_loopStart;
|
|
|
|
calcKey = v1 % v2;
|
|
|
|
calcKey += x14_loopStart;
|
2016-02-05 08:34:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-05 09:52:20 +00:00
|
|
|
int v1 = x10_loopEnd - 1;
|
|
|
|
if (v1 < emitterTime)
|
|
|
|
calcKey = v1;
|
2016-02-05 08:34:14 +00:00
|
|
|
}
|
2016-02-06 00:34:40 +00:00
|
|
|
valOut = x18_keys[calcKey];
|
2016-02-05 08:34:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-09 22:52:33 +00:00
|
|
|
int ltPerc = CParticleGlobals::g_ParticleLifetimePercentage;
|
|
|
|
float ltPercRem = CParticleGlobals::g_ParticleLifetimePercentageRemainder;
|
2016-02-05 08:34:14 +00:00
|
|
|
if (ltPerc == 100)
|
|
|
|
valOut = x18_keys[100];
|
|
|
|
else
|
2016-02-07 00:19:59 +00:00
|
|
|
valOut = ltPercRem * x18_keys[ltPerc+1] + (1.0f - ltPercRem) * x18_keys[ltPerc];
|
2016-02-05 08:34:14 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CRELifetimeTween::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
2016-02-09 22:52:33 +00:00
|
|
|
float ltFac = frame / CParticleGlobals::g_ParticleLifetimeReal;
|
2016-02-05 08:34:14 +00:00
|
|
|
float a, b;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = b * ltFac + (1.0f - ltFac) * a;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREConstant::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
valOut = x4_val;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CRETimeChain::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
int v;
|
2016-02-06 00:34:40 +00:00
|
|
|
xc_swFrame->GetValue(frame, v);
|
2016-02-05 08:34:14 +00:00
|
|
|
if (frame >= v)
|
|
|
|
return x8_b->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
return x4_a->GetValue(frame, valOut);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREAdd::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
float a, b;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = a + b;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-12 06:06:17 +00:00
|
|
|
bool CREClamp::GetValue(int frame,float& valOut) const
|
2016-02-05 08:34:14 +00:00
|
|
|
{
|
|
|
|
float a, b;
|
2016-02-06 00:34:40 +00:00
|
|
|
x4_min->GetValue(frame, a);
|
|
|
|
x8_max->GetValue(frame, b);
|
|
|
|
xc_val->GetValue(frame, valOut);
|
2016-02-05 08:34:14 +00:00
|
|
|
if (valOut > b)
|
|
|
|
valOut = b;
|
|
|
|
if (valOut < a)
|
|
|
|
valOut = a;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-16 05:50:41 +00:00
|
|
|
bool CREInitialRandom::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
if (frame == 0)
|
|
|
|
{
|
|
|
|
float a, b;
|
|
|
|
x4_min->GetValue(frame, a);
|
|
|
|
x8_max->GetValue(frame, b);
|
|
|
|
float rand = CRandom16::GetRandomNumber()->Float();
|
|
|
|
valOut = b * rand + a * (1.0f - rand);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-06 07:31:53 +00:00
|
|
|
bool CRERandom::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
float a, b;
|
|
|
|
x4_min->GetValue(frame, a);
|
|
|
|
x8_max->GetValue(frame, b);
|
|
|
|
float rand = CRandom16::GetRandomNumber()->Float();
|
|
|
|
valOut = b * rand + a * (1.0f - rand);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-12 06:06:17 +00:00
|
|
|
bool CREDotProduct::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f a, b;
|
2016-02-12 06:06:17 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = a.dot(b);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CREMultiply::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
float a, b;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = a * b;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-06 07:31:53 +00:00
|
|
|
bool CREPulse::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
int a, b;
|
|
|
|
x4_aDuration->GetValue(frame, a);
|
|
|
|
x8_bDuration->GetValue(frame, b);
|
|
|
|
int cv = std::max(1, a + b + 1);
|
|
|
|
|
|
|
|
if (b >= 1)
|
|
|
|
{
|
|
|
|
int cv2 = frame % cv;
|
|
|
|
if (cv2 >= a)
|
|
|
|
x10_valB->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
xc_valA->GetValue(frame, valOut);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xc_valA->GetValue(frame, valOut);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CRETimeScale::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
float a;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = float(frame) * a;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CRELifetimePercent::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
float a;
|
|
|
|
x4_percentVal->GetValue(frame, a);
|
|
|
|
a = std::max(0.0f, a);
|
2016-02-09 22:52:33 +00:00
|
|
|
valOut = (a / 100.0f) * CParticleGlobals::g_ParticleLifetimeReal;
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CRESineWave::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
float a, b, c;
|
|
|
|
x4_magnitude->GetValue(frame, a);
|
|
|
|
x8_linearFrame->GetValue(frame, b);
|
|
|
|
xc_constantFrame->GetValue(frame, c);
|
2016-03-04 23:04:53 +00:00
|
|
|
valOut = std::sin(zeus::degToRad(frame * b + c)) * a;
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREISWT::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
if (frame == 0)
|
|
|
|
x4_a->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
x8_b->GetValue(frame, valOut);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CRECompareLessThan::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
float a, b;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
if (a < b)
|
|
|
|
xc_c->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
x10_d->GetValue(frame, valOut);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CRECompareEquals::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
float a, b;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
2016-03-04 23:04:53 +00:00
|
|
|
if (std::fabs(a-b) < 0.00001f)
|
2016-02-06 07:31:53 +00:00
|
|
|
xc_c->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
x10_d->GetValue(frame, valOut);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-28 01:03:46 +00:00
|
|
|
bool CREParticleAccessParam1::GetValue(int /*frame*/, float& valOut) const
|
2016-02-06 07:31:53 +00:00
|
|
|
{
|
2016-02-28 01:03:46 +00:00
|
|
|
valOut = CParticleGlobals::g_papValues[0];
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-28 01:03:46 +00:00
|
|
|
bool CREParticleAccessParam2::GetValue(int /*frame*/, float& valOut) const
|
2016-02-06 07:31:53 +00:00
|
|
|
{
|
2016-02-28 01:03:46 +00:00
|
|
|
valOut = CParticleGlobals::g_papValues[1];
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-28 01:03:46 +00:00
|
|
|
bool CREParticleAccessParam3::GetValue(int /*frame*/, float& valOut) const
|
2016-02-06 07:31:53 +00:00
|
|
|
{
|
2016-02-28 01:03:46 +00:00
|
|
|
valOut = CParticleGlobals::g_papValues[2];
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-28 01:03:46 +00:00
|
|
|
bool CREParticleAccessParam4::GetValue(int /*frame*/, float& valOut) const
|
2016-02-06 07:31:53 +00:00
|
|
|
{
|
2016-02-28 01:03:46 +00:00
|
|
|
valOut = CParticleGlobals::g_papValues[3];
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-28 01:03:46 +00:00
|
|
|
bool CREParticleAccessParam5::GetValue(int /*frame*/, float& valOut) const
|
2016-02-06 07:31:53 +00:00
|
|
|
{
|
2016-02-28 01:03:46 +00:00
|
|
|
valOut = CParticleGlobals::g_papValues[4];
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-28 01:03:46 +00:00
|
|
|
bool CREParticleAccessParam6::GetValue(int /*frame*/, float& valOut) const
|
2016-02-06 07:31:53 +00:00
|
|
|
{
|
2016-02-28 01:03:46 +00:00
|
|
|
valOut = CParticleGlobals::g_papValues[5];
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-28 01:03:46 +00:00
|
|
|
bool CREParticleAccessParam7::GetValue(int /*frame*/, float& valOut) const
|
2016-02-06 07:31:53 +00:00
|
|
|
{
|
2016-02-28 01:03:46 +00:00
|
|
|
valOut = CParticleGlobals::g_papValues[6];
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-28 01:03:46 +00:00
|
|
|
bool CREParticleAccessParam8::GetValue(int /*frame*/, float& valOut) const
|
2016-02-06 07:31:53 +00:00
|
|
|
{
|
2016-02-28 01:03:46 +00:00
|
|
|
valOut = CParticleGlobals::g_papValues[7];
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-28 01:03:46 +00:00
|
|
|
bool CREPSLL::GetValue(int /*frame*/, float& valOut) const
|
2016-02-06 07:31:53 +00:00
|
|
|
{
|
2016-02-28 06:55:05 +00:00
|
|
|
valOut = CElementGen::g_currentParticle->x2c_lineLengthOrSize;
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-28 01:03:46 +00:00
|
|
|
bool CREPRLW::GetValue(int /*frame*/, float& valOut) const
|
2016-02-06 07:31:53 +00:00
|
|
|
{
|
2016-02-28 06:55:05 +00:00
|
|
|
valOut = CElementGen::g_currentParticle->x30_lineWidthOrRota;
|
2016-02-06 07:31:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CRESubtract::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
float a, b;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = a - b;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREVectorMagnitude::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f a;
|
2016-02-06 07:31:53 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a.magnitude();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREVectorXToReal::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f a;
|
2016-02-06 07:31:53 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a[0];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREVectorYToReal::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f a;
|
2016-02-06 07:31:53 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a[1];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREVectorZToReal::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f a;
|
2016-02-06 07:31:53 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a[2];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CRECEXT::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
int a;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
int cv = std::max(0, a);
|
|
|
|
/* TODO: Figure out how value table is generated/stored in 0-00 */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-07 00:19:59 +00:00
|
|
|
bool CREIntTimesReal::GetValue(int frame, float& valOut) const
|
2016-02-06 07:31:53 +00:00
|
|
|
{
|
|
|
|
int a;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
float b;
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = float(a) * b;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-12 06:06:17 +00:00
|
|
|
bool CREConstantRange::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
|
|
|
float val, min, max;
|
|
|
|
x4_val->GetValue(frame, val);
|
|
|
|
x8_min->GetValue(frame, min);
|
|
|
|
xc_max->GetValue(frame, max);
|
|
|
|
|
|
|
|
if (val > min && val < max)
|
2016-02-12 07:14:21 +00:00
|
|
|
x10_inRange->GetValue(frame, valOut);
|
2016-02-12 06:06:17 +00:00
|
|
|
else
|
|
|
|
x14_outOfRange->GetValue(frame, valOut);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREGetComponentRed::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CColor a = zeus::CColor::skBlack;
|
2016-02-12 06:06:17 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a.r;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREGetComponentGreen::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CColor a = zeus::CColor::skBlack;
|
2016-02-12 06:06:17 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a.g;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREGetComponentBlue::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CColor a = zeus::CColor::skBlack;
|
2016-02-12 06:06:17 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a.b;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREGetComponentAlpha::GetValue(int frame, float& valOut) const
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CColor a = zeus::CColor::skBlack;
|
2016-02-12 06:06:17 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a.a;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-05 08:34:14 +00:00
|
|
|
}
|