Now I have a 2D tds browser shooter. On the node server, for physics, I use the 2D MatterJs engine. Now simple mechanics are implemented: synchronization of player movements, shooting, shop. At the moment, the server code has the following structure:
var gameObjects={players:{},walls:{},bases:{}}; // здесь хранится инфа о игроках и других объектах // launch game cycle setInterval(function(){ Matter.Engine.update(engine, engine.timing.delta); //обновление физики },1000/60) io.on('connection', function (socket) { socket.player=createPlayer(socket); socket.on("....",function(){}); socket.on("....",function(data){}); socket.on("....",function(data){}); socket.on("....",function(data){}); socket.on("....",function(data){}); socket.on("....",function(data){}); }); And here is the question. How to implement the room (session)? I came up with this option:
var rooms=[ {players:{},walls:{},bases:{},engine:setInterval(...,1000/60)}, {players:{},walls:{},bases:{},engine:setInterval(...,1000/60)}, {players:{},walls:{},bases:{},engine:setInterval(...,1000/60)} ] Suppose that in one room there can be maxN players, if N players> maxN, then throw them into the next room.
And one question is off topic. Do I need to somehow distribute the load on the server? Flows etc?