From 63e1fd94bd1b7964d085a4c4b93754d6d45895a5 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sat, 29 Apr 2023 10:30:49 +0100 Subject: [PATCH] Simple framerate logging --- src/core/app.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/app.rs b/src/core/app.rs index e6b031e..9fc7d67 100644 --- a/src/core/app.rs +++ b/src/core/app.rs @@ -62,6 +62,8 @@ impl App { let renderer = voxel::VoxelRenderer::new(&self.render_ctx, &camera_controller); + let mut cumulative_dt = 0.0; + let mut frames_accumulated = 0.0; let mut last_render_time = Instant::now(); self.event_loop .run(move |event, _, control_flow| match event { @@ -84,6 +86,17 @@ impl App { camera_controller.update(dt); camera_controller.update_buffer(&self.render_ctx); renderer.render(&self.render_ctx); + + // Simple framerate tracking + cumulative_dt += dt.as_secs_f32(); + frames_accumulated += 1.0; + if cumulative_dt >= 1.0 { + let fps = frames_accumulated * 1.0 / cumulative_dt; + let frame_time = cumulative_dt * 1000.0 / frames_accumulated; + log::info!("FPS: {}, Frame Time: {}", fps.floor(), frame_time); + cumulative_dt = 0.0; + frames_accumulated = 0.0; + } } _ => {} });