summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-04-03 16:34:15 +0000
committerrodri <rgl@antares-labs.eu>2024-04-03 16:34:15 +0000
commitd986df6a1511d9b8e80d060e39aa86600e0a281f (patch)
treee7e7636b09a07b77fd49c278ca0ed3729c538ef1
parente05e6c6e71fe60cf663ab563f75b17365ad94665 (diff)
downloadlibgraphics-d986df6a1511d9b8e80d060e39aa86600e0a281f.tar.gz
libgraphics-d986df6a1511d9b8e80d060e39aa86600e0a281f.tar.bz2
libgraphics-d986df6a1511d9b8e80d060e39aa86600e0a281f.zip
scene: add a way to remove entities and fix the clearscene routine.
-rw-r--r--graphics.h1
-rw-r--r--scene.c12
2 files changed, 12 insertions, 1 deletions
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--;
}
}