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
This commit is contained in:
jacob1
2021-04-18 14:01:51 -04:00
parent 11f6abdfca
commit f441626de4

View File

@@ -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;
}