I’m working on a new inventory data format for Shard Seekers. When an equipment slot references an item in the inventory it will use the inventory length to encode the item’s position in an optimal number of bits.
Powers of two are stored normally at their bit depth:
This is better than when it didn’t know the max, but here’s what it can do for other cases:
It omits redundant bits so that every possible state is meaningful.
If the inventory has just 1 item in it, it will actually use 0 bits because it can only be that item. The equip slots are also sorted by item position when saving, so this also applies when it’s the last possible item in the inventory.
It can store this loadout in just 17 bits! (Right sword, left sword, and glasses)
The format is also future-proof, so I can add new equip-points to any of these items without incrementing the save version number.
It’s also storing a delta-encoded slot type for each of the equips. The current slot type just stores the slotId and itemId, but I’m planning on adding a type that stores the item’s dye color too (so that multiple characters can equip the same item using different colors.) It would also be cool to add types that reference multiple items, or types that don’t even reference the inventory (like for equipping spells.)
The sword currently has 2 equip points that can be used, but I could potentially make it so you can equip glasses on your head or in your shirt pocket, or equip a pair of gloves on just one hand.
JSON might be easy to use, but this is just so insanely compact