Skip to content

Commit

Permalink
Add configure_schedules to App and Schedules to apply `ScheduleBuildS…
Browse files Browse the repository at this point in the history
…ettings` 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::<Schedules>().iter_mut() {
    schedule.set_build_settings(build_settings);
}

// New
app.configure_schedules(build_settings);
```
  • Loading branch information
DevinLeamy authored Aug 28, 2023
1 parent 72fc63e commit a8dc835
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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::<Schedules>()
.configure_schedules(schedule_build_settings);
self
}
}

fn run_once(mut app: App) {
Expand Down
12 changes: 12 additions & 0 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn SystemExecutor> {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a8dc835

Please sign in to comment.