Skip to content

Commit 0a880ee

Browse files
committed
add ability to disable auto syncs for a schedule
1 parent dd820c3 commit 0a880ee

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

crates/bevy_ecs/src/schedule/schedule.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,9 @@ impl ScheduleGraph {
905905
let mut dependency_flattened = self.get_dependency_flattened(&set_systems);
906906

907907
// modify graph with auto sync points
908-
let dependency_flattened = self.insert_sync_points(&mut dependency_flattened)?;
908+
if self.settings.auto_insert_sync_points {
909+
dependency_flattened = self.insert_sync_points(&mut dependency_flattened)?;
910+
}
909911

910912
// topsort
911913
let mut dependency_flattened_dag = Dag {
@@ -1793,6 +1795,16 @@ pub struct ScheduleBuildSettings {
17931795
///
17941796
/// Defaults to [`LogLevel::Warn`].
17951797
pub hierarchy_detection: LogLevel,
1798+
/// Auto insert [`apply_deferred`] sync points after a system into the schedule,
1799+
/// when there are [`Deferred`](crate::prelude::Deferred)
1800+
/// in one system and there are ordering dependencies on that system. [`Commands`](crate::system::Commands) is one
1801+
/// such deferred buffer.
1802+
///
1803+
/// You may want to disable this if you only want to sync deferred params at the end of the schedule,
1804+
/// or want to manually insert all your sync points.
1805+
///
1806+
/// Defaults to `true`
1807+
pub auto_insert_sync_points: bool,
17961808
/// If set to true, node names will be shortened instead of the fully qualified type path.
17971809
///
17981810
/// Defaults to `true`.
@@ -1816,6 +1828,7 @@ impl ScheduleBuildSettings {
18161828
Self {
18171829
ambiguity_detection: LogLevel::Ignore,
18181830
hierarchy_detection: LogLevel::Warn,
1831+
auto_insert_sync_points: true,
18191832
use_shortnames: true,
18201833
report_sets: true,
18211834
}
@@ -1827,7 +1840,9 @@ mod tests {
18271840
use crate::{
18281841
self as bevy_ecs,
18291842
prelude::{Res, Resource},
1830-
schedule::{IntoSystemConfigs, IntoSystemSetConfigs, Schedule, SystemSet},
1843+
schedule::{
1844+
IntoSystemConfigs, IntoSystemSetConfigs, Schedule, ScheduleBuildSettings, SystemSet,
1845+
},
18311846
system::Commands,
18321847
world::World,
18331848
};
@@ -1927,4 +1942,25 @@ mod tests {
19271942

19281943
assert_eq!(schedule.executable.systems.len(), 2);
19291944
}
1945+
1946+
#[test]
1947+
fn disable_auto_sync_points() {
1948+
let mut schedule = Schedule::default();
1949+
schedule.set_build_settings(ScheduleBuildSettings {
1950+
auto_insert_sync_points: false,
1951+
..Default::default()
1952+
});
1953+
let mut world = World::default();
1954+
schedule.add_systems(
1955+
(
1956+
|mut commands: Commands| commands.insert_resource(Resource1),
1957+
|res: Option<Res<Resource1>>| assert!(res.is_none()),
1958+
)
1959+
.chain(),
1960+
);
1961+
schedule.run(&mut world);
1962+
1963+
// inserted a sync point
1964+
assert_eq!(schedule.executable.systems.len(), 2);
1965+
}
19301966
}

0 commit comments

Comments
 (0)