From 5d61d297a4dd9c34c1777db8de5714c517dd6426 Mon Sep 17 00:00:00 2001 From: phuocthanhdo Date: Mon, 21 Nov 2022 13:19:41 +0000 Subject: [PATCH] The `update_frame_count` system should be placed in CorePlugin (#6676) # Objective Latest Release, "bevy 0.9" move the FrameCount updater into RenderPlugin, it leads to user who only run app with Core/Minimal Plugin cannot get the right number of FrameCount, it always return 0. As for use cases like a server app, we don't want to add render dependencies to the app. More detail in #6656 ## Solution - Move the `update_frame_count` into CorePlugin --- crates/bevy_core/src/lib.rs | 17 ++++++++++++++++- crates/bevy_render/src/globals.rs | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index 8390cb37e99ee..ee21feb2ec9ef 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -6,7 +6,7 @@ mod name; mod serde; mod task_pool_options; -use bevy_ecs::system::Resource; +use bevy_ecs::system::{ResMut, Resource}; pub use bytemuck::{bytes_of, cast_slice, Pod, Zeroable}; pub use name::*; pub use task_pool_options::*; @@ -55,6 +55,7 @@ impl Plugin for CorePlugin { register_math_types(app); app.init_resource::(); + app.add_system(update_frame_count); } } @@ -112,6 +113,10 @@ fn register_math_types(app: &mut App) { #[derive(Default, Resource, Clone, Copy)] pub struct FrameCount(pub u32); +fn update_frame_count(mut frame_count: ResMut) { + frame_count.0 = frame_count.0.wrapping_add(1); +} + #[cfg(test)] mod tests { use super::*; @@ -149,4 +154,14 @@ mod tests { compute_rx.try_recv().unwrap(); io_rx.try_recv().unwrap(); } + + #[test] + fn frame_counter_update() { + let mut app = App::new(); + app.add_plugin(CorePlugin::default()); + app.update(); + + let frame_count = app.world.resource::(); + assert_eq!(1, frame_count.0); + } } diff --git a/crates/bevy_render/src/globals.rs b/crates/bevy_render/src/globals.rs index f5fa30482f850..a0b160dd4b27d 100644 --- a/crates/bevy_render/src/globals.rs +++ b/crates/bevy_render/src/globals.rs @@ -19,12 +19,17 @@ impl Plugin for GlobalsPlugin { render_app .init_resource::() .init_resource::