-
Notifications
You must be signed in to change notification settings - Fork 12
/
extras.rs
59 lines (51 loc) · 1.77 KB
/
extras.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use bevy::{
diagnostic::{EntityCountDiagnosticsPlugin, FrameTimeDiagnosticsPlugin},
prelude::*,
};
use crate::{Aggregate, ScreenDiagnostics};
/// Plugin which adds the bevy [`FrameTimeDiagnosticsPlugin`] and adds its diagnostics to [DiagnosticsText]
///
/// Example: ``16.6 ms/frame 60 fps``
pub struct ScreenFrameDiagnosticsPlugin;
impl Plugin for ScreenFrameDiagnosticsPlugin {
fn build(&self, app: &mut App) {
if !app.is_plugin_added::<FrameTimeDiagnosticsPlugin>() {
app.add_plugins(FrameTimeDiagnosticsPlugin);
}
app.add_systems(Startup, setup_frame_diagnostics);
}
}
fn setup_frame_diagnostics(mut diags: ResMut<ScreenDiagnostics>) {
diags
.add("fps".to_string(), FrameTimeDiagnosticsPlugin::FPS)
.aggregate(Aggregate::Value)
.format(|v| format!("{v:.0}"));
diags
.add(
"ms/frame".to_string(),
FrameTimeDiagnosticsPlugin::FRAME_TIME,
)
.aggregate(Aggregate::MovingAverage(5))
.format(|v| format!("{v:.2}"));
}
/// Plugin which adds the bevy [`EntityCountDiagnosticsPlugin`] and adds its diagnostics to [DiagnosticsText]
///
/// Example: ``15 entities``
pub struct ScreenEntityDiagnosticsPlugin;
impl Plugin for ScreenEntityDiagnosticsPlugin {
fn build(&self, app: &mut App) {
if !app.is_plugin_added::<EntityCountDiagnosticsPlugin>() {
app.add_plugins(EntityCountDiagnosticsPlugin);
}
app.add_systems(Startup, setup_entity_diagnostics);
}
}
fn setup_entity_diagnostics(mut diags: ResMut<ScreenDiagnostics>) {
diags
.add(
"entities".to_string(),
EntityCountDiagnosticsPlugin::ENTITY_COUNT,
)
.aggregate(Aggregate::Value)
.format(|v| format!("{v:.0}"));
}