-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 any_component_removed
condition
#8326
Add any_component_removed
condition
#8326
Conversation
// Simply checking `is_empty` would not be enough. | ||
// PERF: note that `count` is efficient (not actually looping/iterating), | ||
// due to Bevy having a specialized implementation for events. | ||
move |mut removals: RemovedComponents<T>| !removals.iter().count() != 0 |
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.
move |mut removals: RemovedComponents<T>| !removals.iter().count() != 0 | |
move |mut removals: RemovedComponents<T>| removals.iter().next().is_none() |
This otherwise potentially does a full traversal.
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.
This contradicts the perf note above.
I would still prefer to remove the perf note and just use is_empty though.
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.
Oh I completely forgot we overrode the default implementations for those. Agreed on the use of is_empty
instead.
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.
is_empty
can't be used. The reason is mentioned in the comment: it won't advance the reader and the condition will be triggered twice. We use the same strategy for events:
move |mut reader: EventReader<T>| reader.iter().count() > 0 |
Co-authored-by: François <[email protected]>
Added helper extracted from #7711. that PR contains some controversy conditions, but this one should be good to go.
Changelog
Added
any_component_removed
condition.