summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-04-03 15:43:46 +0000
committerrodri <rgl@antares-labs.eu>2024-04-03 15:43:46 +0000
commit930e09a2ea12275cf2e04577a170a2be342db045 (patch)
treeea2933cbadbf8cb8725a42a9dd0dfbf55424e7ab
parent0aa5a5517703a7dcbcf0ef2ef29fa37f8f1da6ed (diff)
downloadlibgraphics-930e09a2ea12275cf2e04577a170a2be342db045.tar.gz
libgraphics-930e09a2ea12275cf2e04577a170a2be342db045.tar.bz2
libgraphics-930e09a2ea12275cf2e04577a170a2be342db045.zip
scene: implement full cleanup procedures.
-rw-r--r--graphics.h1
-rw-r--r--scene.c23
2 files changed, 22 insertions, 2 deletions
diff --git a/graphics.h b/graphics.h
index b523c2b..033dcbe 100644
--- a/graphics.h
+++ b/graphics.h
@@ -266,6 +266,7 @@ Entity *newentity(Model*);
void delentity(Entity*);
Scene *newscene(char*);
void delscene(Scene*);
+void clearscene(Scene*);
/* vertex */
void addvattr(Vertex*, char*, int, void*);
diff --git a/scene.c b/scene.c
index 2d74451..6abae09 100644
--- a/scene.c
+++ b/scene.c
@@ -117,6 +117,14 @@ newmodel(void)
void
delmodel(Model *m)
{
+ if(m->obj != nil)
+ objfree(m->obj);
+ if(m->tex != nil)
+ freememimage(m->tex);
+ if(m->nor != nil)
+ freememimage(m->nor);
+ if(m->nelems > 0)
+ free(m->elems);
free(m);
}
@@ -138,7 +146,7 @@ newentity(Model *m)
void
delentity(Entity *e)
{
- /* TODO free model */
+ delmodel(e->mdl);
free(e);
}
@@ -168,7 +176,18 @@ newscene(char *name)
void
delscene(Scene *s)
{
- /* TODO free ents */
+ clearscene(s);
free(s->name);
free(s);
}
+
+void
+clearscene(Scene *s)
+{
+ Entity *e;
+
+ for(e = s->ents.next; e != &s->ents; e = e->next){
+ delentity(e);
+ s->nents--;
+ }
+}