Skip to content

Commit

Permalink
Diagnostics smoothing factor fix (#17354)
Browse files Browse the repository at this point in the history
# 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 <[email protected]>
  • Loading branch information
ickshonpe and mockersf authored Jan 14, 2025
1 parent c96949d commit 0222b35
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_diagnostic/src/frame_time_diagnostics_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
}
}
}
Expand Down

0 comments on commit 0222b35

Please sign in to comment.