From 2166c9099dd97ff49708aa79c99cfa9b3509d32b Mon Sep 17 00:00:00 2001 From: Mike Hsu Date: Wed, 11 May 2022 21:34:02 -0700 Subject: [PATCH] move time update to after render schedule --- crates/bevy_app/src/app.rs | 13 +++++++++++++ crates/bevy_core/src/lib.rs | 11 ++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index cdf1984c8b01e..150dcee9b4d7e 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -56,6 +56,8 @@ pub struct App { pub runner: Box, /// A container of [`Stage`]s set to be run in a linear order. pub schedule: Schedule, + /// A stage run after main schedule and sub app schedules + pub final_stage: SystemStage, sub_apps: HashMap, SubApp>, } @@ -98,6 +100,7 @@ impl App { Self { world: Default::default(), schedule: Default::default(), + final_stage: SystemStage::single_threaded(), runner: Box::new(run_once), sub_apps: HashMap::default(), } @@ -115,6 +118,7 @@ impl App { for sub_app in self.sub_apps.values_mut() { (sub_app.runner)(&mut self.world, &mut sub_app.app); } + self.final_stage.run(&mut self.world); } /// Starts the application by calling the app's [runner function](Self::set_runner). @@ -326,6 +330,15 @@ impl App { self.add_system_to_stage(CoreStage::Update, system) } + /// Adds a system to the final stage that runs after the app and render schedules. + pub fn add_system_to_final_stage( + &mut self, + system: impl IntoSystemDescriptor, + ) -> &mut Self { + self.final_stage.add_system(system); + self + } + /// Adds a [`SystemSet`] to the [update stage](Self::add_default_stages). /// /// # Examples diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index 44b2be465b9cf..4d9de08aca957 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -54,11 +54,12 @@ impl Plugin for CorePlugin { .register_type::() .register_type::>() .register_type::() - // time system is added as an "exclusive system" to ensure it runs before other systems - // in CoreStage::First - .add_system_to_stage( - CoreStage::First, - time_system.exclusive_system().label(CoreSystem::Time), + // time system is added as an "exclusive system at end" to ensure it runs after other systems + .add_system_to_final_stage( + time_system + .exclusive_system() + .at_end() + .label(CoreSystem::Time), ); register_rust_types(app);