Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
721afe5
add has deferred meta data
hymm Aug 27, 2023
fe68418
insert some nodes
hymm Sep 14, 2023
806823f
calculate distances
hymm Sep 14, 2023
bdadc22
temp commit
hymm Sep 15, 2023
3ab7b91
replace temp nodes
hymm Sep 15, 2023
5eb4abf
it seems to work
hymm Sep 16, 2023
2f60752
cleanup logic a little
hymm Sep 16, 2023
ea3d9c4
clippy
hymm Sep 16, 2023
3b42a72
remove manual flushes from bevy
hymm Sep 16, 2023
2ba9058
add no_sync_after api
hymm Sep 17, 2023
4542579
add ability to disable auto syncs for a schedule
hymm Sep 19, 2023
be6a569
ignore ambiguities on auto sync points
hymm Sep 22, 2023
05e0d47
fix rebase from main
hymm Sep 22, 2023
391d02b
move config to GraphInfo
hymm Sep 24, 2023
b55216c
refactor to remove need for temp node
hymm Sep 24, 2023
b5aacd0
fix rendering
hymm Sep 25, 2023
5730f98
fix ci
hymm Sep 25, 2023
8783f41
add no sync edges
hymm Sep 25, 2023
22bba46
remove no_sync_after
hymm Sep 25, 2023
979ab70
rename no_sync -> ignore_deferred
hymm Sep 25, 2023
b50fb31
clean up sync point language
hymm Sep 25, 2023
e63b7df
move edge data into it's own structure to avoid copying
hymm Sep 26, 2023
5f10323
link back to corresponding apis
hymm Sep 27, 2023
0175525
add chain_ignore_deferred
hymm Sep 27, 2023
7e643c8
fix ci errors
hymm Sep 27, 2023
a5376d9
clean up before/after docs
hymm Oct 8, 2023
f823887
modify test to test rebuild (fails currently)
hymm Oct 11, 2023
c203065
cache auto sync points
hymm Oct 12, 2023
d88b7c1
fix doc
hymm Oct 12, 2023
437030c
cleanup
hymm Oct 13, 2023
22230c4
Merge remote-tracking branch 'upstream/main' into auto-sync-points
hymm Oct 16, 2023
8c1dc39
Merge remote-tracking branch 'upstream/main' into auto-sync-points
hymm Nov 22, 2023
631f9ac
fix issues from merge with main
hymm Nov 22, 2023
d50f254
Merge remote-tracking branch 'upstream/main' into auto-sync-points
hymm Dec 14, 2023
86f28db
delete some paths that came back from the merge
hymm Dec 14, 2023
3be88ed
Apply suggestions from code review
hymm Dec 14, 2023
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
161 changes: 152 additions & 9 deletions crates/bevy_ecs/src/schedule/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
condition::{BoxedCondition, Condition},
graph_utils::{Ambiguity, Dependency, DependencyKind, GraphInfo},
set::{InternedSystemSet, IntoSystemSet, SystemSet},
Chain,
},
system::{BoxedSystem, IntoSystem, System},
};
Expand Down Expand Up @@ -67,8 +68,8 @@ pub enum NodeConfigs<T> {
configs: Vec<NodeConfigs<T>>,
/// Run conditions applied to everything in the tuple.
collective_conditions: Vec<BoxedCondition>,
/// If `true`, adds `before -> after` ordering constraints between the successive elements.
chained: bool,
/// See [`Chain`] for usage.
chained: Chain,
},
}

Expand Down Expand Up @@ -137,6 +138,38 @@ impl<T> NodeConfigs<T> {
}
}

fn before_ignore_deferred_inner(&mut self, set: InternedSystemSet) {
match self {
Self::NodeConfig(config) => {
config
.graph_info
.dependencies
.push(Dependency::new(DependencyKind::BeforeNoSync, set));
}
Self::Configs { configs, .. } => {
for config in configs {
config.before_ignore_deferred_inner(set.intern());
}
}
}
}

fn after_ignore_deferred_inner(&mut self, set: InternedSystemSet) {
match self {
Self::NodeConfig(config) => {
config
.graph_info
.dependencies
.push(Dependency::new(DependencyKind::AfterNoSync, set));
}
Self::Configs { configs, .. } => {
for config in configs {
config.after_ignore_deferred_inner(set.intern());
}
}
}
}

