Add max_history_length
to EntityCountDiagnosticsPlugin
(#20085)
# Objective I was building out a diagnostics panel in egui when I noticed that I could specify the max history length for the `FrameTimeDiagnosticsPlugin`, but not for the `EntityCountDiagnosticsPlugin`. The objective was to harmonize the two, making the diagnostic history length configurable for both. ## Solution I added a `EntityCountDiagnosticsPlugin::new`, and a `Default` impl that matches `FrameTimeDiagnosticsPlugin`. This is a breaking change, given the plugin had no fields previously. ## Testing I did not test this.
This commit is contained in:
parent
27fe2e88bd
commit
1525dff7ad
@ -1,19 +1,38 @@
|
|||||||
use bevy_app::prelude::*;
|
use bevy_app::prelude::*;
|
||||||
use bevy_ecs::entity::Entities;
|
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.
|
/// Adds "entity count" diagnostic to an App.
|
||||||
///
|
///
|
||||||
/// # See also
|
/// # See also
|
||||||
///
|
///
|
||||||
/// [`LogDiagnosticsPlugin`](crate::LogDiagnosticsPlugin) to output diagnostics to the console.
|
/// [`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 {
|
impl Plugin for EntityCountDiagnosticsPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.register_diagnostic(Diagnostic::new(Self::ENTITY_COUNT))
|
app.register_diagnostic(
|
||||||
|
Diagnostic::new(Self::ENTITY_COUNT).with_max_history_length(self.max_history_length),
|
||||||
|
)
|
||||||
.add_systems(Update, Self::diagnostic_system);
|
.add_systems(Update, Self::diagnostic_system);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ fn main() {
|
|||||||
// Adds frame time, FPS and frame count diagnostics.
|
// Adds frame time, FPS and frame count diagnostics.
|
||||||
FrameTimeDiagnosticsPlugin::default(),
|
FrameTimeDiagnosticsPlugin::default(),
|
||||||
// Adds an entity count diagnostic.
|
// Adds an entity count diagnostic.
|
||||||
EntityCountDiagnosticsPlugin,
|
EntityCountDiagnosticsPlugin::default(),
|
||||||
// Adds cpu and memory usage diagnostics for systems and the entire game process.
|
// Adds cpu and memory usage diagnostics for systems and the entire game process.
|
||||||
SystemInformationDiagnosticsPlugin,
|
SystemInformationDiagnosticsPlugin,
|
||||||
// Forwards various diagnostics from the render app to the main app.
|
// Forwards various diagnostics from the render app to the main app.
|
||||||
|
Loading…
Reference in New Issue
Block a user