Prevent updating an entity if updateentities() removed it

Otherwise, this would result in the game updating an entity twice, which
isn't good. This is most noticeable in the Gravitron, where many
Gravitron squares are created and destroyed at a time, and it's
especially noticeable during the part near the end of the Gravitron
where the pattern is two Gravitron squares, one at the top and bottom,
and then two Gravitron squares in the middle afterwards. The timing is
just right such that the top one of the two middle ones would be
misaligned with the bottom one of the two when a Gravitron square gets
outside the screen.

To do this, I changed entityclass::updateentities() into a bool, and
made every single caller check its return value. I only needed to do
this for the ones preceding updateentitylogic() and
entitymapcollision(), but I wanted to play it safe and be defensive, so
I did it for the disappearing platform kludge, as well as the
updateentities() within the updateentities() function.
This commit is contained in:
Misa
2020-05-05 13:49:12 -07:00
committed by Ethan Lee
parent 3c80d136e4
commit ce1e212317
3 changed files with 91 additions and 25 deletions

View File

@@ -342,14 +342,32 @@ void gamelogic()
{
//ok, unfortunate case where the disappearing platform hasn't fully disappeared. Accept a little
//graphical uglyness to avoid breaking the room!
while (obj.entities[i].state == 2) obj.updateentities(i);
obj.entities[i].state = 4;
bool entitygone = false;
while (obj.entities[i].state == 2)
{
entitygone = obj.updateentities(i);
if (entitygone)
{
i--;
break;
}
}
if (!entitygone) obj.entities[i].state = 4;
}
else if (map.finalstretch && obj.entities[i].type == 2)
{
//for the final level. probably something 99% of players won't see.
while (obj.entities[i].state == 2) obj.updateentities(i);
obj.entities[i].state = 4;
bool entitygone = false;
while (obj.entities[i].state == 2)
{
entitygone = obj.updateentities(i);
if (entitygone)
{
i--;
break;
}
}
if (!entitygone) obj.entities[i].state = 4;
}
else if (obj.entities[i].type == 23 && game.swnmode && game.deathseq<15)
{
@@ -699,7 +717,8 @@ void gamelogic()
{
obj.removeblockat(obj.entities[i].xp, obj.entities[i].yp);
obj.updateentities(i); // Behavioral logic
bool entitygone = obj.updateentities(i); // Behavioral logic
if (entitygone) continue;
obj.updateentitylogic(i); // Basic Physics
obj.entitymapcollision(i); // Collisions with walls
@@ -728,7 +747,8 @@ void gamelogic()
{
obj.removeblockat(obj.entities[ie].xp, obj.entities[ie].yp);
obj.updateentities(ie); // Behavioral logic
bool entitygone = obj.updateentities(ie); // Behavioral logic
if (entitygone) continue;
obj.updateentitylogic(ie); // Basic Physics
obj.entitymapcollision(ie); // Collisions with walls
@@ -759,7 +779,8 @@ void gamelogic()
{
if (!obj.entities[ie].isplatform)
{
obj.updateentities(ie); // Behavioral logic
bool entitygone = obj.updateentities(ie); // Behavioral logic
if (entitygone) continue;
obj.updateentitylogic(ie); // Basic Physics
obj.entitymapcollision(ie); // Collisions with walls
}