fn distributive_run_if_inner<M>(&mut self, condition: impl Condition<M> + Clone) {
match self {
Self::NodeConfig(config) => {
Expand Down Expand Up @@ -198,7 +231,17 @@ impl<T> NodeConfigs<T> {
match &mut self {
Self::NodeConfig(_) => { /* no op */ }
Self::Configs { chained, .. } => {
*chained = true;
*chained = Chain::Yes;
}
}
self
}

fn chain_ignore_deferred_inner(mut self) -> Self {
match &mut self {
Self::NodeConfig(_) => { /* no op */ }
Self::Configs { chained, .. } => {
*chained = Chain::YesIgnoreDeferred;
}
}
self
Expand Down Expand Up @@ -252,22 +295,46 @@ where
self.into_configs().in_set(set)
}

/// Run before all systems in `set`.
/// Runs before all systems in `set`. If `self` has any systems that produce [`Commands`](crate::system::Commands)
/// or other [`Deferred`](crate::system::Deferred) operations, all systems in `set` will see their effect.
///
/// If automatically inserting [`apply_deferred`](crate::schedule::apply_deferred) like
/// this isn't desired, use [`before_ignore_deferred`](Self::before_ignore_deferred) instead.
///
/// Note: The given set is not implicitly added to the schedule when this system set is added.
/// It is safe, but no dependencies will be created.
fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs {
self.into_configs().before(set)
}

/// Run after all systems in `set`.
/// Run after all systems in `set`. If `set` has any systems that produce [`Commands`](crate::system::Commands)
/// or other [`Deferred`](crate::system::Deferred) operations, all systems in `self` will see their effect.
///
/// If automatically inserting [`apply_deferred`](crate::schedule::apply_deferred) like
/// this isn't desired, use [`after_ignore_deferred`](Self::after_ignore_deferred) instead.
///
/// Note: The given set is not implicitly added to the schedule when this system set is added.
/// It is safe, but no dependencies will be created.
fn after<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs {
self.into_configs().after(set)
}

/// Run before all systems in `set`.
///
/// Unlike [`before`](Self::before), this will not cause the systems in
/// `set` to wait for the deferred effects of `self` to be applied.
fn before_ignore_deferred<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs {
self.into_configs().before_ignore_deferred(set)
}

/// Run after all systems in `set`.
///
/// Unlike [`after`](Self::after), this will not wait for the deferred
/// effects of systems in `set` to be applied.
fn after_ignore_deferred<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs {
self.into_configs().after_ignore_deferred(set)
}

/// Add a run condition to each contained system.
///
/// Each system will receive its own clone of the [`Condition`] and will only run
Expand Down Expand Up @@ -351,9 +418,22 @@ where
/// Treat this collection as a sequence of systems.
///
/// Ordering constraints will be applied between the successive elements.
///
/// If the preceeding node on a edge has deferred parameters, a [`apply_deferred`](crate::schedule::apply_deferred)
/// will be inserted on the edge. If this behavior is not desired consider using
/// [`chain_ignore_deferred`](Self::chain_ignore_deferred) instead.
fn chain(self) -> SystemConfigs {
self.into_configs().chain()
}

/// Treat this collection as a sequence of systems.
///
/// Ordering constraints will be applied between the successive elements.
///
/// Unlike [`chain`](Self::chain) this will **not** add [`apply_deferred`](crate::schedule::apply_deferred) on the edges.
fn chain_ignore_deferred(self) -> SystemConfigs {
self.into_configs().chain_ignore_deferred()
}
}

impl IntoSystemConfigs<()> for SystemConfigs {
Expand Down Expand Up @@ -385,6 +465,18 @@ impl IntoSystemConfigs<()> for SystemConfigs {
self
}

fn before_ignore_deferred<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
let set = set.into_system_set();
self.before_ignore_deferred_inner(set.intern());
self
}

fn after_ignore_deferred<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
let set = set.into_system_set();
self.after_ignore_deferred_inner(set.intern());
self
}

fn distributive_run_if<M>(mut self, condition: impl Condition<M> + Clone) -> SystemConfigs {
self.distributive_run_if_inner(condition);
self
Expand All @@ -409,6 +501,10 @@ impl IntoSystemConfigs<()> for SystemConfigs {
fn chain(self) -> Self {
self.chain_inner()
}

fn chain_ignore_deferred(self) -> Self {
self.chain_ignore_deferred_inner()
}
}

#[doc(hidden)]
Expand All @@ -426,7 +522,7 @@ macro_rules! impl_system_collection {
SystemConfigs::Configs {
configs: vec![$($sys.into_configs(),)*],
collective_conditions: Vec::new(),
chained: false,
chained: Chain::No,
}
}
}
Expand Down Expand Up @@ -474,16 +570,40 @@ where
self.into_configs().in_set(set)
}

