Skip to content

Game Pauses When One Player Backgrounds a Tab #76

@rameshvarun

Description

@rameshvarun

Right now, for both rollback and lockstep netcode, if one user backgrounds their tab, the game will totally freeze. Currently it’s not that big of an issue since we only support two-player games anyway, but as we move on to >2 players this problem must be solved.

Right now the main loops of both netcode implementations look something like this.

start() {
  setInterval(() => {
    this.tick();
  }, this.timestep);
}

The problem is that the browser will stop calling setInterval (and other callbacks like requestAnimationFrame) when the tab is backgrounded meaning that the game wont tick anymore.

The good news is that this is solvable. Even when backgrounded, the pages are responding to messages on the RTCDataChannel, meaning that event listeners are being run. We should be able to tick during these event listeners, though this will require some changes to the main loops to make this possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions