mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-01 06:00:15 +02:00
Manage particle lifetime with create/kill_part only
This should fix the long-standing issue of Create/ChangeType callbacks not being called in all cases when particles were created or changed type. I'm eagerly awaiting reports of the horrendous crashes this will inevitably cause.
This commit is contained in:
@@ -127,15 +127,16 @@ void Simulation::Load(const GameSave *save, bool includePressure, Vec2<int> bloc
|
||||
removeExistingParticles({ x, y });
|
||||
|
||||
// Allocate particle (this location is guaranteed to be empty due to "full scan" logic above)
|
||||
if (pfree == -1)
|
||||
auto i = create_part(-3, x, y, tempPart.type);
|
||||
if (i == -1)
|
||||
{
|
||||
break;
|
||||
auto i = pfree;
|
||||
pfree = parts[i].life;
|
||||
NUM_PARTS += 1;
|
||||
}
|
||||
if (i > parts.lastActiveIndex)
|
||||
{
|
||||
parts.lastActiveIndex = i;
|
||||
}
|
||||
parts[i] = tempPart;
|
||||
elementCount[tempPart.type]++;
|
||||
|
||||
|
||||
switch (parts[i].type)
|
||||
@@ -977,6 +978,13 @@ int Simulation::parts_avg(int ci, int ni,int t)
|
||||
|
||||
void Simulation::clear_sim(void)
|
||||
{
|
||||
for (auto i = 0; i <= parts.lastActiveIndex; i++)
|
||||
{
|
||||
if (parts[i].type)
|
||||
{
|
||||
kill_part(i);
|
||||
}
|
||||
}
|
||||
ensureDeterminism = false;
|
||||
frameCount = 0;
|
||||
debug_nextToUpdate = 0;
|
||||
|
Reference in New Issue
Block a user