Data Compression Overview

Description
RakNet can automatically compress all your outgoing data and decompress your incoming data. To do this, it needs a 'sample' frequency table for your average game so it can pre-compute how to encode the data to get maximum savings. Here is the general process of how to go about this:

1. Run a sample 'average' game. Get the frequency table for the server and for one of the clients (or average all the clients if you want).
2. Generate the decompression layer for the server from the client's frequency table
3. Generate the compression layer for the server from the server's frequency table
4. Generate the decompression layer for the client from the server's frequency table
5. Generate the compression layer for the client from the client's frequency table.

After that everything is handled automatically.
The functions are described below. See Samples\Code Samples\Compression for a full example.

Data Compression Functions

GenerateCompressionLayer(unsigned long inputFrequencyTable[256], bool inputLayer)
Given a frequency table returned by GetSendFrequencyTable, this will generate the internal compression layer. You need to call this twice, one with inputLayer as true and one time as false. inputLayer as true means input - i.e. The server to client frequency table when we are the client and the client to server frequency table when we are the server. We need two layers because the data the server sends is usually quite different than what the client sends, so we can't use the same compression layer for both. See RakServerInterface.h and RakClientInterface.h for the full header description.
DeleteCompressionLayer(bool inputLayer)
This will free the memory for an existing compression layer. As before, you specify either the input layer or the output layer.
GetSendFrequencyTable(unsigned long outputFrequencyTable[256])
Returns the frequency table of all bytes already sent.
float GetCompressionRatio
This returns a number n > 0.0f where lower numbers are better. n == 1.0f means your data is no smaller or greater than the original. This shows how effective your compression rates are.
float GetDecompressionRatio
This returns a number n > 0.0f where higher numbers are better. n == 1.0f means the incoming data was decompressed to be just as large as it was when it came in. This shows how effective your compression rates are.

See Also

Index