Keep a big simulation from freezing after the player switches tabs and comes back
Your city simulation runs at a fixed pace, but when the browser pauses the game for a minute, it tries to make up all the missed steps at once and the screen locks up. Here is the loop that catches up in a controlled way and what to throw away.
Why this works
The world should move in equal small steps, so the result does not depend on how fast the screen draws. But catching up on a long pause makes the next frame slower, which makes the next pause longer. The only way out is to cap the work and knowingly forget the rest.
When not to use it
Not for anything where every missed second counts, such as a build timer or a growing farm. Throwing time away cheats the player there, so use the away calculation instead. Turn-based games need none of it, since they only move when the player acts.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 2 common mistakes and the fix
- 14 lines of example code with 4 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "Keep a big simulation from freezing after the player switches tabs and comes back" (read_entry fixed-timestep-catchup-limit) in my game. Build it step by step, and show me how you checked that it works.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP