From a8dc8350c657817fd10192e9ddcbc84a9de3e5c8 Mon Sep 17 00:00:00 2001 From: DevinLeamy Date: Mon, 28 Aug 2023 14:54:45 -0400 Subject: [PATCH] Add configure_schedules to App and Schedules to apply `ScheduleBuildSettings` to all schedules (#9514) # Objective - Fixes: #9508 - Fixes: #9526 ## Solution - Adds ```rust fn configure_schedules(&mut self, schedule_build_settings: ScheduleBuildSettings) ``` to `Schedules`, and `App` to simplify applying `ScheduleBuildSettings` to all schedules. --- ## Migration Guide - No breaking changes. - Adds `Schedule::get_build_settings()` getter for the schedule's `ScheduleBuildSettings`. - Can replaced manual configuration of all schedules: ```rust // Old for (_, schedule) in app.world.resource_mut::().iter_mut() { schedule.set_build_settings(build_settings); } // New app.configure_schedules(build_settings); ``` --- crates/bevy_app/src/app.rs | 13 ++++++++++++- crates/bevy_ecs/src/schedule/schedule.rs | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 2bc076d205..eadbdaad13 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -5,7 +5,7 @@ use bevy_ecs::{ schedule::{ apply_state_transition, common_conditions::run_once as run_once_condition, run_enter_schedule, BoxedScheduleLabel, IntoSystemConfigs, IntoSystemSetConfigs, - ScheduleLabel, + ScheduleBuildSettings, ScheduleLabel, }, }; use bevy_utils::{tracing::debug, HashMap, HashSet}; @@ -850,6 +850,17 @@ impl App { self } + + /// Applies the provided [`ScheduleBuildSettings`] to all schedules. + pub fn configure_schedules( + &mut self, + schedule_build_settings: ScheduleBuildSettings, + ) -> &mut Self { + self.world + .resource_mut::() + .configure_schedules(schedule_build_settings); + self + } } fn run_once(mut app: App) { diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index 81bc44f23a..b45504b779 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -103,6 +103,13 @@ impl Schedules { schedule.check_change_ticks(change_tick); } } + + /// Applies the provided [`ScheduleBuildSettings`] to all schedules. + pub fn configure_schedules(&mut self, schedule_build_settings: ScheduleBuildSettings) { + for (_, schedule) in self.inner.iter_mut() { + schedule.set_build_settings(schedule_build_settings.clone()); + } + } } fn make_executor(kind: ExecutorKind) -> Box { @@ -200,6 +207,11 @@ impl Schedule { self } + /// Returns the schedule's current `ScheduleBuildSettings`. + pub fn get_build_settings(&self) -> ScheduleBuildSettings { + self.graph.settings.clone() + } + /// Returns the schedule's current execution strategy. pub fn get_executor_kind(&self) -> ExecutorKind { self.executor.kind()