-
Notifications
You must be signed in to change notification settings - Fork 77
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
How to sleep in the main game loop? #580
Comments
assuming quicksilver 3: the update and draw function get executed as often as specified in the settings https://docs.rs/quicksilver/0.3.20/quicksilver/lifecycle/struct.Settings.html For quicksilver 4: I believe the same is true, but then for the events. (I may be wrong on that as I haven't used that version yet). Either way, you shouldn't have a need to sleep yourself |
@PonasKovas I'm assuming from your error that you're running the web backend, where the As @lenscas mentioned, the |
Are there any plans on how to implement that? I may want to contribute |
I don't have firm plans yet; one draft design would look something like: pub struct Timer { ... }
impl Timer {
pub fn new(period_in_ms: f32) -> Timer { ... }
pub fn tick(&mut self) -> bool { ... }
pub fn ms_remaining(&self) -> f32 { ... {
} with a usage pattern that looks roughly like: loop {
// handle events
if update.tick() {
// handle update
}
if draw.tick() {
// handle draw
} A good reference is Fix Your Timestep when implementing timing functionality. |
I've implemented sleep (works in all build targets - desktop/stdweb/web-sys) in https://crates.io/crates/quicksilver-utils-async |
@PonasKovas check out the new timer example, this should let you lock your update and draw rates to whatever speeds you like. |
I'm used to having game loops somewhat like this:
But I doing this on quicksilver appears to break the app: the game gets stuck on the first frame and I get a bunch of
RuntimeError: unreachable executed
errors in the console.How am I supposed to get 60 fps (and not more)?
The text was updated successfully, but these errors were encountered: