New Super Mario Bros. U Headers
Loading...
Searching...
No Matches
UniqueID Class Reference

Safe identifier handle used as an alternative to raw actor pointers. More...

#include <UniqueID.h>

Public Member Functions

 UniqueID ()
 Constructs an invalid UniqueID.
 UniqueID (u32 id)
 Constructs an UniqueID from a raw 32-bit packed value containing both the array index and create index.
 UniqueID (u32 i_array_index, u32 i_create_index)
 Constructs an UniqueID by packing a physical index and a global generation index.
void setValue (u32 id)
 Overwrites the ID with a raw 32-bit packed value containing both the array index and create index.
void setValue (u32 i_array_index, u32 i_create_index)
 Overwrites the ID by packing a physical index and a global generation index.
u32 getValue () const
 The raw 32-bit packed value of this ID.
u32 getArrayIndex () const
 Extracts the physical array index where this actor is stored.
u32 getCreateIndex () const
 Extracts the global generation counter assigned to this actor at creation.
bool isValid () const
 Whether this ID has been assigned a valid value (not equal to cInvalidID).
void invalidate ()
 Clears the ID, setting it back to cInvalidID.

Static Public Attributes

static const u32 cInvalidID = 0
 Represents an invalid or uninitialized ID.
static const u32 cArrayIndexMax = 0x3FF
 The maximum allowed array index (10 bits; 1023).
static const u32 cCreateIndexMax = 0x3FFFFF
 The maximum allowed global create index (22 bits; 4,194,303)

Private Attributes

u32 mValue
 The raw 32-bit packed value containing both the array index and create index.

Friends

bool operator== (const UniqueID &lhs, const UniqueID &rhs)
 Compares two UniqueIDs for equality.
bool operator!= (const UniqueID &lhs, const UniqueID &rhs)
 Compares two UniqueIDs for inequality.

Detailed Description

Safe identifier handle used as an alternative to raw actor pointers.

Combines a physical ActorPtrCache array index with a global generation counter. This ensures that recycled array slots are never misidentified as the original actor.

Constructor & Destructor Documentation

◆ UniqueID() [1/3]

UniqueID::UniqueID ( )
inline

Constructs an invalid UniqueID.

◆ UniqueID() [2/3]

UniqueID::UniqueID ( u32 id)
inlineexplicit

Constructs an UniqueID from a raw 32-bit packed value containing both the array index and create index.

Parameters
idThe raw 32-bit representation of the desired ID to create.

◆ UniqueID() [3/3]

UniqueID::UniqueID ( u32 i_array_index,
u32 i_create_index )
inline

Constructs an UniqueID by packing a physical index and a global generation index.

Parameters
i_array_indexThe 10-bit physical index in the ActorPtrCache array.
i_create_indexThe 22-bit global generation counter.

Member Function Documentation

◆ setValue() [1/2]

void UniqueID::setValue ( u32 id)
inline

Overwrites the ID with a raw 32-bit packed value containing both the array index and create index.

Parameters
idThe raw 32-bit representation of the desired ID to set.

◆ setValue() [2/2]

void UniqueID::setValue ( u32 i_array_index,
u32 i_create_index )
inline

Overwrites the ID by packing a physical index and a global generation index.

Parameters
i_array_indexThe 10-bit physical index in the ActorPtrCache array. Must be <= cArrayIndexMax.
i_create_indexThe 22-bit global generation counter. Must be <= cCreateIndexMax.

◆ getValue()

u32 UniqueID::getValue ( ) const
inline

The raw 32-bit packed value of this ID.

◆ getArrayIndex()

u32 UniqueID::getArrayIndex ( ) const
inline

Extracts the physical array index where this actor is stored.

Returns
The 10-bit array index (top bits of the packed ID).

◆ getCreateIndex()

u32 UniqueID::getCreateIndex ( ) const
inline

Extracts the global generation counter assigned to this actor at creation.

Returns
The 22-bit create index (bottom bits of the packed ID).

◆ isValid()

bool UniqueID::isValid ( ) const
inline

Whether this ID has been assigned a valid value (not equal to cInvalidID).

◆ invalidate()

void UniqueID::invalidate ( )
inline

Clears the ID, setting it back to cInvalidID.

◆ operator==

bool operator== ( const UniqueID & lhs,
const UniqueID & rhs )
friend

Compares two UniqueIDs for equality.

◆ operator!=

bool operator!= ( const UniqueID & lhs,
const UniqueID & rhs )
friend

Compares two UniqueIDs for inequality.

Member Data Documentation

◆ cInvalidID

const u32 UniqueID::cInvalidID = 0
static

Represents an invalid or uninitialized ID.

◆ cArrayIndexMax

const u32 UniqueID::cArrayIndexMax = 0x3FF
static

The maximum allowed array index (10 bits; 1023).

◆ cCreateIndexMax

const u32 UniqueID::cCreateIndexMax = 0x3FFFFF
static

The maximum allowed global create index (22 bits; 4,194,303)

◆ mValue

u32 UniqueID::mValue
private

The raw 32-bit packed value containing both the array index and create index.