diff options
author | pommicket <pommicket@gmail.com> | 2022-12-18 17:40:43 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-18 17:40:43 -0500 |
commit | c81d53fa47863d80436ce808b16c836ea6d3e16c (patch) | |
tree | a8779286f4aa3343eed85adb034b16b777237bd0 /src/main.rs | |
parent | 6545026c6b942b6388e16828703488150bee0714 (diff) |
framerate cap
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 38898a2..f77a3b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,5 @@ /* @TODO: -- options for: - - max framerate - come up with twisty lipschitz continuous function, & add it - (slightly) more interesting constants - Params instead of depth for GenRandom @@ -418,6 +416,15 @@ impl State { // returns false if we should quit fn frame(&mut self) -> bool { + if let Some(max_framerate) = self.settings.get_f32("max-framerate") { + if max_framerate > 0.0 { + let dt = self.frame_time.elapsed().as_secs_f32(); + let sleep_millis = 1000.0 * (1.0 / max_framerate - dt); + if sleep_millis >= 1.0 { + std::thread::sleep(std::time::Duration::from_millis(sleep_millis as u64)); + } + } + } let frame_dt = self.frame_time.elapsed().as_secs_f32(); self.frame_time = Instant::now(); |