From 9a55d4408edb220618408787053f4320e0b4fff5 Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Mon, 5 Jul 2021 13:27:16 +0200 Subject: [PATCH 1/3] Move the CoreStage::Startup to a seperate CoreSchedule enum --- crates/bevy_app/src/app.rs | 16 +++++++++------- crates/bevy_app/src/lib.rs | 17 +++++++++++------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 5bf9805429693..196e84c0108af 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -1,4 +1,6 @@ -use crate::{CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupStage}; +use crate::{ + CoreSchedule, CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupStage, +}; pub use bevy_derive::AppLabel; use bevy_ecs::{ prelude::{FromWorld, IntoExclusiveSystem}, @@ -207,7 +209,7 @@ impl App { /// ``` pub fn add_startup_stage(&mut self, label: impl StageLabel, stage: S) -> &mut Self { self.schedule - .stage(CoreStage::Startup, |schedule: &mut Schedule| { + .stage(CoreSchedule::Startup, |schedule: &mut Schedule| { schedule.add_stage(label, stage) }); self @@ -238,7 +240,7 @@ impl App { stage: S, ) -> &mut Self { self.schedule - .stage(CoreStage::Startup, |schedule: &mut Schedule| { + .stage(CoreSchedule::Startup, |schedule: &mut Schedule| { schedule.add_stage_after(target, label, stage) }); self @@ -269,7 +271,7 @@ impl App { stage: S, ) -> &mut Self { self.schedule - .stage(CoreStage::Startup, |schedule: &mut Schedule| { + .stage(CoreSchedule::Startup, |schedule: &mut Schedule| { schedule.add_stage_before(target, label, stage) }); self @@ -483,7 +485,7 @@ impl App { system: impl IntoSystemDescriptor, ) -> &mut Self { self.schedule - .stage(CoreStage::Startup, |schedule: &mut Schedule| { + .stage(CoreSchedule::Startup, |schedule: &mut Schedule| { schedule.add_system_to_stage(stage_label, system) }); self @@ -519,7 +521,7 @@ impl App { system_set: SystemSet, ) -> &mut Self { self.schedule - .stage(CoreStage::Startup, |schedule: &mut Schedule| { + .stage(CoreSchedule::Startup, |schedule: &mut Schedule| { schedule.add_system_set_to_stage(stage_label, system_set) }); self @@ -588,7 +590,7 @@ impl App { pub fn add_default_stages(&mut self) -> &mut Self { self.add_stage(CoreStage::First, SystemStage::parallel()) .add_stage( - CoreStage::Startup, + CoreSchedule::Startup, Schedule::default() .with_run_criteria(RunOnce::default()) .with_stage(StartupStage::PreStartup, SystemStage::parallel()) diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index a891c5957b786..fc0422c682e43 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -20,7 +20,9 @@ pub use schedule_runner::*; #[allow(missing_docs)] pub mod prelude { #[doc(hidden)] - pub use crate::{app::App, CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupStage}; + pub use crate::{ + app::App, CoreSchedule, CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupStage, + }; } use bevy_ecs::schedule::StageLabel; @@ -30,11 +32,6 @@ use bevy_ecs::schedule::StageLabel; /// The relative stages are added by [`App::add_default_stages`]. #[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)] pub enum CoreStage { - /// Runs only once at the beginning of the app. - /// - /// Consists of the sub-stages defined in [`StartupStage`]. Systems added here are - /// referred to as "startup systems". - Startup, /// Name of app stage that runs before all other app stages First, /// Name of app stage responsible for performing setup before an update. Runs before UPDATE. @@ -47,6 +44,14 @@ pub enum CoreStage { /// Name of app stage that runs after all other app stages Last, } + +/// The names of the default App schedules +#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)] +pub enum CoreSchedule { + /// Runs once at the beginning of the app. + Startup, +} + /// The names of the default App startup stages #[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)] pub enum StartupStage { From b14bb9f20ecfc8e34d9003ac62ecc443bb29f953 Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Mon, 5 Jul 2021 13:59:48 +0200 Subject: [PATCH 2/3] Change the label from an enum to a unit type --- crates/bevy_app/src/app.rs | 14 +++++++------- crates/bevy_app/src/lib.rs | 8 +++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 196e84c0108af..b458af2458b16 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -1,5 +1,5 @@ use crate::{ - CoreSchedule, CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupStage, + CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupSchedule, StartupStage, }; pub use bevy_derive::AppLabel; use bevy_ecs::{ @@ -209,7 +209,7 @@ impl App { /// ``` pub fn add_startup_stage(&mut self, label: impl StageLabel, stage: S) -> &mut Self { self.schedule - .stage(CoreSchedule::Startup, |schedule: &mut Schedule| { + .stage(StartupSchedule, |schedule: &mut Schedule| { schedule.add_stage(label, stage) }); self @@ -240,7 +240,7 @@ impl App { stage: S, ) -> &mut Self { self.schedule - .stage(CoreSchedule::Startup, |schedule: &mut Schedule| { + .stage(StartupSchedule, |schedule: &mut Schedule| { schedule.add_stage_after(target, label, stage) }); self @@ -271,7 +271,7 @@ impl App { stage: S, ) -> &mut Self { self.schedule - .stage(CoreSchedule::Startup, |schedule: &mut Schedule| { + .stage(StartupSchedule, |schedule: &mut Schedule| { schedule.add_stage_before(target, label, stage) }); self @@ -485,7 +485,7 @@ impl App { system: impl IntoSystemDescriptor, ) -> &mut Self { self.schedule - .stage(CoreSchedule::Startup, |schedule: &mut Schedule| { + .stage(StartupSchedule, |schedule: &mut Schedule| { schedule.add_system_to_stage(stage_label, system) }); self @@ -521,7 +521,7 @@ impl App { system_set: SystemSet, ) -> &mut Self { self.schedule - .stage(CoreSchedule::Startup, |schedule: &mut Schedule| { + .stage(StartupSchedule, |schedule: &mut Schedule| { schedule.add_system_set_to_stage(stage_label, system_set) }); self @@ -590,7 +590,7 @@ impl App { pub fn add_default_stages(&mut self) -> &mut Self { self.add_stage(CoreStage::First, SystemStage::parallel()) .add_stage( - CoreSchedule::Startup, + StartupSchedule, Schedule::default() .with_run_criteria(RunOnce::default()) .with_stage(StartupStage::PreStartup, SystemStage::parallel()) diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index fc0422c682e43..2446a14240db4 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -21,7 +21,7 @@ pub use schedule_runner::*; pub mod prelude { #[doc(hidden)] pub use crate::{ - app::App, CoreSchedule, CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupStage, + app::App, CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupSchedule, StartupStage, }; } @@ -46,11 +46,9 @@ pub enum CoreStage { } /// The names of the default App schedules +/// Runs once at the beginning of the app. #[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)] -pub enum CoreSchedule { - /// Runs once at the beginning of the app. - Startup, -} +pub struct StartupSchedule; /// The names of the default App startup stages #[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)] From cb77fcfa259c0770efc9dcafcb2f11dee6312dc6 Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Mon, 5 Jul 2021 14:10:01 +0200 Subject: [PATCH 3/3] Fix doc comment --- crates/bevy_app/src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index 2446a14240db4..2a8eb88c94bae 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -45,8 +45,11 @@ pub enum CoreStage { Last, } -/// The names of the default App schedules -/// Runs once at the beginning of the app. +/// The label for the Startup [`Schedule`](bevy_ecs::schedule::Schedule), +/// which runs once at the beginning of the app. +/// +/// When targeting a [`Stage`](bevy_ecs::schedule::Stage) inside this Schedule, +/// you need to use [`StartupStage`] instead. #[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)] pub struct StartupSchedule;