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

#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 11 of file d_cc.hpp.

Classes

struct  CcData_s
 A structure that contains information about a collider. More...
 
class  InitializedUnkClass
 

Public Types

enum  CC_SHAPE_e {
  CC_SHAPE_BOX ,
  CC_SHAPE_CIRCLE ,
  CC_SHAPE_DAIKEI_UD ,
  CC_SHAPE_DAIKEI_LR
}
 
enum  CC_DATA_FLAG_e {
  CC_DATA_NO_OFFSET = 1 ,
  CC_DATA_PASSIVE = 4
}
 
enum  CC_FLAG_e { CC_DISABLE = 2 }
 
enum  CC_CATEGORY_e {
  CAT_PLAYER_GENERIC ,
  CAT_PLAYER_ATTACK ,
  CAT_YOSHI ,
  CAT_ENTITY ,
  CAT_BALLOON ,
  CAT_ITEM ,
  CAT_PROJECTILE ,
  CAT_CANNON ,
  CAT_GOAL_POLE
}
 
enum  CC_ATTACK_e {
  ATTACK_FIRE = 1 ,
  ATTACK_ICE ,
  ATTACK_STAR ,
  ATTACK_ICE_BREAK ,
  ATTACK_SLIP ,
  ATTACK_KOOPA_FIRE ,
  ATTACK_HIP_ATTK ,
  ATTACK_WIRE_NET ,
  ATTACK_SHELL ,
  ATTACK_PENGUIN_SLIDE ,
  ATTACK_SPIN ,
  ATTACK_UNK12 ,
  ATTACK_SPIN_FALL ,
  ATTACK_FIRE_2 ,
  ATTACK_YOSHI_EAT ,
  ATTACK_YOSHI_MOUTH ,
  ATTACK_CANNON ,
  ATTACK_YOSHI_BULLET ,
  ATTACK_YOSHI_FIRE ,
  ATTACK_ICE_2 ,
  ATTACK_SAND_PILLAR
}
 

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 registerCc (dActor_c *actor, CcData_s *collInfo)
 Registers an owner actor to this collider and sets the collider data.
 
void registerCc (dActor_c *actor, CcData_s *collInfo, u8 nonCollideMask)
 Registers an owner actor to this collider and sets the collider data.
 
void setFriendActor (dActor_c *actor)
 Sets a friend actor for 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.
 

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

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 mNonCollideMask
 The non-collide mask for this collider.
 
u8 mLayer
 The layer this collider is on.
 
u8 mFlag
 Flags for this collider. See CC_FLAG_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

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 (?)].
 
CcData_s mCcData
 The collision data of this collider.
 
bool mIsLinked
 Whether this collider has been placed in the collider list.
 

Static Private Attributes

static char msIsInitialized
 
static InitializedUnkClass msInitializedUnkClass = { 0, 0, 0, true, true }
 
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

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

Definition at line 324 of file d_cc.hpp.

Member Enumeration Documentation

◆ CC_SHAPE_e

Enumerator
CC_SHAPE_BOX 

Rectangular collider.

CC_SHAPE_CIRCLE 

Circular / elliptical collider.

CC_SHAPE_DAIKEI_UD 

Trapezoid-shaped collider (left/right sides are parallel)

CC_SHAPE_DAIKEI_LR 

Trapezoid-shaped collider (top/bottom sides are parallel)

Definition at line 13 of file d_cc.hpp.

◆ CC_DATA_FLAG_e

Enumerator
CC_DATA_NO_OFFSET 

Don't set the collision offset if a collision occurs.

CC_DATA_PASSIVE 

When another collider collides with this one, don't update the result or execute the callback on the other collider.

Definition at line 20 of file d_cc.hpp.

◆ CC_FLAG_e

Enumerator
CC_DISABLE 

Disables all collisions with this collider.

Definition at line 30 of file d_cc.hpp.

◆ CC_CATEGORY_e

Enumerator
CAT_PLAYER_ATTACK 

This collider can attack, which means it will use mAttackCategory and mAttackCategoryInteract to further check if the colliders will collide.

Definition at line 34 of file d_cc.hpp.

◆ CC_ATTACK_e

enum dCc_c::CC_ATTACK_e

Definition at line 50 of file d_cc.hpp.

Constructor & Destructor Documentation

◆ dCc_c()

dCc_c::dCc_c ( )

Constructs a new collider.

Definition at line 23 of file d_cc.cpp.

◆ ~dCc_c()

dCc_c::~dCc_c ( )
virtual

Destroys the collider.

Definition at line 33 of file d_cc.cpp.

Member Function Documentation

◆ clear()

void dCc_c::clear ( )

Clear the data related to previous collisions.

Definition at line 37 of file d_cc.cpp.

◆ entry()

void dCc_c::entry ( )

Places this collider in the collider list.

Definition at line 48 of file d_cc.cpp.

◆ release()

void dCc_c::release ( )

Removes this collider from the collider list.

Definition at line 66 of file d_cc.cpp.

◆ registerCc() [1/2]

void dCc_c::registerCc ( dActor_c * actor,
CcData_s * collInfo )

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

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

Definition at line 87 of file d_cc.cpp.

◆ registerCc() [2/2]

void dCc_c::registerCc ( dActor_c * actor,
CcData_s * collInfo,
u8 nonCollideMask )

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

Unofficial name.
Parameters
actorThe actor to register.
collInfoThe collider data to set.
nonCollideMaskThe non-collide mask to set.

