SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
RailRider.cpp
1#include "Game/LiveActor/RailRider.hpp"
2
3RailRider::RailRider(const JMapInfoIter &rIter) {
4 mBezierRail = nullptr;
5 mCoord = 0.0f;
6 mSpeed = 0.0f;
7 mIsNotReverse = true;
8 mCurPos.x = 0.0f;
9 mCurPos.y = 0.0f;
10 mCurPos.z = 0.0f;
11 mCurDirection.x = 1.0f;
12 mCurDirection.y = 0.0f;
13 mCurDirection.z = 0.0f;
14 mStartPos.x = 0.0f;
15 mStartPos.y = 0.0f;
16 mStartPos.z = 0.0f;
17 mEndPos.x = 0.0f;
18 mEndPos.y = 0.0f;
19 mEndPos.z = 0.0f;
20 const JMapInfo* info = nullptr;
21 JMapInfoIter iter;
22 iter.mInfo = nullptr;
23 iter._4 = -1;
24 MR::getRailInfo(&iter, &info, rIter);
25 initBezierRail(iter, info);
26}
27
28RailRider::RailRider(s32 a1, s32 a2) {
29 mBezierRail = nullptr;
30 mCoord = 0.0f;
31 mSpeed = 0.0f;
32 mIsNotReverse = true;
33 mCurPos.x = 0.0f;
34 mCurPos.y = 0.0f;
35 mCurPos.z = 0.0f;
36 mCurDirection.x = 1.0f;
37 mCurDirection.y = 0.0f;
38 mCurDirection.z = 0.0f;
39 mStartPos.x = 0.0f;
40 mStartPos.y = 0.0f;
41 mStartPos.z = 0.0f;
42 mEndPos.x = 0.0f;
43 mEndPos.y = 0.0f;
44 mEndPos.z = 0.0f;
45 const JMapInfo* info = nullptr;
46 JMapInfoIter iter;
47 iter.mInfo = nullptr;
48 iter._4 = -1;
49 MR::getCameraRailInfo(&iter, &info, a1, a2);
50 initBezierRail(iter, info);
51}
52
53void RailRider::move() {
54 if (mIsNotReverse) {
55 mCoord += mSpeed;
56 }
57 else {
58 mCoord -= mSpeed;
59 }
60
61 mCoord = mBezierRail->normalizePos(mCoord, 1);
62 syncPosDir();
63}
64
65void RailRider::moveToNearestPos(const TVec3f &rPos) {
66 mCoord = mBezierRail->getNearestRailPosCoord(rPos);
67 syncPosDir();
68}
69
70// RailRider::moveToNearestPoint()
71
72void RailRider::moveToNextPoint() {
73 mCoord = mBezierRail->getRailPosCoord(getNextPointNo());
74 syncPosDir();
75}
76
77void RailRider::reverse() {
78 if (mIsNotReverse != false) {
79 mIsNotReverse = false;
80 }
81 else {
82 mIsNotReverse = true;
83 }
84
85 syncPosDir();
86}
87
88void RailRider::calcPosAtCoord(TVec3f *pOutVec, f32 a2) const {
89 mBezierRail->calcPos(pOutVec, a2);
90}
91
92void RailRider::calcDirectionAtCoord(TVec3f *pOutVec, f32 a2) const {
93 mBezierRail->calcDirection(pOutVec, a2);
94}
95
96f32 RailRider::calcNearestPos(const TVec3f &rPos) const {
97 return mBezierRail->getNearestRailPosCoord(rPos);
98}
99
100f32 RailRider::getTotalLength() const {
101 return mBezierRail->getTotalLength();
102}
103
104f32 RailRider::getPartLength(int idx) const {
105 return mBezierRail->getPartLength(idx);
106}
107
108bool RailRider::isLoop() const {
109 return mBezierRail->mIsClosed;
110}
111
112#ifdef NON_MATCHING // Wrong registers
113bool RailRider::isReachedGoal() const {
114 if (mBezierRail->mIsClosed) {
115 return false;
116 }
117
118 bool v3 = true;
119 bool v4 = false;
120
121 if (mIsNotReverse) {
122 if (MR::isNearZero(mLength - mBezierRail->getTotalLength(), 0.0f)) {
123 v4 = true;
124 }
125 }
126
127 if (!v4) {
128 bool v6 = false;
129 if (!mIsNotReverse && MR::isNearZero(mLength, 0.001f)) {
130 v6 = true;
131 }
132
133 if (!v6) {
134 v3 = false;
135 }
136 }
137
138 return v3;
139}
140#endif
141
142bool RailRider::isReachedEdge() const {
143 bool ret;
144
145 if (mBezierRail->mIsClosed) {
146 return false;
147 }
148 else {
149 ret = true;
150
151 if (!MR::isNearZero(mCoord, 0.001f)) {
152 f32 val = mCoord - mBezierRail->getTotalLength();
153 if (!MR::isNearZero(val, 0.001f)) {
154 ret = false;
155 }
156 }
157 }
158
159 return ret;
160}
161
162#ifdef NON_MATCHING // missing frsp instruction
163void RailRider::setCoord(f32 coord) {
164 mCoord = coord;
165 mBezierRail->normalizePos(coord, 1);
166 syncPosDir();
167}
168#endif
169
170void RailRider::setSpeed(f32 coord) {
171 mSpeed = coord;
172}
173
174bool RailRider::getRailArgWithInit(const char *pStr, s32 *pOut) const {
175 s32 val;
176 if (!mBezierRail->mIter->getValue<s32>(pStr, &val)) {
177 return false;
178 }
179
180 *pOut = val;
181 return true;
182}
183
184bool RailRider::getRailArgNoInit(const char *pStr, s32 *pOut) const {
185 s32 val;
186 if (!mBezierRail->mIter->getValue<s32>(pStr, &val)) {
187 return false;
188 }
189
190 if (val == -1) {
191 return false;
192 }
193
194 *pOut = val;
195 return true;
196}
197
198f32 RailRider::getNextPointCoord() const {
199 return mBezierRail->getRailPosCoord(getNextPointNo());
200}
201
202f32 RailRider::getCurrentPointCoord() const {
203 return mBezierRail->getRailPosCoord(mCurPoint);
204}
205
206s32 RailRider::getPointNum() const {
207 return mBezierRail->mPointNum;
208}
209
210void RailRider::copyPointPos(TVec3f *pOut, s32 pointNum) const {
211 JMapInfoIter iter;
212 iter.mInfo = nullptr;
213 iter._4 = -1;
214 mBezierRail->calcRailCtrlPointIter(&iter, pointNum);
215 MR::getRailPointPos0(iter, pOut);
216}
217
218f32 RailRider::getPointCoord(s32 idx) const {
219 return mBezierRail->getRailPosCoord(idx);
220}
221
222#ifdef NON_MATCHING // Second call to setCoord gets inlined
223void RailRider::initBezierRail(const JMapInfoIter &rIter, const JMapInfo *pInfo) {
224 mBezierRail = new BezierRail(rIter, pInfo);
225 syncPosDir();
226 setCoord(mBezierRail->getTotalLength());
227 mEndPos.set(mCurPos);
228 setCoord(0.0f);
229 mStartPos.set(mCurPos);
230}
231#endif
232
233bool RailRider::getPointArgS32NoInit(const char *pStr, s32 *pOut, s32 pointNum) const {
234 s32 val;
235 JMapInfoIter iter;
236 iter.mInfo = nullptr;
237 iter._4 = -1;
238
239 mBezierRail->calcRailCtrlPointIter(&iter, pointNum);
240 val = -1;
241 iter.getValue<s32>(pStr, &val);
242
243 if (val != -1) {
244 *pOut = val;
245 return true;
246 }
247
248 return false;
249}
250
251bool RailRider::getPointArgS32WithInit(const char *pStr, s32 *pOut, s32 pointNum) const {
252 JMapInfoIter iter;
253 iter.mInfo = nullptr;
254 iter._4 = -1;
255 mBezierRail->calcRailCtrlPointIter(&iter, pointNum);
256 iter.getValue<s32>(pStr, pOut);
257 return true;
258}
259
260bool RailRider::getCurrentPointArgS32NoInit(const char *pStr, s32 *pOut) const {
261 s32 val;
262 JMapInfoIter iter;
263 iter.mInfo = nullptr;
264 iter._4 = -1;
265
266 mBezierRail->calcRailCtrlPointIter(&iter, mCurPoint);
267 val = -1;
268 iter.getValue<s32>(pStr, &val);
269
270 if (val != -1) {
271 *pOut = val;
272 return true;
273 }
274
275 return false;
276}
277
278bool RailRider::getCurrentPointArgS32WithInit(const char *pStr, s32 *pOut) const {
279 JMapInfoIter iter;
280 iter.mInfo = nullptr;
281 iter._4 = -1;
282 mBezierRail->calcRailCtrlPointIter(&iter, mCurPoint);
283 iter.getValue<s32>(pStr, pOut);
284 return true;
285}
286
287bool RailRider::getNextPointArgS32NoInit(const char *pStr, s32 *pOut) const {
288 s32 val;
289 JMapInfoIter iter;
290 iter.mInfo = nullptr;
291 iter._4 = -1;
292
293 mBezierRail->calcRailCtrlPointIter(&iter, getNextPointNo());
294 val = -1;
295 iter.getValue<s32>(pStr, &val);
296
297 if (val != -1) {
298 *pOut = val;
299 return true;
300 }
301
302 return false;
303}
304
305bool RailRider::getNextPointArgS32WithInit(const char *pStr, s32 *pOut) const {
306 JMapInfoIter iter;
307 iter.mInfo = nullptr;
308 iter._4 = -1;
309 mBezierRail->calcRailCtrlPointIter(&iter, getNextPointNo());
310 iter.getValue<s32>(pStr, pOut);
311 return true;
312}
313
314// RailRider::getNextPointNo()
315
316void RailRider::syncPosDir() {
317 if (0.0f < mCoord && mCoord < mBezierRail->getTotalLength()) {
318 mBezierRail->calcPosDir(&mCurPos, &mCurDirection, mCoord);
319 }
320 else {
321 if (mCoord == 0.0f) {
322 mBezierRail->calcPos(&mCurPos, mCoord);
323 mBezierRail->calcDirection(&mCurDirection, 0.1f);
324 }
325 else {
326 mBezierRail->calcPos(&mCurPos, mCoord);
327 mBezierRail->calcDirection(&mCurDirection, (mBezierRail->getTotalLength() - 0x1f));
328 }
329 }
330
331 if (!mIsNotReverse) {
332 mCurDirection.x *= -1.0f;
333 mCurDirection.y *= -1.0f;
334 mCurDirection.z *= -1.0f;
335 }
336
337 JMapInfoIter iter;
338 iter.mInfo = nullptr;
339 iter._4 = -1;
340 mBezierRail->calcCurrentRailCtrlPointIter(&iter, mCoord, mIsNotReverse);
341 iter.getValue<s32>("id", &mCurPoint);
342}