Huffman coding

From ioquake3 wiki
Jump to: navigation, search

ioquake3 compresses all of its messages using Huffman coding to save bandwidth. The MSG_WriteBits() function uses Huff_putBit() and Huff_offsetTransmit() to compress data as a message is composed. These functions use a static coding tree that is seeded by MSG_initHuffman(). The contents of the tree is defined in msg_hData, which is presumably tuned to compress typical message data as efficiently as possible.

The NET_OutOfBandData() function uses Huff_Compress() to compress an entire message at once. This function uses adaptive Huffman coding, where every message starts with an empty coding tree.