How to package network data?

Blitz3D Forums/Blitz3D Programming/How to package network data?

Vorderman(Posted 2006) [#1]
Is there a best way to package up (mostly floating point) data for packet transmission? Currently I'm using a modified version of the example code that came with Blitzplay Lite, shown below.

Ideally I'd like to transmit more than just the simple things shown below, including more trivial things like the position and orientation of each individual wheel, the driver's head and arms positions, exhaust flames etc..., but not if it means transmitting huge packets.

Is there a better way?


Type TYPE_netdata
	Field x#,y#,z#
	Field yaw# , pitch# , roll#
	Field velx# , vely# , velz#
	
	Field name$
	Field net_id%
	
	Field mesh
End Type


			pnet.TYPE_netdata = First TYPE_netdata

			pnet\x# = EntityX#(GAMEDATA\vehicle1\chassis_mesh , True)
			pnet\y# = EntityY#(GAMEDATA\vehicle1\chassis_mesh , True)
			pnet\z# = EntityZ#(GAMEDATA\vehicle1\chassis_mesh , True)
			pnet\pitch# = EntityPitch#(GAMEDATA\vehicle1\chassis_mesh , True)
			pnet\yaw# = EntityYaw#(GAMEDATA\vehicle1\chassis_mesh , True)
			pnet\roll# = EntityRoll#(GAMEDATA\vehicle1\chassis_mesh , True)
			pnet\velx# = TOKRB_GetVelocityX#(GAMEDATA\vehicle1\chassis_RB)
			pnet\vely# = TOKRB_GetVelocityY#(GAMEDATA\vehicle1\chassis_RB)
			pnet\velz# = TOKRB_GetVelocityZ#(GAMEDATA\vehicle1\chassis_RB)

			msgtosend$ = BP_FloatToStr(pnet\x#) + BP_FloatToStr(pnet\y#) + BP_FloatToStr(pnet\z#) 
			msgtosend$ = msgtosend$ + BP_FloatToStr(pnet\pitch#)  + BP_FloatToStr(pnet\yaw#)  + BP_FloatToStr(pnet\roll#)
			msgtosend$ = msgtosend$ + BP_FloatToStr(pnet\velx#)  + BP_FloatToStr(pnet\vely#)  + BP_FloatToStr(pnet\velz#)

			If UI\NETWORK_sendupdates 
				BP_UDPMessage (0,1,msgtosend)
			EndIf




Ross C(Posted 2006) [#2]
Just a quick point, but exhaust flames should not really be transmitted, if it's just an effect.


degac(Posted 2006) [#3]
Stupid question: why don't transmit only the difference?
I mean: if an entity is stopped, but it is still rotating, you can send only the rotation axes (eg: roll).
That's only an idea, I don't have any practice in networking game and I don't know 'how much cost' checking if there is some data to transmit...
byez


KuRiX(Posted 2006) [#4]
The best way is to send the data as you are doing it, voderman, it is the most accuracy solution, but not the most efficient.

There is other aproximation, and i will try to tell you:

- You are sending the velocity of the objects, and perhaps the velocity won't be great that some value, for example 100.

Then you can convert the float to integer, and send it like 2 bytes.

For example, the float: 2,144 can be sent as 2 bytes as the integer 2144, then in the other side you can convert it to float again.

The problem is the accuracy, because if you can have velocities like: 34,123145 then you can't store that number in 2 bytes, but what's the problem about sending the integer 34123??? The error is not accumulative so you won't notice the difference.

Good luck!


Vorderman(Posted 2006) [#5]
Just a quick point, but exhaust flames should not really be transmitted, if it's just an effect.

It was an example only, what I'm interested in is the most efficient way to package up floating-point data.

The problem is the accuracy, because if you can have velocities like: 34,123145 then you can't store that number in 2 bytes, but what's the problem about sending the integer 34123??? The error is not accumulative so you won't notice the difference.

Hmm, I could certainly lose the accuracy, especially on the more trivial items.

Are there any compression techniques for packing data into fewer bytes?

How can I quantify the amount of network data being sent as too much or too little? - I have no idea if I should be OK sending strings of 10 chars or strings of 10000. I imagine FPS games send more as they have to account for 16 or 32 players, vehicles, bullets, explosions etc... All I have to account for is 4 vehicles.


Damien Sturdy(Posted 2006) [#6]
I do what Kurix does in my Racer-

Convert the velicities into ints-

and I personally COULD convert the rotation into a byte- which doesnt always work too well, but it certainly lowers traffic

Since i'm being pretty unefficient in that I'm also sending wheel locations, i DO set those rotations to bytes- since they don't need to be that accurate and since theyre small you wont really notice.

Overall, the racer works dandy over the internet, with the problem being the amount of time it takes the signal to reach the other side rather than network glitches.