Only set entity size once. Test entity is dead before testing alive (race condition when adding to quadtree).

This commit is contained in:
Steve 2018-02-04 12:01:55 +00:00
parent 7e88125864
commit a84f261154
1 changed files with 25 additions and 17 deletions

View File

@ -75,11 +75,18 @@ void doEntities(void)
prev = &world.entityHead;
for (self = world.entityHead.next ; self != NULL ; self = self->next)
{
/*
* Most things retain their dimensions, so this isn't a big deal. If we set
* this each frame, it will muck up the bouncing, especially in the case of grenades.
*/
if (self->w == 0 || self->h == 0)
{
r = &self->sprite[self->facing]->frames[self->spriteFrame]->rect;
self->w = r->w;
self->h = r->h;
}
removeFromQuadtree(self, &world.quadtree);
@ -173,7 +180,20 @@ void doEntities(void)
self->isOnScreen = 0;
}
if (self->alive == ALIVE_ALIVE)
if (self->alive == ALIVE_DEAD)
{
prev->next = self->next;
if (self == world.entityTail)
{
world.entityTail = prev;
}
free(self);
self = prev;
}
else if (self->alive == ALIVE_ALIVE)
{
if (self->health <= 0)
{
@ -186,18 +206,6 @@ void doEntities(void)
addToQuadtree(self, &world.quadtree);
}
}
if (self->alive == ALIVE_DEAD)
{
prev->next = self->next;
if (self == world.entityTail)
{
world.entityTail = prev;
}
self = prev;
}
}
prev = self;