-
-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API for traversing hierarchy depth-first #72
Comments
@teksoc-1 Currently you can get the children for a given parent by creating an In the next major version of Flecs this will change however, as I'm changing the way children are stored to solve some of the biggest problems that todays implementation has. There will be an API for traversing entities depth-first, but I don't know yet what it will look like. |
@SanderMertens Ahh ok, thank you for the response. |
The API to do depth-first traversal is implemented on the v2 branch, and looks like this: void print_tree(
ecs_world_t *world,
ecs_entity_t entity)
{
printf("%*s%s\n", indent * 2, "", ecs_get_name(world, entity));
indent ++;
// Get an iterator to the children of the current entity
ecs_view_t it = ecs_tree_iter(world, entity);
// Iterate all the tables that contain children for the parent
while (ecs_tree_next(&it)) {
for (int i = 0; i < it.count; i ++) {
// Print the child, and recursively iterate
print_tree(world, it.entities[i]);
}
}
indent --;
} |
A common pattern for applications dealing with hierarchies is to access the data in a depth-first way. As asked by @teksoc-1 in #63 :
The text was updated successfully, but these errors were encountered: