diff options
author | rodri <rgl@antares-labs.eu> | 2024-04-03 16:34:15 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-04-03 16:34:15 +0000 |
commit | d986df6a1511d9b8e80d060e39aa86600e0a281f (patch) | |
tree | e7e7636b09a07b77fd49c278ca0ed3729c538ef1 | |
parent | e05e6c6e71fe60cf663ab563f75b17365ad94665 (diff) | |
download | libgraphics-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.h | 1 | ||||
-rw-r--r-- | scene.c | 12 |
2 files changed, 12 insertions, 1 deletions
@@ -128,6 +128,7 @@ struct Scene ulong nents; void (*addent)(Scene*, Entity*); + void (*delent)(Scene*, Entity*); }; /* shader params */ @@ -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--; } } |