diff options
author | Ben Bridle <ben@derelict.engineering> | 2024-12-16 14:41:22 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2024-12-16 14:41:45 +1300 |
commit | 5f3f80959cd76466e9a026069ab7ab88a7d944b6 (patch) | |
tree | 782fdb38955951c5e57f3512b6fb2ace664f6eb6 /src/phosphor.rs | |
parent | 393d4f309ba238f81d100aae409a784f82d88c15 (diff) | |
download | phosphor-5f3f80959cd76466e9a026069ab7ab88a7d944b6.zip |
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.
Diffstat (limited to 'src/phosphor.rs')
-rw-r--r-- | src/phosphor.rs | 10 |
1 files changed, 5 insertions, 5 deletions
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) { |