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.
This commit is contained in:
Edgar Geier 2023-02-16 17:09:46 +00:00
parent b35818c0a3
commit 6a63940367
2 changed files with 41 additions and 13 deletions

View File

@ -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();

View File

@ -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);
}