shithub: libgraphics

Download patch

ref: 5ebbe977e9a25feff261b7c5fbbfe7af777dd681
parent: 7dc2c0d02e6fb4fbdafb15bd66aa7d45768eb6ac
author: rodri <rgl@antares-labs.eu>
date: Sun Aug 25 12:10:04 EDT 2024

scene: add a method to get an entity from a scene.

--- a/graphics.h
+++ b/graphics.h
@@ -187,6 +187,7 @@
 
 	void (*addent)(Scene*, Entity*);
 	void (*delent)(Scene*, Entity*);
+	Entity *(*getent)(Scene*, char*);
 };
 
 /* shader params */
--- a/scene.c
+++ b/scene.c
@@ -153,6 +153,17 @@
 	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 @@
 	s->skybox = nil;
 	s->addent = scene_addent;
 	s->delent = scene_delent;
+	s->getent = scene_getent;
 	return s;
 }