NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_cc.hpp
1#pragma once
2#include <types.h>
3#include <game/mLib/m_vec.hpp>
4
5class dActor_c;
6
7///< @unofficial
8enum CC_SHAPE_e {
9 CC_SHAPE_BOX, ///< Rectangular collider
10 CC_SHAPE_CIRCLE, ///< Circular / elliptical collider
11 CC_SHAPE_DAIKEI_UD, ///< Trapezoid-shaped collider (left/right sides are parallel)
12 CC_SHAPE_DAIKEI_LR, ///< Trapezoid-shaped collider (top/bottom sides are parallel)
13};
14
15///< @unofficial
16enum CC_STATUS_FLAG_e {
17 CC_STATUS_NONE = 0,
18 CC_STATUS_NO_REVISION = BIT_FLAG(0), ///< Don't set the collision offset if a collision occurs
19 /**
20 * When another collider collides with this one,
21 * don't update the result or execute the callback
22 * on the other collider.
23 */
24 CC_STATUS_NO_PASS_INFO = BIT_FLAG(2),
25};
26
27///< @unofficial
28enum CC_INFO_e {
29 CC_NO_HIT = BIT_FLAG(1), ///< Disables all collisions with this collider
30};
31
32///< @unofficial
33enum CC_KIND_e {
34 CC_KIND_PLAYER,
35 /**
36 * This collider can attack, which means it will use mAttackCategory and
37 * mAttackCategoryInteract to further check if the colliders will collide.
38 */
39 CC_KIND_PLAYER_ATTACK,
40 CC_KIND_YOSHI,
41 CC_KIND_ENEMY,
42 CC_KIND_BALLOON,
43 CC_KIND_ITEM,
44 CC_KIND_TAMA,
45 CC_KIND_KILLER,
46 CC_KIND_GOAL_POLE
47};
48
49///< @unofficial
50enum CC_ATTACK_e {
51 CC_ATTACK_NONE,
52 CC_ATTACK_FIREBALL,
53 CC_ATTACK_ICEBALL,
54 CC_ATTACK_STAR,
55 CC_ATTACK_ICE_BREAK,
56 CC_ATTACK_SLIP,
57 CC_ATTACK_KOOPA_FIRE,
58 CC_ATTACK_HIP_ATTACK,
59 CC_ATTACK_WIRE_NET,
60 CC_ATTACK_SHELL,
61 CC_ATTACK_PENGUIN_SLIDE,
62 CC_ATTACK_SPIN,
63 CC_ATTACK_UNK12,
64 CC_ATTACK_SPIN_FALL,
65 CC_ATTACK_FIRE_2,
66 CC_ATTACK_YOSHI_EAT,
67 CC_ATTACK_YOSHI_MOUTH,
68 CC_ATTACK_CANNON,
69 CC_ATTACK_SPIN_LIFT_UP,
70 CC_ATTACK_YOSHI_BULLET,
71 CC_ATTACK_YOSHI_FIRE,
72 CC_ATTACK_ICE_2,
73 CC_ATTACK_SAND_PILLAR
74};
75
76class dCc_c;
77
78/**
79* @brief A structure that contains information about a collider.
80* @unofficial
81*/
82struct sCcDatNewF {
83 mVec2_POD_c mOffset; ///< The offset of the collider.
84
85 ///< @brief The size of the collider.
86 ///< Note: This is the distance from the center to the edge, so half the actual size.
87 mVec2_POD_c mSize;
88
89 u8 mKind; ///< The type of this collider. See CC_KIND_e.
90 u8 mAttack; ///< The attack type of this collider. See CC_ATTACK_e.
91
92 ///< @brief Which types this collider should be able to collide with.
93 ///< This is a bitfield with the bits enumerated by CC_KIND_e.
95
96 ///< @brief Which attack types this collider should be able to receive.
97 ///< This is a bitfield with the bits enumerated by CC_ATTACK_e.
98 u32 mVsDamage;
99
100 u16 mStatus; ///< Status flags for this collider. See CC_STATUS_FLAG_e.
101
102 void (*mCallback)(dCc_c *self, dCc_c *target); ///< The callback to execute when a collision occurs.
103};
104
105/**
106 * @brief Collider ("Collision Check") class - handles collisions between actors.
107 *
108 * It also includes logic that handles collisions
109 * within a horizontally looping stage (like 2-C).
110 */
111class dCc_c {
112public:
113 ///< @unofficial
114 class U32Holder {
115 public:
116 U32Holder(u32 value) : mValue(value) {}
117
118 u32 mValue;
119 };
120
121 ///< @unofficial
123 u32 a;
124 U32Holder b;
125 U32Holder c;
126 bool d, e;
127 };
128
129public:
130 dCc_c(); ///< Constructs a new collider.
131 virtual ~dCc_c(); ///< Destroys the collider.
132
133 void clear(); ///< Clear the data related to previous collisions.
134
135 void entry(); ///< Places this collider in the collider list.
136 void release(); ///< Removes this collider from the collider list.
137
138 /**
139 * @brief Registers an owner actor to this collider and sets the collider data.
140 * @param actor The actor to register.
141 * @param collInfo The collider data to set.
142 */
143 void set(dActor_c *actor, sCcDatNewF *collInfo);
144
145 /**
146 * @brief Registers an owner actor to this collider and sets the collider data.
147 * @param actor The actor to register.
148 * @param collInfo The collider data to set.
149 * @param amiLine The chainline fence layer to set.
150 */
151 void set(dActor_c *actor, sCcDatNewF *collInfo, u8 amiLine);
152
153 /// Sets a friend actor for this collider.
154 void setFriendActor(dActor_c *actor) { mFriendActor = actor; }
155
156 dActor_c *getOwner() const { return mpOwner; } ///< Gets the owner actor of this collider.
157
158 /**
159 * @brief Gets the result of a hit check.
160 * @param mask The mask to check.
161 * @return The result of the hit check.
162 */
163 u16 isHit(u16 mask) const;
164
165 /**
166 * @brief Gets the result of an attack hit check.
167 * @param mask The mask to check.
168 * @return The result of the attack hit check.
169 */
170 u16 isHitAtDmg(u16 mask) const;
171
172 float getTopPos(); ///< Gets the Y position of the top of the collider.
173 float getUnderPos(); ///< Gets the Y position of the bottom of the collider.
174 float getCenterPosY(); ///< Gets the Y position of the center of the collider.
175
176 float getRightPos(); ///< Gets the X position of the right side of the collider.
177 float getLeftPos(); ///< Gets the X position of the left side of the collider.
178 float getCenterPosX(); ///< Gets the X position of the center of the collider.
179
180 /// Gets the center of the collider as a vector.
183 }
184
185 /**
186 * @brief Checks if this collider is inside another collider.
187 *
188 * @param other The collider to check against.
189 */
190 bool isInside(dCc_c *other);
191
192private:
193 float getTrpOffset(int idx) {
194 return mTrpOffsets[idx];
195 }
196
197public:
198 /**
199 * @brief Checks for collisions between two colliders.
200 *
201 * @param c1 The first collider.
202 * @param c2 The second collider.
203 * @param active Whether to update the result and execute the callback if a collision occurs.
204 * @return Whether the first collider collided with the second collider.
205 */
206 static bool checkCollision(dCc_c *c1, dCc_c *c2, int active);
207
208 static void execute(); ///< Check all colliders against each other for collisions.
209
210 /**
211 * @brief Clears the collider list.
212 *
213 * It also sets the hit check to the correct type (normal / looping stage).
214 * Note that this does not clean up the colliders themselves!
215 */
216 static void reset();
217
218 float getCollPosX() const { return mCollPos.x; }
219 float getCollPosY() const { return mCollPos.y; }
220
221private:
222 /**
223 * @brief A hit check function for rectangular colliders. Used in _hitCheckNormal and _hitCheckLoop.
224 * @param c1 The first collider.
225 * @param c2 The second collider.
226 * @param pos1 The position of the first collider.
227 * @param pos2 The position of the second collider.
228 */
229 static bool _hitCheckSquare(dCc_c *c1, dCc_c *c2, mVec2_c pos1, mVec2_c pos2);
230
231 /// Check two rectangular colliders against each other for collisions without stage looping.
232 static bool _hitCheckNormal(dCc_c *c1, dCc_c *c2);
233 /// Check two rectangular colliders against each other for collisions with stage looping.
234 static bool _hitCheckLoop(dCc_c *c1, dCc_c *c2);
235 /// Check two circle colliders against each other for collisions.
236 static bool _hitCheckCircle(dCc_c *c1, dCc_c *c2);
237 /// Check a rectangular and a circle collider against each other for collisions.
238 static bool _hitCheckBoxCircle(dCc_c *c1, dCc_c *c2);
239
240 static int _lineCheckUD(mVec2_c p1, mVec2_c p2, float p3, float p4);
241 /// Check a rectangular collider against a trapezoid-shaped collider for collisions.
242 static bool _hitCheckDaikeiUD_R(dCc_c *ccBox, dCc_c *ccTrp);
243 /// Check a trapezoid-shaped collider against a rectangular collider for collisions.
244 static bool _hitCheckDaikeiUD(dCc_c *ccTrp, dCc_c *ccBox);
245
246 static int _lineCheckLR(mVec2_c p1, mVec2_c p2, float p3, float p4);
247 /// Check a rectangular collider against a trapezoid-shaped collider for collisions.
248 static bool _hitCheckDaikeiLR_R(dCc_c *ccBox, dCc_c *ccTrp);
249 /// Check a trapezoid-shaped collider against a rectangular collider for collisions.
250 static bool _hitCheckDaikeiLR(dCc_c *ccTrp, dCc_c *ccBox);
251
252public:
253 dActor_c *mpOwner; ///< The actor this collider belongs to.
254 dActor_c *mFriendActor; ///< A second actor that this collider will not collide with.
255
256 u32 unk2; ///< [Unused (?)].
257
258 dCc_c *mpNext; ///< The next collider in the list.
259 dCc_c *mpPrev; ///< The previous collider in the list.
260
261 u32 unk3; ///< [Unused (?)].
262
263 sCcDatNewF mCcData; ///< The collision data of this collider.
264
265 /**
266 * @brief The X or Y offset of the four corners of a trapezoid-shaped collider.
267 *
268 * Relative to the center of the collider.
269 * If mShape is CC_SHAPE_DAIKEI_UD, this is the Y offset.
270 * If mShape is CC_SHAPE_DAIKEI_LR, this is the X offset.
271 */
272 float mTrpOffsets[4];
273
274 /**
275 * @brief The X offset for a collision.
276 *
277 * One entry per category. Each entry describes by how much the collider must be
278 * offset in the X direction in order to not collide with the other collider.
279 */
280 float mCollOffsetX[8];
281 /**
282 * @brief The Y offset for a collision.
283 *
284 * One entry per category. Each entry describes by how much the collider must be
285 * offset in the Y direction in order to not collide with the other collider.
286 */
287 float mCollOffsetY[8];
288
289 mVec2_c mCollPos; ///< The position where the last collision occurred.
290
291 u16 mCollidedWith; ///< The categories of the previously collided with colliders.
292 u16 mAttSent; ///< The attack types sent by this collider in the previous collisions.
293 u16 mAttReceived; ///< The attack types received by this collider in the previous collisions.
294
295 u8 mShape; ///< The shape of the collider. See @ref CC_SHAPE_e .
296
297 /**
298 * @brief The non-collide mask for this collider.
299 *
300 * If the same bit is set in a second actor's non-collide mask,
301 * the two actors will not collide.
302 */
304
305 /**
306 * @brief The layer this collider is on.
307 *
308 * Colliders can only collide with other colliders on the same layer.
309 */
311
312 u8 mInfo; ///< Info flags for this collider. See CC_INFO_e.
313
314private:
315 bool mIsLinked; ///< Whether this collider has been placed in the collider list.
316
317 typedef bool (*hitCheck)(dCc_c *, dCc_c *);
318
319 /**
320 * @brief The hit check function for each combination of collider shapes.
321 *
322 * The first index is the shape of the first collider and the second index
323 * is the shape of the second collider.
324 */
325 static hitCheck _hitCheck[4][4];
326
327 static dCc_c *mEntryN; ///< The first collider in the list.
328 static dCc_c *mEntryB; ///< The last collider in the list.
329};
The minimum required implementation for a stage actor.
Definition d_actor.hpp:17
Collider ("Collision Check") class - handles collisions between actors.
Definition d_cc.hpp:111
void set(dActor_c *actor, sCcDatNewF *collInfo)
Registers an owner actor to this collider and sets the collider data.
Definition d_cc.cpp:91
mVec2_c getCenterVec()
Gets the center of the collider as a vector.
Definition d_cc.hpp:181
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.
Definition d_cc.cpp:279
bool mIsLinked
Whether this collider has been placed in the collider list.
Definition d_cc.hpp:315
static bool checkCollision(dCc_c *c1, dCc_c *c2, int active)
Checks for collisions between two colliders.
Definition d_cc.cpp:175
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
dActor_c * mpOwner
The actor this collider belongs to.
Definition d_cc.hpp:253
float getUnderPos()
Gets the Y position of the bottom of the collider.
Definition d_cc.cpp:135
static bool _hitCheckLoop(dCc_c *c1, dCc_c *c2)
Check two rectangular colliders against each other for collisions with stage looping.
Definition d_cc.cpp:328
u32 unk3
[Unused (?)].
Definition d_cc.hpp:261
float getTopPos()
Gets the Y position of the top of the collider.
Definition d_cc.cpp:131
static dCc_c * mEntryN
The first collider in the list.
Definition d_cc.hpp:327
u16 isHitAtDmg(u16 mask) const
Gets the result of an attack hit check.
Definition d_cc.cpp:127
u8 mInfo
Info flags for this collider. See CC_INFO_e.
Definition d_cc.hpp:312
float mTrpOffsets[4]
The X or Y offset of the four corners of a trapezoid-shaped collider.
Definition d_cc.hpp:272
dCc_c * mpPrev
The previous collider in the list.
Definition d_cc.hpp:259
void clear()
Clear the data related to previous collisions.
Definition d_cc.cpp:41
float getCenterPosY()
Gets the Y position of the center of the collider.
Definition d_cc.cpp:139
float mCollOffsetY[8]
The Y offset for a collision.
Definition d_cc.hpp:287
void entry()
Places this collider in the collider list.
Definition d_cc.cpp:52
u16 mCollidedWith
The categories of the previously collided with colliders.
Definition d_cc.hpp:291
u8 mShape
The shape of the collider. See CC_SHAPE_e .
Definition d_cc.hpp:295
u16 mAttSent
The attack types sent by this collider in the previous collisions.
Definition d_cc.hpp:292
u32 unk2
[Unused (?)].
Definition d_cc.hpp:256
u16 isHit(u16 mask) const
Gets the result of a hit check.
Definition d_cc.cpp:123
static hitCheck _hitCheck[4][4]
The hit check function for each combination of collider shapes.
Definition d_cc.hpp:20
u16 mAttReceived
The attack types received by this collider in the previous collisions.
Definition d_cc.hpp:293
u8 mLayer
The layer this collider is on.
Definition d_cc.hpp:310
float getCenterPosX()
Gets the X position of the center of the collider.
Definition d_cc.cpp:151
static bool _hitCheckCircle(dCc_c *c1, dCc_c *c2)
Check two circle colliders against each other for collisions.
Definition d_cc.cpp:352
float getLeftPos()
Gets the X position of the left side of the collider.
Definition d_cc.cpp:147
mVec2_c mCollPos
The position where the last collision occurred.
Definition d_cc.hpp:289
float getRightPos()
Gets the X position of the right side of the collider.
Definition d_cc.cpp:143
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
virtual ~dCc_c()
Destroys the collider.
Definition d_cc.cpp:37
static void execute()
Check all colliders against each other for collisions.
Definition d_cc.cpp:271
dActor_c * getOwner() const
Gets the owner actor of this collider.
Definition d_cc.hpp:156
dActor_c * mFriendActor
A second actor that this collider will not collide with.
Definition d_cc.hpp:254
void release()
Removes this collider from the collider list.
Definition d_cc.cpp:70
sCcDatNewF mCcData
The collision data of this collider.
Definition d_cc.hpp:263
float mCollOffsetX[8]
The X offset for a collision.
Definition d_cc.hpp:280
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
u8 mAmiLine
The non-collide mask for this collider.
Definition d_cc.hpp:303
void setFriendActor(dActor_c *actor)
Sets a friend actor for this collider.
Definition d_cc.hpp:154
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 void reset()
Clears the collider list.
Definition d_cc.cpp:109
dCc_c * mpNext
The next collider in the list.
Definition d_cc.hpp:258
dCc_c()
Constructs a new collider.
Definition d_cc.cpp:27
static dCc_c * mEntryB
The last collider in the list.
Definition d_cc.hpp:328
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
bool isInside(dCc_c *other)
Checks if this collider is inside another collider.
Definition d_cc.cpp:155
A two-dimensional floating point vector.
Definition m_vec.hpp:16
A structure that contains information about a collider.
Definition d_cc.hpp:82
void(* mCallback)(dCc_c *self, dCc_c *target)
The callback to execute when a collision occurs.
Definition d_cc.hpp:102
u8 mKind
The type of this collider. See CC_KIND_e.
Definition d_cc.hpp:89
u8 mAttack
The attack type of this collider. See CC_ATTACK_e.
Definition d_cc.hpp:90
u16 mStatus
Status flags for this collider. See CC_STATUS_FLAG_e.
Definition d_cc.hpp:100
mVec2_POD_c mOffset
The offset of the collider.
Definition d_cc.hpp:83
u32 mVsKind
Which attack types this collider should be able to receive. This is a bitfield with the bits enumerat...
Definition d_cc.hpp:94