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] - Move the CoreStage::Startup to a seperate StartupSchedule label #2434

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 9 additions & 7 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupStage};
use crate::{
CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupSchedule, StartupStage,
};
pub use bevy_derive::AppLabel;
use bevy_ecs::{
prelude::{FromWorld, IntoExclusiveSystem},
Expand Down Expand Up @@ -207,7 +209,7 @@ impl App {
/// ```
pub fn add_startup_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
self.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
.stage(StartupSchedule, |schedule: &mut Schedule| {
schedule.add_stage(label, stage)
});
self
Expand Down Expand Up @@ -238,7 +240,7 @@ impl App {
stage: S,
) -> &mut Self {
self.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
.stage(StartupSchedule, |schedule: &mut Schedule| {
schedule.add_stage_after(target, label, stage)
});
self
Expand Down Expand Up @@ -269,7 +271,7 @@ impl App {
stage: S,
) -> &mut Self {
self.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
.stage(StartupSchedule, |schedule: &mut Schedule| {
schedule.add_stage_before(target, label, stage)
});
self
Expand Down Expand Up @@ -483,7 +485,7 @@ impl App {
system: impl IntoSystemDescriptor<Params>,
) -> &mut Self {
self.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
.stage(StartupSchedule, |schedule: &mut Schedule| {
schedule.add_system_to_stage(stage_label, system)
});
self
Expand Down Expand Up @@ -519,7 +521,7 @@ impl App {
system_set: SystemSet,
) -> &mut Self {
self.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
.stage(StartupSchedule, |schedule: &mut Schedule| {
schedule.add_system_set_to_stage(stage_label, system_set)
});
self
Expand Down Expand Up @@ -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,
StartupSchedule,
Schedule::default()
.with_run_criteria(RunOnce::default())
.with_stage(StartupStage::PreStartup, SystemStage::parallel())
Expand Down
18 changes: 12 additions & 6 deletions crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupSchedule, StartupStage,
};
}

use bevy_ecs::schedule::StageLabel;
Expand All @@ -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.
Expand All @@ -47,6 +44,15 @@ pub enum CoreStage {
/// Name of app stage that runs after all other app stages
Last,
}

/// 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;
Copy link
Member

@mockersf mockersf Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it could be not pub to make sure its only access is through the official methods from App?

Copy link
Member

@cart cart Dec 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think theres no real harm in giving people direct access to the startup schedule if they want it. I think the "foot guns" have been resolved in this pr, and this gives "feature parity" with the other stages.


/// The names of the default App startup stages
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
pub enum StartupStage {
Expand Down