NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches

#include <game/bases/d_cc.hpp>

Description

Collider ("Collision Check") class - handles collisions between actors.

It also includes logic that handles collisions within a horizontally looping stage (like 2-C).

Definition at line 111 of file d_cc.hpp.

Classes

class  U32Holder
 < More...
struct  GlobalData_t

Public Member Functions

 dCc_c ()
 Constructs a new collider.
virtual ~dCc_c ()
 Destroys the collider.
void clear ()
 Clear the data related to previous collisions.
void entry ()
 Places this collider in the collider list.
void release ()
 Removes this collider from the collider list.
void set (dActor_c *actor, sCcDatNewF *collInfo)
 Registers an owner actor to this collider and sets the collider data.
void set (dActor_c *actor, sCcDatNewF *collInfo, u8 amiLine)
 Registers an owner actor to this collider and sets the collider data.
void setFriendActor (dActor_c *actor)
 Sets a friend actor for this collider.
dActor_cgetOwner () const
 Gets the owner actor of this collider.
u16 isHit (u16 mask) const
 Gets the result of a hit check.
u16 isHitAtDmg (u16 mask) const
 Gets the result of an attack hit check.
float getTopPos ()
 Gets the Y position of the top of the collider.
float getUnderPos ()
 Gets the Y position of the bottom of the collider.
float getCenterPosY ()
 Gets the Y position of the center of the collider.
float getRightPos ()
 Gets the X position of the right side of the collider.
float getLeftPos ()
 Gets the X position of the left side of the collider.
float getCenterPosX ()
 Gets the X position of the center of the collider.
mVec2_c getCenterVec ()
 Gets the center of the collider as a vector.
bool isInside (dCc_c *other)
 Checks if this collider is inside another collider.
float getCollPosX () const
float getCollPosY () const

Static Public Member Functions

static bool checkCollision (dCc_c *c1, dCc_c *c2, int active)
 Checks for collisions between two colliders.
static void execute ()
 Check all colliders against each other for collisions.
static void reset ()
 Clears the collider list.

Public Attributes

dActor_cmpOwner
 The actor this collider belongs to.
dActor_cmFriendActor
 A second actor that this collider will not collide with.
u32 unk2
 [Unused (?)].
dCc_cmpNext
 The next collider in the list.
dCc_cmpPrev
 The previous collider in the list.
u32 unk3
 [Unused (?)].
sCcDatNewF mCcData
 The collision data of this collider.
float mTrpOffsets [4]
 The X or Y offset of the four corners of a trapezoid-shaped collider.
float mCollOffsetX [8]
 The X offset for a collision.
float mCollOffsetY [8]
 The Y offset for a collision.
mVec2_c mCollPos
 The position where the last collision occurred.
u16 mCollidedWith
 The categories of the previously collided with colliders.
u16 mAttSent
 The attack types sent by this collider in the previous collisions.
u16 mAttReceived
 The attack types received by this collider in the previous collisions.
u8 mShape
 The shape of the collider. See CC_SHAPE_e .
u8 mAmiLine
 The non-collide mask for this collider.
u8 mLayer
 The layer this collider is on.
u8 mInfo
 Info flags for this collider. See CC_INFO_e.

Private Types

typedef bool(* hitCheck) (dCc_c *, dCc_c *)

Private Member Functions

float getTrpOffset (int idx)

Static Private Member Functions

static bool _hitCheckSquare (dCc_c *c1, dCc_c *c2, mVec2_c pos1, mVec2_c pos2)
 A hit check function for rectangular colliders. Used in _hitCheckNormal and _hitCheckLoop.
static bool _hitCheckNormal (dCc_c *c1, dCc_c *c2)
 Check two rectangular colliders against each other for collisions without stage looping.
static bool _hitCheckLoop (dCc_c *c1, dCc_c *c2)
 Check two rectangular colliders against each other for collisions with stage looping.
static bool _hitCheckCircle (dCc_c *c1, dCc_c *c2)
 Check two circle colliders against each other for collisions.
static bool _hitCheckBoxCircle (dCc_c *c1, dCc_c *c2)
 Check a rectangular and a circle collider against each other for collisions.
static int _lineCheckUD (mVec2_c p1, mVec2_c p2, float p3, float p4)
static bool _hitCheckDaikeiUD_R (dCc_c *ccBox, dCc_c *ccTrp)
 Check a rectangular collider against a trapezoid-shaped collider for collisions.
static bool _hitCheckDaikeiUD (dCc_c *ccTrp, dCc_c *ccBox)
 Check a trapezoid-shaped collider against a rectangular collider for collisions.
