SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
LiveActor.cpp
1#include "Game/LiveActor/LiveActor.hpp"
2#include "Game/LiveActor/AllLiveActorGroup.hpp"
3#include "Game/LiveActor/Binder.hpp"
4#include "Game/LiveActor/ClippingDirector.hpp"
5#include "Game/LiveActor/ActorPadAndCameraCtrl.hpp"
6#include "Game/NameObj/NameObjExecuteHolder.hpp"
7#include "Game/Util.hpp"
8
9LiveActor::LiveActor(const char* pName) : NameObj(pName),
10 mPosition(0.0f), mRotation(0.0f), mScale(1.0f), mVelocity(0.0f), mGravity(0.0f, -1.0f, 0.0f),
11 mModelManager(nullptr), mAnimationKeeper(nullptr), mSpine(nullptr),
12 mSensorKeeper(nullptr), mBinder(nullptr), mRailRider(nullptr),
13 mEffectKeeper(nullptr), mSoundObject(nullptr) {
14
15 mShadowList = nullptr;
16 mCollisionParts = nullptr;
17 mStageSwitchCtrl = nullptr;
18 mStarPointerTarget = nullptr;
19 mActorLightCtrl = nullptr;
20 mCameraCtrl = nullptr;
21
22 MR::getAllLiveActorGroup()->registerActor(this);
23 MR::getClippingDirector()->registerActor(this);
24}
25
27
28}
29
30void LiveActor::appear() {
31 makeActorAppeared();
32}
33
34void LiveActor::makeActorAppeared() {
35 if (mSensorKeeper) {
36 mSensorKeeper->validateBySystem();
37 }
38
39 if (MR::isClipped(this)) {
40 endClipped();
41 }
42
43 mFlags.mIsDead = false;
44 if (mCollisionParts) {
45 MR::validateCollisionParts(this);
46 }
47
48 MR::resetPosition(this);
49 if (mActorLightCtrl) {
50 mActorLightCtrl->reset();
51 }
52
53 MR::tryUpdateHitSensorsAll(this);
54 MR::addToClippingTarget(this);
55 MR::connectToSceneTemporarily(this);
56
57 if (!MR::isNoEntryDrawBuffer(this)) {
58 MR::connectToDrawTemporarily(this);
59 }
60}
61
62void LiveActor::kill() {
63 makeActorDead();
64}
65
66#ifdef NON_MATCHING
67void LiveActor::makeActorDead() {
68 mVelocity.z = 0.0f;
69 mVelocity.y = 0.0f;
70 mVelocity.x = 0.0f;
71 MR::clearHitSensors(this);
72
73 if (mSensorKeeper) {
74 mSensorKeeper->invalidateBySystem();
75 }
76
77 if (mBinder) {
78 mBinder->clear();
79 }
80
81 if (mEffectKeeper) {
82 mEffectKeeper->clear();
83 }
84
85 if (mCollisionParts) {
86 MR::invalidateCollisionParts(this);
87 }
88
89 mFlags.mIsDead = true;
90 MR::removeFromClippingTarget(this);
91 MR::disconnectToSceneTemporarily(this);
92 MR::disconnectToDrawTemporarily(this);
93}
94#endif
95
96MtxPtr LiveActor::getTakingMtx() const {
97 return getBaseMtx();
98}
99
100void LiveActor::setNerve(const Nerve *pNerve) {
101 mSpine->setNerve(pNerve);
102}
103
104bool LiveActor::isNerve(const Nerve *pNerve) const {
105 return mSpine->getCurrentNerve() == pNerve;
106}
107
108s32 LiveActor::getNerveStep() const {
109 return mSpine->mStep;
110}
111
112HitSensor* LiveActor::getSensor(const char *pSensorName) const {
113 if (mSensorKeeper) {
114 return mSensorKeeper->getSensor(pSensorName);
115 }
116
117 return 0;
118}
119
120MtxPtr LiveActor::getBaseMtx() const {
121 if (!MR::getJ3DModel(this)) {
122 return 0;
123 }
124
125 return MR::getJ3DModel(this)->_24;
126}
127
128#ifdef NON_MATCHING
129// prologue refuses to schedule right for both of these
130void LiveActor::startClipped() {
132
133 mFlags.onClipped();
134
135 if (keeper != 0) {
136 keeper->invalidateBySystem();
137 }
138
139 EffectKeeper* effectKeeper = mEffectKeeper;
140 if (effectKeeper) {
141 effectKeeper->stopEmitterOnClipped();
142 }
143
144 MR::disconnectToSceneTemporarily(this);
145
146 if (!MR::isNoEntryDrawBuffer(this)) {
147 MR::disconnectToDrawTemporarily(this);
148 }
149}
150
151void LiveActor::endClipped() {
152 mFlags.mIsClipped = false;
153
154 if (mSensorKeeper) {
155 mSensorKeeper->validateBySystem();
156 MR::updateHitSensorsAll(this);
157 }
158
159 if (mEffectKeeper) {
160 mEffectKeeper->playEmitterOffClipped();
161 }
162
163 MR::connectToSceneTemporarily(this);
164
165 if (!MR::isNoEntryDrawBuffer(this)) {
166 MR::connectToDrawTemporarily(this);
167 }
168}
169#endif
170
171void LiveActor::initModelManagerWithAnm(const char *pName, const char *a2, bool a3) {
173 mModelManager->init(pName, a2, a3);
174 MR::getJ3DModel(this)->setBaseScale(reinterpret_cast<const Vec &>(mScale));
176 MR::calcJ3DModel(this);
177 mAnimationKeeper = ActorAnimKeeper::tryCreate(this);
178 mCameraCtrl = ActorPadAndCameraCtrl::tryCreate(mModelManager, &mPosition);
179}
180
181void LiveActor::initNerve(const Nerve *pNerve) {
182 mSpine = new Spine(this, pNerve);
183}
184
185void LiveActor::initHitSensor(int numSensors) {
186 mSensorKeeper = new HitSensorKeeper(numSensors);
187}
188
189// LiveActor::initBinder
190
191void LiveActor::initRailRider(const JMapInfoIter &rIter) {
192 mRailRider = new RailRider(rIter);
193}
194
195#ifdef NON_MATCHING
196void LiveActor::initEffectKeeper(int a1, const char *a2, bool doSort) {
197 EffectKeeper* keeper = new EffectKeeper(mName, MR::getModelResourceHolder(this), a1, a2);
198 mEffectKeeper = keeper;
199
200 if (doSort) {
201 keeper->enableSort();
202 }
203
204 keeper->init(this);
205
206 if (mBinder) {
207 keeper->setBinder(mBinder);
208 }
209}
210#endif
211
212// LiveActor::initSound
213
214void LiveActor::initShadowControllerList(u32 numShadows) {
215 mShadowList = new ShadowControllerList(this, numShadows);
216}
217
218// LiveActor::initActorCollisionParts
219
220void LiveActor::initStageSwitch(const JMapInfoIter &rIter) {
221 mStageSwitchCtrl = MR::createStageSwitchCtrl(this, rIter);
222}
223
224// LiveActor::initActorStarPointerTarget
225
226void LiveActor::initActorLightCtrl() {
227 mActorLightCtrl = new ActorLightCtrl(this);
228}
229
230void LiveActor::attackSensor(HitSensor *, HitSensor *) {
231
232}
233
234u32 LiveActor::receiveMsgApart(HitSensor *pSensor_0, HitSensor *pSensor_1) {
235 MR::setHitSensorApart(pSensor_0, pSensor_1);
236 return 1;
237}
RailRider * mRailRider
A pointer to a RailRider instance, used for allowing the actor to ride on paths.
HitSensorKeeper * mSensorKeeper
A pointer to a HitSensorKeeper instance, used for storing HitSensor instances.
TVec3f mPosition
3D vector of the actor's position.
Definition LiveActor.hpp:95
LiveActor(const char *pName)
Constructs a new LiveActor instance.
Definition LiveActor.cpp:9
TVec3f mScale
3D vector of the actor's scale.
Definition LiveActor.hpp:97
TVec3f mVelocity
3D vector of the actor's velocity.
Definition LiveActor.hpp:98
StageSwitchCtrl * mStageSwitchCtrl
A pointer to a StageSwitchCtrl instance, used for activating and deactivating switches.
LiveActorFlag mFlags
Flags relating to drawing, animation calculation, etc.
virtual void init(JMapInfoIter const &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition LiveActor.cpp:26
virtual void calcAndSetBaseMtx()
Calculates and sets the base matrix of the actor.
ModelManager * mModelManager
A pointer to a ModelManager instance, used for drawing a 3D model.
ActorAnimKeeper * mAnimationKeeper
A pointer to a ActorAnimKeeper instance, used for storing and playing model animations.
virtual MtxPtr getBaseMtx() const
Gets the base matrix of the model used for the actor.
HitSensor * getSensor(const char *pSensorName) const
Gets a sensor.
The most basic form of an object.
Definition NameObj.hpp:11
const char * mName
A string to identify the NameObj.
Definition NameObj.hpp:38
Used for executing states of a LiveActor.
Definition Nerve.hpp:6
Definition Spine.hpp:9