SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
MapPartsRotator.cpp
1#include "Game/MapObj/MapPartsRotator.hpp"
2#include "Game/LiveActor/Spine.hpp"
3#include "Game/Util.hpp"
4
5#ifdef NON_MATCHING
6// floating reg order on the inlined matrix set, but oh well
7MapPartsRotator::MapPartsRotator(LiveActor *pActor) : MapPartsFunction(pActor, "自身回転") {
8 _18 = 0.0f;
9 mRotateAngle = 0.0f;
10 mRotateStopTime = 0;
11 mTargetAngle = 0.0f;
12 mRotateSpeed = 0.0f;
13 mAngle = 0.0f;
14 mRotateAxis = 0;
15 mRotateAccelType = 0;
16 mRotateType = 1;
17 mSignMotionType = 0;
18 _A0 = 0.0f;
19 mIsOnReverse = false;
20 _40.identity();
21 _70.identity();
22 updateBaseHostMtx();
23 _70.setInline(_40);
24}
25#endif
26
28 MR::getMapPartsArgRotateAngle(&mRotateAngle, rIter);
29 MR::getMapPartsArgRotateAxis(&mRotateAxis, rIter);
30 MR::getMapPartsArgRotateAccelType(&mRotateAccelType, rIter);
31 initRotateSpeed(rIter);
32 MR::getMapPartsArgRotateStopTime(&mRotateStopTime, rIter);
33 MR::getMapPartsArgRotateType(&mRotateType, rIter);
34 MR::getMapPartsArgSignMotionType(&mSignMotionType, rIter);
35
36 if (MR::isNearZero(_18, 0.001f)) {
37 initNerve(&NrvMapPartsRotator::HostTypeNeverMove::sInstance);
38 }
39 else {
40 initNerve(&NrvMapPartsRotator::HostTypeWait::sInstance);
41 }
42
43 bool cond = 0.0f < _18;
44 f32 angle;
45
46 if (cond) {
47 angle = mRotateAngle;
48 }
49 else {
50 angle = -mRotateAngle;
51 }
52
53 mTargetAngle = angle;
54}
55
56void MapPartsRotator::start() {
57 updateTargetAngle();
58 updateRotateMtx((AxisType)mRotateAxis, mAngle);
59 setNerve(&NrvMapPartsRotator::HostTypeRotate::sInstance);
60}
61
62void MapPartsRotator::end() {
63 setNerve(&NrvMapPartsRotator::HostTypeWait::sInstance);
64}
65
66bool MapPartsRotator::isWorking() const {
67 if (!isNerve(&NrvMapPartsRotator::HostTypeNeverMove::sInstance)) {
68 return !isNerve(&NrvMapPartsRotator::HostTypeWait::sInstance);
69 }
70
71 return false;
72}
73
74void MapPartsRotator::startWithSignalMotion() {
75 updateBaseHostMtx();
76 updateTargetAngle();
77 setNerve(&NrvMapPartsRotator::HostTypeRotateStart::sInstance);
78}
79
80void MapPartsRotator::cancelSignalMotion() {
81 mAngle = _A0;
82 updateRotateMtx((AxisType)mRotateAxis, _A0);
83 setNerve(&NrvMapPartsRotator::HostTypeWait::sInstance);
84}
85
86bool MapPartsRotator::isMoving() const {
87 return isNerve(&NrvMapPartsRotator::HostTypeRotate::sInstance);
88}
89
90void MapPartsRotator::restartAtEnd() {
91 if (mRotateType != 0) {
92 if (mRotateType == 1) {
93 _18 *= -1.0f;
94 }
95
96 updateTargetAngle();
97
98 if (MR::hasMapPartsMoveStartSignMotion(mSignMotionType)) {
99 setNerve(&NrvMapPartsRotator::HostTypeRotateStart::sInstance);
100 }
101 else {
102 setNerve(&NrvMapPartsRotator::HostTypeRotate::sInstance);
103 }
104 }
105}
106
107void MapPartsRotator::initRotateSpeed(const JMapInfoIter &rIter) {
108 if (mRotateAccelType == 2) {
109 s32 rotate_time = 0;
110 MR::getMapPartsArgRotateTime(&rotate_time, rIter);
111 _18 = mRotateAngle / rotate_time;
112 }
113 else {
114 MR::getMapPartsArgRotateSpeed(&mRotateSpeed, rIter);
115 _18 *= 0.0099999998f;
116 }
117
118 if (mRotateAngle < 0.0f) {
119 _18 = 0.0f;
120 }
121}
122
123void MapPartsRotator::calcRotateAxisDir(AxisType type, TVec3f *pDir) const {
124 f32 x, y, z;
125 switch (type) {
126 case 0:
127 z = _40.mMtx[2][0];
128 y = _40.mMtx[1][0];
129 x = _40.mMtx[0][0];
130 pDir->set(x, y, z);
131 break;
132 case 1:
133 z = _40.mMtx[2][1];
134 y = _40.mMtx[1][1];
135 x = _40.mMtx[0][1];
136 pDir->set(x, y, z);
137 break;
138 case 2:
139 z = _40.mMtx[2][2];
140 y = _40.mMtx[1][2];
141 x = _40.mMtx[0][2];
142 pDir->set(x, y, z);
143 break;
144 }
145}
146
147MapPartsRotator::~MapPartsRotator() {
148
149}
150
151namespace NrvMapPartsRotator {
152 HostTypeNeverMove HostTypeNeverMove::sInstance;
153 HostTypeWait HostTypeWait::sInstance;
154 HostTypeRotateStart HostTypeRotateStart::sInstance;
155 HostTypeRotate HostTypeRotate::sInstance;
156 HostTypeStopAtEnd HostTypeStopAtEnd::sInstance;
157
158 void HostTypeStopAtEnd::execute(Spine *pSpine) const {
159 MapPartsRotator* rotator = reinterpret_cast<MapPartsRotator*>(pSpine->mExecutor);
160 if (rotator->isStep(rotator->mRotateStopTime)) {
161 rotator->restartAtEnd();
162 }
163 }
164
165 void HostTypeRotate::execute(Spine *pSpine) const {
166 MapPartsRotator* rotator = reinterpret_cast<MapPartsRotator*>(pSpine->mExecutor);
167 rotator->exeRotate();
168 }
169
170 void HostTypeRotateStart::execute(Spine *pSpine) const {
171 MapPartsRotator* rotator = reinterpret_cast<MapPartsRotator*>(pSpine->mExecutor);
172 rotator->exeRotateStart();
173 }
174
175 void HostTypeWait::execute(Spine *pSpine) const {
176
177 }
178
179 void HostTypeNeverMove::execute(Spine *pSpine) const {
180
181 }
182};
183
184bool MapPartsRotator::isOnReverse() const {
185 return mIsOnReverse;
186}
187
188f32 MapPartsRotator::getRotateSpeed() const {
189 return mRotateSpeed;
190}
The basis of a drawable actor that can contain states (see: Nerve)
Definition LiveActor.hpp:24
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition Spine.hpp:9