static int _lineCheckLR (mVec2_c p1, mVec2_c p2, float p3, float p4)
static bool _hitCheckDaikeiLR_R (dCc_c *ccBox, dCc_c *ccTrp)
 Check a rectangular collider against a trapezoid-shaped collider for collisions.
static bool _hitCheckDaikeiLR (dCc_c *ccTrp, dCc_c *ccBox)
 Check a trapezoid-shaped collider against a rectangular collider for collisions.

Private Attributes

bool mIsLinked
 Whether this collider has been placed in the collider list.

Static Private Attributes

static hitCheck _hitCheck [4][4]
 The hit check function for each combination of collider shapes.
static dCc_cmEntryN
 The first collider in the list.
static dCc_cmEntryB
 The last collider in the list.

Member Typedef Documentation

◆ hitCheck

typedef bool(* dCc_c::hitCheck) (dCc_c *, dCc_c *)
private

Definition at line 317 of file d_cc.hpp.

Constructor & Destructor Documentation

◆ dCc_c()

dCc_c::dCc_c ( )

Constructs a new collider.

Definition at line 27 of file d_cc.cpp.

◆ ~dCc_c()

dCc_c::~dCc_c ( )
virtual

Destroys the collider.

Definition at line 37 of file d_cc.cpp.

Member Function Documentation

◆ clear()

void dCc_c::clear ( )

Clear the data related to previous collisions.

Definition at line 41 of file d_cc.cpp.

◆ entry()

void dCc_c::entry ( )

Places this collider in the collider list.

Definition at line 52 of file d_cc.cpp.

◆ release()

void dCc_c::release ( )

Removes this collider from the collider list.

Definition at line 70 of file d_cc.cpp.

◆ set() [1/2]

void dCc_c::set ( dActor_c * actor,
sCcDatNewF * collInfo )

Registers an owner actor to this collider and sets the collider data.

Parameters
actorThe actor to register.
collInfoThe collider data to set.

Definition at line 91 of file d_cc.cpp.

◆ set() [2/2]

void dCc_c::set ( dActor_c * actor,
sCcDatNewF * collInfo,
u8 amiLine )

Registers an owner actor to this collider and sets the collider data.

Parameters
actorThe actor to register.
collInfoThe collider data to set.
amiLineThe chainline fence layer to set.

Definition at line 104 of file d_cc.cpp.

◆ setFriendActor()

void dCc_c::setFriendActor ( dActor_c * actor)
inline

Sets a friend actor for this collider.

Definition at line 154 of file d_cc.hpp.

◆ getOwner()

dActor_c * dCc_c::getOwner ( ) const
inline

Gets the owner actor of this collider.

Definition at line 156 of file d_cc.hpp.

◆ isHit()

u16 dCc_c::isHit ( u16 mask) const

Gets the result of a hit check.

Parameters
maskThe mask to check.
Returns
The result of the hit check.

Definition at line 123 of file d_cc.cpp.

◆ isHitAtDmg()

u16 dCc_c::isHitAtDmg ( u16 mask) const

Gets the result of an attack hit check.

Parameters
maskThe mask to check.
Returns
The result of the attack hit check.

Definition at line 127 of file d_cc.cpp.

◆ getTopPos()

float dCc_c::getTopPos ( )

Gets the Y position of the top of the collider.

Definition at line 131 of file d_cc.cpp.

◆ getUnderPos()

float dCc_c::getUnderPos ( )

Gets the Y position of the bottom of the collider.

Definition at line 135 of file d_cc.cpp.

◆ getCenterPosY()

float dCc_c::getCenterPosY ( )

Gets the Y position of the center of the collider.

Definition at line 139 of file d_cc.cpp.

◆ getRightPos()

float dCc_c::getRightPos ( )

Gets the X position of the right side of the collider.

Definition at line 143 of file d_cc.cpp.

◆ getLeftPos()

float dCc_c::getLeftPos ( )

Gets the X position of the left side of the collider.

Definition at line 147 of file d_cc.cpp.

◆ getCenterPosX()

float dCc_c::getCenterPosX ( )

Gets the X position of the center of the collider.

Definition at line 151 of file d_cc.cpp.

◆ getCenterVec()

mVec2_c dCc_c::getCenterVec ( )
inline

Gets the center of the collider as a vector.

Definition at line 181 of file d_cc.hpp.

◆ isInside()

bool dCc_c::isInside ( dCc_c * other)

Checks if this collider is inside another collider.

Parameters
otherThe collider to check against.

Definition at line 155 of file d_cc.cpp.

◆ getTrpOffset()

float dCc_c::getTrpOffset ( int idx)
inlineprivate

Definition at line 193 of file d_cc.hpp.

◆ checkCollision()

bool dCc_c::checkCollision ( dCc_c * c1,
dCc_c * c2,
int active )
static

