41template <std::u
int32_t IndexBits, std::u
int32_t GenBits>
43 static_assert(IndexBits + GenBits <= 32,
44 "PackedId index+generation must fit in a u32 (keeps the id 4 bytes, "
45 "a JS safe integer, and within box2d's 32-bit wasm32 user-data). "
46 "Widen the storage as a deliberate, ABI-versioned change instead.");
47 static_assert(IndexBits > 0 && GenBits > 0,
"both fields need at least one bit");
50 static constexpr std::uint32_t
GEN_BITS = GenBits;
51 static constexpr std::uint32_t
INDEX_MASK = (std::uint32_t{1} << IndexBits) - 1;
52 static constexpr std::uint32_t
GEN_MASK = (std::uint32_t{1} << GenBits) - 1;
63 return (raw >> IndexBits) &
GEN_MASK;
71 static constexpr std::uint32_t
pack(std::uint32_t index, std::uint32_t generation) {
Index+generation packing into a u32, parameterized by the bit split.
static constexpr std::uint32_t generationOf(std::uint32_t raw)
Extract the generation from a packed value.
static constexpr std::uint32_t maxIndex()
Largest representable slot index.
static constexpr std::uint32_t INDEX_MASK
static constexpr std::uint32_t pack(std::uint32_t index, std::uint32_t generation)
Pack an index + generation. Out-of-range inputs are masked, not trusted — callers that mint ids from ...
static constexpr std::uint32_t maxGeneration()
Largest representable generation before it wraps.
static constexpr std::uint32_t INDEX_BITS
static constexpr std::uint32_t indexOf(std::uint32_t raw)
Extract the slot index from a packed value.
static constexpr std::uint32_t GEN_BITS
static constexpr std::uint32_t GEN_MASK