Add non-blocking update function#72
Conversation
rfuest
left a comment
There was a problem hiding this comment.
Thanks for the PR.
I would prefer to implement this in another way, without requiring two variants of the update method. There is already a way to change the target FPS via Window::set_max_fps and MultiWindow::set_max_fps and the option to disable the FPS limit should be accessible in a similar way. I would suggest to add disable_fps_limit methods to Window and MultiWindow, which set the fps_limiter field to None.
|
I wanted to avoid having an What if the check is in fn sleep(&mut self) {
if self.max_fps == 0 {
return;
}
let sleep_duration = (self.frame_start + self.desired_loop_duration())
.saturating_duration_since(Instant::now());
thread::sleep(sleep_duration);
self.frame_start = Instant::now();
}This way the Window functions do not need any modification and the fps limit can be adjusted flexibly |
Why do you want to avoid this? This doesn't seem bad to me: pub fn update<C>(&mut self, display: &SimulatorDisplay<C>)
where
C: PixelColor + Into<Rgb888> + From<Rgb888>,
{
...
if let Some(fps_limiter) = self.fps_limiter.as_mut() {
fps_limiter.sleep();
}
}Using |
It is not possible to later restore the FpsLimiter if needed
Then it should be Option<NonNull<u32>> |
Why not? Calling
Inside the |
|
Okay updated the PR, please check if it is good |
rfuest
left a comment
There was a problem hiding this comment.
Not really what I was thinking, because it still uses 0 as a special value in set_max_fps. But I'm OK with merging this, when you change the documentation of the set_max_fps methods to mention that 0 has a special meaning.
Co-authored-by: Ralf Fuest <mail@rfuest.de>
Co-authored-by: Ralf Fuest <mail@rfuest.de>
|
Ok done |
Thank you for helping out with embedded-graphics-simulator development! Please:
CHANGELOG.mdentry in the Unreleased section under the appropriate heading (Added, Fixed, etc) if your changes affect the public APIrustfmton the projectjust build(Linux/macOS only) and make sure it passes. If you use Windows, check that CI passes once you've opened the PR.PR description
Resolves #70