show average fps on console

This commit is contained in:
Michael Sippel 2024-07-31 19:18:00 +02:00
parent f8148462d2
commit 17de5bcb76
Signed by: senvas
GPG key ID: 060F22F65102F95C

View file

@ -111,6 +111,9 @@ async fn main() {
let mut last_tap = std::time::Instant::now(); let mut last_tap = std::time::Instant::now();
let mut z = 0; let mut z = 0;
let mut frame_count = 0;
let mut fps_sum_window = std::time::Instant::now();
let mut active = false; let mut active = false;
for i in 0..5 { for i in 0..5 {
@ -119,9 +122,18 @@ async fn main() {
event_loop.run(move |event, elwt| { event_loop.run(move |event, elwt| {
let tcur = std::time::Instant::now(); let tcur = std::time::Instant::now();
if (tcur - fps_sum_window).as_millis() > 5000 {
let avg_fps = (1000.0 * frame_count as f32) / ((tcur - fps_sum_window).as_millis() as f32);
eprintln!("avg fps: {}", avg_fps);
fps_sum_window = tcur;
frame_count = 0;
} else {
frame_count += 1;
}
elwt.set_control_flow(ControlFlow:: elwt.set_control_flow(ControlFlow::
WaitUntil( WaitUntil(
tcur + Duration::from_millis(100) tcur + Duration::from_millis(25)
)); ));
inputs.write().unwrap().t = tcur - tbegin; inputs.write().unwrap().t = tcur - tbegin;
inputs.write().unwrap().transition_time = tcur - transition_begin; inputs.write().unwrap().transition_time = tcur - transition_begin;
@ -237,12 +249,12 @@ async fn main() {
eprintln!("--------------"); eprintln!("--------------");
} }
} }
_ => {} _ => {}
}
} }
} }
}
_ => {} _ => {}
} }
let (width, height) = *dim.lock().unwrap(); let (width, height) = *dim.lock().unwrap();
@ -252,7 +264,7 @@ async fn main() {
NonZeroU32::new(height).unwrap(), NonZeroU32::new(height).unwrap(),
) )
.unwrap(); .unwrap();
if let Ok(mut buf) = surface.lock().unwrap().buffer_mut() { if let Ok(mut buf) = surface.lock().unwrap().buffer_mut() {
lighting_setup.draw_preview( &mut buf, width, height ); lighting_setup.draw_preview( &mut buf, width, height );
buf.present().unwrap(); buf.present().unwrap();