Definition at line 93 of file d_cc.cpp.

◆ setFriendActor()

void dCc_c::setFriendActor ( dActor_c * actor)
inline

Sets a friend actor for this collider.

Definition at line 165 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 112 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 116 of file d_cc.cpp.

◆ getTopPos()

float dCc_c::getTopPos ( )

Gets the Y position of the top of the collider.

Definition at line 120 of file d_cc.cpp.

◆ getUnderPos()

float dCc_c::getUnderPos ( )

Gets the Y position of the bottom of the collider.

Definition at line 124 of file d_cc.cpp.

◆ getCenterPosY()

float dCc_c::getCenterPosY ( )

Gets the Y position of the center of the collider.

Definition at line 128 of file d_cc.cpp.

◆ getRightPos()

float dCc_c::getRightPos ( )

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

Definition at line 132 of file d_cc.cpp.

◆ getLeftPos()

float dCc_c::getLeftPos ( )

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

Definition at line 136 of file d_cc.cpp.

◆ getCenterPosX()

float dCc_c::getCenterPosX ( )

Gets the X position of the center of the collider.

Definition at line 140 of file d_cc.cpp.

◆ getCenterVec()

mVec2_c dCc_c::getCenterVec ( )
inline

Gets the center of the collider as a vector.

Definition at line 190 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 144 of file d_cc.cpp.

◆ getTrpOffset()

float dCc_c::getTrpOffset ( int idx)
inlineprivate

Definition at line 202 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 164 of file d_cc.cpp.

◆ execute()

void dCc_c::execute ( )
static

Check all colliders against each other for collisions.

Definition at line 260 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 98 of file d_cc.cpp.

◆ _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 268 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 311 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 317 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 341 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 387 of file d_cc.cpp.

◆ _lineCheckUD()

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

Definition at line 491 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 504 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 508 of file d_cc.cpp.

◆ _lineCheckLR()

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

Definition at line 563 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 576 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 580 of file d_cc.cpp.

Member Data Documentation

◆ msIsInitialized

char dCc_c::msIsInitialized
staticprivate

Definition at line 135 of file d_cc.hpp.

◆ msInitializedUnkClass

dCc_c::InitializedUnkClass dCc_c::msInitializedUnkClass = { 0, 0, 0, true, true }
staticprivate

Definition at line 11 of file d_cc.hpp.

◆ mpOwner

dActor_c* dCc_c::mpOwner
private

The actor this collider belongs to.

Definition at line 259 of file d_cc.hpp.

◆ mFriendActor

dActor_c* dCc_c::mFriendActor
private

A second actor that this collider will not collide with.

Definition at line 260 of file d_cc.hpp.

◆ unk2

u32 dCc_c::unk2
private

[Unused (?)].

Definition at line 262 of file d_cc.hpp.

◆ mpNext

dCc_c* dCc_c::mpNext
private

The next collider in the list.

Definition at line 264 of file d_cc.hpp.

◆ mpPrev

dCc_c* dCc_c::mpPrev
private

The previous collider in the list.

Definition at line 265 of file d_cc.hpp.

◆ unk3

u32 dCc_c::unk3
private

[Unused (?)].

Definition at line 267 of file d_cc.hpp.

◆ mCcData

CcData_s dCc_c::mCcData
private

The collision data of this collider.

Definition at line 269 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 279 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 287 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 294 of file d_cc.hpp.

◆ mCollPos

mVec2_c dCc_c::mCollPos

The position where the last collision occurred.

Definition at line 296 of file d_cc.hpp.

◆ mCollidedWith

u16 dCc_c::mCollidedWith

The categories of the previously collided with colliders.

Definition at line 298 of file d_cc.hpp.

◆ mAttSent

u16 dCc_c::mAttSent

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

Definition at line 299 of file d_cc.hpp.

◆ mAttReceived

u16 dCc_c::mAttReceived

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

Definition at line 300 of file d_cc.hpp.

◆ mShape

u8 dCc_c::mShape

The shape of the collider. See CC_SHAPE_e .

Definition at line 302 of file d_cc.hpp.

◆ mNonCollideMask

u8 dCc_c::mNonCollideMask

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 310 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 317 of file d_cc.hpp.

◆ mFlag

u8 dCc_c::mFlag

Flags for this collider. See CC_FLAG_e .

Definition at line 319 of file d_cc.hpp.

◆ mIsLinked

bool dCc_c::mIsLinked
private

Whether this collider has been placed in the collider list.

Definition at line 322 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:504
static bool _hitCheckCircle(dCc_c *c1, dCc_c *c2)
Check two circle colliders against each other for collisions.
Definition d_cc.cpp:341
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:576
static bool _hitCheckDaikeiLR(dCc_c *ccTrp, dCc_c *ccBox)
Check a trapezoid-shaped collider against a rectangular collider for collisions.
Definition d_cc.cpp:580
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:387
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:311
static bool _hitCheckDaikeiUD(dCc_c *ccTrp, dCc_c *ccBox)
Check a trapezoid-shaped collider against a rectangular collider for collisions.
Definition d_cc.cpp:508

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 16 of file d_cc.hpp.

◆ mEntryN

dCc_c * dCc_c::mEntryN
staticprivate

The first collider in the list.

Definition at line 334 of file d_cc.hpp.

◆ mEntryB

dCc_c * dCc_c::mEntryB
staticprivate

The last collider in the list.

Definition at line 335 of file d_cc.hpp.