-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Add more tools for traversing hierarchies #15627
Add more tools for traversing hierarchies #15627
Conversation
Did a PR with fixed siblings iter. The problem was that the query has to be Also got rid of the SiblingsIter since it wasn't really necessary. Instead we got a ugly mess of I wonder if it would be a good idea to convert |
Fix iter_siblings and some readability improvements for tests
I'm pretty sure it predates the |
Pushed some more commits, PR here
Edit: Here's another PR which also adds depth-first and changes iter_leaves to use it. |
Clean up the hierarchy APIs a bit
Add depth-first descendant traversal and change `iter_leaves` to use it
@villor you're the best. I really appreciate your help with this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the options this provides, and helps justify the existence of what is otherwise a pretty small crate! I do think this should be refactored into a SystemParam
, but that's a larger change that can easily be built on top of this work in 0.16. I also see a lot of refactoring in the near future anyway with #15635, so no real need to do that here and now.
SystemParam is going to be the bomb! I imagine we could add other APIs as well like change detection on different parts of the hierarchy. A lot more options open up once we can control the queries more 😁 And when we have #15635 we can make it generic over any one-to-many relation! |
Co-authored-by: poopy <gonesbird@gmail.com>
Co-authored-by: Christian Hughes <9044780+ItsDoot@users.noreply.github.com>
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1718 if you'd like to help out. |
Objective
Solution
Extend
HierarchyQueryExt
with the following methods:parent
children
root_parent
iter_leaves
iter_siblings
iter_descendants_depth_first
I've opted to make both
iter_leaves
anditer_siblings
collect the list of matching Entities for now, rather that operate by reference like the existingiter_descendants
. This was simpler, and in the case ofiter_siblings
especially, the number of matching entities is likely to be much smaller.I've kept the generics in the type signature however, so we can go back and optimize that freely without a breaking change whenever we want.
Testing
I've added some basic testing, but they're currently failing. If you'd like to help, I'd welcome suggestions or a PR to my PR over the weekend <3