Don't add capital ship components to quadtree until they've been positioned.

This commit is contained in:
Steve 2016-03-06 17:13:57 +00:00
parent 721ca3e110
commit 497977c665
1 changed files with 13 additions and 2 deletions

View File

@ -35,6 +35,7 @@ static void restrictToBattleArea(Entity *e);
static void drawTargetRects(Entity *e); static void drawTargetRects(Entity *e);
static int drawComparator(const void *a, const void *b); static int drawComparator(const void *a, const void *b);
static void notifyNewArrivals(void); static void notifyNewArrivals(void);
static int isCapitalShipComponent(Entity *e);
void initEntities(void) void initEntities(void)
{ {
@ -162,8 +163,11 @@ void doEntities(void)
e->x += e->dx; e->x += e->dx;
e->y += e->dy; e->y += e->dy;
if (!isCapitalShipComponent(e))
{
addToQuadtree(e, &battle.quadtree); addToQuadtree(e, &battle.quadtree);
} }
}
else else
{ {
if (e == battle.entityTail) if (e == battle.entityTail)
@ -321,7 +325,7 @@ static void alignComponents(void)
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (e->type == ET_CAPITAL_SHIP_COMPONENT || e->type == ET_CAPITAL_SHIP_GUN || e->type == ET_CAPITAL_SHIP_ENGINE) if (isCapitalShipComponent(e))
{ {
s = sin(TO_RAIDANS(e->owner->angle)); s = sin(TO_RAIDANS(e->owner->angle));
c = cos(TO_RAIDANS(e->owner->angle)); c = cos(TO_RAIDANS(e->owner->angle));
@ -339,10 +343,17 @@ static void alignComponents(void)
{ {
e->angle = e->owner->angle; e->angle = e->owner->angle;
} }
addToQuadtree(e, &battle.quadtree);
} }
} }
} }
static int isCapitalShipComponent(Entity *e)
{
return (e->type == ET_CAPITAL_SHIP_COMPONENT || e->type == ET_CAPITAL_SHIP_GUN || e->type == ET_CAPITAL_SHIP_ENGINE);
}
void drawEntities(void) void drawEntities(void)
{ {
Entity *e, **candidates; Entity *e, **candidates;