Skip to content

Commit

Permalink
Allow adding systems to multiple sets that share the same base set (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
geieredgar committed Feb 16, 2023
1 parent b35818c commit 6a63940
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
22 changes: 22 additions & 0 deletions crates/bevy_ecs/src/schedule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
32 changes: 19 additions & 13 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 6a63940

Please sign in to comment.