From f441626de43dc6c663606c0b330a806fea77e104 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 18 Apr 2021 14:01:51 -0400 Subject: [PATCH] Fix some issues in elementCount Count goes negative if an element is killed due to .life=0 on the same frame an elementRecount is scheduled element count skyrockets when recount is scheduled during game pause Element count increases by a static amount when undoing, because it schedules a recount without clearing the old counts --- src/simulation/Simulation.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 477d7f653..5b36ca8f2 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -545,6 +545,7 @@ Snapshot * Simulation::CreateSnapshot() void Simulation::Restore(const Snapshot & snap) { parts_lastActiveIndex = NPART-1; + std::fill(elementCount, elementCount+PT_NUM, 0); elementRecount = true; force_stacking_check = true; @@ -4710,6 +4711,9 @@ void Simulation::RecalcFreeParticles(bool do_life_dec) lastPartUsed = i; NUM_PARTS ++; + if (elementRecount && t >= 0 && t < PT_NUM && elements[t].Enabled) + elementCount[t]++; + //decrease particle life if (do_life_dec && (!sys_pause || framerender)) { @@ -4738,9 +4742,6 @@ void Simulation::RecalcFreeParticles(bool do_life_dec) continue; } } - - if (elementRecount) - elementCount[t]++; } else { @@ -4764,7 +4765,7 @@ void Simulation::RecalcFreeParticles(bool do_life_dec) parts[lastPartUnused].life = parts_lastActiveIndex+1; } parts_lastActiveIndex = lastPartUsed; - if (elementRecount && (!sys_pause || framerender)) + if (elementRecount) elementRecount = false; }