SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
LodCtrl.cpp
1#include "Game/LiveActor/LodCtrl.hpp"
2#include "Game/LiveActor/ClippingDirector.hpp"
3
4#include <cstdio>
5
6namespace {
7 void LodFuntionCall(LodCtrl *pCtrl, void (*pFunc)(LiveActor *)) {
8 pFunc(pCtrl->mActor);
9
10 if (pCtrl->_10) {
11 pFunc(pCtrl->_10);
12 }
13
14 if (pCtrl->_14) {
15 pFunc(pCtrl->_14);
16 }
17 }
18
19 template<typename T>
20 void LodFuntionCall(LodCtrl *pCtrl, void (*pFunc)(LiveActor *, T), T arg) {
21 pFunc(pCtrl->mActor, arg);
22
23 if (pCtrl->_10) {
24 pFunc(pCtrl->_10, arg);
25 }
26
27 if (pCtrl->_14) {
28 pFunc(pCtrl->_14, arg);
29 }
30 }
31};
32
33const bool def = false;
34
35LodCtrl::LodCtrl(LiveActor *pActor, const JMapInfoIter &rIter) {
36 _0 = 2000.0f;
37 _4 = 3000.0f;
38 _8 = pActor;
39 mActor = pActor;
40 _10 = nullptr;
41 _14 = nullptr;
42 _18 = 0;
43 _19 = 0;
44 _1A = 1;
45 _1B = 0;
46 mViewGroupID = -1;
47 mActorLightCtrl = nullptr;
48 _1C = &def;
49 _20 = &def;
50 _24 = &def;
51 _28 = &def;
52 MR::getClippingDirector()->entryLodCtrl(this, rIter);
53 mActorLightCtrl = mActor->mActorLightCtrl;
54}
55
56void LodCtrl::offSyncShadowHost() {
57 MR::offShadowVisibleSyncHostAll(mActor);
58 _1A = 0;
59}
60
61void LodCtrl::appear() {
62 MR::showModel(mActor);
63 mActorLightCtrl = mActor->mActorLightCtrl;
64
65 if (_10) {
66 if (MR::isDead(_10)) {
67 _10->kill();
68 }
69 }
70
71 if (_14) {
72 if (MR::isDead(_14)) {
73 _14->kill();
74 }
75 }
76
77 if (_1A) {
78 MR::offShadowVisibleSyncHostAll(mActor);
79 }
80}
81
82void LodCtrl::kill() {
83 MR::showModel(mActor);
84
85 if (_10) {
86 if (MR::isDead(_10)) {
87 _10->kill();
88 }
89 }
90
91 if (_14) {
92 if (MR::isDead(_14)) {
93 _14->kill();
94 }
95 }
96
97 if (_1A) {
98 MR::onShadowVisibleSyncHostAll(mActor);
99 }
100
101 mActorLightCtrl = 0;
102}
103
104void LodCtrl::validate() {
105 appear();
106 _18 = 1;
107}
108
109void LodCtrl::invalidate() {
110 kill();
111 _18 = 0;
112}
113
114bool LodCtrl::isShowLowModel() const {
115 ModelObj* obj = _14;
116 bool ret = false;
117
118 if (obj && obj == _8) {
119 ret = true;
120 }
121
122 return ret;
123}
124
125void LodCtrl::setDistanceToMiddle(f32 dist) {
126 _0 = dist;
127}
128
129f32 LodCtrl::calcDistanceToCamera() const {
130 if (_1B) {
131 return MR::calcCameraDistanceZ(mActor->mPosition);
132 }
133
134 return MR::calcDistanceToPlayer(mActor);
135}
136
137void LodCtrl::setDistanceToLow(f32 dist) {
138 _4 = dist;
139}
140
141void LodCtrl::setDistanceToMiddleAndLow(f32 mid_dist, f32 low_dist) {
142 _0 = mid_dist;
143 _4 = low_dist;
144}
145
146void LodCtrl::setClippingTypeSphereContainsModelBoundingBox(f32 bounds) {
147 LodFuntionCall<f32>(this, MR::setClippingTypeSphereContainsModelBoundingBox, bounds);
148}
149
150void LodCtrl::setFarClipping(f32 clip) {
151 LodFuntionCall<f32>(this, MR::setClippingFar, clip);
152}
153
154void LodCtrl::invalidateClipping() {
155 LodFuntionCall(this, MR::invalidateClipping);
156}
157
158void LodCtrl::showHighModel() {
159 if (MR::isHiddenModel(mActor)) {
160 if (mActorLightCtrl) {
161 mActor->mActorLightCtrl->copy(mActorLightCtrl);
162 }
163
164 mActorLightCtrl = mActor->mActorLightCtrl;
165 MR::showModel(mActor);
166 }
167 else {
168 if (_10) {
169 if (!MR::isDead(_10)) {
170 _10->makeActorDead();
171 }
172 }
173
174 if (_14) {
175 if (!MR::isDead(_14)) {
176 _14->makeActorDead();
177 }
178 }
179 }
180
181 _8 = mActor;
182}
183
184void LodCtrl::showMiddleModel() {
185 if (MR::isDead(_10)) {
186 if (mActorLightCtrl) {
187 _10->mActorLightCtrl->copy(mActorLightCtrl);
188 }
189
190 mActorLightCtrl = _10->mActorLightCtrl;
191 _10->makeActorAppeared();
192 MR::calcAnimDirect(mActor);
193 }
194 else {
195 if (!MR::isHiddenModel(mActor)) {
196 MR::hideModelAndOnCalcAnim(mActor);
197 }
198
199 if (_14) {
200 if (!MR::isDead(_14)) {
201 _14->makeActorDead();
202 }
203 }
204 }
205
206 _8 = _10;
207}
208
209void LodCtrl::showLowModel() {
210 if (MR::isDead(_14)) {
211 if (mActorLightCtrl) {
212 _14->mActorLightCtrl->copy(mActorLightCtrl);
213 }
214
215 mActorLightCtrl = _14->mActorLightCtrl;
216 _14->makeActorAppeared();
217 MR::calcAnimDirect(mActor);
218 }
219 else {
220 if (!MR::isHiddenModel(mActor)) {
221 MR::hideModelAndOnCalcAnim(mActor);
222 }
223
224 if (_10 && !MR::isDead(_10)) {
225 _10->makeActorDead();
226 }
227 }
228
229 _8 = _14;
230}
231
232void LodCtrl::hideAllModel() {
233 if (!MR::isHiddenModel(mActor)) {
234 MR::hideModelAndOnCalcAnim(mActor);
235 }
236
237 if (_10) {
238 if (!MR::isDead(_10)) {
239 _10->makeActorDead();
240 }
241 }
242
243 if (_14) {
244 if (!MR::isDead(_14)) {
245 _14->makeActorDead();
246 }
247 }
248
249 _8 = 0;
250}
251
252void LodCtrl::setViewCtrlPtr(const bool *a1, const bool *a2, const bool *a3, const bool *a4) {
253 _1C = a1;
254 _20 = a2;
255 _24 = a3;
256 _28 = a4;
257}
258
259void LodCtrl::createLodModel(int a1, int a2, int a3) {
260 _10 = initLodModel(a1, a2, a3, false);
261 _14 = initLodModel(a1, a2, a3, true);
262
263 if (_10 || _14) {
264 appear();
265 _18 = 1;
266 }
267 else {
268 kill();
269 _18 = 0;
270 }
271}
272
273void LodCtrl::syncMaterialAnimation() {
274 if (_10) {
275 MR::syncMaterialAnimation(_10, mActor);
276 }
277
278 if (_14) {
279 MR::syncMaterialAnimation(_14, mActor);
280 }
281}
282
283void LodCtrl::syncJointAnimation() {
284 if (_10) {
285 MR::syncJointAnimation(_10, mActor);
286 }
287
288 if (_14) {
289 MR::syncJointAnimation(_14, mActor);
290 }
291}
292
293void LodCtrl::initLightCtrl() {
294 if (_10) {
295 MR::initLightCtrl(_10);
296 }
297
298 if (_14) {
299 MR::initLightCtrl(_14);
300 }
301}
302
303ModelObj* LodCtrl::initLodModel(int a1, int a2, int a3, bool isLowModel) const {
304 const char* res = MR::getModelResName(mActor);
305 const char* type = isLowModel ? "Low" : "Middle";
306 char buf[0x100];
307 snprintf(buf, 0x100, "/ObjectData/%s%s.arc", res, type);
308
309 if (!MR::isFileExist(buf, false)) {
310 return nullptr;
311 }
312
313 const char* objName = isLowModel ? MR::createLowModelObjName(mActor) : MR::createMiddleModelObjName(mActor);
314 snprintf(buf, 0x100, "%s%s", res, type);
315 ModelObj* obj = new ModelObj(objName, buf, mActor->getBaseMtx(), a1, a2, a3, false);
316 obj->initWithoutIter();
317 obj->makeActorDead();
318 MR::setClippingTypeSphereContainsModelBoundingBox(obj, 100.0f);
319 MR::copyTransRotateScale(mActor, obj);
320 return obj;
321}
322
323bool LodCtrlFunction::isExistLodLowModel(const char *pName) {
324 char buf[0x100];
325 snprintf(buf, 0x100, "/ObjectData/%sLow.arc", pName);
326 return MR::isFileExist(buf, false);
327}
The basis of a drawable actor that can contain states (see: Nerve)
Definition LiveActor.hpp:24
TVec3f mPosition
3D vector of the actor's position.
Definition LiveActor.hpp:95
virtual MtxPtr getBaseMtx() const
Gets the base matrix of the model used for the actor.
void initWithoutIter()
Initializes a NameObj without a JMapInfoIter instance.
Definition NameObj.cpp:41