From 5c2fa005c7ab74cbac57cba3c422d2ddf84a36ff Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Sat, 14 Dec 2024 14:51:05 +0100 Subject: [PATCH] render: only update fps counter when we need it --- src/render.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/render.rs b/src/render.rs index 2df0f44..2961084 100644 --- a/src/render.rs +++ b/src/render.rs @@ -54,7 +54,8 @@ pub struct Renderer { surfaces: S, fps: RealTimeRunningAverage, fps_display: Periodically, - frame: usize + frame: usize, + frame_count: usize } impl Renderer { @@ -64,7 +65,8 @@ impl Renderer { surfaces: surfaces, fps: RealTimeRunningAverage::default(), fps_display: Periodically::new_every_n_seconds(5), - frame: 0 + frame: 0, + frame_count: 0 } } } @@ -81,10 +83,12 @@ impl Task for Renderer { self.output.commit(); - self.fps.insert(1); self.frame += 1; self.fps_display.run(|| { - log::info!("FPS: {}", self.fps.measurement()); + self.fps.insert((self.frame - self.frame_count) as u32); + self.frame_count = self.frame; + let fps = self.fps.measurement(); + bus.push(Event::new_property_change("output.fps", fps.rate() as u32)); }); }, _ => self.output.on_event(event)