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

Game Pauses When One Player Backgrounds a Tab #76

Open
rameshvarun opened this issue Mar 24, 2023 · 0 comments
Open

Game Pauses When One Player Backgrounds a Tab #76

rameshvarun opened this issue Mar 24, 2023 · 0 comments

Comments

@rameshvarun
Copy link
Owner

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.

@rameshvarun rameshvarun changed the title The Browser Pause Problem Game Pauses When One Player Backgrounds a Tab Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant