From eaa805102d37264cc5828443fd171cf1098efe43 Mon Sep 17 00:00:00 2001 From: Periwink Date: Mon, 19 Aug 2024 17:32:45 -0400 Subject: [PATCH] add docs explaining the two accesses of a System meta (#14580) # Objective When reading the ECS code it is sometimes confusing to understand why we have 2 accesses, one of ComponentId and one of ArchetypeComponentId ## Solution Make the usage of these 2 accesses more explicit --------- Co-authored-by: Pascal Hertleif --- crates/bevy_ecs/src/system/function_system.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index da7ed8e5a9..fe2420a663 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -20,7 +20,19 @@ use super::{In, IntoSystem, ReadOnlySystem, SystemParamBuilder}; #[derive(Clone)] pub struct SystemMeta { pub(crate) name: Cow<'static, str>, + /// The set of component accesses for this system. This is used to determine + /// - soundness issues (e.g. multiple [`SystemParam`]s mutably accessing the same component) + /// - ambiguities in the schedule (e.g. two systems that have some sort of conflicting access) pub(crate) component_access_set: FilteredAccessSet, + /// This [`Access`] is used to determine which systems can run in parallel with each other + /// in the multithreaded executor. + /// + /// We use a [`ArchetypeComponentId`] as it is more precise than just checking [`ComponentId`]: + /// for example if you have one system with `Query<&mut T, With>` and one system with `Query<&mut T, With>` + /// they conflict if you just look at the [`ComponentId`] of `T`; but if there are no archetypes with + /// both `A`, `B` and `T` then in practice there's no risk of conflict. By using [`ArchetypeComponentId`] + /// we can be more precise because we can check if the existing archetypes of the [`World`] + /// cause a conflict pub(crate) archetype_component_access: Access, // NOTE: this must be kept private. making a SystemMeta non-send is irreversible to prevent // SystemParams from overriding each other