I am thinking about creating a networking game.
The game should be a 2D platform shooter, created with Libgdx and Box2D.
For the networking I planed following structure:
view frustum
First question: What do you think about this structure?
Next question: 45 times per second could be a lot of data upload from the serverside, if there are a few players which shoot a lot of bullets (player and bullet positions need to be send).
To limit the upload needed i thought about using view frustum culling
and send only the data/updates the client will actually see.
Now i have seen the KryoNet
method sendToAllTCP
and wondered, if this method is somehow more efficient and could somehow upload the data only once, instead of once per client.
I am not that experienced with networking and i don't really think that it is possible to have 1 upload for more then one client. But to be sure i ask.
So is it more efficient to send every update of the level with sendToAllTCP
or is it more efficient to send once for every client and then only things they can see?
KryoNet is open source, and you can see what it is doing here: https://github.com/EsotericSoftware/kryonet
The sendToAllTCP
method is here:
https://github.com/EsotericSoftware/kryonet/blob/master/src/com/esotericsoftware/kryonet/Server.java#L447
The sendToAllTCP
method just loops over the TCP connections and sends the same data to each one. There is a comment in the source that they should only be serializing the data once, and send the serialized object multiple times, but its not doing that yet.
Generally, the ability to send data to multiple hosts on a single send is called "multicast". For lots of reasons it is not generally available and is only useful in highly specialized situations. See http://www.tcpipguide.com/free/t_IPMulticasting.htm
The performance problems you're going to run into are more likely around internet latency than on the server's raw ability to send packets. I wouldn't worry too much about optimizing TCP connection sends just yet.