From 5ebbe977e9a25feff261b7c5fbbfe7af777dd681 Mon Sep 17 00:00:00 2001 From: rodri Date: Sun, 25 Aug 2024 16:10:04 +0000 Subject: scene: add a method to get an entity from a scene. --- graphics.h | 1 + scene.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/graphics.h b/graphics.h index a2c42e2..61f4bf4 100644 --- a/graphics.h +++ b/graphics.h @@ -187,6 +187,7 @@ struct Scene void (*addent)(Scene*, Entity*); void (*delent)(Scene*, Entity*); + Entity *(*getent)(Scene*, char*); }; /* shader params */ diff --git a/scene.c b/scene.c index 7cf6868..8971c30 100644 --- a/scene.c +++ b/scene.c @@ -153,6 +153,17 @@ scene_delent(Scene *s, Entity *e) s->nents--; } +static Entity * +scene_getent(Scene *s, char *name) +{ + Entity *e; + + for(e = s->ents.next; e != &s->ents; e = e->next) + if(strcmp(e->name, name) == 0) + return e; + return nil; +} + Scene * newscene(char *name) { @@ -165,6 +176,7 @@ newscene(char *name) s->skybox = nil; s->addent = scene_addent; s->delent = scene_delent; + s->getent = scene_getent; return s; } -- cgit v1.2.3