Skip to content

Commit

Permalink
Updates for Bevy main (will become 0.13)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Feb 1, 2024
1 parent 6479002 commit 6896eed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct EnableText;

fn toggle_plugin(
mut settings: ResMut<bevy_framepace::FramepaceSettings>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
) {
if input.just_pressed(KeyCode::Space) {
use bevy_framepace::Limiter;
Expand Down
24 changes: 9 additions & 15 deletions src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Adds diagnostic logging and a cursor for debugging.
use bevy::{
diagnostic::{Diagnostic, DiagnosticId, Diagnostics, RegisterDiagnostic},
diagnostic::{Diagnostic, DiagnosticPath, Diagnostics, RegisterDiagnostic},
prelude::*,
};

Expand All @@ -12,24 +12,18 @@ impl Plugin for DiagnosticsPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, Self::diagnostic_system);

app.register_diagnostic(
Diagnostic::new(Self::FRAMEPACE_FRAMETIME, "framepace::frametime", 128)
.with_suffix("ms"),
);
app.register_diagnostic(
Diagnostic::new(Self::FRAMEPACE_OVERSLEEP, "framepace::oversleep", 128)
.with_suffix("µs"),
);
app.register_diagnostic(Diagnostic::new(Self::FRAMEPACE_FRAMETIME).with_suffix("ms"));
app.register_diagnostic(Diagnostic::new(Self::FRAMEPACE_OVERSLEEP).with_suffix("µs"));
}
}

impl DiagnosticsPlugin {
/// [`DiagnosticId`] for the frametime
pub const FRAMEPACE_FRAMETIME: DiagnosticId =
DiagnosticId::from_u128(8021378406439507683279787892187089153);
pub const FRAMEPACE_FRAMETIME: DiagnosticPath =
DiagnosticPath::const_new("framepace/frametime");
/// [`DiagnosticId`] for failures to meet frame time target
pub const FRAMEPACE_OVERSLEEP: DiagnosticId =
DiagnosticId::from_u128(978023490268634078905367093342937);
pub const FRAMEPACE_OVERSLEEP: DiagnosticPath =
DiagnosticPath::const_new("framepace/oversleep");

/// Updates diagnostic data from measurements
pub fn diagnostic_system(
Expand All @@ -44,7 +38,7 @@ impl DiagnosticsPlugin {
let frametime_millis = stats.frametime.try_lock().unwrap().as_secs_f64() * 1_000_f64;
let error_micros = stats.oversleep.try_lock().unwrap().as_secs_f64() * 1_000_000_f64;

diagnostics.add_measurement(Self::FRAMEPACE_FRAMETIME, || frametime_millis);
diagnostics.add_measurement(Self::FRAMEPACE_OVERSLEEP, || error_micros);
diagnostics.add_measurement(&Self::FRAMEPACE_FRAMETIME, || frametime_millis);
diagnostics.add_measurement(&Self::FRAMEPACE_OVERSLEEP, || error_micros);
}
}

0 comments on commit 6896eed

Please sign in to comment.