feat: added get child by typeid function with option to recurse

This commit is contained in:
Sara 2024-09-27 10:34:32 +02:00
parent b3f9d7222e
commit 30d8182f4d
2 changed files with 21 additions and 4 deletions

View file

@ -170,8 +170,23 @@ SceneNode *SceneNodeGetChildByTypeclass(SceneNode *self, char const *typeclass,
SceneNodeEntity entity = (*child)->entity;
if(mirror_get_function(entity.data, entity.mirror, typeclass))
return *child;
if(recurse)
SceneNodeGetChildByTypeclass(*child, typeclass, recurse);
if(recurse) {
SceneNode *recursed = SceneNodeGetChildByTypeclass(*child, typeclass, recurse);
if(recursed != NULL) return recursed;
}
}
return NULL;
}
SceneNode *SceneNodeGetChildByTypeid(SceneNode *self, typeid id, bool recurse) {
list_foreach(SceneNode **,child, &self->children) {
SceneNodeEntity entity = (*child)->entity;
if(entity.mirror->get_typeid() == id)
return *child;
if(recurse) {
SceneNode *recursed = SceneNodeGetChildByTypeid(*child, id, recurse);
if(recursed != NULL) return recursed;
}
}
return NULL;
}

View file

@ -41,10 +41,12 @@ 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.
//! Returns the first child node with an entity that implements a specific typeclass.
//! Optionally recurses through the entire branch
extern SceneNode *SceneNodeGetChildByTypeclass(SceneNode *self, char const *typeclass, bool recurse);
//! Returns the first child node with an entity that matches the given typeid.
//! Optionally recurses through the entire branch.
extern SceneNode *SceneNodeGetChildByTypeid(SceneNode *self, typeid id, bool recurse);
//! Instantiate a new scene with a root node.
extern Scene *CreateScene(SceneNode *root);
//! Destroy a node and it's scene tree.