From 40007cdb2eaa16e4b81bb41d919a1620ef801111 Mon Sep 17 00:00:00 2001 From: spvky <30451500+spvky@users.noreply.github.com> Date: Fri, 24 Jan 2025 00:57:36 -0500 Subject: [PATCH] Adds update interval config for FpsOverlayPlugin (#17489) # Objective Fixes #17487 - Adds a new field `refresh_interval` to `FpsOverlayConfig` to allow the user setting a minimum time before each refresh of the FPS display ## Solution - Add `refresh_interval` to `FpsOverlayConfig` - When updating the on screen text, check a duration of `refresh_interval` has passed, if not, don't update the FPS counter ## Testing - Created a new bevy project - Included the `FpsOverlayPlugin` with the default `refresh_interval` (100 ms) - Included the `FpsOverlayPlugin` with an obnoxious `refresh_interval` (2 seconds) --- --------- Co-authored-by: Benjamin Brienen Co-authored-by: Alice Cecile --- crates/bevy_dev_tools/src/fps_overlay.rs | 23 +++++++++++++++++++---- examples/dev_tools/fps_overlay.rs | 2 ++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/bevy_dev_tools/src/fps_overlay.rs b/crates/bevy_dev_tools/src/fps_overlay.rs index 38e10ec312..358a7f2045 100644 --- a/crates/bevy_dev_tools/src/fps_overlay.rs +++ b/crates/bevy_dev_tools/src/fps_overlay.rs @@ -8,6 +8,7 @@ use bevy_ecs::{ change_detection::DetectChangesMut, component::Component, entity::Entity, + prelude::Local, query::With, resource::Resource, schedule::{common_conditions::resource_changed, IntoSystemConfigs}, @@ -15,10 +16,12 @@ use bevy_ecs::{ }; use bevy_render::view::Visibility; use bevy_text::{Font, TextColor, TextFont, TextSpan}; +use bevy_time::Time; use bevy_ui::{ widget::{Text, TextUiWriter}, GlobalZIndex, Node, PositionType, }; +use core::time::Duration; /// [`GlobalZIndex`] used to render the fps overlay. /// @@ -65,6 +68,10 @@ pub struct FpsOverlayConfig { pub text_color: Color, /// Displays the FPS overlay if true. pub enabled: bool, + /// The period after which the FPS overlay re-renders. + /// + /// Defaults to once every 100 ms. + pub refresh_interval: Duration, } impl Default for FpsOverlayConfig { @@ -77,6 +84,7 @@ impl Default for FpsOverlayConfig { }, text_color: Color::WHITE, enabled: true, + refresh_interval: Duration::from_millis(100), } } } @@ -110,11 +118,18 @@ fn update_text( diagnostic: Res, query: Query>, mut writer: TextUiWriter, + time: Res