I'm working on a web game using HTML5 websockets and Java as backend. Currently creating a new instance of the game class for every player, which also creates a timer with a timer task to run the game loop and send updates to the frontend every 60fps.
As these timers would be very heavy on server resources with alot of players playing, I was thinking to apply the Singleton pattern in the game class and keep an array of matches. Instead of creating a timer for every single player, I would create 1 single timer that updates the game loop with a for loop for every match in the array.
I wonder if there is a better approach, as i've heard there are alot of cons that come with the singleton pattern especially for unit testing.
Aucun commentaire:
Enregistrer un commentaire