From 04aec9231b25724364792eb7339f5ddcdee89ca9 Mon Sep 17 00:00:00 2001 From: Matthew Gordon Date: Thu, 12 Jun 2025 10:53:32 -0300 Subject: [PATCH] Add file missing from earlier commit --- src/app/statistics_reporter.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/app/statistics_reporter.rs diff --git a/src/app/statistics_reporter.rs b/src/app/statistics_reporter.rs new file mode 100644 index 0000000..7f61c0a --- /dev/null +++ b/src/app/statistics_reporter.rs @@ -0,0 +1,31 @@ +use log::info; + +pub struct StatisticsReporter { + total_time_seconds: f64, + frame_count: u32, +} + +impl StatisticsReporter { + pub fn new() -> Self { + let total_time_seconds = 0.0; + let frame_count = 0; + Self { + total_time_seconds, + frame_count, + } + } + + pub fn log_frame_time_seconds(&mut self, t: f64) { + self.total_time_seconds += t; + self.frame_count += 1; + if self.total_time_seconds >= 1.0 { + info!( + "Average frame time: {:.0} ms ({:.1} fps)", + self.total_time_seconds * 1000.0 / (self.frame_count as f64), + (self.frame_count as f64) / self.total_time_seconds + ); + self.total_time_seconds = 0.0; + self.frame_count = 0; + } + } +}