-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
crates/bevy_asset/src/diagnostic/asset_count_diagnostics_plugin.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::{Asset, Assets}; | ||
use bevy_app::prelude::*; | ||
use bevy_diagnostic::{Diagnostic, DiagnosticId, Diagnostics}; | ||
use bevy_ecs::{IntoSystem, Res, ResMut}; | ||
|
||
/// Adds "asset count" diagnostic to an App | ||
#[derive(Default)] | ||
pub struct AssetCountDiagnosticsPlugin<T: Asset> { | ||
marker: std::marker::PhantomData<T>, | ||
} | ||
|
||
impl<T: Asset> Plugin for AssetCountDiagnosticsPlugin<T> { | ||
fn build(&self, app: &mut AppBuilder) { | ||
app.add_startup_system(Self::setup_system.system()) | ||
.add_system(Self::diagnostic_system.system()); | ||
} | ||
} | ||
|
||
impl<T: Asset> AssetCountDiagnosticsPlugin<T> { | ||
pub fn diagnostic_id() -> DiagnosticId { | ||
DiagnosticId(T::TYPE_UUID) | ||
} | ||
|
||
pub fn setup_system(mut diagnostics: ResMut<Diagnostics>) { | ||
diagnostics.add(Diagnostic::new( | ||
Self::diagnostic_id(), | ||
&format!("asset_count {}", std::any::type_name::<T>()), | ||
20, | ||
)); | ||
} | ||
|
||
pub fn diagnostic_system(mut diagnostics: ResMut<Diagnostics>, assets: Res<Assets<T>>) { | ||
diagnostics.add_measurement(Self::diagnostic_id(), assets.len() as f64); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod asset_count_diagnostics_plugin; | ||
pub use asset_count_diagnostics_plugin::AssetCountDiagnosticsPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters