Skip to content

Commit d37d2c4

Browse files
authored
Merge pull request #70 from nichilum/fps-counter
add fps counter
2 parents f82ff8f + a5b34a0 commit d37d2c4

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/ui/draw.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
12
use bevy::ecs::system::SystemParam;
23
use bevy::prelude::*;
34
use bevy_file_dialog::prelude::*;
@@ -122,6 +123,7 @@ pub fn draw_egui(
122123
sim_time: Res<SimTime>,
123124
time: Res<Time>,
124125
mut fixed_timestep: ResMut<Time<Fixed>>,
126+
diagnostics: Res<DiagnosticsStore>,
125127
) {
126128
let QuerySystemParams {
127129
mut rect_wall_set,
@@ -1178,11 +1180,21 @@ pub fn draw_egui(
11781180
});
11791181

11801182
ui.add_space(5.);
1181-
ui.label(format!(
1182-
"Simulation Time: {:.5} ms",
1183-
sim_time.time_since_start * 1000.
1184-
));
1185-
1183+
ui.horizontal(|ui| {
1184+
ui.label(format!(
1185+
"Simulation Time: {:.5} ms",
1186+
sim_time.time_since_start * 1000.
1187+
));
1188+
1189+
ui.add(egui::Separator::default().vertical());
1190+
ui.label(format!(
1191+
"FPS: {:.1} ms",
1192+
diagnostics
1193+
.get(&FrameTimeDiagnosticsPlugin::FPS)
1194+
.and_then(|fps| fps.smoothed())
1195+
.unwrap_or(0.0)
1196+
));
1197+
});
11861198
ui.add_space(5.);
11871199
});
11881200

src/ui/plugin.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use bevy::diagnostic::FrameTimeDiagnosticsPlugin;
12
use bevy::prelude::*;
23
use bevy_file_dialog::FileDialogPlugin;
34

@@ -14,11 +15,12 @@ impl Plugin for UiPlugin {
1415
.init_resource::<ClipboardBuffer>()
1516
.init_resource::<DockState>()
1617
.init_resource::<FftMicrophone>()
17-
.add_plugins(
18+
.add_plugins((
1819
FileDialogPlugin::new()
1920
.with_save_file::<SaveFileContents>()
2021
.with_load_file::<SaveFileContents>(),
21-
)
22+
FrameTimeDiagnosticsPlugin,
23+
))
2224
.add_systems(Update, (draw_egui, file_loaded));
2325
}
2426
}

0 commit comments

Comments
 (0)