Skip to content

Commit

Permalink
Cleanup ScheduleBuildSettings (#7721)
Browse files Browse the repository at this point in the history
# Objective
Fix #7440. Fix #7441. 

## Solution

 * Remove builder functions on `ScheduleBuildSettings` in favor of public fields, move docs to the fields.
 * Add `use_shortnames` and use it in `get_node_name` to feed it through `bevy_utils::get_short_name`.
  • Loading branch information
james7132 committed Feb 17, 2023
1 parent 16feb9a commit 0425673
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
14 changes: 8 additions & 6 deletions crates/bevy_ecs/src/schedule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,10 @@ mod tests {
let mut world = World::new();
let mut schedule = Schedule::new();

schedule.set_build_settings(
ScheduleBuildSettings::new().with_hierarchy_detection(LogLevel::Error),
);
schedule.set_build_settings(ScheduleBuildSettings {
hierarchy_detection: LogLevel::Error,
..Default::default()
});

// Add `A`.
schedule.configure_set(TestSet::A);
Expand Down Expand Up @@ -636,9 +637,10 @@ mod tests {
let mut world = World::new();
let mut schedule = Schedule::new();

schedule.set_build_settings(
ScheduleBuildSettings::new().with_ambiguity_detection(LogLevel::Error),
);
schedule.set_build_settings(ScheduleBuildSettings {
ambiguity_detection: LogLevel::Error,
..Default::default()
});

schedule.add_systems((res_ref, res_mut));
let result = schedule.initialize(&mut world);
Expand Down
33 changes: 15 additions & 18 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1333,10 +1333,14 @@ impl ScheduleGraph {
// methods for reporting errors
impl ScheduleGraph {
fn get_node_name(&self, id: &NodeId) -> String {
match id {
let mut name = match id {
NodeId::System(_) => self.systems[id.index()].get().unwrap().name().to_string(),
NodeId::Set(_) => self.system_sets[id.index()].name(),
};
if self.settings.use_shortnames {
name = bevy_utils::get_short_name(&name);
}
name
}

fn get_node_kind(id: &NodeId) -> &'static str {
Expand Down Expand Up @@ -1519,8 +1523,15 @@ pub enum LogLevel {
/// Specifies miscellaneous settings for schedule construction.
#[derive(Clone, Debug)]
pub struct ScheduleBuildSettings {
ambiguity_detection: LogLevel,
hierarchy_detection: LogLevel,
/// Determines whether the presence of ambiguities (systems with conflicting access but indeterminate order)
/// is only logged or also results in an [`Ambiguity`](ScheduleBuildError::Ambiguity) error.
pub ambiguity_detection: LogLevel,
/// Determines whether the presence of redundant edges in the hierarchy of system sets is only
/// logged or also results in a [`HierarchyRedundancy`](ScheduleBuildError::HierarchyRedundancy)
/// error.
pub hierarchy_detection: LogLevel,
/// If set to true, node names will be shortened instead of the fully qualified type path.
pub use_shortnames: bool,
}

impl Default for ScheduleBuildSettings {
Expand All @@ -1534,21 +1545,7 @@ impl ScheduleBuildSettings {
Self {
ambiguity_detection: LogLevel::Ignore,
hierarchy_detection: LogLevel::Warn,
use_shortnames: false,
}
}

/// Determines whether the presence of ambiguities (systems with conflicting access but indeterminate order)
/// is only logged or also results in an [`Ambiguity`](ScheduleBuildError::Ambiguity) error.
pub fn with_ambiguity_detection(mut self, level: LogLevel) -> Self {
self.ambiguity_detection = level;
self
}

/// Determines whether the presence of redundant edges in the hierarchy of system sets is only
/// logged or also results in a [`HierarchyRedundancy`](ScheduleBuildError::HierarchyRedundancy)
/// error.
pub fn with_hierarchy_detection(mut self, level: LogLevel) -> Self {
self.hierarchy_detection = level;
self
}
}
7 changes: 4 additions & 3 deletions examples/ecs/nondeterministic_system_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ fn main() {
App::new()
// We can modify the reporting strategy for system execution order ambiguities on a per-schedule basis
.edit_schedule(CoreSchedule::Main, |schedule| {
schedule.set_build_settings(
ScheduleBuildSettings::new().with_ambiguity_detection(LogLevel::Warn),
);
schedule.set_build_settings(ScheduleBuildSettings {
ambiguity_detection: LogLevel::Warn,
..default()
});
})
.init_resource::<A>()
.init_resource::<B>()
Expand Down

0 comments on commit 0425673

Please sign in to comment.