|
| 1 | +#include "Player/TouchControl.hpp" |
| 2 | +#include "Unknown/UnkMemFuncs.h" |
| 3 | + |
| 4 | +// non-matching |
| 5 | +ARM void TouchControl::UpdateState(TouchState *state, TouchStateFlags *stateFlags) { |
| 6 | + if (stateFlags->touch == 1) { |
| 7 | + if (stateFlags->flags == 0) { |
| 8 | + Vec2us pos; |
| 9 | + pos.y = stateFlags->touchPos.y; |
| 10 | + pos.x = stateFlags->touchPos.x; |
| 11 | + |
| 12 | + state->touch = true; |
| 13 | + state->touchPos.x = pos.x; |
| 14 | + state->touchPos.y = pos.y; |
| 15 | + } else { |
| 16 | + if ((stateFlags->flags & 1) == 0) { |
| 17 | + state->touchPos.x = stateFlags->touchPos.x; |
| 18 | + } |
| 19 | + |
| 20 | + if ((stateFlags->flags & 2) == 0) { |
| 21 | + state->touchPos.y = stateFlags->touchPos.y; |
| 22 | + } |
| 23 | + |
| 24 | + if (state->touchPos.x >= 0 && state->touchPos.x < 0x100 && state->touchPos.y >= 0 && state->touchPos.y < 0xC0) { |
| 25 | + state->touch = true; |
| 26 | + } else { |
| 27 | + state->touch = false; |
| 28 | + state->unk_01 = false; |
| 29 | + state->touchPos.x = -1; |
| 30 | + state->touchPos.y = -1; |
| 31 | + } |
| 32 | + } |
| 33 | + } else { |
| 34 | + state->touch = false; |
| 35 | + state->unk_01 = false; |
| 36 | + state->touchPos.x = -1; |
| 37 | + state->touchPos.y = -1; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +THUMB TouchControl::TouchControl() { |
| 42 | + this->mSpeed = 1; |
| 43 | + this->mTimeBetweenTouches = -1; |
| 44 | + this->mTimeSinceTouch = -1; |
| 45 | + this->mRepeatStart = 20; |
| 46 | + this->mRepeatLoop = 6; |
| 47 | + this->mTouchPosLast.x = 128; |
| 48 | + this->mRepeatTimer = 0; |
| 49 | + |
| 50 | + this->mState.touch = false; |
| 51 | + this->mState.unk_01 = false; |
| 52 | + this->mState.touchPos.x = -1; |
| 53 | + this->mState.touchPos.y = -1; |
| 54 | + |
| 55 | + this->mPrevState.touch = false; |
| 56 | + this->mPrevState.unk_01 = false; |
| 57 | + this->mPrevState.touchPos.x = -1; |
| 58 | + this->mPrevState.touchPos.y = -1; |
| 59 | + |
| 60 | + this->mTouchPosLast.y = 96; |
| 61 | + this->mTouchPosStart.x = -1; |
| 62 | + this->mTouchPosStart.y = -1; |
| 63 | + this->mFlags = TouchFlag_None; |
| 64 | +} |
| 65 | + |
| 66 | +ARM void TouchControl::IncreaseSpeed(u16 increase) { |
| 67 | + this->mFlags = TouchFlag_None; |
| 68 | + this->mSpeed += increase; |
| 69 | +} |
| 70 | + |
| 71 | +// non-matching |
| 72 | +ARM void TouchControl::UpdateFlags(u16 speed) { |
| 73 | + this->mFlags = TouchFlag_None; |
| 74 | + |
| 75 | + if (this->mPrevState.unk_01 == false && this->mState.unk_01 == false) { |
| 76 | + if (this->mPrevState.touch == false && this->mState.touch == true) { |
| 77 | + this->mFlags |= TouchFlag_TouchedNow; |
| 78 | + } |
| 79 | + |
| 80 | + if (this->mPrevState.touch == true && this->mState.touch == false) { |
| 81 | + this->mFlags |= TouchFlag_UntouchedNow; |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + if (this->mSpeed < speed) { |
| 86 | + this->mSpeed = speed; |
| 87 | + } |
| 88 | + |
| 89 | + switch (!(this->mFlags & TouchFlag_TouchedNow)) { |
| 90 | + default: |
| 91 | + this->mFlags |= TouchFlag_Repeat; |
| 92 | + this->mRepeatTimer = this->mRepeatStart; |
| 93 | + break; |
| 94 | + case 0: |
| 95 | + if (this->mState.touch != false && this->mRepeatTimer != 0) { |
| 96 | + if (this->mRepeatTimer - this->mSpeed > 0) { |
| 97 | + this->mRepeatTimer -= this->mSpeed; |
| 98 | + } else { |
| 99 | + this->mFlags |= TouchFlag_Repeat; |
| 100 | + this->mRepeatTimer = this->mRepeatLoop; |
| 101 | + } |
| 102 | + } |
| 103 | + break; |
| 104 | + } |
| 105 | + |
| 106 | + if (this->mTimeSinceTouch + this->mSpeed < 0xFFFF) { |
| 107 | + this->mTimeSinceTouch += this->mSpeed; |
| 108 | + } else { |
| 109 | + this->mTimeSinceTouch = -1; |
| 110 | + } |
| 111 | + |
| 112 | + if (this->mFlags & TouchFlag_TouchedNow) { |
| 113 | + this->mTimeBetweenTouches = this->mTimeSinceTouch; |
| 114 | + this->mTimeSinceTouch = 0; |
| 115 | + this->mTouchPosStart.x = this->mState.touchPos.x; |
| 116 | + this->mTouchPosStart.y = this->mState.touchPos.y; |
| 117 | + } |
| 118 | + |
| 119 | + this->mSpeed = speed; |
| 120 | + |
| 121 | + if (this->mState.touch) { |
| 122 | + this->mTouchPosLast.x = this->mState.touchPos.x; |
| 123 | + this->mTouchPosLast.y = this->mState.touchPos.y; |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +ARM void TouchControl::UpdateWithStateFlags(TouchStateFlags *state, u16 speed) { |
| 128 | + *(TouchStateU *) &this->mPrevState = *(TouchStateU *) &this->mState; |
| 129 | + this->UpdateState(&this->mState, state); |
| 130 | + this->UpdateFlags(speed); |
| 131 | +} |
| 132 | + |
| 133 | +ARM void TouchControl::Update(TouchState *state, u16 speed) { |
| 134 | + TouchStateU curState = *(TouchStateU *) &this->mState; |
| 135 | + TouchStateU newState = *(TouchStateU *) &*state; |
| 136 | + |
| 137 | + this->mPrevState.touch = curState.touch; |
| 138 | + |
| 139 | + this->mPrevState.touch = curState.touch; |
| 140 | + this->mPrevState.unk_01 = curState.unk_01; |
| 141 | + this->mPrevState.touchPos.x = curState.touchPos.x; |
| 142 | + this->mPrevState.touchPos.y = curState.touchPos.y; |
| 143 | + |
| 144 | + this->mState.touch = newState.touch; |
| 145 | + this->mState.unk_01 = newState.unk_01; |
| 146 | + this->mState.touchPos.x = newState.touchPos.x; |
| 147 | + this->mState.touchPos.y = newState.touchPos.y; |
| 148 | + |
| 149 | + this->UpdateFlags(speed); |
| 150 | +} |
| 151 | + |
| 152 | +ARM bool TouchControl::func_020143f0() { |
| 153 | + return ((*((u16 *) 0x027FFFA8) & 0x8000) >> 15) == 1; |
| 154 | +} |
| 155 | + |
| 156 | +ARM void TouchControl::func_02014414(u16 speedIncrease, bool shouldIncrease) { |
| 157 | + TouchStateFlags touchState; |
| 158 | + |
| 159 | + if (shouldIncrease) { |
| 160 | + this->IncreaseSpeed(speedIncrease); |
| 161 | + return; |
| 162 | + } |
| 163 | + |
| 164 | + if (TouchControl::func_020143f0()) { |
| 165 | + Fill16(0, (u16 *) &touchState, sizeof(TouchStateFlags)); |
| 166 | + } else { |
| 167 | + TP_GetTouchStateFlags(&touchState); |
| 168 | + } |
| 169 | + |
| 170 | + this->UpdateWithStateFlags(&touchState, speedIncrease); |
| 171 | +} |
| 172 | + |
| 173 | +ARM void TouchControl::func_02014478(TouchState *state, u16 speed) { |
| 174 | + TouchControl::func_020143f0(); |
| 175 | + this->Update(state, speed); |
| 176 | +} |
0 commit comments