Add max_history_length to EntityCountDiagnosticsPlugin

This commit is contained in:
Oliver Nordbjerg 2025-07-11 16:14:12 +02:00
parent 20dfae9a2d
commit 37fefd855e
No known key found for this signature in database
GPG Key ID: 3B182D3AD953AB4B
2 changed files with 21 additions and 4 deletions

View File

@ -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) {

View File

@ -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.