diff --git a/doppler/src/consts.rs b/doppler/src/consts.rs index 6e2f3ae..5ec8cf1 100644 --- a/doppler/src/consts.rs +++ b/doppler/src/consts.rs @@ -1,6 +1,7 @@ #![allow(dead_code)] // settings +pub const FRAMES_STORED : usize = 30; pub const SCR_WIDTH: u32 = 1280; pub const SCR_HEIGHT: u32 = 720; diff --git a/doppler/src/engine.rs b/doppler/src/engine.rs index fa4cd26..0e20866 100644 --- a/doppler/src/engine.rs +++ b/doppler/src/engine.rs @@ -10,6 +10,7 @@ use imgui_winit_support::{HiDpiMode, WinitPlatform}; use std::time::Instant; use log::info; use log::LevelFilter; +use std::collections::VecDeque; #[derive(Debug)] pub struct TimeStep { @@ -18,9 +19,13 @@ pub struct TimeStep { frame_count: u32, frame_time: f32, last_frame_count: u32, + frames: VecDeque, } impl TimeStep { + pub fn frames(&self) -> Vec { + self.frames.clone().into() + } pub fn new() -> TimeStep { TimeStep { last_time: Instant::now(), @@ -28,6 +33,7 @@ impl TimeStep { frame_count: 0, frame_time: 0.0, last_frame_count: 42, + frames: VecDeque::with_capacity(consts::FRAMES_STORED), } } @@ -44,8 +50,12 @@ impl TimeStep { // per second if self.frame_time >= 1000.0 { self.last_frame_count = self.frame_count; + self.frames.push_back(self.frame_count as f32); self.frame_count = 0; self.frame_time = 0.0; + if self.frames.len() > consts::FRAMES_STORED { + let _ = self.frames.pop_front(); + } } } @@ -284,6 +294,8 @@ impl Engine { #[cfg(feature = "imgui_inspect")] if self.debug_layer { + + let frames_vec = timestep.frames(); imgui.io_mut().display_size = [screensize.0 as f32, screensize.1 as f32]; let imgui_size = imgui.io().display_size; let ui = imgui.frame(); @@ -306,8 +318,8 @@ impl Engine { .bg_alpha(0.8) .save_settings(false) .build(&ui, || { - ui.text("Welcome in doppler world!"); - ui.text(format!("FPS: {:.0}", fps)); + ui.plot_histogram(im_str!("FPS"), &frames_vec).scale_min(0.0).build(); + ui.text(format!("Current FPS: {:.0}", fps)); ui.separator(); ui.text(format!("Mouse position: ({:4.1},{:4.1})", last_x, last_y)); }); diff --git a/src/example_client.rs b/src/example_client.rs index 2efdef2..49f1d1e 100644 --- a/src/example_client.rs +++ b/src/example_client.rs @@ -15,12 +15,12 @@ pub struct ExampleClient { camera: Camera, lighting_system: LightingSystem, sky: Sky, + delta: f32, show_object_info: bool, show_camera_info: bool, object_info_id: i32, show_light_info: bool, light_info_id: i32, - delta: f32, } impl Default for ExampleClient {