Use grid to determine drawn entities.

This commit is contained in:
Steve 2015-11-02 13:19:31 +00:00
parent e620ceccad
commit 950cffcb4f
2 changed files with 12 additions and 2 deletions

View File

@ -160,9 +160,14 @@ static void doEntity(void)
void drawEntities(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) if (e->active)
{ {
@ -177,6 +182,10 @@ void drawEntities(void)
break; break;
} }
} }
i++;
e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL;
} }
} }

View File

@ -28,6 +28,7 @@ extern void drawFighter(Entity *e);
extern void doFighter(void); extern void doFighter(void);
extern void addToGrid(Entity *e); extern void addToGrid(Entity *e);
extern void removeFromGrid(Entity *e); extern void removeFromGrid(Entity *e);
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
extern Battle battle; extern Battle battle;
extern Entity *self; extern Entity *self;