
- changed `EntityCountDiagnosticsPlugin` to not use an exclusive system to get its entity count - removed mention of `WgpuResourceDiagnosticsPlugin` in example `log_diagnostics` as it doesn't exist anymore - added ability to enable, disable ~~or toggle~~ a diagnostic (fix #3767) - made diagnostic values lazy, so they are only computed if the diagnostic is enabled - do not log an average for diagnostics with only one value - removed `sum` function from diagnostic as it isn't really useful - ~~do not keep an average of the FPS diagnostic. it is already an average on the last 20 frames, so the average FPS was an average of the last 20 frames over the last 20 frames~~ - do not compute the FPS value as an average over the last 20 frames but give the actual "instant FPS" - updated log format to use variable capture - added some doc - the frame counter diagnostic value can be reseted to 0
29 lines
921 B
Rust
29 lines
921 B
Rust
use bevy_app::{App, Plugin};
|
|
use bevy_ecs::{entity::Entities, system::ResMut};
|
|
|
|
use crate::{Diagnostic, DiagnosticId, Diagnostics};
|
|
|
|
/// Adds "entity count" diagnostic to an App
|
|
#[derive(Default)]
|
|
pub struct EntityCountDiagnosticsPlugin;
|
|
|
|
impl Plugin for EntityCountDiagnosticsPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_startup_system(Self::setup_system)
|
|
.add_system(Self::diagnostic_system);
|
|
}
|
|
}
|
|
|
|
impl EntityCountDiagnosticsPlugin {
|
|
pub const ENTITY_COUNT: DiagnosticId =
|
|
DiagnosticId::from_u128(187513512115068938494459732780662867798);
|
|
|
|
pub fn setup_system(mut diagnostics: ResMut<Diagnostics>) {
|
|
diagnostics.add(Diagnostic::new(Self::ENTITY_COUNT, "entity_count", 20));
|
|
}
|
|
|
|
pub fn diagnostic_system(mut diagnostics: ResMut<Diagnostics>, entities: &Entities) {
|
|
diagnostics.add_measurement(Self::ENTITY_COUNT, || entities.len() as f64);
|
|
}
|
|
}
|