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

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

#include <ActorUniqueID.h>

Public Member Functions

 ActorUniqueID ()
 Constructs an invalid ActorUniqueID.
 ActorUniqueID (u32 id)
 Constructs an ActorUniqueID from a raw 32-bit packed value containing both the array index and create index.
 ActorUniqueID (u32 i_array_index, u32 i_create_index)
 Constructs an ActorUniqueID 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 ActorUniqueID &lhs, const ActorUniqueID &rhs)
 Compares two ActorUniqueIDs for equality.
bool operator!= (const ActorUniqueID &lhs, const ActorUniqueID &rhs)
 Compares two ActorUniqueIDs 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

◆ ActorUniqueID() [1/3]

ActorUniqueID::ActorUniqueID ( )
inline

Constructs an invalid ActorUniqueID.

◆ ActorUniqueID() [2/3]

ActorUniqueID::ActorUniqueID ( u32 id)
inline

Constructs an ActorUniqueID 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.

◆ ActorUniqueID() [3/3]

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

Constructs an ActorUniqueID 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 ActorUniqueID::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 ActorUniqueID::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 ActorUniqueID::getValue ( ) const
inline

The raw 32-bit packed value of this ID.

◆ getArrayIndex()

u32 ActorUniqueID::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 ActorUniqueID::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 ActorUniqueID::isValid ( ) const
inline

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

◆ invalidate()

void ActorUniqueID::invalidate ( )
inline

Clears the ID, setting it back to cInvalidID.

◆ operator==

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

Compares two ActorUniqueIDs for equality.

◆ operator!=

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

Compares two ActorUniqueIDs for inequality.

Member Data Documentation

◆ cInvalidID

const u32 ActorUniqueID::cInvalidID = 0
static

Represents an invalid or uninitialized ID.

◆ cArrayIndexMax

const u32 ActorUniqueID::cArrayIndexMax = 0x3ff
static

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

◆ cCreateIndexMax

const u32 ActorUniqueID::cCreateIndexMax = 0x3fffff
static

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

◆ mValue

u32 ActorUniqueID::mValue
private

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