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 in either language, with zero runtime overhead.
Why use it?
- Space‑efficient – 1 ×
u16word ≙ 16 flags. Scale from 1 to 4096 words (65 536 flags). - Zero‑cost abstractions – branch‑free bit‑twiddling; compiles to a handful of instructions.
- Header‑only / single‑crate – drop a header (C) or add a tiny dependency (Rust). No heap, no
alloc. - Infinitely scalable – need 10 flags or 10 000? Just resize the array.
- Proven in‑game design – directly mirrors OoT’s save‑file format.
Installation
C / C++
- Copy
oot_bitset.hsomewhere in your include path. - Compile with any C99 (or later) compiler—no extra flags required.
Rust
Add the crate to your Cargo.toml:
[]
= "0.1"
Quick start
C example
;
int
Compile:
Rust example
use ;
Run:
API reference
C functions & macros
static inline uint16_t ; // word (0–4095)
static inline uint16_t ; // bit (0–15)
static inline bool ;
static inline void ;
static inline void ;
Rust equivalents
pub const ;
pub const ;
;
;
;
;
All functions are #[inline(always)] and panic if the slice is too short.
Sizing the array
max_flags = words × 16
words = ceil(max_flags / 16)
Use as few or as many words as your project needs. OoT used 30 words (480 flags), but nothing stops you from using 1 word (16 flags) or 4 096 words (65 536 flags).
Flag encoding
| Bits | 15…4 (12 bits) | 3…0 (4 bits) |
|---|---|---|
| Use | word index | bit index |
| Max | 0–4095 words | 0–15 bits |
Because each hex digit is 4 bits, you can read a flag as “word:bit”.
Example: 0x1AC → word 26, bit 12.
Example output
Words[0] = 0x0004 // FLAG_TALKED_TO_MALON_FIRST_TIME
Words[1] = 0x0401 // FLAG_SAW_BOB | FLAG_SAW_ALICE