-
-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
set_loop_mode doesn't limit fps #708
Comments
I'm experiencing the same issue. With app.set_loop_mode(LoopMode::rate_fps(2.0)); I expect update and view to be called every half second to result in 2 frames per second, but the parameter seems to be ignored. |
Thanks for the report @SuperCuber, @sidwellr! In nannou's old I believe at the time of the refactor toward |
An ugly hack to get around this is to put in both if app.elapsed_frames() % 60 != 0 {
return;
} |
Constantly limiting the frame rate like @tqwewe suggested was causing animations to be choppy. I worked around that by adding this code to my render function: use std::sync::atomic::{AtomicU64, Ordering};
static RENDER_TICKS: AtomicU64 = AtomicU64::new(0);
fn should_render(model: &Model) -> bool {
let render_ticks = RENDER_TICKS.load(Ordering::SeqCst);
let should_render = model.ticks != render_ticks;
if should_render {
RENDER_TICKS.fetch_add(model.ticks - render_ticks, Ordering::SeqCst);
}
should_render
}
pub fn view(app: &App, model: &Model, frame: Frame) {
if !should_render(model) {
return
}
// the rest of your view rendering here
} And then incrementing a new This means:
I could see a benefit to combining both approaches and still performing a few renders a second so fewer code paths need to increment |
OS: Windows 10
GPU: GTX1060
Code:
Expected behavior: visually very choppy animation
Actual behavior: fps is synced to monitor refresh rate which is 144hz for me (verified by fps measuring tool)
The text was updated successfully, but these errors were encountered: