Huffman coding

From ioquake3 wiki
Jump to navigation Jump to search

ioquake3 compresses all of its messages using Huffman coding to save bandwidth. The {{#ifexist:MSG_WriteBits|MSG_WriteBits()|MSG_WriteBits()}} function uses {{#ifexist:Huff_putBit|Huff_putBit()|Huff_putBit()}} and {{#ifexist:Huff_offsetTransmit|Huff_offsetTransmit()|Huff_offsetTransmit()}} to compress data as a message is composed. These functions use a static coding tree that is seeded by {{#ifexist:MSG_initHuffman|MSG_initHuffman()|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 {{#ifexist:NET_OutOfBandData|NET_OutOfBandData()|NET_OutOfBandData()}} function uses {{#ifexist:Huff_Compress|Huff_Compress()|Huff_Compress()}} to compress an entire message at once. This function uses adaptive Huffman coding, where every message starts with an empty coding tree.