Checks for collisions between two colliders.

Parameters
c1The first collider.
c2The second collider.
activeWhether to update the result and execute the callback if a collision occurs.
Returns
Whether the first collider collided with the second collider.

Definition at line 175 of file d_cc.cpp.

◆ execute()

void dCc_c::execute ( )
static

Check all colliders against each other for collisions.

Definition at line 271 of file d_cc.cpp.

◆ reset()

void dCc_c::reset ( )
static

Clears the collider list.

It also sets the hit check to the correct type (normal / looping stage). Note that this does not clean up the colliders themselves!

Definition at line 109 of file d_cc.cpp.

◆ getCollPosX()

float dCc_c::getCollPosX ( ) const
inline

Definition at line 218 of file d_cc.hpp.

◆ getCollPosY()

float dCc_c::getCollPosY ( ) const
inline

Definition at line 219 of file d_cc.hpp.

◆ _hitCheckSquare()

bool dCc_c::_hitCheckSquare ( dCc_c * c1,
dCc_c * c2,
mVec2_c pos1,
mVec2_c pos2 )
staticprivate

A hit check function for rectangular colliders. Used in _hitCheckNormal and _hitCheckLoop.

Parameters
c1The first collider.
c2The second collider.
pos1The position of the first collider.
pos2The position of the second collider.

Definition at line 279 of file d_cc.cpp.

◆ _hitCheckNormal()

bool dCc_c::_hitCheckNormal ( dCc_c * c1,
dCc_c * c2 )
staticprivate

Check two rectangular colliders against each other for collisions without stage looping.

Definition at line 322 of file d_cc.cpp.

◆ _hitCheckLoop()

bool dCc_c::_hitCheckLoop ( dCc_c * c1,
dCc_c * c2 )
staticprivate

Check two rectangular colliders against each other for collisions with stage looping.

Definition at line 328 of file d_cc.cpp.

◆ _hitCheckCircle()

bool dCc_c::_hitCheckCircle ( dCc_c * c1,
dCc_c * c2 )
staticprivate

Check two circle colliders against each other for collisions.

Definition at line 352 of file d_cc.cpp.

◆ _hitCheckBoxCircle()

bool dCc_c::_hitCheckBoxCircle ( dCc_c * c1,
dCc_c * c2 )
staticprivate

Check a rectangular and a circle collider against each other for collisions.

Definition at line 398 of file d_cc.cpp.

◆ _lineCheckUD()

int dCc_c::_lineCheckUD ( mVec2_c p1,
mVec2_c p2,
float p3,
float p4 )
staticprivate

Definition at line 502 of file d_cc.cpp.

◆ _hitCheckDaikeiUD_R()

bool dCc_c::_hitCheckDaikeiUD_R ( dCc_c * ccBox,
dCc_c * ccTrp )
staticprivate

Check a rectangular collider against a trapezoid-shaped collider for collisions.

Definition at line 515 of file d_cc.cpp.

◆ _hitCheckDaikeiUD()

bool dCc_c::_hitCheckDaikeiUD ( dCc_c * ccTrp,
dCc_c * ccBox )
staticprivate

Check a trapezoid-shaped collider against a rectangular collider for collisions.

Definition at line 519 of file d_cc.cpp.

◆ _lineCheckLR()

int dCc_c::_lineCheckLR ( mVec2_c p1,
mVec2_c p2,
float p3,
float p4 )
staticprivate

Definition at line 574 of file d_cc.cpp.

◆ _hitCheckDaikeiLR_R()

bool dCc_c::_hitCheckDaikeiLR_R ( dCc_c * ccBox,
dCc_c * ccTrp )
staticprivate

Check a rectangular collider against a trapezoid-shaped collider for collisions.

Definition at line 587 of file d_cc.cpp.

◆ _hitCheckDaikeiLR()

bool dCc_c::_hitCheckDaikeiLR ( dCc_c * ccTrp,
dCc_c * ccBox )
staticprivate

Check a trapezoid-shaped collider against a rectangular collider for collisions.

Definition at line 591 of file d_cc.cpp.

Member Data Documentation

◆ mpOwner

dActor_c* dCc_c::mpOwner

The actor this collider belongs to.

Definition at line 253 of file d_cc.hpp.

◆ mFriendActor

dActor_c* dCc_c::mFriendActor

A second actor that this collider will not collide with.

Definition at line 254 of file d_cc.hpp.

◆ unk2

u32 dCc_c::unk2

[Unused (?)].

Definition at line 256 of file d_cc.hpp.

◆ mpNext

dCc_c* dCc_c::mpNext

The next collider in the list.

Definition at line 258 of file d_cc.hpp.

◆ mpPrev

dCc_c* dCc_c::mpPrev

