From a3073cfa729d4bc2796d6956764d77bde049aad1 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Fri, 4 Apr 2025 04:18:55 -0400 Subject: Stop doing goofy stuff with the timestep --- src/state.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index 1316cf2..09f0f77 100644 --- a/src/state.rs +++ b/src/state.rs @@ -24,6 +24,7 @@ pub struct Response { pub trait Game { fn initialize(&self, ctx: &context::Context, st: &State) -> utils::Erm<()> { Ok(()) } + fn finalize(&self, ctx: &context::Context, st: &State) -> utils::Erm<()> { Ok(()) } fn initialize_audio(&self, ctx: &context::Context, st: &State, actx: &audio::Context) -> HashMap { @@ -485,22 +486,14 @@ impl State { pub fn run_update(&mut self, ctx: &context::Context, game: &mut G) -> utils::Erm<()> where G: Game { let now = now(ctx); - let diff = now - self.last; - self.acc += diff; - self.last = now; - // update, if enough time has accumulated since last update - if self.acc >= DELTA_TIME { - self.acc -= DELTA_TIME; + if diff >= DELTA_TIME { + self.last = now; self.tick += 1; - game.update(ctx, self)?; - - // if a lot of time has elapsed (e.g. if window is unfocused and not - // running update loop), prevent "death spiral" - if self.acc >= DELTA_TIME { self.acc = 0.0 } + self.acc = 0.0; } Ok(()) } -- cgit v1.2.3