Zemanzo / web-marbles

Aims to recreate Marble Racing from the ground up, as a fully web based game
https://playmarbl.es/
GNU General Public License v3.0
23 stars 12 forks source link

Bugfix: Inactive tab / network buffer issue #298

Closed Qaomen closed 3 years ago

Qaomen commented 3 years ago

Fixes the increasing network delay issue when the client page is an inactive tab for a while.

Previously, game/network updates were triggered by the rendering only. This generally worked fine, except that the rendering loop slows significantly when the tab isn't active, causing the network to still receive data while the update functions weren't called. This pull request adds a simple updateManager module to create a more centralized way of adding update functions to a list and allows any other module to trigger an update (instead of completely leaving it the renderer's responsibility).

Because the network packets stop right after the end of a race (as there's no new data to send at that time), there is a tiny bit of network buffer left at the end of a race that doesn't get processed immediately if the tab stays inactive. This would still cause a "delay", unless the client switches back to the tab again at some point or once the game state changes from finished to waiting. I'd consider this only a small issue, and given how the solution to that would involve creating a worker thread to periodically force updates I don't it's worth addressing.

Referencing issues Closes #232