OoT Bitset
A no‑frills, zero‑overhead flag system inspired by The Legend of Zelda: Ocarina of Time
Implemented in C / C++, and Rust
Need to pack hundreds (or thousands) of one‑bit flags—“talked to an NPC”, “opened a chest”, etc.—into a save file without wasting bytes? Ocarina of Time solved this by storing flags in an array of uint16_t words. oot_bitset offers the same trick!
I learned about this technique from reading the OoT decompilation project source code. See the original code that implements these flags for OoT's save file event information tables.
Why use it?
Simple, header‑only, zero deps – drop a header (C) or add a tiny dependency (Rust). No heap, no alloc .
– drop a header (C) or add a tiny dependency (Rust). No heap, no . Space‑efficient – 1 × u16 word ≙ 16 flags. Scale from 1 to 4096 words (65 536 flags).
– 1 × word ≙ 16 flags. Scale from 1 to 4096 words (65 536 flags). Fast – branch‑free bit‑twiddling; compiles to a handful of instructions.
– branch‑free bit‑twiddling; compiles to a handful of instructions. Scalable – need 10 flags or 10 000? Just resize the array.
... continue reading