From 950cffcb4ff1692216df249c76d8e290c3cd33a1 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 2 Nov 2015 13:19:31 +0000 Subject: [PATCH] Use grid to determine drawn entities. --- src/battle/entities.c | 13 +++++++++++-- src/battle/entities.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) 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;