From 86e6b9534cdb2b9e76503affdc0ec03c2b0703f5 Mon Sep 17 00:00:00 2001 From: Christian Hughes Date: Fri, 11 Jul 2025 20:40:05 -0500 Subject: [PATCH] use a range instead of a start index --- crates/bevy_ecs/src/schedule/schedule.rs | 25 ++++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index eac0fd4c30..e5c9675475 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -15,6 +15,7 @@ use bevy_utils::{default, prelude::DebugName, TypeIdMap}; use core::{ any::{Any, TypeId}, fmt::{Debug, Write}, + ops::Range, }; use fixedbitset::FixedBitSet; use log::{error, info, warn}; @@ -765,21 +766,20 @@ enum UninitializedId { /// A system set's conditions that have not been initialized yet. Set { key: SystemSetKey, - /// The index in [`SystemSets::conditions`] where the first - /// uninitialized condition is. All conditions after this index also - /// still need to be initialized. + /// The range of indices in [`SystemSets::conditions`] that correspond + /// to conditions that have not been initialized yet. /// - /// Conditions might be added multiple times to a system set (e.g. when - /// `configure_sets` is called multiple times with the same set), so we - /// need to track where the newly added conditions start in the - /// `conditions` list. + /// [`SystemSets::conditions`] for a given set may be appended to + /// multiple times (e.g. when `configure_sets` is called multiple with + /// the same set), so we need to track which conditions in that list + /// are newly added and not yet initialized. /// /// Note: We don't need to do this for systems because calling /// `add_systems` multiple times with the same system results in /// multiple duplicates of that system in the graph, each with their own /// separate list of conditions. That means all of a system's conditions /// are always initialized together. - first_uninit_condition: usize, + uninitialized_conditions: Range, }, } @@ -1123,9 +1123,10 @@ impl ScheduleGraph { // system init has to be deferred (need `&mut World`) let system_set_conditions = self.system_sets.conditions.entry(key).unwrap().or_default(); + let start = system_set_conditions.len(); self.uninit.push(UninitializedId::Set { key, - first_uninit_condition: system_set_conditions.len(), + uninitialized_conditions: start..(start + conditions.len()), }); system_set_conditions.extend(conditions.into_iter().map(ConditionWithAccess::new)); @@ -1211,11 +1212,9 @@ impl ScheduleGraph { } UninitializedId::Set { key, - first_uninit_condition, + uninitialized_conditions, } => { - for condition in self.system_sets.conditions[key] - .iter_mut() - .skip(first_uninit_condition) + for condition in &mut self.system_sets.conditions[key][uninitialized_conditions] { condition.access = condition.condition.initialize(world); }