-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Populated
(query) system param
#15488
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
Changes from all commits
64b27aa
ad39f5c
0064c78
6ba3d75
125aaf4
328c2c8
47b3834
4e35ed6
22a0fd1
4dba08c
a331b3b
e4f2ede
38fc5ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ use core::{ | |
ops::{Deref, DerefMut}, | ||
}; | ||
|
||
use super::Populated; | ||
|
||
/// A parameter that can be used in a [`System`](super::System). | ||
/// | ||
/// # Derive | ||
|
@@ -497,6 +499,61 @@ unsafe impl<'a, D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOn | |
{ | ||
} | ||
|
||
// SAFETY: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemMeta. If | ||
// this Query conflicts with any prior access, a panic will occur. | ||
unsafe impl<D: QueryData + 'static, F: QueryFilter + 'static> SystemParam | ||
for Populated<'_, '_, D, F> | ||
{ | ||
type State = QueryState<D, F>; | ||
type Item<'w, 's> = Populated<'w, 's, D, F>; | ||
|
||
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { | ||
Query::init_state(world, system_meta) | ||
} | ||
|
||
unsafe fn new_archetype( | ||
state: &mut Self::State, | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But then the doc comment says exactly what's written |
||
unsafe { Query::new_archetype(state, archetype, system_meta) }; | ||
} | ||
|
||
#[inline] | ||
unsafe fn get_param<'w, 's>( | ||
state: &'s mut Self::State, | ||
system_meta: &SystemMeta, | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
let query = unsafe { Query::get_param(state, system_meta, world, change_tick) }; | ||
Populated(query) | ||
} | ||
|
||
#[inline] | ||
unsafe fn validate_param( | ||
state: &Self::State, | ||
system_meta: &SystemMeta, | ||
world: UnsafeWorldCell, | ||
) -> bool { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Might be clearer to say something like, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a common term in ECS safety comments, |
||
!unsafe { | ||
state.is_empty_unsafe_world_cell(world, system_meta.last_run, world.change_tick()) | ||
} | ||
} | ||
} | ||
|
||
// SAFETY: QueryState is constrained to read-only fetches, so it only reads World. | ||
unsafe impl<'w, 's, D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOnlySystemParam | ||
for Populated<'w, 's, D, F> | ||
{ | ||
} | ||
|
||
/// A collection of potentially conflicting [`SystemParam`]s allowed by disjoint access. | ||
/// | ||
/// Allows systems to safely access and interact with up to 8 mutually exclusive [`SystemParam`]s, such as | ||
|
Uh oh!
There was an error while loading. Please reload this page.