-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Populated
(query) system param
#15488
Conversation
523f599
to
64b27aa
Compare
It looks fine but this is too much unsafe for me to have any idea if it is correct |
archetype: &Archetype, | ||
system_meta: &mut SystemMeta, | ||
) { | ||
// SAFETY: Delegate to existing `SystemParam` implementations. |
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.
SAFETY: Delegate to existing ``Query`` implementation.
?
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.
But then the doc comment says exactly what's written
The point is, we use a different SystemParam
implementation which satisfies the same safety restrictions
world: UnsafeWorldCell<'w>, | ||
change_tick: Tick, | ||
) -> Self::Item<'w, 's> { | ||
// SAFETY: Delegate to existing `SystemParam` implementations. |
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.
Same here
state.validate_world(world.id()); | ||
// SAFETY: | ||
// - We have read-only access to the components accessed by query. | ||
// - The world has been validated. |
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.
Might be clearer to say something like, The world matches the one used to create ``state``.
(Just means the reader doesn't need to look at validate_world
to know what it does)
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.
it's a common term in ECS safety comments,
I'm pretty sure all of the safety comments here are copy-pasted from other implementations
let query = unsafe { | ||
Query::<'world, 'state, D, F>::get_param(state, system_meta, world, change_tick) | ||
}; | ||
QueryNonEmpty(query) |
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 the plan for QueryNonEmpty
to have some of its own methods or could it just return Query
as its Item
as its logic is just during validation?
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.
It's just a newtyped Query, we can modify it in the future to be it's own thing which provides non-empty-based methods
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.
But I'd expect this to also require extracting traits for shared methods, bit too much work for this PR and not the focus
How about |
I'm afraid that has different meaning from intended |
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.
Lovely; nice and simple (you know, as far as manual SystemParam impls go) and I really like the end user API. Good docs too!
Co-authored-by: Alice Cecile <[email protected]>
# Objective Add a `Populated` system parameter that acts like `Query`, but prevents system from running if there are no matching entities. Fixes: bevyengine#15302 ## Solution Implement the system param which newtypes the `Query`. The only change is new validation, which fails if query is empty. The new system param is used in `fallible_params` example. ## Testing Ran `fallible_params` example. --------- Co-authored-by: Alice Cecile <[email protected]>
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#1706 if you'd like to help out. |
Objective
Add a
Populated
system parameter that acts likeQuery
, but prevents system from running if there are no matching entities.Fixes: #15302
Solution
Implement the system param which newtypes the
Query
.The only change is new validation, which fails if query is empty.
The new system param is used in
fallible_params
example.Testing
Ran
fallible_params
example.