fu5ha / ggez_snake

25 stars 3 forks source link

Suggestion for limiting the update frequency #1

Open blackgear opened 6 years ago

blackgear commented 6 years ago

In ggez 0.4, we could use check_update_time() to limit the update frequency:

https://docs.rs/ggez/0.4.2/ggez/timer/fn.check_update_time.html

fn update(&mut self, ctx: &mut Context) -> GameResult<()>
    while(timer::check_update_time(ctx, 60)) {
        update_game_physics()?;
    }
    Ok(())
}

Instead of

fn update(&mut self, ctx: &mut Context) -> GameResult<()>
    if Instant::now() - self.last_update >= Duration::from_millis(MILLIS_PER_UPDATE) {

    }
    Ok(())
}
fu5ha commented 6 years ago

Hey thanks for this. You're absolutely right; I'll try to update this soon, or if you make a PR I'd be happy to merge it :)