Entity grouping code for entity inspector - #25010
Conversation
Add more tests Use faster EntityHashSet Leave a PERF note about entity set iterator
This comment was marked as spam.
This comment was marked as spam.
|
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
|
This is one of those things that is subjective, I can think of other possible orderings that an alternate, third-party entity browser might want - like a fixed order (cameras first, then lights, etc.), or "search relevance". Each implementation of "list entities widget" will likely have its own opinions about how entities should be grouped. That means that this code isn't universal or fundamental IMHO. I don't have a problem with the algorithms specifically. |
|
I agree! But I'd like to get something in now, and add more variants, so we can ship a better organization than "by entity ID" in the first-party inspector tools. If you would like me to make this more extensible; just let me know and I can do some sort of trait based design. |
| /// Generates an [`EntityGrouping`] based on the components of the provided entities. | ||
| pub fn generate( | ||
| world: &World, | ||
| entities: impl IntoIterator<Item = Entity>, | ||
| strategy: GroupingStrategy, | ||
| ) -> Self { | ||
| match strategy { | ||
| GroupingStrategy::Hierarchy => hierarchy_group(world, entities), | ||
| GroupingStrategy::ArchetypeSimilarity => archetype_group(world, entities), | ||
| } | ||
| } |
There was a problem hiding this comment.
it feels strange to me that we have to choose between grouping by hierarchy and by archetype similarity. i would imagine that instead we have a hierarchy of entities based on a relationship (be it ChildOf or a custom one), and each set of children is then grouped by archetype similarity
There was a problem hiding this comment.
I believe this ordering would primarily be used for root entities, which have no relationship between them. In a typical scene there can be a large number of these, so some sort of grouping can be helpful.
There was a problem hiding this comment.
Yep, ideally you'd do a first pass of archetype similarity for root entities, and then a second for hierarchy within them :) I can make that more explicit, via either code or docs if you'd like?
There was a problem hiding this comment.
i think a utility function to do that would be handy, yes!
Objective
As part of #23013, we want to be able to order our list of entities in some sensible way, grouping and sorting them.
Solution
During prototyping in
feathers_inspector, @Nilirad and I found that there were two helpful, straightforward approaches: hierachical grouping and relying on archetype similarity, so similar entities are presented together.The code from there has been adapted and mildly cleaned up, and is offered unto the Bevy review gods for incremental review, rather than giving y'all a 20k line diff.
Testing
See
testsmodule :) I've added some extra to cover the archetype grouping strategy, which was untested.This module is very algorithmic with nice invariants, so testing was quite pleasant!