
# Objective Deny missing docs in bevy_diagnostic, towards https://github.com/bevyengine/bevy/issues/3492.
30 lines
970 B
Rust
30 lines
970 B
Rust
use bevy_app::prelude::*;
|
|
use bevy_ecs::entity::Entities;
|
|
|
|
use crate::{Diagnostic, DiagnosticPath, Diagnostics, RegisterDiagnostic};
|
|
|
|
/// Adds "entity count" diagnostic to an App.
|
|
///
|
|
/// # See also
|
|
///
|
|
/// [`LogDiagnosticsPlugin`](crate::LogDiagnosticsPlugin) to output diagnostics to the console.
|
|
#[derive(Default)]
|
|
pub struct EntityCountDiagnosticsPlugin;
|
|
|
|
impl Plugin for EntityCountDiagnosticsPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.register_diagnostic(Diagnostic::new(Self::ENTITY_COUNT))
|
|
.add_systems(Update, Self::diagnostic_system);
|
|
}
|
|
}
|
|
|
|
impl EntityCountDiagnosticsPlugin {
|
|
/// Number of currently allocated entities.
|
|
pub const ENTITY_COUNT: DiagnosticPath = DiagnosticPath::const_new("entity_count");
|
|
|
|
/// Updates entity count measurement.
|
|
pub fn diagnostic_system(mut diagnostics: Diagnostics, entities: &Entities) {
|
|
diagnostics.add_measurement(&Self::ENTITY_COUNT, || entities.len() as f64);
|
|
}
|
|
}
|