CParticleElectric: Make use of const where applicable

Makes it easier to read long functions by knowing which variables are
mutable.
This commit is contained in:
Lioncash 2020-04-14 04:08:40 -04:00
parent fed72614ef
commit 8aef2cf95d
1 changed files with 201 additions and 118 deletions

View File

@ -1,5 +1,7 @@
#include "Runtime/Particle/CParticleElectric.hpp" #include "Runtime/Particle/CParticleElectric.hpp"
#include <algorithm>
#include "Runtime/GameGlobalObjects.hpp" #include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CBooRenderer.hpp"
#include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CGraphics.hpp"
@ -31,18 +33,21 @@ CParticleElectric::CParticleElectric(const TToken<CElectricDescription>& token)
CElectricDescription* desc = x1c_elecDesc.GetObj(); CElectricDescription* desc = x1c_elecDesc.GetObj();
if (CIntElement* sseg = desc->x10_SSEG.get()) if (CIntElement* sseg = desc->x10_SSEG.get()) {
sseg->GetValue(x28_currentFrame, x150_SSEG); sseg->GetValue(x28_currentFrame, x150_SSEG);
}
if (CIntElement* scnt = desc->xc_SCNT.get()) if (CIntElement* scnt = desc->xc_SCNT.get()) {
scnt->GetValue(x28_currentFrame, x154_SCNT); scnt->GetValue(x28_currentFrame, x154_SCNT);
}
x154_SCNT = std::min(x154_SCNT, 32); x154_SCNT = std::min(x154_SCNT, 32);
if (CIntElement* life = desc->x0_LIFE.get()) if (CIntElement* life = desc->x0_LIFE.get()) {
life->GetValue(0, x2c_LIFE); life->GetValue(0, x2c_LIFE);
else } else {
x2c_LIFE = INT_MAX; x2c_LIFE = INT_MAX;
}
if (desc->x40_SSWH) { if (desc->x40_SSWH) {
x450_27_haveSSWH = true; x450_27_haveSSWH = true;
@ -84,8 +89,9 @@ CParticleElectric::CParticleElectric(const TToken<CElectricDescription>& token)
} }
void CParticleElectric::RenderSwooshes() { void CParticleElectric::RenderSwooshes() {
for (CParticleElectricManager& elec : x3e8_electricManagers) for (const CParticleElectricManager& elec : x3e8_electricManagers) {
x1e0_swooshGenerators[elec.x0_idx]->Render(); x1e0_swooshGenerators[elec.x0_idx]->Render();
}
} }
void CParticleElectric::SetupLineGXMaterial() { void CParticleElectric::SetupLineGXMaterial() {
@ -94,18 +100,21 @@ void CParticleElectric::SetupLineGXMaterial() {
void CParticleElectric::DrawLineStrip(const std::vector<zeus::CVector3f>& verts, float width, void CParticleElectric::DrawLineStrip(const std::vector<zeus::CVector3f>& verts, float width,
const zeus::CColor& color) { const zeus::CColor& color) {
size_t useIdx = m_nextLineRenderer; const size_t useIdx = m_nextLineRenderer;
if (++m_nextLineRenderer > m_lineRenderers.size()) if (++m_nextLineRenderer > m_lineRenderers.size()) {
m_lineRenderers.resize(m_nextLineRenderer); m_lineRenderers.resize(m_nextLineRenderer);
if (!m_lineRenderers[useIdx]) }
if (!m_lineRenderers[useIdx]) {
m_lineRenderers[useIdx] = m_lineRenderers[useIdx] =
std::make_unique<CLineRenderer>(CLineRenderer::EPrimitiveMode::LineStrip, x150_SSEG, nullptr, true, true); std::make_unique<CLineRenderer>(CLineRenderer::EPrimitiveMode::LineStrip, x150_SSEG, nullptr, true, true);
}
CLineRenderer& renderer = *m_lineRenderers[useIdx]; CLineRenderer& renderer = *m_lineRenderers[useIdx];
zeus::CColor useColor = x1b8_moduColor * color; const zeus::CColor useColor = x1b8_moduColor * color;
renderer.Reset(); renderer.Reset();
for (const zeus::CVector3f& vert : verts) for (const zeus::CVector3f& vert : verts) {
renderer.AddVertex(vert, useColor, width); renderer.AddVertex(vert, useColor, width);
}
renderer.Render(g_Renderer->IsThermalVisorHotPass()); renderer.Render(g_Renderer->IsThermalVisorHotPass());
} }
@ -122,12 +131,15 @@ void CParticleElectric::RenderLines() {
SetupLineGXMaterial(); SetupLineGXMaterial();
for (CParticleElectricManager& elec : x3e8_electricManagers) { for (CParticleElectricManager& elec : x3e8_electricManagers) {
CLineManager& line = *x2e4_lineManagers[elec.x0_idx]; CLineManager& line = *x2e4_lineManagers[elec.x0_idx];
if (x1c_elecDesc->x28_LWD1) if (x1c_elecDesc->x28_LWD1) {
DrawLineStrip(line.x0_verts, line.x10_widths[0], line.x1c_colors[0]); DrawLineStrip(line.x0_verts, line.x10_widths[0], line.x1c_colors[0]);
if (x1c_elecDesc->x2c_LWD2) }
if (x1c_elecDesc->x2c_LWD2) {
DrawLineStrip(line.x0_verts, line.x10_widths[1], line.x1c_colors[1]); DrawLineStrip(line.x0_verts, line.x10_widths[1], line.x1c_colors[1]);
if (x1c_elecDesc->x30_LWD3) }
if (x1c_elecDesc->x30_LWD3) {
DrawLineStrip(line.x0_verts, line.x10_widths[2], line.x1c_colors[2]); DrawLineStrip(line.x0_verts, line.x10_widths[2], line.x1c_colors[2]);
}
} }
// Enable culling // Enable culling
@ -143,19 +155,25 @@ void CParticleElectric::UpdateCachedTransform() {
void CParticleElectric::UpdateLine(int idx, int frame) { void CParticleElectric::UpdateLine(int idx, int frame) {
CLineManager& line = *x2e4_lineManagers[idx]; CLineManager& line = *x2e4_lineManagers[idx];
if (CColorElement* lcl1 = x1c_elecDesc->x34_LCL1.get()) if (CColorElement* lcl1 = x1c_elecDesc->x34_LCL1.get()) {
lcl1->GetValue(frame, line.x1c_colors[0]); lcl1->GetValue(frame, line.x1c_colors[0]);
if (CColorElement* lcl2 = x1c_elecDesc->x38_LCL2.get()) }
if (CColorElement* lcl2 = x1c_elecDesc->x38_LCL2.get()) {
lcl2->GetValue(frame, line.x1c_colors[1]); lcl2->GetValue(frame, line.x1c_colors[1]);
if (CColorElement* lcl3 = x1c_elecDesc->x3c_LCL3.get()) }
if (CColorElement* lcl3 = x1c_elecDesc->x3c_LCL3.get()) {
lcl3->GetValue(frame, line.x1c_colors[2]); lcl3->GetValue(frame, line.x1c_colors[2]);
}
if (CRealElement* lwd1 = x1c_elecDesc->x28_LWD1.get()) if (CRealElement* lwd1 = x1c_elecDesc->x28_LWD1.get()) {
lwd1->GetValue(frame, line.x10_widths[0]); lwd1->GetValue(frame, line.x10_widths[0]);
if (CRealElement* lwd2 = x1c_elecDesc->x2c_LWD2.get()) }
if (CRealElement* lwd2 = x1c_elecDesc->x2c_LWD2.get()) {
lwd2->GetValue(frame, line.x10_widths[1]); lwd2->GetValue(frame, line.x10_widths[1]);
if (CRealElement* lwd3 = x1c_elecDesc->x30_LWD3.get()) }
if (CRealElement* lwd3 = x1c_elecDesc->x30_LWD3.get()) {
lwd3->GetValue(frame, line.x10_widths[2]); lwd3->GetValue(frame, line.x10_widths[2]);
}
} }
void CParticleElectric::UpdateElectricalEffects() { void CParticleElectric::UpdateElectricalEffects() {
@ -163,28 +181,32 @@ void CParticleElectric::UpdateElectricalEffects() {
CParticleElectricManager& elec = *it; CParticleElectricManager& elec = *it;
if (elec.x4_slif <= 1) { if (elec.x4_slif <= 1) {
x1bc_allocated[elec.x0_idx] = false; x1bc_allocated[elec.x0_idx] = false;
if (elec.x10_gpsmIdx != -1) if (elec.x10_gpsmIdx != -1) {
x400_gpsmGenerators[elec.x10_gpsmIdx]->SetParticleEmission(false); x400_gpsmGenerators[elec.x10_gpsmIdx]->SetParticleEmission(false);
if (elec.x14_epsmIdx != -1) }
if (elec.x14_epsmIdx != -1) {
x410_epsmGenerators[elec.x14_epsmIdx]->SetParticleEmission(false); x410_epsmGenerators[elec.x14_epsmIdx]->SetParticleEmission(false);
}
it = x3e8_electricManagers.erase(it); it = x3e8_electricManagers.erase(it);
continue; continue;
} }
CParticleGlobals::instance()->SetParticleLifetime(elec.xc_endFrame - elec.x8_startFrame); CParticleGlobals::instance()->SetParticleLifetime(elec.xc_endFrame - elec.x8_startFrame);
int frame = x28_currentFrame - elec.x8_startFrame; const int frame = x28_currentFrame - elec.x8_startFrame;
CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(frame); CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(frame);
if (x450_27_haveSSWH) { if (x450_27_haveSSWH) {
CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx]; CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx];
zeus::CColor color = zeus::skWhite; zeus::CColor color = zeus::skWhite;
if (CColorElement* colr = x1c_elecDesc->x14_COLR.get()) if (CColorElement* colr = x1c_elecDesc->x14_COLR.get()) {
colr->GetValue(frame, color); colr->GetValue(frame, color);
}
swoosh.SetModulationColor(color * x1b8_moduColor); swoosh.SetModulationColor(color * x1b8_moduColor);
} }
if (x450_28_haveLWD) if (x450_28_haveLWD) {
UpdateLine(elec.x0_idx, frame); UpdateLine(elec.x0_idx, frame);
}
elec.x4_slif -= 1; elec.x4_slif -= 1;
++it; ++it;
@ -192,28 +214,34 @@ void CParticleElectric::UpdateElectricalEffects() {
} }
void CParticleElectric::CalculateFractal(int start, int end, float ampl, float ampd) { void CParticleElectric::CalculateFractal(int start, int end, float ampl, float ampd) {
float tmp = (end - start) / float(x430_fractalMags.size()) * ampl; const float tmp = float(end - start) / float(x430_fractalMags.size()) * ampl;
int storeIdx = (start + end) / 2; const int storeIdx = (start + end) / 2;
x430_fractalMags[storeIdx] = (x430_fractalMags[start] + x430_fractalMags[end]) * 0.5f + tmp * x14c_randState.Float() - x430_fractalMags[storeIdx] = (x430_fractalMags[start] + x430_fractalMags[end]) * 0.5f + tmp * x14c_randState.Float() -
tmp * 0.5f + ampd * x14c_randState.Float() - ampd * 0.5f; tmp * 0.5f + ampd * x14c_randState.Float() - ampd * 0.5f;
if ((start + end) & 1) if ((start + end) & 1) {
x430_fractalMags[end - 1] = x430_fractalMags[end]; x430_fractalMags[end - 1] = x430_fractalMags[end];
}
if (storeIdx - start > 1) if (storeIdx - start > 1) {
CalculateFractal(start, storeIdx, ampl, ampd); CalculateFractal(start, storeIdx, ampl, ampd);
if (end - storeIdx > 1) }
if (end - storeIdx > 1) {
CalculateFractal(storeIdx, end, ampl, ampd); CalculateFractal(storeIdx, end, ampl, ampd);
}
} }
void CParticleElectric::CalculatePoints() { void CParticleElectric::CalculatePoints() {
zeus::CVector3f pos, vel; zeus::CVector3f pos, vel;
if (CEmitterElement* iemt = x1c_elecDesc->x18_IEMT.get()) if (CEmitterElement* iemt = x1c_elecDesc->x18_IEMT.get()) {
iemt->GetValue(x28_currentFrame, pos, vel); iemt->GetValue(x28_currentFrame, pos, vel);
}
if (x178_overrideIPos) if (x178_overrideIPos) {
pos = *x178_overrideIPos; pos = *x178_overrideIPos;
if (x188_overrideIVel) }
if (x188_overrideIVel) {
vel = *x188_overrideIVel; vel = *x188_overrideIVel;
}
rstl::reserved_vector<zeus::CVector3f, 4> points; rstl::reserved_vector<zeus::CVector3f, 4> points;
@ -227,13 +255,16 @@ void CParticleElectric::CalculatePoints() {
zeus::CVector3f fpos = zeus::skForward; zeus::CVector3f fpos = zeus::skForward;
zeus::CVector3f fvel; zeus::CVector3f fvel;
if (CEmitterElement* femt = x1c_elecDesc->x1c_FEMT.get()) if (CEmitterElement* femt = x1c_elecDesc->x1c_FEMT.get()) {
femt->GetValue(x28_currentFrame, fpos, fvel); femt->GetValue(x28_currentFrame, fpos, fvel);
}
if (x198_overrideFPos) if (x198_overrideFPos) {
fpos = *x198_overrideFPos; fpos = *x198_overrideFPos;
if (x1a8_overrideFVel) }
if (x1a8_overrideFVel) {
fvel = *x1a8_overrideFVel; fvel = *x1a8_overrideFVel;
}
if (!fvel.isZero()) { if (!fvel.isZero()) {
if (points.size() == 3) { if (points.size() == 3) {
@ -249,21 +280,21 @@ void CParticleElectric::CalculatePoints() {
} }
if (points.size() == 4) { if (points.size() == 4) {
int segs = x150_SSEG - 1; const int segs = x150_SSEG - 1;
float segDiv = 1.f / float(segs); const float segDiv = 1.f / float(segs);
float curDiv = segDiv; float curDiv = segDiv;
for (int i = 1; i < segs; ++i) { for (int i = 1; i < segs; ++i) {
float t = segDiv * x14c_randState.Range(-0.45f, 0.45f) + curDiv; const float t = segDiv * x14c_randState.Range(-0.45f, 0.45f) + curDiv;
x420_calculatedVerts[i] = zeus::getBezierPoint(points[0], points[1], points[2], points[3], t); x420_calculatedVerts[i] = zeus::getBezierPoint(points[0], points[1], points[2], points[3], t);
curDiv += segDiv; curDiv += segDiv;
} }
x420_calculatedVerts[segs] = points[3]; x420_calculatedVerts[segs] = points[3];
} else { } else {
x420_calculatedVerts[0] = pos; x420_calculatedVerts[0] = pos;
int segs = x150_SSEG - 1; const int segs = x150_SSEG - 1;
float segDiv = 1.f / float(segs); const float segDiv = 1.f / float(segs);
zeus::CVector3f accum = x420_calculatedVerts[0]; zeus::CVector3f accum = x420_calculatedVerts[0];
zeus::CVector3f segDelta = (fpos - pos) * segDiv; const zeus::CVector3f segDelta = (fpos - pos) * segDiv;
for (int i = 1; i < segs; ++i) { for (int i = 1; i < segs; ++i) {
float r = x14c_randState.Range(-0.45f, 0.45f); float r = x14c_randState.Range(-0.45f, 0.45f);
x420_calculatedVerts[i] = segDelta * r + accum; x420_calculatedVerts[i] = segDelta * r + accum;
@ -272,8 +303,9 @@ void CParticleElectric::CalculatePoints() {
x420_calculatedVerts[segs] = fpos; x420_calculatedVerts[segs] = fpos;
} }
for (int i = 0; i < x150_SSEG; ++i) for (int i = 0; i < x150_SSEG; ++i) {
x430_fractalMags[i] = 0.f; x430_fractalMags[i] = 0.f;
}
float amplVal = 1.f; float amplVal = 1.f;
if (CRealElement* ampl = x1c_elecDesc->x20_AMPL.get()) { if (CRealElement* ampl = x1c_elecDesc->x20_AMPL.get()) {
@ -282,8 +314,9 @@ void CParticleElectric::CalculatePoints() {
} }
float ampdVal = 0.f; float ampdVal = 0.f;
if (CRealElement* ampd = x1c_elecDesc->x24_AMPD.get()) if (CRealElement* ampd = x1c_elecDesc->x24_AMPD.get()) {
ampd->GetValue(x28_currentFrame, ampdVal); ampd->GetValue(x28_currentFrame, ampdVal);
}
CalculateFractal(0, x420_calculatedVerts.size() - 1, amplVal, ampdVal); CalculateFractal(0, x420_calculatedVerts.size() - 1, amplVal, ampdVal);
@ -294,55 +327,63 @@ void CParticleElectric::CalculatePoints() {
v0.normalize(); v0.normalize();
v1.normalize(); v1.normalize();
float dot = v0.dot(v1); float dot = v0.dot(v1);
if (dot < 0) if (dot < 0) {
dot = -dot; dot = -dot;
if (std::fabs(dot - 1.f) < 0.00001f) }
if (std::fabs(dot - 1.f) < 0.00001f) {
upVec = zeus::lookAt(x420_calculatedVerts[0], x420_calculatedVerts[1]).basis[2]; upVec = zeus::lookAt(x420_calculatedVerts[0], x420_calculatedVerts[1]).basis[2];
else } else {
upVec = v0.cross(v1).normalized(); upVec = v0.cross(v1).normalized();
}
} else if (x420_calculatedVerts[0] != x420_calculatedVerts[1]) { } else if (x420_calculatedVerts[0] != x420_calculatedVerts[1]) {
upVec = zeus::lookAt(x420_calculatedVerts[0], x420_calculatedVerts[1]).basis[2]; upVec = zeus::lookAt(x420_calculatedVerts[0], x420_calculatedVerts[1]).basis[2];
} }
float commonRand = x14c_randState.Range(0.f, 360.f); const float commonRand = x14c_randState.Range(0.f, 360.f);
for (int i = 1; i < x420_calculatedVerts.size() - 1; ++i) { for (size_t i = 1; i < x420_calculatedVerts.size() - 1; ++i) {
zeus::CVector3f delta = x420_calculatedVerts[i] - x420_calculatedVerts[i - 1]; const zeus::CVector3f delta = x420_calculatedVerts[i] - x420_calculatedVerts[i - 1];
if (!delta.isZero()) { if (!delta.isZero()) {
zeus::CRelAngle angle = const zeus::CRelAngle angle =
zeus::degToRad(x430_fractalMags[i] / amplVal * 16.f * x14c_randState.Range(-1.f, 1.f) + commonRand); zeus::degToRad(x430_fractalMags[i] / amplVal * 16.f * x14c_randState.Range(-1.f, 1.f) + commonRand);
x440_fractalOffsets[i] = zeus::CQuaternion::fromAxisAngle(delta, angle).transform(x430_fractalMags[i] * upVec); x440_fractalOffsets[i] = zeus::CQuaternion::fromAxisAngle(delta, angle).transform(x430_fractalMags[i] * upVec);
} }
} }
for (int i = 1; i < x420_calculatedVerts.size() - 1; ++i) for (size_t i = 1; i < x420_calculatedVerts.size() - 1; ++i) {
x420_calculatedVerts[i] += x440_fractalOffsets[i]; x420_calculatedVerts[i] += x440_fractalOffsets[i];
}
if (x1c_elecDesc->x70_ZERY) if (x1c_elecDesc->x70_ZERY) {
for (int i = 0; i < x420_calculatedVerts.size(); ++i) for (auto& calculatedVert : x420_calculatedVerts) {
x420_calculatedVerts[i].y() = 0.f; calculatedVert.y() = 0.f;
}
}
} }
void CParticleElectric::CreateNewParticles(int count) { void CParticleElectric::CreateNewParticles(int count) {
int allocIdx = 0; int allocIdx = 0;
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
if (x3e8_electricManagers.size() < x154_SCNT) { if (x3e8_electricManagers.size() < x154_SCNT) {
zeus::CTransform cachedRot = xf8_cachedXf.getRotation(); const zeus::CTransform cachedRot = xf8_cachedXf.getRotation();
int toAdd = x1bc_allocated.size() - allocIdx; const int toAdd = x1bc_allocated.size() - allocIdx;
for (int j = 0; j < toAdd; ++j, ++allocIdx) { for (int j = 0; j < toAdd; ++j, ++allocIdx) {
if (x1bc_allocated[allocIdx]) if (x1bc_allocated[allocIdx]) {
continue; continue;
}
x1bc_allocated[allocIdx] = true; x1bc_allocated[allocIdx] = true;
int lifetime = 1; int lifetime = 1;
if (CIntElement* slif = x1c_elecDesc->x4_SLIF.get()) if (CIntElement* slif = x1c_elecDesc->x4_SLIF.get()) {
slif->GetValue(x28_currentFrame, lifetime); slif->GetValue(x28_currentFrame, lifetime);
}
x3e8_electricManagers.emplace_back(allocIdx, lifetime, x28_currentFrame); x3e8_electricManagers.emplace_back(allocIdx, lifetime, x28_currentFrame);
CParticleElectricManager& elec = x3e8_electricManagers.back(); CParticleElectricManager& elec = x3e8_electricManagers.back();
CParticleGlobals::instance()->SetParticleLifetime(elec.xc_endFrame - elec.x8_startFrame); CParticleGlobals::instance()->SetParticleLifetime(elec.xc_endFrame - elec.x8_startFrame);
int frame = x28_currentFrame - elec.x8_startFrame; const int frame = x28_currentFrame - elec.x8_startFrame;
CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(frame); CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(frame);
CalculatePoints(); CalculatePoints();
@ -354,8 +395,9 @@ void CParticleElectric::CreateNewParticles(int count) {
swoosh.SetGlobalScale(xe0_globalScale); swoosh.SetGlobalScale(xe0_globalScale);
swoosh.SetLocalScale(xec_localScale); swoosh.SetLocalScale(xec_localScale);
zeus::CColor color = zeus::skWhite; zeus::CColor color = zeus::skWhite;
if (CColorElement* colr = x1c_elecDesc->x14_COLR.get()) if (CColorElement* colr = x1c_elecDesc->x14_COLR.get()) {
colr->GetValue(frame, color); colr->GetValue(frame, color);
}
swoosh.SetModulationColor(color * x1b8_moduColor); swoosh.SetModulationColor(color * x1b8_moduColor);
swoosh.DoElectricCreate(x420_calculatedVerts); swoosh.DoElectricCreate(x420_calculatedVerts);
} }
@ -366,8 +408,9 @@ void CParticleElectric::CreateNewParticles(int count) {
UpdateLine(allocIdx, 0); UpdateLine(allocIdx, 0);
if (x450_27_haveSSWH) { if (x450_27_haveSSWH) {
x130_buildBounds = zeus::CAABox(); x130_buildBounds = zeus::CAABox();
for (const zeus::CVector3f& vec : x420_calculatedVerts) for (const zeus::CVector3f& vec : x420_calculatedVerts) {
x130_buildBounds.accumulateBounds(vec); x130_buildBounds.accumulateBounds(vec);
}
line.x28_aabb = x130_buildBounds; line.x28_aabb = x130_buildBounds;
} }
} }
@ -376,7 +419,7 @@ void CParticleElectric::CreateNewParticles(int count) {
for (int k = 0; k < x154_SCNT; ++k) { for (int k = 0; k < x154_SCNT; ++k) {
CElementGen& gen = *x400_gpsmGenerators[k]; CElementGen& gen = *x400_gpsmGenerators[k];
if (!gen.GetParticleEmission()) { if (!gen.GetParticleEmission()) {
zeus::CTransform scale = const zeus::CTransform scale =
zeus::CTransform::Scale(xe0_globalScale) * zeus::CTransform::Scale(xec_localScale); zeus::CTransform::Scale(xe0_globalScale) * zeus::CTransform::Scale(xec_localScale);
gen.SetTranslation(scale * x420_calculatedVerts.front()); gen.SetTranslation(scale * x420_calculatedVerts.front());
gen.SetParticleEmission(true); gen.SetParticleEmission(true);
@ -390,7 +433,7 @@ void CParticleElectric::CreateNewParticles(int count) {
for (int k = 0; k < x154_SCNT; ++k) { for (int k = 0; k < x154_SCNT; ++k) {
CElementGen& gen = *x410_epsmGenerators[k]; CElementGen& gen = *x410_epsmGenerators[k];
if (!gen.GetParticleEmission()) { if (!gen.GetParticleEmission()) {
zeus::CTransform scale = const zeus::CTransform scale =
zeus::CTransform::Scale(xe0_globalScale) * zeus::CTransform::Scale(xec_localScale); zeus::CTransform::Scale(xe0_globalScale) * zeus::CTransform::Scale(xec_localScale);
gen.SetTranslation(scale * x420_calculatedVerts.back()); gen.SetTranslation(scale * x420_calculatedVerts.back());
gen.SetParticleEmission(true); gen.SetParticleEmission(true);
@ -411,8 +454,7 @@ void CParticleElectric::AddElectricalEffects() {
if (CRealElement* grat = x1c_elecDesc->x8_GRAT.get()) { if (CRealElement* grat = x1c_elecDesc->x8_GRAT.get()) {
if (grat->GetValue(x28_currentFrame, genRate)) { if (grat->GetValue(x28_currentFrame, genRate)) {
x3e8_electricManagers.clear(); x3e8_electricManagers.clear();
for (int i = 0; i < x1bc_allocated.size(); ++i) std::fill(x1bc_allocated.begin(), x1bc_allocated.end(), false);
x1bc_allocated[i] = false;
return; return;
} else { } else {
genRate = std::max(0.f, genRate); genRate = std::max(0.f, genRate);
@ -420,7 +462,7 @@ void CParticleElectric::AddElectricalEffects() {
} }
x15c_genRem += genRate; x15c_genRem += genRate;
int partCount = std::floor(x15c_genRem); const int partCount = std::floor(x15c_genRem);
x15c_genRem -= partCount; x15c_genRem -= partCount;
CreateNewParticles(partCount); CreateNewParticles(partCount);
} }
@ -434,14 +476,15 @@ void CParticleElectric::BuildBounds() {
x160_systemBounds = zeus::CAABox(); x160_systemBounds = zeus::CAABox();
if (x450_27_haveSSWH) { if (x450_27_haveSSWH) {
for (CParticleElectricManager& elec : x3e8_electricManagers) { for (const CParticleElectricManager& elec : x3e8_electricManagers) {
CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx]; const CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx];
if (auto bounds = swoosh.GetBounds()) if (const auto bounds = swoosh.GetBounds()) {
x160_systemBounds.accumulateBounds(*bounds); x160_systemBounds.accumulateBounds(*bounds);
}
} }
} else if (x450_28_haveLWD) { } else if (x450_28_haveLWD) {
zeus::CAABox tmp = zeus::CAABox(); zeus::CAABox tmp = zeus::CAABox();
for (CParticleElectricManager& elec : x3e8_electricManagers) { for (const CParticleElectricManager& elec : x3e8_electricManagers) {
CLineManager& line = *x2e4_lineManagers[elec.x0_idx]; CLineManager& line = *x2e4_lineManagers[elec.x0_idx];
tmp.accumulateBounds(line.x28_aabb); tmp.accumulateBounds(line.x28_aabb);
} }
@ -453,15 +496,19 @@ void CParticleElectric::BuildBounds() {
} }
if (x450_25_haveGPSM) { if (x450_25_haveGPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
if (auto bounds = x400_gpsmGenerators[i]->GetBounds()) if (auto bounds = x400_gpsmGenerators[i]->GetBounds()) {
x160_systemBounds.accumulateBounds(*bounds); x160_systemBounds.accumulateBounds(*bounds);
}
}
} }
if (x450_26_haveEPSM) { if (x450_26_haveEPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
if (auto bounds = x410_epsmGenerators[i]->GetBounds()) if (auto bounds = x410_epsmGenerators[i]->GetBounds()) {
x160_systemBounds.accumulateBounds(*bounds); x160_systemBounds.accumulateBounds(*bounds);
}
}
} }
} }
@ -470,27 +517,31 @@ bool CParticleElectric::Update(double dt) {
bool ret = false; bool ret = false;
if (x450_25_haveGPSM) { if (x450_25_haveGPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
if (!x400_gpsmGenerators[i]->IsSystemDeletable()) if (!x400_gpsmGenerators[i]->IsSystemDeletable()) {
break; break;
}
}
} }
if (x450_26_haveEPSM) { if (x450_26_haveEPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
if (!x410_epsmGenerators[i]->IsSystemDeletable()) if (!x410_epsmGenerators[i]->IsSystemDeletable()) {
break; break;
}
}
} }
bool emitting = x450_24_emitting && x28_currentFrame < x2c_LIFE; const bool emitting = x450_24_emitting && x28_currentFrame < x2c_LIFE;
double evalTime = x28_currentFrame / 60.0; double evalTime = x28_currentFrame / 60.0;
x30_curTime += dt; x30_curTime += dt;
if (x450_29_transformDirty) { if (x450_29_transformDirty) {
UpdateCachedTransform(); UpdateCachedTransform();
zeus::CTransform globalOrient = xf8_cachedXf.getRotation(); const zeus::CTransform globalOrient = xf8_cachedXf.getRotation();
if (x450_27_haveSSWH) { if (x450_27_haveSSWH) {
for (CParticleElectricManager& elec : x3e8_electricManagers) { for (const CParticleElectricManager& elec : x3e8_electricManagers) {
CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx]; CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx];
swoosh.SetGlobalTranslation(xf8_cachedXf.origin); swoosh.SetGlobalTranslation(xf8_cachedXf.origin);
swoosh.SetGlobalOrientation(globalOrient); swoosh.SetGlobalOrientation(globalOrient);
@ -500,7 +551,7 @@ bool CParticleElectric::Update(double dt) {
} }
if (x450_25_haveGPSM) { if (x450_25_haveGPSM) {
for (CParticleElectricManager& elec : x3e8_electricManagers) { for (const CParticleElectricManager& elec : x3e8_electricManagers) {
CElementGen& gen = *x400_gpsmGenerators[elec.x0_idx]; CElementGen& gen = *x400_gpsmGenerators[elec.x0_idx];
gen.SetGlobalTranslation(xf8_cachedXf.origin); gen.SetGlobalTranslation(xf8_cachedXf.origin);
gen.SetGlobalOrientation(globalOrient); gen.SetGlobalOrientation(globalOrient);
@ -510,7 +561,7 @@ bool CParticleElectric::Update(double dt) {
} }
if (x450_26_haveEPSM) { if (x450_26_haveEPSM) {
for (CParticleElectricManager& elec : x3e8_electricManagers) { for (const CParticleElectricManager& elec : x3e8_electricManagers) {
CElementGen& gen = *x410_epsmGenerators[elec.x0_idx]; CElementGen& gen = *x410_epsmGenerators[elec.x0_idx];
gen.SetGlobalTranslation(xf8_cachedXf.origin); gen.SetGlobalTranslation(xf8_cachedXf.origin);
gen.SetGlobalOrientation(globalOrient); gen.SetGlobalOrientation(globalOrient);
@ -529,19 +580,25 @@ bool CParticleElectric::Update(double dt) {
AddElectricalEffects(); AddElectricalEffects();
if (x450_25_haveGPSM) { if (x450_25_haveGPSM) {
if (x28_currentFrame >= x2c_LIFE) if (x28_currentFrame >= x2c_LIFE) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
x400_gpsmGenerators[i]->EndLifetime(); x400_gpsmGenerators[i]->EndLifetime();
for (int i = 0; i < x154_SCNT; ++i) }
}
for (int i = 0; i < x154_SCNT; ++i) {
x400_gpsmGenerators[i]->Update(1.0 / 60.0); x400_gpsmGenerators[i]->Update(1.0 / 60.0);
}
} }
if (x450_26_haveEPSM) { if (x450_26_haveEPSM) {
if (x28_currentFrame >= x2c_LIFE) if (x28_currentFrame >= x2c_LIFE) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
x410_epsmGenerators[i]->EndLifetime(); x410_epsmGenerators[i]->EndLifetime();
for (int i = 0; i < x154_SCNT; ++i) }
}
for (int i = 0; i < x154_SCNT; ++i) {
x410_epsmGenerators[i]->Update(1.0 / 60.0); x410_epsmGenerators[i]->Update(1.0 / 60.0);
}
} }
ret = true; ret = true;
@ -549,8 +606,9 @@ bool CParticleElectric::Update(double dt) {
x28_currentFrame += 1; x28_currentFrame += 1;
} }
if (ret) if (ret) {
BuildBounds(); BuildBounds();
}
return ret; return ret;
} }
@ -560,22 +618,27 @@ void CParticleElectric::Render(const CActorLights* lights) {
*x1c_elecDesc.GetObjectTag()).c_str(), zeus::skYellow); *x1c_elecDesc.GetObjectTag()).c_str(), zeus::skYellow);
if (x3e8_electricManagers.size()) { if (x3e8_electricManagers.size()) {
if (x450_29_transformDirty) if (x450_29_transformDirty) {
UpdateCachedTransform(); UpdateCachedTransform();
if (x450_27_haveSSWH) }
if (x450_27_haveSSWH) {
RenderSwooshes(); RenderSwooshes();
if (x450_28_haveLWD) }
if (x450_28_haveLWD) {
RenderLines(); RenderLines();
}
} }
if (x450_25_haveGPSM) { if (x450_25_haveGPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
x400_gpsmGenerators[i]->Render(lights); x400_gpsmGenerators[i]->Render(lights);
}
} }
if (x450_26_haveEPSM) { if (x450_26_haveEPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
x410_epsmGenerators[i]->Render(lights); x410_epsmGenerators[i]->Render(lights);
}
} }
} }
@ -595,20 +658,22 @@ void CParticleElectric::SetGlobalOrientation(const zeus::CTransform& orientation
x450_29_transformDirty = true; x450_29_transformDirty = true;
if (x450_27_haveSSWH) { if (x450_27_haveSSWH) {
for (CParticleElectricManager& elec : x3e8_electricManagers) { for (const CParticleElectricManager& elec : x3e8_electricManagers) {
CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx]; CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx];
swoosh.SetGlobalOrientation(xb0_globalOrientation); swoosh.SetGlobalOrientation(xb0_globalOrientation);
} }
} }
if (x450_25_haveGPSM) { if (x450_25_haveGPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
x400_gpsmGenerators[i]->SetGlobalOrientation(xb0_globalOrientation); x400_gpsmGenerators[i]->SetGlobalOrientation(xb0_globalOrientation);
}
} }
if (x450_26_haveEPSM) { if (x450_26_haveEPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
x410_epsmGenerators[i]->SetGlobalOrientation(xb0_globalOrientation); x410_epsmGenerators[i]->SetGlobalOrientation(xb0_globalOrientation);
}
} }
} }
@ -617,20 +682,22 @@ void CParticleElectric::SetGlobalTranslation(const zeus::CVector3f& translation)
x450_29_transformDirty = true; x450_29_transformDirty = true;
if (x450_27_haveSSWH) { if (x450_27_haveSSWH) {
for (CParticleElectricManager& elec : x3e8_electricManagers) { for (const CParticleElectricManager& elec : x3e8_electricManagers) {
CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx]; CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx];
swoosh.SetGlobalTranslation(xa4_globalTranslation); swoosh.SetGlobalTranslation(xa4_globalTranslation);
} }
} }
if (x450_25_haveGPSM) { if (x450_25_haveGPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
x400_gpsmGenerators[i]->SetGlobalTranslation(xa4_globalTranslation); x400_gpsmGenerators[i]->SetGlobalTranslation(xa4_globalTranslation);
}
} }
if (x450_26_haveEPSM) { if (x450_26_haveEPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
x410_epsmGenerators[i]->SetGlobalTranslation(xa4_globalTranslation); x410_epsmGenerators[i]->SetGlobalTranslation(xa4_globalTranslation);
}
} }
} }
@ -644,20 +711,22 @@ void CParticleElectric::SetLocalScale(const zeus::CVector3f& scale) {
x450_29_transformDirty = true; x450_29_transformDirty = true;
if (x450_27_haveSSWH) { if (x450_27_haveSSWH) {
for (CParticleElectricManager& elec : x3e8_electricManagers) { for (const CParticleElectricManager& elec : x3e8_electricManagers) {
CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx]; CParticleSwoosh& swoosh = *x1e0_swooshGenerators[elec.x0_idx];
swoosh.SetLocalScale(xec_localScale); swoosh.SetLocalScale(xec_localScale);
} }
} }
if (x450_25_haveGPSM) { if (x450_25_haveGPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
x400_gpsmGenerators[i]->SetLocalScale(xec_localScale); x400_gpsmGenerators[i]->SetLocalScale(xec_localScale);
}
} }
if (x450_26_haveEPSM) { if (x450_26_haveEPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
x410_epsmGenerators[i]->SetLocalScale(xec_localScale); x410_epsmGenerators[i]->SetLocalScale(xec_localScale);
}
} }
} }
@ -678,22 +747,28 @@ const zeus::CVector3f& CParticleElectric::GetGlobalScale() const { return xe0_gl
const zeus::CColor& CParticleElectric::GetModulationColor() const { return x1b8_moduColor; } const zeus::CColor& CParticleElectric::GetModulationColor() const { return x1b8_moduColor; }
bool CParticleElectric::IsSystemDeletable() const { bool CParticleElectric::IsSystemDeletable() const {
if (x450_24_emitting && x28_currentFrame < x2c_LIFE) if (x450_24_emitting && x28_currentFrame < x2c_LIFE) {
return false; return false;
}
if (x3e8_electricManagers.size()) if (x3e8_electricManagers.size()) {
return false; return false;
}
if (x450_25_haveGPSM) { if (x450_25_haveGPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
if (!x400_gpsmGenerators[i]->IsSystemDeletable()) if (!x400_gpsmGenerators[i]->IsSystemDeletable()) {
return false; return false;
}
}
} }
if (x450_26_haveEPSM) { if (x450_26_haveEPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
if (!x410_epsmGenerators[i]->IsSystemDeletable()) if (!x410_epsmGenerators[i]->IsSystemDeletable()) {
return false; return false;
}
}
} }
return true; return true;
@ -711,38 +786,46 @@ u32 CParticleElectric::GetParticleCount() const {
u32 ret = 0; u32 ret = 0;
for (const CParticleElectricManager& elec : x3e8_electricManagers) { for (const CParticleElectricManager& elec : x3e8_electricManagers) {
if (x450_27_haveSSWH) if (x450_27_haveSSWH) {
ret += x1e0_swooshGenerators[elec.x0_idx]->GetParticleCount(); ret += x1e0_swooshGenerators[elec.x0_idx]->GetParticleCount();
if (x450_28_haveLWD) }
if (x450_28_haveLWD) {
ret += x150_SSEG; ret += x150_SSEG;
}
} }
if (x450_25_haveGPSM) { if (x450_25_haveGPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
ret += x400_gpsmGenerators[i]->GetParticleCount(); ret += x400_gpsmGenerators[i]->GetParticleCount();
}
} }
if (x450_26_haveEPSM) { if (x450_26_haveEPSM) {
for (int i = 0; i < x154_SCNT; ++i) for (int i = 0; i < x154_SCNT; ++i) {
ret += x410_epsmGenerators[i]->GetParticleCount(); ret += x410_epsmGenerators[i]->GetParticleCount();
}
} }
return ret; return ret;
} }
bool CParticleElectric::SystemHasLight() const { bool CParticleElectric::SystemHasLight() const {
if (x450_25_haveGPSM) if (x450_25_haveGPSM) {
return x400_gpsmGenerators.front()->SystemHasLight(); return x400_gpsmGenerators.front()->SystemHasLight();
else if (x450_26_haveEPSM) }
if (x450_26_haveEPSM) {
return x410_epsmGenerators.front()->SystemHasLight(); return x410_epsmGenerators.front()->SystemHasLight();
}
return false; return false;
} }
CLight CParticleElectric::GetLight() const { CLight CParticleElectric::GetLight() const {
if (x450_25_haveGPSM) if (x450_25_haveGPSM) {
return x400_gpsmGenerators.front()->GetLight(); return x400_gpsmGenerators.front()->GetLight();
else if (x450_26_haveEPSM) }
if (x450_26_haveEPSM) {
return x410_epsmGenerators.front()->GetLight(); return x410_epsmGenerators.front()->GetLight();
}
return CLight::BuildLocalAmbient(GetGlobalTranslation(), zeus::skOrange); return CLight::BuildLocalAmbient(GetGlobalTranslation(), zeus::skOrange);
} }