print average fps and smooth out average a little bit

This commit is contained in:
Carter Anderson 2020-05-18 14:53:57 -07:00
parent e65fe0e736
commit 8bc0eb45ee
2 changed files with 6 additions and 4 deletions

View file

@ -19,8 +19,8 @@ impl FrameTimeDiagnosticsPlugin {
DiagnosticId::from_u128(54021991829115352065418785002088010276);
pub fn setup_system(mut diagnostics: ResMut<Diagnostics>) {
diagnostics.add(Diagnostic::new(Self::FRAME_TIME, "frame_time", 10));
diagnostics.add(Diagnostic::new(Self::FPS, "fps", 10));
diagnostics.add(Diagnostic::new(Self::FRAME_TIME, "frame_time", 20));
diagnostics.add(Diagnostic::new(Self::FPS, "fps", 20));
}
pub fn diagnostic_system(mut diagnostics: ResMut<Diagnostics>, time: Res<Time>) {

View file

@ -13,8 +13,10 @@ fn main() {
}
fn text_update_system(diagnostics: Res<Diagnostics>, mut label: ComMut<Label>) {
if let Some(fps) = diagnostics.get_measurement(FrameTimeDiagnosticsPlugin::FPS) {
label.text = format!("FPS: {}", fps.value.round());
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
if let Some(average) = fps.average() {
label.text = format!("FPS: {}", average.round());
}
}
}