I'm making a multiplayer game using socketio + nodejs. Currently I use setInterval on my server and requestAnimation on my client render. Now I want to create multiple game instances for each room and so I ask how to do so efficiently:
- Do I initialize a new setInterval for every game created and call clearInterval when that game ends? or...
- Should I create only one instance of setInterval and loop through each active game and update them?
- Should I be using setInterval at all?
EDIT: For clarification, my current single setInterval simply does this at about 15hz:
-update each player position based on input
-notify all clients of new positions
input is received as soon as the client sends them, handled by socketio. Sending this many emits is intentional because my server is authoritative and my game is slow (imagine a snakes clone). I intend to allow as many games as there are rooms, which is indefinite (or as many as one server can handle)