Skip to content

Commit 38bbb67

Browse files
vil-momockersf
authored andcommitted
Expose SystemMeta's access field as part of public API (#16625)
# Objective Outside of the `bevy_ecs` crate it's hard to implement `SystemParam` trait on params that require access to the `World`, because `init_state` expects user to extend access in `SystemMeta` and access-related fields of `SystemMeta` are private. ## Solution Expose those fields as a functions
1 parent 31bd723 commit 38bbb67

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

crates/bevy_ecs/src/system/function_system.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,55 @@ impl SystemMeta {
136136
{
137137
self.param_warn_policy.try_warn::<P>(&self.name);
138138
}
139+
140+
/// Archetype component access that is used to determine which systems can run in parallel with each other
141+
/// in the multithreaded executor.
142+
///
143+
/// We use an [`ArchetypeComponentId`] as it is more precise than just checking [`ComponentId`]:
144+
/// for example if you have one system with `Query<&mut A, With<B>`, and one system with `Query<&mut A, Without<B>`,
145+
/// they conflict if you just look at the [`ComponentId`];
146+
/// but no archetype that matches the first query will match the second and vice versa,
147+
/// which means there's no risk of conflict.
148+
#[inline]
149+
pub fn archetype_component_access(&self) -> &Access<ArchetypeComponentId> {
150+
&self.archetype_component_access
151+
}
152+
153+
/// Returns a mutable reference to the [`Access`] for [`ArchetypeComponentId`].
154+
/// This is used to determine which systems can run in parallel with each other
155+
/// in the multithreaded executor.
156+
///
157+
/// We use an [`ArchetypeComponentId`] as it is more precise than just checking [`ComponentId`]:
158+
/// for example if you have one system with `Query<&mut A, With<B>`, and one system with `Query<&mut A, Without<B>`,
159+
/// they conflict if you just look at the [`ComponentId`];
160+
/// but no archetype that matches the first query will match the second and vice versa,
161+
/// which means there's no risk of conflict.
162+
///
163+
/// # Safety
164+
///
165+
/// No access can be removed from the returned [`Access`].
166+
#[inline]
167+
pub unsafe fn archetype_component_access_mut(&mut self) -> &mut Access<ArchetypeComponentId> {
168+
&mut self.archetype_component_access
169+
}
170+
171+
/// Returns a reference to the [`FilteredAccessSet`] for [`ComponentId`].
172+
/// Used to check if systems and/or system params have conflicting access.
173+
#[inline]
174+
pub fn component_access_set(&self) -> &FilteredAccessSet<ComponentId> {
175+
&self.component_access_set
176+
}
177+
178+
/// Returns a mutable reference to the [`FilteredAccessSet`] for [`ComponentId`].
179+
/// Used internally to statically check if systems have conflicting access.
180+
///
181+
/// # Safety
182+
///
183+
/// No access can be removed from the returned [`FilteredAccessSet`].
184+
#[inline]
185+
pub unsafe fn component_access_set_mut(&mut self) -> &mut FilteredAccessSet<ComponentId> {
186+
&mut self.component_access_set
187+
}
139188
}
140189

141190
/// State machine for emitting warnings when [system params are invalid](System::validate_param).

0 commit comments

Comments
 (0)