From 5f3f80959cd76466e9a026069ab7ab88a7d944b6 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 16 Dec 2024 14:41:22 +1300 Subject: Wait a minimum duration of 1ms between frames The code to do this was already in place, but was only being run on the very first frame of the program. Programs will now sleep if the previous frame completed in fewer than 1 millisecond, to prevent processor time from being wasted by a rapidly spinning program. --- src/phosphor.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/phosphor.rs') diff --git a/src/phosphor.rs b/src/phosphor.rs index 08c71da..00d391a 100644 --- a/src/phosphor.rs +++ b/src/phosphor.rs @@ -193,14 +193,14 @@ impl ApplicationHandler for PhosphorApplication { fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause) { if let StartCause::Init = cause { - // Ensure a minimum duration between frames. - const MINIMUM_WAIT: Duration = Duration::from_millis(1); - std::thread::sleep(MINIMUM_WAIT.saturating_sub(self.frame_start.elapsed())); - self.frame_start = Instant::now(); - event_loop.set_control_flow(ControlFlow::Poll); self.handle_builders_and_destructors(event_loop); } + + // Ensure a minimum duration between frames. + const MINIMUM_WAIT: Duration = Duration::from_millis(1); + std::thread::sleep(MINIMUM_WAIT.saturating_sub(self.frame_start.elapsed())); + self.frame_start = Instant::now(); } fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) { -- cgit v1.2.3-70-g09d2