From 087b6f9c9063730db14da0d1e0562c93523e396a Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Sat, 16 Oct 2021 17:50:11 +0100 Subject: [PATCH 1/4] Don't make Stopwatch a Component --- crates/bevy_core/src/time/stopwatch.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/bevy_core/src/time/stopwatch.rs b/crates/bevy_core/src/time/stopwatch.rs index 9fa84cba07a6b..c13f2773918a8 100644 --- a/crates/bevy_core/src/time/stopwatch.rs +++ b/crates/bevy_core/src/time/stopwatch.rs @@ -1,4 +1,3 @@ -use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_reflect::Reflect; use bevy_utils::Duration; @@ -23,8 +22,7 @@ use bevy_utils::Duration; /// assert!(stopwatch.paused()); /// assert_eq!(stopwatch.elapsed_secs(), 0.0); /// ``` -#[derive(Component, Clone, Debug, Default, Reflect)] -#[reflect(Component)] +#[derive(Clone, Debug, Default, Reflect)] pub struct Stopwatch { elapsed: Duration, paused: bool, From ba5cf2d74b5a1a4a7b230ea9df96ac49e9ee0097 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Sat, 16 Oct 2021 19:16:02 +0100 Subject: [PATCH 2/4] Make `Timer` not be a Component --- crates/bevy_core/src/time/timer.rs | 4 +--- examples/2d/many_sprites.rs | 16 +++++++++------- examples/2d/sprite_sheet.rs | 19 +++++++++++++------ examples/ecs/timers.rs | 21 +++++++++++++-------- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/crates/bevy_core/src/time/timer.rs b/crates/bevy_core/src/time/timer.rs index b9bd0800de38e..0cf3e89d4f5fa 100644 --- a/crates/bevy_core/src/time/timer.rs +++ b/crates/bevy_core/src/time/timer.rs @@ -1,5 +1,4 @@ use crate::Stopwatch; -use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_reflect::Reflect; use bevy_utils::Duration; @@ -10,8 +9,7 @@ use bevy_utils::Duration; /// exceeded, and can still be reset at any given point. /// /// Paused timers will not have elapsed time increased. -#[derive(Component, Clone, Debug, Default, Reflect)] -#[reflect(Component)] +#[derive(Clone, Debug, Default, Reflect)] pub struct Timer { stopwatch: Stopwatch, duration: Duration, diff --git a/examples/2d/many_sprites.rs b/examples/2d/many_sprites.rs index cc291703f0e2f..42f82b74cdfa8 100644 --- a/examples/2d/many_sprites.rs +++ b/examples/2d/many_sprites.rs @@ -17,8 +17,12 @@ fn main() { .add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_plugins(DefaultPlugins) .add_startup_system(setup) - .add_system(tick_system.label("Tick")) - .add_system(move_camera_system.after("Tick")) + .add_system( + print_sprite_count + .config(|((), timer, ())| *timer = Some(Timer::from_seconds(1.0, true))) + .label("Tick"), + ) + .add_system(move_camera.after("Tick")) .run() } @@ -37,7 +41,6 @@ fn setup(mut commands: Commands, assets: Res) { commands .spawn() .insert_bundle(OrthographicCameraBundle::new_2d()) - .insert(Timer::from_seconds(1.0, true)) .insert(Transform::from_xyz(0.0, 0.0, 1000.0)); // Builds and spawns the sprites @@ -68,7 +71,7 @@ fn setup(mut commands: Commands, assets: Res) { } // System for rotating and translating the camera -fn move_camera_system(time: Res