diff --git a/src/battle/entities.c b/src/battle/entities.c index 48830aa..f8a9109 100644 --- a/src/battle/entities.c +++ b/src/battle/entities.c @@ -160,9 +160,14 @@ static void doEntity(void) void drawEntities(void) { - Entity *e; + Entity *e, **candidates; + int i; - for (e = battle.entityHead.next ; e != NULL ; e = e->next) + candidates = getAllEntsWithin(battle.camera.x, battle.camera.y, SCREEN_WIDTH, SCREEN_HEIGHT, NULL); + i = 0; + e = candidates[i]; + + while (e) { if (e->active) { @@ -177,6 +182,10 @@ void drawEntities(void) break; } } + + i++; + + e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL; } } diff --git a/src/battle/entities.h b/src/battle/entities.h index d52aa5f..8431755 100644 --- a/src/battle/entities.h +++ b/src/battle/entities.h @@ -28,6 +28,7 @@ extern void drawFighter(Entity *e); extern void doFighter(void); extern void addToGrid(Entity *e); extern void removeFromGrid(Entity *e); +extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern Battle battle; extern Entity *self;