diff options
| author | LLLL Colonq <llll@colonq> | 2025-04-04 04:18:55 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2025-04-04 04:18:55 -0400 |
| commit | a3073cfa729d4bc2796d6956764d77bde049aad1 (patch) | |
| tree | 56b30f8423a7381b414ace7245f590d6899e6d74 /src/state.rs | |
| parent | 4ba01304ede403816de069357ca5aeff535ccac7 (diff) | |
Stop doing goofy stuff with the timestep
Diffstat (limited to 'src/state.rs')
| -rw-r--r-- | src/state.rs | 15 |
1 files changed, 4 insertions, 11 deletions
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<String, audio::Audio> { @@ -485,22 +486,14 @@ impl State { pub fn run_update<G>(&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(()) } |