/// Run before all systems in `set`.
/// Runs before all systems in `set`. If `self` has any systems that produce [`Commands`](crate::system::Commands)
/// or other [`Deferred`](crate::system::Deferred) operations, all systems in `set` will see their effect.
///
/// If automatically inserting [`apply_deferred`](crate::schedule::apply_deferred) like
/// this isn't desired, use [`before_ignore_deferred`](Self::before_ignore_deferred) instead.
fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemSetConfigs {
self.into_configs().before(set)
}

/// Run after all systems in `set`.
/// Runs before all systems in `set`. If `set` has any systems that produce [`Commands`](crate::system::Commands)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be "runs after"

/// or other [`Deferred`](crate::system::Deferred) operations, all systems in `self` will see their effect.
///
/// If automatically inserting [`apply_deferred`](crate::schedule::apply_deferred) like
/// this isn't desired, use [`after_ignore_deferred`](Self::after_ignore_deferred) instead.
fn after<M>(self, set: impl IntoSystemSet<M>) -> SystemSetConfigs {
self.into_configs().after(set)
}

/// Run before all systems in `set`.
///
/// Unlike [`before`](Self::before), this will not cause the systems in `set` to wait for the
/// deferred effects of `self` to be applied.
fn before_ignore_deferred<M>(self, set: impl IntoSystemSet<M>) -> SystemSetConfigs {
self.into_configs().before_ignore_deferred(set)
}

/// Run after all systems in `set`.
///
/// Unlike [`after`](Self::after), this may not see the deferred
/// effects of systems in `set` to be applied.
fn after_ignore_deferred<M>(self, set: impl IntoSystemSet<M>) -> SystemSetConfigs {
self.into_configs().after_ignore_deferred(set)
}

/// Run the systems in this set(s) only if the [`Condition`] is `true`.
///
/// The `Condition` will be evaluated at most once (per schedule run),
Expand All @@ -510,6 +630,15 @@ where
fn chain(self) -> SystemSetConfigs {
self.into_configs().chain()
}

/// Treat this collection as a sequence of systems.
///
/// Ordering constraints will be applied between the successive elements.
///
/// Unlike [`chain`](Self::chain) this will **not** add [`apply_deferred`](crate::schedule::apply_deferred) on the edges.
fn chain_ignore_deferred(self) -> SystemConfigs {
self.into_configs().chain_ignore_deferred()
}
}

impl IntoSystemSetConfigs for SystemSetConfigs {
Expand Down Expand Up @@ -542,6 +671,20 @@ impl IntoSystemSetConfigs for SystemSetConfigs {
self
}

fn before_ignore_deferred<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
let set = set.into_system_set();
self.before_ignore_deferred_inner(set.intern());

self
}

fn after_ignore_deferred<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
let set = set.into_system_set();
self.after_ignore_deferred_inner(set.intern());

self
}

fn run_if<M>(mut self, condition: impl Condition<M>) -> SystemSetConfigs {
self.run_if_dyn(new_condition(condition));

Expand Down Expand Up @@ -588,7 +731,7 @@ macro_rules! impl_system_set_collection {
SystemSetConfigs::Configs {
configs: vec![$($set.into_configs(),)*],
collective_conditions: Vec::new(),
chained: false,
chained: Chain::No,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/schedule/graph_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub(crate) enum DependencyKind {
Before,
/// A node that should be succeeded.
After,
/// A node that should be preceded and will **not** automatically insert an instance of `apply_deferred` on the edge.
BeforeNoSync,
/// A node that should be succeeded and will **not** automatically insert an instance of `apply_deferred` on the edge.
AfterNoSync,
}

/// An edge to be added to the dependency graph.
Expand Down
Loading