Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - expose ambiguities of ScheduleGraph #7716

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}

Comment on lines +237 to +241
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed to call build_schedule, otherwise you won't have the ambiguities

/// 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