From 37fefd855e90ef6c08928c98b3a1980d53b6162c Mon Sep 17 00:00:00 2001 From: Oliver Nordbjerg Date: Fri, 11 Jul 2025 16:14:12 +0200 Subject: [PATCH] Add `max_history_length` to `EntityCountDiagnosticsPlugin` --- .../src/entity_count_diagnostics_plugin.rs | 23 ++++++++++++++++--- examples/diagnostics/log_diagnostics.rs | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/bevy_diagnostic/src/entity_count_diagnostics_plugin.rs b/crates/bevy_diagnostic/src/entity_count_diagnostics_plugin.rs index b20a82bf6c..8a1754a43d 100644 --- a/crates/bevy_diagnostic/src/entity_count_diagnostics_plugin.rs +++ b/crates/bevy_diagnostic/src/entity_count_diagnostics_plugin.rs @@ -1,15 +1,32 @@ use bevy_app::prelude::*; use bevy_ecs::entity::Entities; -use crate::{Diagnostic, DiagnosticPath, Diagnostics, RegisterDiagnostic}; +use crate::{ + Diagnostic, DiagnosticPath, Diagnostics, RegisterDiagnostic, DEFAULT_MAX_HISTORY_LENGTH, +}; /// Adds "entity count" diagnostic to an App. /// /// # See also /// /// [`LogDiagnosticsPlugin`](crate::LogDiagnosticsPlugin) to output diagnostics to the console. -#[derive(Default)] -pub struct EntityCountDiagnosticsPlugin; +pub struct EntityCountDiagnosticsPlugin { + /// The total number of values to keep. + pub max_history_length: usize, +} + +impl Default for EntityCountDiagnosticsPlugin { + fn default() -> Self { + Self::new(DEFAULT_MAX_HISTORY_LENGTH) + } +} + +impl EntityCountDiagnosticsPlugin { + /// Creates a new `EntityCountDiagnosticsPlugin` with the specified `max_history_length`. + pub fn new(max_history_length: usize) -> Self { + Self { max_history_length } + } +} impl Plugin for EntityCountDiagnosticsPlugin { fn build(&self, app: &mut App) { diff --git a/examples/diagnostics/log_diagnostics.rs b/examples/diagnostics/log_diagnostics.rs index 0e00e69ccd..1a36f9a1f2 100644 --- a/examples/diagnostics/log_diagnostics.rs +++ b/examples/diagnostics/log_diagnostics.rs @@ -33,7 +33,7 @@ fn main() { // Adds frame time, FPS and frame count diagnostics. FrameTimeDiagnosticsPlugin::default(), // Adds an entity count diagnostic. - EntityCountDiagnosticsPlugin, + EntityCountDiagnosticsPlugin::default(), // Adds cpu and memory usage diagnostics for systems and the entire game process. SystemInformationDiagnosticsPlugin, // Forwards various diagnostics from the render app to the main app.