The previous collider in the list.

Definition at line 259 of file d_cc.hpp.

◆ unk3

u32 dCc_c::unk3

[Unused (?)].

Definition at line 261 of file d_cc.hpp.

◆ mCcData

sCcDatNewF dCc_c::mCcData

The collision data of this collider.

Definition at line 263 of file d_cc.hpp.

◆ mTrpOffsets

float dCc_c::mTrpOffsets[4]

The X or Y offset of the four corners of a trapezoid-shaped collider.

Relative to the center of the collider. If mShape is CC_SHAPE_DAIKEI_UD, this is the Y offset. If mShape is CC_SHAPE_DAIKEI_LR, this is the X offset.

Definition at line 272 of file d_cc.hpp.

◆ mCollOffsetX

float dCc_c::mCollOffsetX[8]

The X offset for a collision.

One entry per category. Each entry describes by how much the collider must be offset in the X direction in order to not collide with the other collider.

Definition at line 280 of file d_cc.hpp.

◆ mCollOffsetY

float dCc_c::mCollOffsetY[8]

The Y offset for a collision.

One entry per category. Each entry describes by how much the collider must be offset in the Y direction in order to not collide with the other collider.

Definition at line 287 of file d_cc.hpp.

◆ mCollPos

mVec2_c dCc_c::mCollPos

The position where the last collision occurred.

Definition at line 289 of file d_cc.hpp.

◆ mCollidedWith

u16 dCc_c::mCollidedWith

The categories of the previously collided with colliders.

Definition at line 291 of file d_cc.hpp.

◆ mAttSent

u16 dCc_c::mAttSent

The attack types sent by this collider in the previous collisions.

Definition at line 292 of file d_cc.hpp.

◆ mAttReceived

u16 dCc_c::mAttReceived

The attack types received by this collider in the previous collisions.

Definition at line 293 of file d_cc.hpp.

◆ mShape

u8 dCc_c::mShape

The shape of the collider. See CC_SHAPE_e .

Definition at line 295 of file d_cc.hpp.

◆ mAmiLine

u8 dCc_c::mAmiLine

The non-collide mask for this collider.

If the same bit is set in a second actor's non-collide mask, the two actors will not collide.

Definition at line 303 of file d_cc.hpp.

◆ mLayer

u8 dCc_c::mLayer

The layer this collider is on.

Colliders can only collide with other colliders on the same layer.

Definition at line 310 of file d_cc.hpp.

◆ mInfo

u8 dCc_c::mInfo

Info flags for this collider. See CC_INFO_e.

Definition at line 312 of file d_cc.hpp.

◆ mIsLinked

bool dCc_c::mIsLinked
private

Whether this collider has been placed in the collider list.

Definition at line 315 of file d_cc.hpp.

◆ _hitCheck

dCc_c::hitCheck dCc_c::_hitCheck
staticprivate
Initial value:
= {
}
static bool _hitCheckDaikeiUD_R(dCc_c *ccBox, dCc_c *ccTrp)
Check a rectangular collider against a trapezoid-shaped collider for collisions.
Definition d_cc.cpp:515
static bool _hitCheckCircle(dCc_c *c1, dCc_c *c2)
Check two circle colliders against each other for collisions.
Definition d_cc.cpp:352
static bool _hitCheckDaikeiLR_R(dCc_c *ccBox, dCc_c *ccTrp)
Check a rectangular collider against a trapezoid-shaped collider for collisions.
Definition d_cc.cpp:587
static bool _hitCheckDaikeiLR(dCc_c *ccTrp, dCc_c *ccBox)
Check a trapezoid-shaped collider against a rectangular collider for collisions.
Definition d_cc.cpp:591
static bool _hitCheckBoxCircle(dCc_c *c1, dCc_c *c2)
Check a rectangular and a circle collider against each other for collisions.
Definition d_cc.cpp:398
static bool _hitCheckNormal(dCc_c *c1, dCc_c *c2)
Check two rectangular colliders against each other for collisions without stage looping.
Definition d_cc.cpp:322
static bool _hitCheckDaikeiUD(dCc_c *ccTrp, dCc_c *ccBox)
Check a trapezoid-shaped collider against a rectangular collider for collisions.
Definition d_cc.cpp:519

The hit check function for each combination of collider shapes.

The first index is the shape of the first collider and the second index is the shape of the second collider.

Definition at line 20 of file d_cc.hpp.

◆ mEntryN

dCc_c * dCc_c::mEntryN
staticprivate

The first collider in the list.

Definition at line 327 of file d_cc.hpp.

◆ mEntryB

dCc_c * dCc_c::mEntryB
staticprivate

The last collider in the list.

Definition at line 328 of file d_cc.hpp.