Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added frame count to FrameTimeDiagnosticsPlugin #678

Merged
merged 5 commits into from
Oct 14, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,32 +3,47 @@ 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think id prefer a fully-random uuid just so these are more distinguishable when printed. I generated one for you :)

73441630925388532774622109383099159699

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>,
) {
if time.delta_seconds_f64 == 0.0 {
return;
}

state.frame_count += 1.0;
diagnostics.add_measurement(Self::FRAME_COUNT, state.frame_count);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should probably move this above the time.delta_seconds_f64 == 0.0 check. A frame still happens even if the delta time is 0.


diagnostics.add_measurement(Self::FRAME_TIME, time.delta_seconds_f64);
if let Some(fps) = diagnostics
.get(Self::FRAME_TIME)
Expand Down