-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Posting this here so it doesn't get lost
32th System
I have an idea on frame limiting to 60 fps on a 144hz monitor with WaitForVBlank:
144 / 60 = 2 with a remainder of 24. 24/60 can be simplified to 2/5. Based on this, this is my idea:
WaitForVBlank would be called twice every frame. It would be called a third time based on this criteria:
You have a 5 byte circular buffer{ 0, 1, 0, 1, 0 }and you keep track of an indexiinto this buffer. Because it's a circular buffer, ifiever overflows outside the buffer it loops back around to the start. Every frame you take the byte at positioniin the buffer and incrementi. If the byte atiis 1, you WaitForVBlank one more time. If it's 0, you don't
--
Khangaroo
seems to check out
fn main() {
const LAG_FRAMES: &[bool] = &[false, true, false, true, false];
const SECONDS: usize = 60;
let mut lag_idx = 0;
let mut drawn_frames = 0;
let mut time = 0.0;
while time < SECONDS as f64 {
// Wait for vblank twice
time += 2.0 / 144.0;
// Check if we should wait another frame
if LAG_FRAMES[lag_idx % LAG_FRAMES.len()] {
time += 1.0 / 144.0;
}
drawn_frames += 1;
lag_idx += 1;
}
// Drawn frames: 3601, expected 3600
println!("Drawn frames: {}, expected {}", drawn_frames, SECONDS * 60);
}though i wonder how this can be generalized
actually it doesn't seem that hard
fn main() {
const LAG_FRAMES: &[bool] = &[false, false, false, true];
const SECONDS: usize = 60;
let mut lag_idx = 0;
let mut drawn_frames = 0;
let mut time = 0.0;
while time < SECONDS as f64 {
// Wait for vblank
time += 1.0 / 75.0;
// Check if we should wait another frame
if LAG_FRAMES[lag_idx % LAG_FRAMES.len()] {
time += 1.0 / 75.0;
}
drawn_frames += 1;
lag_idx += 1;
}
println!("Drawn frames: {}, expected {}", drawn_frames, SECONDS * 60);
}