|
1 | 1 | use bevy_app::prelude::*;
|
2 | 2 | use bevy_ecs::entity::Entities;
|
3 | 3 |
|
4 |
| -use crate::{Diagnostic, DiagnosticPath, Diagnostics, RegisterDiagnostic}; |
| 4 | +use crate::{ |
| 5 | + Diagnostic, DiagnosticPath, Diagnostics, RegisterDiagnostic, DEFAULT_MAX_HISTORY_LENGTH, |
| 6 | +}; |
5 | 7 |
|
6 | 8 | /// Adds "entity count" diagnostic to an App.
|
7 | 9 | ///
|
8 | 10 | /// # See also
|
9 | 11 | ///
|
10 | 12 | /// [`LogDiagnosticsPlugin`](crate::LogDiagnosticsPlugin) to output diagnostics to the console.
|
11 |
| -#[derive(Default)] |
12 |
| -pub struct EntityCountDiagnosticsPlugin; |
| 13 | +pub struct EntityCountDiagnosticsPlugin { |
| 14 | + /// The total number of values to keep. |
| 15 | + pub max_history_length: usize, |
| 16 | +} |
| 17 | + |
| 18 | +impl Default for EntityCountDiagnosticsPlugin { |
| 19 | + fn default() -> Self { |
| 20 | + Self::new(DEFAULT_MAX_HISTORY_LENGTH) |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +impl EntityCountDiagnosticsPlugin { |
| 25 | + /// Creates a new `EntityCountDiagnosticsPlugin` with the specified `max_history_length`. |
| 26 | + pub fn new(max_history_length: usize) -> Self { |
| 27 | + Self { max_history_length } |
| 28 | + } |
| 29 | +} |
13 | 30 |
|
14 | 31 | impl Plugin for EntityCountDiagnosticsPlugin {
|
15 | 32 | fn build(&self, app: &mut App) {
|
16 |
| - app.register_diagnostic(Diagnostic::new(Self::ENTITY_COUNT)) |
17 |
| - .add_systems(Update, Self::diagnostic_system); |
| 33 | + app.register_diagnostic( |
| 34 | + Diagnostic::new(Self::ENTITY_COUNT).with_max_history_length(self.max_history_length), |
| 35 | + ) |
| 36 | + .add_systems(Update, Self::diagnostic_system); |
18 | 37 | }
|
19 | 38 | }
|
20 | 39 |
|
|
0 commit comments