Skip to content

Commit

Permalink
expose ambiguities of ScheduleGraph (#7716)
Browse files Browse the repository at this point in the history
# Objective

- other tools (bevy_mod_debugdump) would like to have access to the ambiguities so that they can do their own reporting/visualization

## Solution

- store `conflicting_systems` in `ScheduleGraph` after calling `build_schedule`

The solution isn't very pretty and as pointed out it #7522, there may be a better way of exposing this, but this is the quick and dirty way if we want to have this functionality exposed in 0.10.
  • Loading branch information
jakobhellermann committed Feb 17, 2023
1 parent c5702b9 commit 45442f7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ impl Schedule {
&self.graph
}

/// Returns a mutable reference to the [`ScheduleGraph`].
pub fn graph_mut(&mut self) -> &mut ScheduleGraph {
&mut self.graph
}

/// Iterates the change ticks of all systems in the schedule and clamps any older than
/// [`MAX_CHANGE_AGE`](crate::change_detection::MAX_CHANGE_AGE).
/// This prevents overflow and thus prevents false positives.
Expand Down Expand Up @@ -377,6 +382,7 @@ pub struct ScheduleGraph {
ambiguous_with: UnGraphMap<NodeId, ()>,
ambiguous_with_flattened: UnGraphMap<NodeId, ()>,
ambiguous_with_all: HashSet<NodeId>,
conflicting_systems: Vec<(NodeId, NodeId, Vec<ComponentId>)>,
changed: bool,
settings: ScheduleBuildSettings,
default_base_set: Option<BoxedSystemSet>,
Expand All @@ -398,6 +404,7 @@ impl ScheduleGraph {
ambiguous_with: UnGraphMap::new(),
ambiguous_with_flattened: UnGraphMap::new(),
ambiguous_with_all: HashSet::new(),
conflicting_systems: Vec::new(),
changed: false,
settings: default(),
default_base_set: None,
Expand Down Expand Up @@ -500,6 +507,14 @@ impl ScheduleGraph {
&self.dependency
}

/// Returns the list of systems that conflict with each other, i.e. have ambiguities in their access.
///
/// If the `Vec<ComponentId>` is empty, the systems conflict on [`World`] access.
/// Must be called after [`ScheduleGraph::build_schedule`] to be non-empty.
pub fn conflicting_systems(&self) -> &[(NodeId, NodeId, Vec<ComponentId>)] {
&self.conflicting_systems
}

fn add_systems<P>(&mut self, systems: impl IntoSystemConfigs<P>) {
let SystemConfigs { systems, chained } = systems.into_configs();
let mut system_iter = systems.into_iter();
Expand Down Expand Up @@ -1149,6 +1164,7 @@ impl ScheduleGraph {
return Err(ScheduleBuildError::Ambiguity);
}
}
self.conflicting_systems = conflicting_systems;

// build the schedule
let dg_system_ids = self.dependency_flattened.topsort.clone();
Expand Down

0 comments on commit 45442f7

Please sign in to comment.