Data Compression

Blitz3D Forums/Blitz3D Programming/Data Compression

ringwraith(Posted 2008) [#1]
What is the most efficient way to compress packets for a network game? I've looked through the code archives and forums can't seem to find anything definitive.


Jasu(Posted 2008) [#2]
Packet compressing is not as important as narrowing down data being sent over (size and frequency). Actually I think that compression is an overkill unless you are talking about packets around 1kB. If you are sending binary data only, avoid using integers and floats whenever possible as they take 4 bytes each.

If you are sending text data, then it's a different case. If I recall correcly, netgames usually have compression algorithms for text that include short codes for words commonly used, like 'frag' 'LOL' or 'noob' (poor examples, I know ;). Building such a compression a bit devious task and I don't believe that there are such available for free. If at all publicly.


GrahamK(Posted 2008) [#3]
Wot Jasu says!

Unless there is a lot of data to be moved (which isn't advisable) then it may end up taking more time to compress/decompress than it will to actually send it raw.

(it's also much easier to debug if its uncompressed)


Snarkbait(Posted 2008) [#4]
zlib...


ringwraith(Posted 2008) [#5]
I've already taken into account what you've said Jasu and Graham(the largest variable I'm sending is 2 bytes), but nonetheless, compression might be neccessary in certain extreme cases for my game if a packet exceeds a certain size.

Snarkbait, is there any way to get ZLib for Blitz?


Snarkbait(Posted 2008) [#6]
Yep, several ways...

one way is Phil Newtons Blitz ZipAPI libray, found here:
http://www.sodaware.net/dev/blitz/libs/blitz.zipapi/

That's a complete implementation, however if you need just the compress/decompress routines you can use simpler functions, and zlib is very fast for smaller chunks of data... (I can provide if you need)

Another trick to use for sending simple variables (if you send a lot of boolean variables) is to pack them into one byte as 8 bitflags.