I'm creating a multiplayer game using LibGdx (with Box2d) and Kryonet. Since this is the first time I work on multiplayer games, I read a bit about server - client implementations, and it turns out that the server should handle important tasks like collision detection, hits, characters dying etc...
Based on some articles (like the excellent Gabriel Gambetta Fast paced multiplayer series), I also know that the client should work in parallel to avoid the lag while the server responds to commands.
Physics wise, each game will have 2 players, and any projectiles fired.
What I'm thinking of doing is the following:
Create a physics world on the client
When the game is signaled to start, I create the same physics world on the server (without any rendering obviously).
Whenever the player issues a command (move or fire), I send the command to the server and immediately start processing it on the client.
When the server receives the command, it applies it on the server's world (set velocity etc...)
Each 100ms, the server sends the new state to the client which corrects what was calculated locally.
Any critical action (hit, death, level up) is calculated only on the server and sent to the client.
Essentially, I would have a Box2d World object running on the server for each game in progress, in sync with the worlds running on the clients.
The alternative would be to do my own calculations on the server instead of relying on Box2D to do them for me, but I'm trying to avoid that.
My question is:
- Is it wise to have, for example, 1000 instances of the World object running and executing steps on the server? Tomcat used around 750 MBytes of memory when trying it without any object added to the world. Anybody tried that before?
- If not, is there any alternative? Google did not help me, are there any guidelines to use when you want to have physics on both the client and the server?
Thanks for any help.