summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-18 17:40:43 -0500
committerpommicket <pommicket@gmail.com>2022-12-18 17:40:43 -0500
commitc81d53fa47863d80436ce808b16c836ea6d3e16c (patch)
treea8779286f4aa3343eed85adb034b16b777237bd0
parent6545026c6b942b6388e16828703488150bee0714 (diff)
framerate cap
-rw-r--r--settings.txt4
-rw-r--r--src/main.rs11
2 files changed, 13 insertions, 2 deletions
diff --git a/settings.txt b/settings.txt
index fa8db82..13482df 100644
--- a/settings.txt
+++ b/settings.txt
@@ -21,3 +21,7 @@ focal-length 1
fov 45
# set this to 1 to use HSV instead of RGB for color
hsv 0
+# framerate cap.
+# by default, vsync is enabled, so you don't need to change this unless you want
+# to run at an even lower framerate than your monitor's refresh rate
+max-framerate 1000
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();