-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add VisitEntities for generic and reflectable Entity iteration
#15425
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 VisitEntities for generic and reflectable Entity iteration
#15425
Conversation
0e0ad70 to
04f1b89
Compare
04f1b89 to
c5be438
Compare
Once the `*_world_entities` reflect methods are removed, we can also remove the distinction between the two and consolidate to a single `RelfectMapEntities` that isn't bound by `T: Component`.
|
@cBournhonesque @Shatur I'd appreciate your opinions on which of these PRs you prefer. |
|
Thanks for the ping! |
|
Can we borrow from |
|
That would be the best approach! |
|
But I think that we need to try to implement it first to see if it's possible and after that rework the |
Yeah, I hear this. It's not my favorite either. A couple of alternatives to consider with some pros and cons:
I think removing the supertrait bound is the best immediate compromise, since the read-only map/iterator traits are strictly new functionality and are unnecessary for previous behavior. The derive idea sounds interesting, but I'm not sure how it would work in practice. I think there's too much type-knowledge needed to implement the |
11ec538 to
c8dbb30
Compare
|
Ok, I've brought in the changes from #15426, but hidden the fact that the descendant/ancestor iterators are now implemented via the generic |
2f2c31c to
202393c
Compare
|
I'm sorry if it wasn't clear, but in my opinion we need to ensure that it's possible to use iteration with entity mapping. |
It isn't. At least not while also supporting types like We could bring back I'm about ready to shelve/close this PR for now. It's only served as a distraction from getting #15422 merged, which solves a much more real problem. |
Yes, I understand the problem.
And that's exactly what I suggesting! Yes, it's not nice to derive one trait and reflect another, but if it lets us avoid manually implementing MapEntities (in most cases) - it's totally worth it. Again, it's just my opinion. Feel free to oppose or suggest alternatives.
That's up to you. Sometimes adding changes requires a bit of discussion/iteration. When it's a big project like Bevy, it's better to try to architecture things properly. It's impossible to avoid having breaking changes at all, but it's good to try to minimize it. Sorry if it demotivated you a little. |
|
What's demotivating is that we've more or less been in the state you're now asking for as of roughly this commit. I then took the "too many traits, only keep what's needed" feedback and stated my plan to decouple this change from Then, the feedback was "too standalone, needs to be used elsewhere in the engine. Either bring in changes from #15426 or the blanket What's more, the |
I just asked here your opinion about keeping only a single trait for accessing entities. I suggested a wrong one since we can't reflect
Sorry for this. Not sure about @alice-i-cecile, but I get your plan wrong. It's my fault, I should have read it more carefully :(
This isn't what I meant; there was probably a miscommunication. Yes, a PR like this is more likely to be merged when combined with this PR, but I believe we need to utilize visiting for use in mapping. This is what I was trying to explain here. You said that the change should stand alone. I disagreed here and insisted that it should be used with mappings, explaining why. But you brought that changes from #15426.
This is true, but I think that we need to introduce both in a single PR. Just to ensure that we won't need to rewrite it later. Sometimes you see issues after the implementation. Like the problem with HashMap/HashSet. Again, I just expressing the opinion. |
|
OK, so if I bring back |
|
Pretty much, yes! |
73d774e to
f041668
Compare
9983b40 to
8c6e4e5
Compare
8c6e4e5 to
36022e8
Compare
Shatur
left a comment
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.
LGTM!
…yengine#15425) # Objective - Provide a generic and _reflectable_ way to iterate over contained entities ## Solution Adds two new traits: * `VisitEntities`: Reflectable iteration, accepts a closure rather than producing an iterator. Implemented by default for `IntoIterator` implementing types. A proc macro is also provided. * A `Mut` variant of the above. Its derive macro uses the same field attribute to avoid repetition. ## Testing Added a test for `VisitEntities` that also transitively tests its derive macro as well as the default `MapEntities` impl.
Objective
Solution
Adds two new traits:
VisitEntities: Reflectable iteration, accepts a closure rather than producing an iterator. Implemented by default forIntoIteratorimplementing types. A proc macro is also provided.Mutvariant of the above. Its derive macro uses the same field attribute to avoid repetition.Testing
Added a test for
VisitEntitiesthat also transitively tests its derive macro as well as the defaultMapEntitiesimpl.