From 6a63940367de6e3e43072e51b2e5d5d62767961d Mon Sep 17 00:00:00 2001 From: Edgar Geier Date: Thu, 16 Feb 2023 17:09:46 +0000 Subject: [PATCH] Allow adding systems to multiple sets that share the same base set (#7709) # Objective Fixes #7702. ## Solution - Added an test that ensures that no error is returned if a system or set is inside two different sets that share the same base set. - Added an check to only return an error if the two base sets are not equal. --- crates/bevy_ecs/src/schedule/mod.rs | 22 ++++++++++++++++ crates/bevy_ecs/src/schedule/schedule.rs | 32 ++++++++++++++---------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/mod.rs b/crates/bevy_ecs/src/schedule/mod.rs index 5be608768fbcc..91d24615e116f 100644 --- a/crates/bevy_ecs/src/schedule/mod.rs +++ b/crates/bevy_ecs/src/schedule/mod.rs @@ -797,6 +797,28 @@ mod tests { )); } + #[test] + fn allow_same_base_sets() { + let mut world = World::new(); + + let mut schedule = Schedule::new(); + schedule + .configure_set(Normal::X.in_base_set(Base::A)) + .configure_set(Normal::Y.in_base_set(Base::A)) + .add_system(named_system.in_set(Normal::X).in_set(Normal::Y)); + + let result = schedule.initialize(&mut world); + assert!(matches!(result, Ok(()))); + + let mut schedule = Schedule::new(); + schedule + .configure_set(Normal::X.in_base_set(Base::A)) + .configure_set(Normal::Y.in_base_set(Base::A).in_set(Normal::X)); + + let result = schedule.initialize(&mut world); + assert!(matches!(result, Ok(()))); + } + #[test] fn default_base_set_ordering() { let mut world = World::default(); diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index 49e0b1afe2e39..581f80f0086ad 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -840,20 +840,26 @@ impl ScheduleGraph { neighbor, )? { if let Some(first_set) = base_set { - return Err(match node_id { - NodeId::System(index) => { - ScheduleBuildError::SystemInMultipleBaseSets { - system: systems[index].name(), - first_set: system_sets[first_set.index()].name(), - second_set: system_sets[calculated_base_set.index()].name(), + if first_set != calculated_base_set { + return Err(match node_id { + NodeId::System(index) => { + ScheduleBuildError::SystemInMultipleBaseSets { + system: systems[index].name(), + first_set: system_sets[first_set.index()].name(), + second_set: system_sets[calculated_base_set.index()] + .name(), + } } - } - NodeId::Set(index) => ScheduleBuildError::SetInMultipleBaseSets { - set: system_sets[index].name(), - first_set: system_sets[first_set.index()].name(), - second_set: system_sets[calculated_base_set.index()].name(), - }, - }); + NodeId::Set(index) => { + ScheduleBuildError::SetInMultipleBaseSets { + set: system_sets[index].name(), + first_set: system_sets[first_set.index()].name(), + second_set: system_sets[calculated_base_set.index()] + .name(), + } + } + }); + } } base_set = Some(calculated_base_set); }