feat: added SceneNodeGetChildByTypeclass

This commit is contained in:
Sara 2024-09-25 17:34:17 +02:00
parent 94e00bf0fd
commit d44f10c87b
2 changed files with 14 additions and 0 deletions

View file

@ -165,6 +165,16 @@ SceneNodeEntity SceneNodeDetachEntity(SceneNode *self) {
return e;
}
SceneNode *SceneNodeGetChildByTypeclass(SceneNode *self, char const *typeclass, bool recurse) {
list_foreach(SceneNode **,child, &self->children) {
SceneNodeEntity entity = (*child)->entity;
if(mirror_get_function(entity.data, entity.mirror, typeclass))
return *child;
if(recurse)
SceneNodeGetChildByTypeclass(*child, typeclass, recurse);
}
}
Scene *CreateScene(SceneNode *root) {
Scene *scene = new(Scene);
ASSERT_RETURN(scene != NULL, NULL, "CreateScene: Failed to allocate scene");

View file

@ -2,6 +2,7 @@
#define SCENE_H
#include "stddef.h"
#include "stdbool.h"
#include "scene_node_entity.h"
#include "utils/list.h"
#include "utils/typeclass_helpers.h"
@ -40,6 +41,9 @@ extern void SceneNodeRemoveChild(SceneNode *self, SceneNode *child);
extern void SceneNodeAttachEntity(SceneNode *self, SceneNodeEntity entity);
//! Detach an entity from a scene node
extern SceneNodeEntity SceneNodeDetachEntity(SceneNode *self);
//! Returns the first child node that implements a specific typeclass.
//! Optionally recurses through the entire branch
extern SceneNode *SceneNodeGetChildByTypeclass(SceneNode *self, char const *typeclass, bool recurse);
//! Instantiate a new scene with a root node.
extern Scene *CreateScene(SceneNode *root);