4 ms·
I played a game that implemented something like this. A player could have 32 buffs simultaneously, and on release there were fewer than 255 unique buffs. The id
by tvb12 6y ago
I played a game that implemented something like this. A player could have 32 buffs simultaneously, and on release there were fewer than 255 unique buffs. The id for each buff was stored in one byte and was bundled along with all of the other buffs into a much larger packet which also contained other player data.
The game later surpassed 255 unique buffs. Rather than change the packet structure, they repurposed a group of 64 bits which had previously been padding. Each buff id could then be unpacked by using the nth pair of bits from the block of 64 as the two high bits, and tacking on the original byte as the lower eight.
- pishpash 6y agoOr use compression, people used to do that.
- r3trohack3r 6y agoA byte can represent 256 unique values. 256 unique values can not be compressed to less than a byte. Proof is left as an exercise for the reader.
- chrismcb 6y agoI think the idea was the group of ids could be compressed. Rather than storing up to 64 ids as 8 bus plus the high bit elsewhere, store them as 9 bits, then compress the chunk. But honestly, that is probably more work than it is worth. Storing the high but elsewhere is simple.
- tvb12 6y agoSorry for the late reply -- this is my weekend this week! I remember reading that the packets were encrypted using blowfish and compressed using a custom Huffman table. There's a lot of bit-packing in the game's packets, so I initially thought it was strange that they didn't use 10 bits for each id and pack all 32 in a row. I'm not very knowledgeable, but my guess is that wasn't done because it would right-shift the rest of the chunk by 64 bits. They would then have to go through the code for unpacking and increase the offset for each field. I believe the ids were right at the start of the chunk, and there were almost 30 other fields. Also, there was always a belief that the game's code was a fine spaghetti. A part of me wonders if the chunk was actually unpacked in multiple places, which would make correcting the offsets that much more tedious.