From d986df6a1511d9b8e80d060e39aa86600e0a281f Mon Sep 17 00:00:00 2001 From: rodri Date: Wed, 3 Apr 2024 16:34:15 +0000 Subject: scene: add a way to remove entities and fix the clearscene routine. --- graphics.h | 1 + scene.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/graphics.h b/graphics.h index 033dcbe..7dcc7ff 100644 --- a/graphics.h +++ b/graphics.h @@ -128,6 +128,7 @@ struct Scene ulong nents; void (*addent)(Scene*, Entity*); + void (*delent)(Scene*, Entity*); }; /* shader params */ diff --git a/scene.c b/scene.c index cb890a5..ec1d236 100644 --- a/scene.c +++ b/scene.c @@ -165,6 +165,15 @@ scene_addent(Scene *s, Entity *e) s->nents++; } +static void +scene_delent(Scene *s, Entity *e) +{ + e->prev->next = e->next; + e->next->prev = e->prev; + e->prev = e->next = nil; + s->nents--; +} + Scene * newscene(char *name) { @@ -175,6 +184,7 @@ newscene(char *name) s->ents.prev = s->ents.next = &s->ents; s->nents = 0; s->addent = scene_addent; + s->delent = scene_delent; return s; } @@ -194,7 +204,7 @@ clearscene(Scene *s) Entity *e; for(e = s->ents.next; e != &s->ents; e = e->next){ + s->delent(s, e); delentity(e); - s->nents--; } } -- cgit v1.2.3