From 212d7b915b95e831ddccb6d3cbf6e485207a2697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Sallai?= Date: Sun, 22 Jan 2023 20:27:46 +0200 Subject: [PATCH] don't try to render fps counter on no data scene --- src/game/shared_game_state.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/game/shared_game_state.rs b/src/game/shared_game_state.rs index b8f326b..22ed560 100644 --- a/src/game/shared_game_state.rs +++ b/src/game/shared_game_state.rs @@ -151,11 +151,12 @@ pub struct Fps { pub tick_count: u32, pub tps: u32, last_capture: u128, + should_draw: bool, } impl Fps { pub fn new() -> Fps { - Fps { frame_count: 0, fps: 0, tick_count: 0, tps: 0, last_capture: 0 } + Fps { frame_count: 0, fps: 0, tick_count: 0, tps: 0, last_capture: 0, should_draw: true } } pub fn act(&mut self, state: &mut SharedGameState, ctx: &mut Context, time: u128) -> GameResult { @@ -168,8 +169,13 @@ impl Fps { } else { self.frame_count = self.frame_count.saturating_add(1); } - draw_number(state.canvas_size.0 - 8.0, 8.0, self.fps as usize, Alignment::Right, state, ctx)?; - draw_number(state.canvas_size.0 - 8.0, 16.0, self.tps as usize, Alignment::Right, state, ctx)?; + + if self.should_draw { + let first = draw_number(state.canvas_size.0 - 8.0, 8.0, self.fps as usize, Alignment::Right, state, ctx); + let second = draw_number(state.canvas_size.0 - 8.0, 16.0, self.tps as usize, Alignment::Right, state, ctx); + self.should_draw = first.is_ok() && second.is_ok(); + } + Ok(()) } }