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] - Support system.in_schedule() and system.on_startup() #7790

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
969ccff
make `IntoSystemConfig` more generic
JoJoJet Feb 23, 2023
94f10f3
add extension methods for inserting systems into a schedule
JoJoJet Feb 23, 2023
fe9d5f0
remove dead code
JoJoJet Feb 23, 2023
c19dd54
add app-aware set configuration
JoJoJet Feb 23, 2023
05bf8c6
add a trait to the prelude
JoJoJet Feb 23, 2023
b462ce9
add an extension method for startup systems
JoJoJet Feb 23, 2023
661ecf5
use a defaulted type param instead of an associated type
JoJoJet Feb 23, 2023
e4c3a8c
simplify `IntoSystemSetConfig`
JoJoJet Feb 23, 2023
c29a766
add a missing impl
JoJoJet Feb 23, 2023
c52c844
revert system set changes
JoJoJet Feb 23, 2023
56f991a
revert a comment
JoJoJet Feb 23, 2023
373076e
remove an unused import
JoJoJet Feb 23, 2023
568efa2
DRY
JoJoJet Feb 23, 2023
70c9b23
add extension methods to system collections
JoJoJet Feb 23, 2023
ea3ce94
add a `.on_startup()` extension method
JoJoJet Feb 23, 2023
9e66a59
add extension methods for state schedules
JoJoJet Feb 23, 2023
4809e53
update some examples
JoJoJet Feb 23, 2023
9027c76
track callers
JoJoJet Feb 23, 2023
b147c6d
fix a doctest
JoJoJet Feb 23, 2023
9a80674
Update config.rs
JoJoJet Feb 23, 2023
bc4fddb
use an explicit deref
JoJoJet Feb 23, 2023
1a7cfe0
Revert "Update config.rs"
JoJoJet Feb 23, 2023
420b8d8
remove an unused method
JoJoJet Feb 23, 2023
b4167fb
add state extension methods to system configs
JoJoJet Feb 23, 2023
c900ce7
qualify a doc link
JoJoJet Feb 23, 2023
ab5deb1
remove an inaccurate doc note
JoJoJet Feb 23, 2023
38f3fcc
reduce churn
JoJoJet Feb 23, 2023
28de066
Merge remote-tracking branch 'upstream/main' into in_schedule
JoJoJet Feb 23, 2023
f8f43ea
simplify `IntoSystemAppConfig` generics
JoJoJet Feb 23, 2023
cd7b09f
document an enum
JoJoJet Feb 23, 2023
e87f21f
improve documentation
JoJoJet Feb 23, 2023
8506485
add more docs to `ScheduleMode`
JoJoJet Feb 23, 2023
c262c03
cargo fmt
JoJoJet Feb 23, 2023
63c8563
remove `on_enter`/`on_exit`
JoJoJet Feb 23, 2023
bd453ad
update examples
JoJoJet Feb 23, 2023
e8862af
replace usages of `add_system_to_schedule`
JoJoJet Feb 23, 2023
d28e6ea
yeet `add_system{s}_to_schedule`
JoJoJet Feb 23, 2023
a6e103a
clean up leftovers
JoJoJet Feb 23, 2023
756a87e
more leftovers
JoJoJet Feb 23, 2023
4ac15af
improve documentation for `add_systems`
JoJoJet Feb 23, 2023
c740ff1
remove `IntoIterator` impl for `SystemConfigs`
JoJoJet Feb 24, 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
81 changes: 36 additions & 45 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{CoreSchedule, CoreSet, Plugin, PluginGroup, StartupSet};
use crate::{
CoreSchedule, CoreSet, IntoSystemAppConfig, IntoSystemAppConfigs, Plugin, PluginGroup,
StartupSet, SystemAppConfig,
};
pub use bevy_derive::AppLabel;
use bevy_ecs::{
prelude::*,
Expand Down Expand Up @@ -378,10 +381,18 @@ impl App {
/// #
/// app.add_system(my_system);
/// ```
pub fn add_system<M>(&mut self, system: impl IntoSystemConfig<M>) -> &mut Self {
pub fn add_system<M>(&mut self, system: impl IntoSystemAppConfig<M>) -> &mut Self {
let mut schedules = self.world.resource_mut::<Schedules>();

if let Some(default_schedule) = schedules.get_mut(&*self.default_schedule_label) {
let SystemAppConfig { system, schedule } = system.into_app_config();

if let Some(schedule_label) = schedule {
if let Some(schedule) = schedules.get_mut(&*schedule_label) {
schedule.add_system(system);
} else {
panic!("Schedule {schedule_label:?} does not exist.")
}
} else if let Some(default_schedule) = schedules.get_mut(&*self.default_schedule_label) {
default_schedule.add_system(system);
} else {
let schedule_label = &self.default_schedule_label;
Expand All @@ -406,48 +417,28 @@ impl App {
/// #
/// app.add_systems((system_a, system_b, system_c));
/// ```
pub fn add_systems<M>(&mut self, systems: impl IntoSystemConfigs<M>) -> &mut Self {
let mut schedules = self.world.resource_mut::<Schedules>();

if let Some(default_schedule) = schedules.get_mut(&*self.default_schedule_label) {
default_schedule.add_systems(systems);
} else {
let schedule_label = &self.default_schedule_label;
panic!("Default schedule {schedule_label:?} does not exist.")
}

self
}

/// Adds a system to the provided [`Schedule`].
pub fn add_system_to_schedule<M>(
&mut self,
schedule_label: impl ScheduleLabel,
system: impl IntoSystemConfig<M>,
) -> &mut Self {
let mut schedules = self.world.resource_mut::<Schedules>();

if let Some(schedule) = schedules.get_mut(&schedule_label) {
schedule.add_system(system);
} else {
panic!("Provided schedule {schedule_label:?} does not exist.")
}

self
}

/// Adds a collection of system to the provided [`Schedule`].
pub fn add_systems_to_schedule<M>(
&mut self,
schedule_label: impl ScheduleLabel,
systems: impl IntoSystemConfigs<M>,
) -> &mut Self {
pub fn add_systems<M>(&mut self, systems: impl IntoSystemAppConfigs<M>) -> &mut Self {
let mut schedules = self.world.resource_mut::<Schedules>();

if let Some(schedule) = schedules.get_mut(&schedule_label) {
schedule.add_systems(systems);
} else {
panic!("Provided schedule {schedule_label:?} does not exist.")
match systems.into_app_configs().0 {
crate::InnerConfigs::Blanket { systems, schedule } => {
let schedule = if let Some(label) = schedule {
schedules
.get_mut(&*label)
.unwrap_or_else(|| panic!("Schedule '{label:?}' does not exist."))
} else {
let label = &*self.default_schedule_label;
schedules
.get_mut(label)
.unwrap_or_else(|| panic!("Default schedule '{label:?}' does not exist."))
};
schedule.add_systems(systems);
}
crate::InnerConfigs::Granular(systems) => {
for system in systems {
self.add_system(system);
}
}
}

self
Expand All @@ -472,7 +463,7 @@ impl App {
/// .add_startup_system(my_startup_system);
/// ```
pub fn add_startup_system<M>(&mut self, system: impl IntoSystemConfig<M>) -> &mut Self {
self.add_system_to_schedule(CoreSchedule::Startup, system)
self.add_system(system.in_schedule(CoreSchedule::Startup))
}

/// Adds a collection of systems to [`CoreSchedule::Startup`].
Expand All @@ -497,7 +488,7 @@ impl App {
/// );
/// ```
pub fn add_startup_systems<M>(&mut self, systems: impl IntoSystemConfigs<M>) -> &mut Self {
self.add_systems_to_schedule(CoreSchedule::Startup, systems)
self.add_systems(systems.into_configs().in_schedule(CoreSchedule::Startup))
}

/// Configures a system set in the default schedule, adding the set if it does not exist.
Expand Down
Loading