Rewrote entity candidate for loops.

This commit is contained in:
Steve 2015-11-11 19:15:41 +00:00
parent ad405c57ae
commit 4da58014d5
4 changed files with 6 additions and 38 deletions

View File

@ -401,26 +401,19 @@ void doCivilianAI(void)
static int nearExtractionPoint(void) static int nearExtractionPoint(void)
{ {
Entity *e, **candidates;
int i; int i;
Entity *e, **candidates;
candidates = getAllEntsWithin(self->x - 500, self->y - 500, 1000, 1000, self); candidates = getAllEntsWithin(self->x - 500, self->y - 500, 1000, 1000, self);
i = 0;
e = candidates[i];
self->target = NULL; self->target = NULL;
while (e) for (i = 0, e = candidates[i] ; e != NULL ; i++, e = candidates[i])
{ {
if (e->type == ET_EXTRACTION_POINT) if (e->type == ET_EXTRACTION_POINT)
{ {
self->target = e; self->target = e;
} }
i++;
e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL;
} }
if (self->target != NULL) if (self->target != NULL)

View File

@ -97,11 +97,8 @@ static void checkCollisions(Bullet *b)
int i; int i;
candidates = getAllEntsWithin(b->x, b->y, b->w, b->h, NULL); candidates = getAllEntsWithin(b->x, b->y, b->w, b->h, NULL);
i = 0;
e = candidates[i]; for (i = 0, e = candidates[i] ; e != NULL ; i++, e = candidates[i])
while (e)
{ {
if (e->type == ET_FIGHTER) if (e->type == ET_FIGHTER)
{ {
@ -139,10 +136,6 @@ static void checkCollisions(Bullet *b)
return; return;
} }
} }
i++;
e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL;
} }
} }

View File

@ -204,22 +204,14 @@ void drawEntities(void)
candidates = getAllEntsWithin(battle.camera.x, battle.camera.y, SCREEN_WIDTH, SCREEN_HEIGHT, NULL); candidates = getAllEntsWithin(battle.camera.x, battle.camera.y, SCREEN_WIDTH, SCREEN_HEIGHT, NULL);
i = 0; for (i = 0, e = candidates[i] ; e != NULL ; i++, e = candidates[i])
e = candidates[i];
while (e)
{ {
i++;
e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL;
} }
qsort(candidates, i, sizeof(Entity*), drawComparator); qsort(candidates, i, sizeof(Entity*), drawComparator);
i = 0; for (i = 0, e = candidates[i] ; e != NULL ; i++, e = candidates[i])
e = candidates[i];
while (e)
{ {
if (e->active) if (e->active)
{ {
@ -234,10 +226,6 @@ void drawEntities(void)
break; break;
} }
} }
i++;
e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL;
} }
} }

View File

@ -274,10 +274,8 @@ static void separate(void)
force = 0; force = 0;
candidates = getAllEntsWithin(self->x, self->y, self->w, self->h, self); candidates = getAllEntsWithin(self->x, self->y, self->w, self->h, self);
i = 0;
e = candidates[i];
while (e) for (i = 0, e = candidates[i] ; e != NULL ; i++, e = candidates[i])
{ {
if (e->type == ET_FIGHTER) if (e->type == ET_FIGHTER)
{ {
@ -294,10 +292,6 @@ static void separate(void)
count++; count++;
} }
} }
i++;
e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL;
} }
if (count > 0) if (count > 0)