Skip to content

Commit

Permalink
added frame count to FrameTimeDiagnosticsPlugin (bevyengine#678)
Browse files Browse the repository at this point in the history
added frame count to FrameTimeDiagnosticsPlugin
  • Loading branch information
Olaren15 authored and joshuajbouw committed Oct 24, 2020
1 parent 87230be commit 4485f5b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions crates/bevy_diagnostic/src/frame_time_diagnostics_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,43 @@ use bevy_app::prelude::*;
use bevy_core::Time;
use bevy_ecs::{IntoQuerySystem, Res, ResMut};

/// Adds "frame time" diagnostic to an App, specifically "frame time" and "fps"
/// Adds "frame time" diagnostic to an App, specifically "frame time", "fps" and "frame count"
#[derive(Default)]
pub struct FrameTimeDiagnosticsPlugin;

pub struct FrameTimeDiagnosticsState {
frame_count: f64,
}

impl Plugin for FrameTimeDiagnosticsPlugin {
fn build(&self, app: &mut bevy_app::AppBuilder) {
app.add_startup_system(Self::setup_system.system())
.add_resource(FrameTimeDiagnosticsState { frame_count: 0.0 })
.add_system(Self::diagnostic_system.system());
}
}

impl FrameTimeDiagnosticsPlugin {
pub const FPS: DiagnosticId = DiagnosticId::from_u128(288146834822086093791974408528866909483);
pub const FRAME_COUNT: DiagnosticId =
DiagnosticId::from_u128(54021991829115352065418785002088010277);
pub const FRAME_TIME: DiagnosticId =
DiagnosticId::from_u128(54021991829115352065418785002088010276);
DiagnosticId::from_u128(73441630925388532774622109383099159699);

pub fn setup_system(mut diagnostics: ResMut<Diagnostics>) {
diagnostics.add(Diagnostic::new(Self::FRAME_TIME, "frame_time", 20));
diagnostics.add(Diagnostic::new(Self::FPS, "fps", 20));
diagnostics.add(Diagnostic::new(Self::FRAME_COUNT, "frame_count", 1));
}

pub fn diagnostic_system(mut diagnostics: ResMut<Diagnostics>, time: Res<Time>) {
pub fn diagnostic_system(
mut diagnostics: ResMut<Diagnostics>,
time: Res<Time>,
mut state: ResMut<FrameTimeDiagnosticsState>,
) {
state.frame_count += 1.0;
diagnostics.add_measurement(Self::FRAME_COUNT, state.frame_count);

if time.delta_seconds_f64 == 0.0 {
return;
}
Expand Down

0 comments on commit 4485f5b

Please sign in to comment.