NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_ac_py_key.cpp
1#include <game/bases/d_ac_py_key.hpp>
2#include <game/bases/d_game_key.hpp>
3
9
11
13 mRemoconID = -1;
14}
15
19
20 if (mRemoconID == -1) {
21 mDownButtons = 0;
23 return;
24 }
25
26 if (mStatus & FLAG_NO_INPUT) {
27 mDownButtons = 0;
29 } else if (mStatus & FLAG_DEMO) {
32 } else if (mStatus & FLAG_FORCE_RIGHT) {
33 mDownButtons = BUTTON_RIGHT;
35 } else {
36 dGameKey_c *gameKey = dGameKey_c::m_instance;
37 mDownButtons = gameKey->keys[mRemoconID]->mDownButtons;
39 if (mStatus & FLAG_DISABLE_LR) {
41 }
42 }
43
44 if (mStatus & FLAG_SHAKE_COOLDOWN) {
46 mShakeCooldown = 10;
47 }
48 if (mShakeCooldown != 0) {
50 }
51
54 if (!(mStatus & FLAG_NO_INPUT) && !(mStatus & FLAG_FORCE_RIGHT)) {
55 if (mStatus & FLAG_DEMO) {
58 } else if (mShakeCooldown == 0 && dGameKey_c::m_instance->keys[mRemoconID]->mIsShaking) {
61 }
62 }
63
64 if (!mHipAtkRead) {
65 mHipAtkHoldStart = false;
67 }
68 mHipAtkRead = false;
69
70 int *triggerHistory = mJumpTriggeredHistory[mRemoconID];
71 int *buttonHistory = mJumpButtonHistory[mRemoconID];
72 for (int i = ARRAY_SIZE(mJumpTriggeredHistory[0]) - 1; i >= 1; i--) {
73 triggerHistory[i] = triggerHistory[i - 1];
74 buttonHistory[i] = buttonHistory[i - 1];
75 }
76 triggerHistory[0] = triggerJumpBase();
77 buttonHistory[0] = buttonJump();
79 mDemoDoShake = 0;
80}
81
83 mActionTriggered = false;
84 if (mRemoconID == -1) {
85 return;
86 }
87 if (mStatus & FLAG_DEMO) {
88 return;
89 }
90 mDownButtons = dGameKey_c::m_instance->keys[mRemoconID]->mDownButtons;
91 mTriggeredButtons = dGameKey_c::m_instance->keys[mRemoconID]->mTriggeredButtons;
92}
93
95 mHipAtkRead = true;
96 if (!mHipAtkHoldStart) {
97 if (triggerDown()) {
98 mHipAtkHoldStart = true;
100 }
101 } else if (buttonDown()) {
102 if (buttonHipAttack() && ++mHipAtkHoldCount >= 4) {
103 return true;
104 }
105 } else {
106 mHipAtkHoldStart = false;
107 }
108 return false;
109}
110
111void dAcPyKey_c::onStatus(u16 status) {
112 switch (status) {
115 break;
116
119 break;
120
121 case STATUS_NO_INPUT:
122 case STATUS_DEMO:
124 clearAllKey();
125 break;
126
129 break;
130
131 default:
132 break;
133 }
134 mStatus |= (1 << status);
135}
136
137void dAcPyKey_c::offStatus(u16 status) {
138 mStatus &= ~(1 << status);
139}
140
149
151 mDownButtons &= ~(BUTTON_LEFT | BUTTON_RIGHT);
152 mTriggeredButtons &= ~(BUTTON_LEFT | BUTTON_RIGHT);
153}
154
156 return mTriggeredButtons & BUTTON_A;
157}
158
160 return mDownButtons & BUTTON_CROSS;
161}
162
164 return mTriggeredButtons & BUTTON_CROSS;
165}
166
168 return mDownButtons & BUTTON_UP;
169}
170
172 return mDownButtons & BUTTON_DOWN;
173}
174
176 return mDownButtons & BUTTON_LEFT;
177}
178
180 return mDownButtons & BUTTON_RIGHT;
181}
182
184 return mTriggeredButtons & BUTTON_UP;
185}
186
188 return mTriggeredButtons & BUTTON_DOWN;
189}
190
192 return mTriggeredButtons & BUTTON_LEFT;
193}
194
196 return mTriggeredButtons & BUTTON_RIGHT;
197}
198
200 return mTriggeredButtons & BUTTON_TWO;
201}
202
204 return mDownButtons & BUTTON_TWO;
205}
206
208 if (dGameKey_c::m_instance->keys[mRemoconID]->mAttachedExtension == dGameKeyCore_c::EXTENSION_NUNCHUK) {
209 return mTriggeredButtons & BUTTON_B;
210 } else {
211 return mTriggeredButtons & BUTTON_ONE;
212 }
213}
214
216 if (dGameKey_c::m_instance->keys[mRemoconID]->mAttachedExtension == dGameKeyCore_c::EXTENSION_NUNCHUK) {
217 return mDownButtons & BUTTON_B;
218 } else {
219 return mDownButtons & BUTTON_ONE;
220 }
221}
222
224 return mDownButtons & BUTTON_ONE;
225}
226
228 return triggerOne();
229}
230
232 if (triggerOne()) {
233 mActionTriggered = true;
234 return true;
235 }
236 return false;
237}
238
240 return buttonOne();
241}
242
244 if (triggerOne()) {
245 mActionTriggered = true;
246 return true;
247 }
248 return false;
249}
250
252 return triggerTwo();
253}
254
256 if (triggerJumpBase()) {
257 mActionTriggered = true;
258 return true;
259 }
260 return false;
261}
262
264 if (mStatus & FLAG_FORCE_JUMP) {
265 return true;
266 }
267 if (mStatus & FLAG_FORCE_NO_JUMP) {
268 return false;
269 }
270 return buttonTwo();
271}
272
274 return buttonTwo();
275}
276
280
285
286bool dAcPyKey_c::buttonWalk(int *direction) const {
287 if (buttonRight()) {
288 if (direction != nullptr) {
289 *direction = 0;
290 }
291 return true;
292 } else if (buttonLeft()) {
293 if (direction != nullptr) {
294 *direction = 1;
295 }
296 return true;
297 }
298 return false;
299}
300
302 return buttonDown();
303}
304
306 if (buttonCross() & (BUTTON_UP | BUTTON_LEFT | BUTTON_RIGHT)) {
307 return 0;
308 }
309 return buttonDown();
310}
311
313 if (mDownButtons & (BUTTON_LEFT | BUTTON_RIGHT)) {
314 return 0;
315 }
316 return buttonUp();
317}
318
320 if (mRemoconID == -1) {
321 return false;
322 }
323 if (lastN > 10) {
324 lastN = 10;
325 }
326 int *history = mJumpTriggeredHistory[mRemoconID];
327 for (int i = 0; i < lastN; i++) {
328 if (history[i]) {
329 return true;
330 }
331 }
332 return false;
333}
334
335void dAcPyKey_c::onDemoButton(int buttons) {
336 if (mStatus & FLAG_DEMO) {
337 mDownButtonsDemo |= buttons;
338 }
339}
340
341void dAcPyKey_c::offDemoButton(int buttons) {
342 if (mStatus & FLAG_DEMO) {
343 mDownButtonsDemo &= ~buttons;
344 }
345}
346
347void dAcPyKey_c::onDemoTrigger(int buttons) {
348 if (mStatus & FLAG_DEMO) {
349 mTriggeredButtonsDemo |= buttons;
350 }
351}
352
354 if (mStatus & FLAG_DEMO) {
355 mDemoDoShake = 1;
356 }
357}
void offStatus(u16 status)
Disables a status flag.
void updateEnd()
Get the new button states for the next frame.
bool triggerJump()
Returns whether the jump button (2) was pressed this frame.
void onStatus(u16 status)
Enables a status flag.
int triggerA() const
Returns whether A was pressed this frame.
u16 mTriggeredButtonsDemo
The buttons newly pressed down in demo mode.
int triggerJumpBase() const
Returns whether the jump button (2) was pressed this frame.
bool checkHipAttack()
Checks whether a hip attack should be performed this frame.
void offDemoButton(int)
Sets a button for demo mode to not pressed down.
int buttonCrouch() const
Returns whether the crouch button (down) is pressed down.
bool triggerJumpBuf(int n)
Returns whether a jump occurred in the last n frames.
int buttonDoor() const
Returns whether the correct buttons (up, no left or right) for a door open is pressed down.
u16 mDemoDoShake
Trigger a shake event in demo mode.
u8 mHipAtkHoldCount
Counts how long the down button is held for the hip attack.
int buttonCross() const
Returns whether a directional button is pressed down.
int mRemoconID
This remote's ID, -1 if invalid.
int buttonUp() const
Returns whether the up button is pressed down.
u8 mActiveShakeJump
Whether a shake is active this frame.
int buttonLeft() const
Returns whether the left button is pressed down.
bool mActionTriggered
Set if eat, fire or jump is triggered.
bool mHipAtkHoldStart
Whether the hip attack holding started.
int triggerAttack() const
Returns whether the attack button (1 / B) was pressed this frame.
u16 mPrevDownButtons
The buttons pressed down in the last frame.
~dAcPyKey_c()
Destroys the controller manager.
bool buttonWalk(int *direction) const
Returns whether left / right is pressed down. Sets the direction to 0 for right and 1 for left.
void onDemoTrigger(int)
Sets a button for demo mode to pressed this frame.
int mShakeCooldown
Cooldown counter for shake events.
void clearCrossKey()
Clears the left and right directional buttons.
int buttonTwo() const
Returns whether the two button is pressed down.
void onDemoButton(int)
Sets a button for demo mode to pressed down.
u8 triggerShakeJump() const
Returns whether a shake event was triggered this frame.
int buttonHipAttack() const
Returns whether the correct buttons (down, no other directions) for a hip attack is pressed down.
int triggerOne() const
Returns whether the one button was pressed this frame.
int buttonRight() const
Returns whether the right button is pressed down.
u16 mDownButtons
The buttons currently pressed down.
int triggerCross() const
Returns whether a directional button was pressed this frame.
int buttonCarry() const
Returns whether the carry button (1 / B) is pressed down.
int triggerDown() const
Returns whether the down button was pressed this frame.
void update()
Call each frame to process the inputs.
void clearAllKey()
Clears all input state.
int buttonOne() const
Returns whether the one button is pressed down.
u16 mPrevTriggeredButtons
The buttons newly pressed down in the last frame.
int triggerTwo() const
Returns whether the two button was pressed this frame.
int triggerLeft() const
Returns whether the left button was pressed this frame.
bool triggerFire()
Returns whether the fire button was pressed this frame.
int triggerRight() const
Returns whether the right button was pressed this frame.
dAcPyKey_c()
Constructs a new controller manager.
int buttonYoshiJump() const
Returns whether the Yoshi jump button (2) is pressed down.
bool triggerEat()
Returns whether the eat button (1 / B) was pressed this frame.
bool mHipAtkRead
Whether hip attack was checked for this frame.
u8 mTriggerShakeJump
Whether a shake was triggered this frame.
u16 mTriggeredButtons
The buttons newly pressed down.
int triggerUp() const
Returns whether the up button was pressed this frame.
@ STATUS_SHAKE_COOLDOWN
Is in cooldown for shake events.
@ STATUS_FORCE_NO_JUMP
Force a jump input to be ignored.
@ STATUS_FORCE_RIGHT
Override the input to always only be the right button.
@ STATUS_DISABLE_LR
Disable left and right directional buttons.
@ STATUS_FORCE_JUMP
Force the jump button to be pressed down.
@ STATUS_DEMO
Do not use inputs from the remote.
@ STATUS_NO_INPUT
Disable all inputs.
void clearShakeJump()
Clears the shake event state.
int buttonDush() const
Returns whether the run button is pressed down.
void onDemoShake()
Sets a shake event for demo mode to be triggered this frame.
u16 mDownButtonsDemo
The buttons currently pressed down in demo mode.
int buttonDown() const
Returns whether the down button is pressed down.
int mJumpButtonHistory[4][10]
Stores the last 10 frames of the jump button state for each remote.
int mJumpTriggeredHistory[4][10]
Stores the last 10 frames of jump events for each remote.
int buttonJump()
Returns whether the jump button (2) is pressed down.
void init()
Initialize the button manager.
u16 mStatus
Uses FLAGS_e enum.
int mDownButtons
The buttons currently pressed down.
int mTriggeredButtons
The buttons newly pressed down.