Posted: 15th Oct 2004 10:29
I am working on a pretty complicated multiplayer game at the moment, and I need some help deciding how to send data. This is an action game, kinda like Battlefield 1942, including the vehicles. This is a server-client game, because the server handles most of the code.
I already have all the parts dealing with connecting, loading, processing the data and the basic gameplay options. I even have a way of sending data, so I DID manage to make the game work and play online.
The problem is, the way of exchanging data is so inefficient that I get 40 fps with just two players and only half of the gaming options! Just walking, turning, driving vehicles and basic collision, so the fps drop (from about 500 without any clients connecting to the server) is because of the sending problems.
Most of the game's data is stored in two arrays, one for the players and one for the vehicles. The vehicles array has a fixed size, and the players array is dynamic, changing when clients connect and disconnect. I need to copy these arrays, stored in the server, to all the clients, so they will share the same data. The way I did it so far is the simplest, but the least efficient – I just created a memblock from them and sent it to all the clients. This resulted in a 2.5kb memblock and the fps drop mentioned above. It is obvious I can't continue this way, so I need to find a better way to send the data.
I need to send only the data that has changed during the last cycle. I don't need to send everyone the coordinates of a player that stayed on the same place. I just don't know how to do it well enough. As I understand it, you can't send anything during cycles, only in the end. So I can't send new data as I change it. There are two options that I see: To send lots of individual details, each with an "address", so the clients will know where to put it, or to send entire array cells.
The first way is the most accurate, sending only the information that has changed, but the server will need to keep track of the information that has changed (to send only the new speed, and not the angle, for example) and you will have to add two bytes before every piece of information, to tell the client that "12.5" stands for speed, and not health. So the final memblock, made from combining all the new information, might not be small enough.
The second way is less effective, but easier and can save clock cycles. Instead of sending just the new angle of a player, you send all the information about the player – speed, angle, location, condition, health. You don't need, however, to send his nickname. Most of the time all those parameters change together. This way you can only track WHO changed, and not WHAT changed, saving memory and time. You also don't need to tell the clients what is the meaning of every piece of information, just the number of the player / vehicle. The problem is that the memblock size will probably be bigger.
So, what do you think is the best method? I will be glad if you will help me choose, or suggest another way.
Thanks.