ref: d986df6a1511d9b8e80d060e39aa86600e0a281f
parent: e05e6c6e71fe60cf663ab563f75b17365ad94665
author: rodri <rgl@antares-labs.eu>
date: Wed Apr 3 12:34:15 EDT 2024
scene: add a way to remove entities and fix the clearscene routine.
--- a/graphics.h
+++ b/graphics.h
@@ -128,6 +128,7 @@
ulong nents;
void (*addent)(Scene*, Entity*);
+ void (*delent)(Scene*, Entity*);
};
/* shader params */
--- a/scene.c
+++ b/scene.c
@@ -165,6 +165,15 @@
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 @@
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 @@
Entity *e;
for(e = s->ents.next; e != &s->ents; e = e->next){
+ s->delent(s, e);
delentity(e);
- s->nents--;
}
}