From 0222b35f6d8341b285eff4fb2d2e8a4328deff3e Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Tue, 14 Jan 2025 01:13:24 +0000 Subject: [PATCH] Diagnostics smoothing factor fix (#17354) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective Diagnostics is reporting incorrect FPS and frame time. ## Solution Looks like the smoothing value should be `2 / (history_length + 1)` not `(history_length + 1) / 2`. Co-authored-by: François Mockers --- crates/bevy_diagnostic/src/frame_time_diagnostics_plugin.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_diagnostic/src/frame_time_diagnostics_plugin.rs b/crates/bevy_diagnostic/src/frame_time_diagnostics_plugin.rs index f344d6c5c2972..22b6176fa2856 100644 --- a/crates/bevy_diagnostic/src/frame_time_diagnostics_plugin.rs +++ b/crates/bevy_diagnostic/src/frame_time_diagnostics_plugin.rs @@ -14,7 +14,7 @@ use bevy_time::{Real, Time}; pub struct FrameTimeDiagnosticsPlugin { /// The total number of values to keep for averaging. pub max_history_length: usize, - /// The smoothing factor for the exponential moving average. Usually `(history_length + 1.0) / 2.0)`. + /// The smoothing factor for the exponential moving average. Usually `2.0 / (history_length + 1.0)`. pub smoothing_factor: f64, } impl Default for FrameTimeDiagnosticsPlugin { @@ -28,7 +28,7 @@ impl FrameTimeDiagnosticsPlugin { pub fn new(max_history_length: usize) -> Self { Self { max_history_length, - smoothing_factor: (max_history_length as f64 + 1.0) / 2.0, + smoothing_factor: 2.0 / (max_history_length as f64 + 1.0), } } }