Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / What is the best way to send data?

Author
Message
AciDucK
21
Years of Service
User Offline
Joined: 13th Aug 2003
Location:
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.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 15th Oct 2004 11:23
I will post a better answer when I have time, but based on my experience with DarkTOPIA I'd code the client in dbp (obviously) but seek another solution for the server application (C++,Java,.NET). DarkTOPIA uses a dbp-java solution.


DBP_NETLIB_v1.4.3 DarkTOPIA site coming soon!
AciDucK
21
Years of Service
User Offline
Joined: 13th Aug 2003
Location:
Posted: 19th Oct 2004 23:25
Anyone? It is a simple questions, and I just need this little advice in order to continue my work. I'm sure it will help the community as well, because there are probably others that need to send large amounts of information.
Karlos
22
Years of Service
User Offline
Joined: 18th Nov 2002
Location: United Kingdom
Posted: 19th Oct 2004 23:50
First things first - don't send the data before every sync - just send 1 in 5 or 10 or so.

don't create the memlock from an array.

create your own simple datablock.
byte 1 = player number
bytes 2-5 = xpos
bytes 6-8 = ypos

etc etc

use integers rather than floats for your data if you can.

try to track changes only - and put a header in your memblock - you only need 1 byte to tell the server what type of data it is.


good luck

All Hail the Glory of the HypnoToad
XP Pro - Radeon 9000 Mobility- P4 3.0ish
Football management - Football Manager
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 20th Oct 2004 02:17
Why? Ints and Floats are the same size.. The only difference is their range as far as I know.. I think a float can hold less +/-"0" than an int..

I may be wrong tho.. Could have sworn they were both 32bit numbers.

Apart from that your method sounds about as good as it gets.

You CAN optimise it if ur clever for prediction.. eg calculate the lag offset and then calculat the position based on the current pos + lag*speed.. That way the syncing should less effort..

AciDucK
21
Years of Service
User Offline
Joined: 13th Aug 2003
Location:
Posted: 21st Oct 2004 00:53
Thanks! I will try it, and I hope I will get enough FPS to run the game smoothly.
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 21st Oct 2004 01:26
well if you do as Karlos suggested - only send it every few frames..

Maybe not even FPS based.. have a variable that increments by the frameTime in millis or whatever and send data ever 0.25s or 0.1s
An idea..?!

anomer
20
Years of Service
User Offline
Joined: 11th Oct 2004
Location: City of Tears
Posted: 21st Oct 2004 13:46
imo floats are faster than integers, just less acurate.

~fades

Login to post a reply

Server time is: 2025-06-12 10:57:56
Your offset time is: 2025-06-12 10:57:56