-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3f6968c
added frame count to FrameTimeDiagnosticsPlugin
Olaren15 9336292
fixed format from last commit
Olaren15 8eb36cd
fixed newline character
Olaren15 92e87a3
use more random UUID
Olaren15 267caa0
fixed frame count measurement location
Olaren15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
pub const FRAME_TIME: DiagnosticId = | ||
DiagnosticId::from_u128(54021991829115352065418785002088010276); | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we should probably move this above the |
||
|
||
diagnostics.add_measurement(Self::FRAME_TIME, time.delta_seconds_f64); | ||
if let Some(fps) = diagnostics | ||
.get(Self::FRAME_TIME) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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