Skip to content
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

Avoid "spiral of death" by capping maximum number of ticks per frame #42

Closed
byorgey opened this issue Sep 23, 2021 · 0 comments · Fixed by #215
Closed

Avoid "spiral of death" by capping maximum number of ticks per frame #42

byorgey opened this issue Sep 23, 2021 · 0 comments · Fixed by #215
Labels
Bug The observed behaviour is incorrect or unexpected. C-Low Hanging Fruit Ideal issue for new contributors. S-Moderate The fix or feature would substantially improve user experience. T-UI Involves the user interface. Z-User Experience This issue seeks to make the game more enjoyable to play.

Comments

@byorgey
Copy link
Member

byorgey commented Sep 23, 2021

At the moment, Swarm is susceptible to the "spiral of death" described at https://gafferongames.com/post/fix_your_timestep/ : when the amount of computation we have to do for a frame takes longer than the amount of time allotted for the frame, it starts getting further and further behind. This could in theory be triggered either by a lot of robots doing a lot of computation, or by the user pushing the ticks/second rate too high. If this happens, each frame will take longer than the previous frame and the game will essentially grind to a halt as it tries futilely to catch up but only gets further and further behind.

There is a simple way to avoid this, which is simply to cap the maximum number of ticks per frame (based on my own experience so far, a cap of around 25 seems reasonable). When it hits the cap, the game will slow down: it will essentially be running at a slower ticks/second rate than requested. Perhaps we could signal this by e.g. drawing the ticks per second rate in red, or something like that.

@byorgey byorgey added Bug The observed behaviour is incorrect or unexpected. Z-User Experience This issue seeks to make the game more enjoyable to play. C-Low Hanging Fruit Ideal issue for new contributors. S-Moderate The fix or feature would substantially improve user experience. T-UI Involves the user interface. labels Sep 23, 2021
byorgey added a commit that referenced this issue Oct 12, 2021
This is in order to avoid the "spiral of death", see
https://gafferongames.com/post/fix_your_timestep/.

Set the maximum number of ticks in a single game (arbitrarily) to 30.

To observe this in effect, try going into creative mode, cranking up
the ticks per second to 32 or so, and run `repeat 1000 { build ""
{forever {move; turn left}}}`.  Before applying this PR, it should
grind to a halt after a while.  After this PR, it should keep running,
albeit with lots of lag.

Closes #42.
@mergify mergify bot closed this as completed in #215 Oct 12, 2021
mergify bot pushed a commit that referenced this issue Oct 12, 2021
Cap the maximum number of ticks per frame (arbitrarily) at 30, to
prevent the "spiral of death" (see
https://gafferongames.com/post/fix_your_timestep/).

To see this in effect, go into Creative mode, crank up the ticks per
second to 32 or so, then (for suitable definitions of `repeat` and
`forever`) execute

`repeat 1000 { build "" {forever {move; turn left}}}`

Without this PR, it should eventually grind to a halt.  With this PR,
the game should keep running, though with lots of lag.

Closes #42 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The observed behaviour is incorrect or unexpected. C-Low Hanging Fruit Ideal issue for new contributors. S-Moderate The fix or feature would substantially improve user experience. T-UI Involves the user interface. Z-User Experience This issue seeks to make the game more enjoyable to play.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant