2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Particle/CRealElement.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CRandom16.hpp"
|
|
|
|
#include "Runtime/Graphics/CTexture.hpp"
|
|
|
|
#include "Runtime/Particle/CElementGen.hpp"
|
|
|
|
#include "Runtime/Particle/CGenDescription.hpp"
|
|
|
|
#include "Runtime/Particle/CParticleGlobals.hpp"
|
|
|
|
|
|
|
|
#include <zeus/Math.hpp>
|
2016-02-05 08:34:14 +00:00
|
|
|
|
2019-12-03 08:47:05 +00:00
|
|
|
/* Documentation at: https://wiki.axiodl.com/w/Particle_Script#Real_Elements */
|
2016-02-28 06:55:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
|
|
|
|
|
|
|
CREKeyframeEmitter::CREKeyframeEmitter(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.readFloatBig());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREKeyframeEmitter::GetValue(int frame, float& valOut) const {
|
|
|
|
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-05 08:34:14 +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-05 08:34:14 +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-05 08:34:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CRELifetimeTween::GetValue(int frame, float& valOut) const {
|
2019-12-03 08:47:05 +00:00
|
|
|
float ltFac = frame / CParticleGlobals::instance()->instance()->m_ParticleLifetimeReal;
|
2018-12-08 05:30:43 +00:00
|
|
|
float a, b;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = b * ltFac + (1.0f - ltFac) * a;
|
|
|
|
return false;
|
2016-02-05 08:34:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREConstant::GetValue(int frame, float& valOut) const {
|
|
|
|
valOut = x4_val;
|
|
|
|
return false;
|
2016-02-05 08:34:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CRETimeChain::GetValue(int frame, float& valOut) const {
|
|
|
|
int v;
|
|
|
|
xc_swFrame->GetValue(frame, v);
|
|
|
|
if (frame >= v)
|
|
|
|
return x8_b->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
return x4_a->GetValue(frame, valOut);
|
2016-02-05 08:34:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
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-05 08:34:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREClamp::GetValue(int frame, float& valOut) const {
|
|
|
|
float a, b;
|
|
|
|
x4_min->GetValue(frame, a);
|
|
|
|
x8_max->GetValue(frame, b);
|
|
|
|
xc_val->GetValue(frame, valOut);
|
|
|
|
if (valOut > b)
|
|
|
|
valOut = b;
|
|
|
|
if (valOut < a)
|
|
|
|
valOut = a;
|
|
|
|
return false;
|
2016-02-16 05:50:41 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREInitialRandom::GetValue(int frame, float& valOut) const {
|
|
|
|
if (frame == 0) {
|
2016-02-06 07:31:53 +00:00
|
|
|
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);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREDotProduct::GetValue(int frame, float& valOut) const {
|
|
|
|
zeus::CVector3f a, b;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = a.dot(b);
|
|
|
|
return false;
|
2016-02-12 06:06:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
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-12 06:06:17 +00:00
|
|
|
|
2018-12-08 05:30:43 +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);
|
2016-02-06 07:31:53 +00:00
|
|
|
else
|
2018-12-08 05:30:43 +00:00
|
|
|
xc_valA->GetValue(frame, valOut);
|
|
|
|
} else
|
|
|
|
xc_valA->GetValue(frame, valOut);
|
2016-02-06 07:31:53 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CRETimeScale::GetValue(int frame, float& valOut) const {
|
|
|
|
float a;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = float(frame) * a;
|
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CRELifetimePercent::GetValue(int frame, float& valOut) const {
|
|
|
|
float a;
|
|
|
|
x4_percentVal->GetValue(frame, a);
|
|
|
|
a = std::max(0.0f, a);
|
2019-12-03 08:47:05 +00:00
|
|
|
valOut = (a / 100.0f) * CParticleGlobals::instance()->m_ParticleLifetimeReal;
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CRESineWave::GetValue(int frame, float& valOut) const {
|
|
|
|
float a, b, c;
|
|
|
|
x4_frequency->GetValue(frame, a);
|
|
|
|
x8_amplitude->GetValue(frame, b);
|
|
|
|
xc_phase->GetValue(frame, c);
|
|
|
|
valOut = std::sin(zeus::degToRad(frame * a + c)) * b;
|
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREInitialSwitch::GetValue(int frame, float& valOut) const {
|
|
|
|
if (frame == 0)
|
|
|
|
x4_a->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
x8_b->GetValue(frame, valOut);
|
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
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;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CRECompareEquals::GetValue(int frame, float& valOut) const {
|
|
|
|
float a, b;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
if (std::fabs(a - b) < 0.00001f)
|
|
|
|
xc_c->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
x10_d->GetValue(frame, valOut);
|
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREParticleAccessParam1::GetValue(int /*frame*/, float& valOut) const {
|
2019-12-03 08:47:05 +00:00
|
|
|
valOut = (*CParticleGlobals::instance()->m_particleAccessParameters)[0];
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREParticleAccessParam2::GetValue(int /*frame*/, float& valOut) const {
|
2019-12-03 08:47:05 +00:00
|
|
|
valOut = (*CParticleGlobals::instance()->m_particleAccessParameters)[1];
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREParticleAccessParam3::GetValue(int /*frame*/, float& valOut) const {
|
2019-12-03 08:47:05 +00:00
|
|
|
valOut = (*CParticleGlobals::instance()->m_particleAccessParameters)[2];
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREParticleAccessParam4::GetValue(int /*frame*/, float& valOut) const {
|
2019-12-03 08:47:05 +00:00
|
|
|
valOut = (*CParticleGlobals::instance()->m_particleAccessParameters)[3];
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREParticleAccessParam5::GetValue(int /*frame*/, float& valOut) const {
|
2019-12-03 08:47:05 +00:00
|
|
|
valOut = (*CParticleGlobals::instance()->m_particleAccessParameters)[4];
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREParticleAccessParam6::GetValue(int /*frame*/, float& valOut) const {
|
2019-12-03 08:47:05 +00:00
|
|
|
valOut = (*CParticleGlobals::instance()->m_particleAccessParameters)[5];
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREParticleAccessParam7::GetValue(int /*frame*/, float& valOut) const {
|
2019-12-03 08:47:05 +00:00
|
|
|
valOut = (*CParticleGlobals::instance()->m_particleAccessParameters)[6];
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREParticleAccessParam8::GetValue(int /*frame*/, float& valOut) const {
|
2019-12-03 08:47:05 +00:00
|
|
|
valOut = (*CParticleGlobals::instance()->m_particleAccessParameters)[7];
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREParticleSizeOrLineLength::GetValue(int /*frame*/, float& valOut) const {
|
|
|
|
valOut = CElementGen::g_currentParticle->x2c_lineLengthOrSize;
|
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREParticleRotationOrLineWidth::GetValue(int /*frame*/, float& valOut) const {
|
|
|
|
valOut = CElementGen::g_currentParticle->x30_lineWidthOrRota;
|
|
|
|
return false;
|
2016-02-06 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-02-12 06:06:17 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREVectorMagnitude::GetValue(int frame, float& valOut) const {
|
|
|
|
zeus::CVector3f a;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a.magnitude();
|
|
|
|
return false;
|
2016-02-12 06:06:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREVectorXToReal::GetValue(int frame, float& valOut) const {
|
|
|
|
zeus::CVector3f a;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a[0];
|
|
|
|
return false;
|
2016-02-12 06:06:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREVectorYToReal::GetValue(int frame, float& valOut) const {
|
|
|
|
zeus::CVector3f a;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a[1];
|
|
|
|
return false;
|
2016-02-12 06:06:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREVectorZToReal::GetValue(int frame, float& valOut) const {
|
|
|
|
zeus::CVector3f a;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a[2];
|
|
|
|
return false;
|
2016-02-12 06:06:17 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 23:06:25 +00:00
|
|
|
bool CREExternalVar::GetValue(int frame, float& valOut) const {
|
2018-12-08 05:30:43 +00:00
|
|
|
int a;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
int cv = std::max(0, a);
|
2019-12-03 08:47:05 +00:00
|
|
|
valOut = CParticleGlobals::instance()->m_currentParticleSystem->x4_system->GetExternalVar(cv & 0xf);
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-12 06:06:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CREIntTimesReal::GetValue(int frame, float& valOut) const {
|
|
|
|
int a;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
float b;
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = float(a) * b;
|
|
|
|
return false;
|
2016-02-05 08:34:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +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)
|
|
|
|
x10_inRange->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
x14_outOfRange->GetValue(frame, valOut);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREGetComponentRed::GetValue(int frame, float& valOut) const {
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor a = zeus::skBlack;
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a.r();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREGetComponentGreen::GetValue(int frame, float& valOut) const {
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor a = zeus::skBlack;
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a.g();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREGetComponentBlue::GetValue(int frame, float& valOut) const {
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor a = zeus::skBlack;
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a.b();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CREGetComponentAlpha::GetValue(int frame, float& valOut) const {
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor a = zeus::skBlack;
|
2018-12-08 05:30:43 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
valOut = a.a();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace urde
|