SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
AreaObj.cpp
1#include "Game/AreaObj/AreaObj.hpp"
2#include "Game/AreaObj/AreaObjFollower.hpp"
3#include "Game/Map/SleepControllerHolder.hpp"
4#include "Game/Util.hpp"
5
6AreaObj::AreaObj(int type, const char *pName) : NameObj(pName) {
7 mType = type;
8 mValid = true;
9 _15 = true;
10 mAwake = true;
11 mObjArg0 = -1;
12 mObjArg1 = -1;
13 mObjArg2 = -1;
14 mObjArg3 = -1;
15 mObjArg4 = -1;
16 mObjArg5 = -1;
17 mObjArg6 = -1;
18 mObjArg7 = -1;
19 mSwitchCtrl = 0;
20
21 switch(type) {
22 case 0:
23 mForm = new AreaFormCube(0);
24 break;
25 case 1:
26 mForm = new AreaFormCube(1);
27 break;
28 case 2:
29 mForm = new AreaFormSphere();
30 break;
31 case 4:
32 mForm = new AreaFormBowl();
33 break;
34 case 3:
35 mForm = new AreaFormCylinder();
36 break;
37 }
38}
39
40// Issues with functors
41void AreaObj::init(const JMapInfoIter &rIter) {
42 mForm->init(rIter);
43 MR::addBaseMatrixFollowerAreaObj(this, rIter);
44 MR::getJMapInfoArg0WithInit(rIter, &mObjArg0);
45 MR::getJMapInfoArg1WithInit(rIter, &mObjArg1);
46 MR::getJMapInfoArg2WithInit(rIter, &mObjArg2);
47 MR::getJMapInfoArg3WithInit(rIter, &mObjArg3);
48 MR::getJMapInfoArg4WithInit(rIter, &mObjArg4);
49 MR::getJMapInfoArg5WithInit(rIter, &mObjArg5);
50 MR::getJMapInfoArg6WithInit(rIter, &mObjArg6);
51 MR::getJMapInfoArg7WithInit(rIter, &mObjArg7);
52 mSwitchCtrl = MR::createStageSwitchCtrl(this, rIter);
53
54 if (mSwitchCtrl->isValidSwitchAppear()) {
55 MR::FunctorV0M<AreaObj *, void (AreaObj::*)()> validateFunc = MR::Functor<AreaObj>(this, &AreaObj::validate);
56 MR::FunctorV0M<AreaObj *, void (AreaObj::*)()> invalidateFunc = MR::Functor<AreaObj>(this, &AreaObj::invalidate);
57 MR::listenNameObjStageSwitchOnOffAppear(this, mSwitchCtrl, validateFunc, invalidateFunc);
58 mValid = false;
59 }
60
61 const char* objName;
62 bool validName = MR::getObjectName(&objName, rIter);
63
64 if (validName) {
65 setName(objName);
66 }
67
68 const char* managerName = getManagerName();
69 MR::getAreaObjManager(managerName)->entry(this);
70 MR::getAreaObjManager(getManagerName());
71 SleepControlFunc::addSleepControl(this, rIter);
72}
73
74bool AreaObj::isInVolume(const TVec3f &rPos) const {
75 bool ret = false;
76
77 if (mValid && _15 && mAwake) {
78 if (mForm->isInVolume(rPos)) {
79 ret = true;
80 }
81 }
82
83 return ret;
84}
85
86void AreaObj::onSwitchA() {
87 mSwitchCtrl->onSwitchA();
88}
89
90void AreaObj::offSwitchA() {
91 mSwitchCtrl->offSwitchA();
92}
93
94bool AreaObj::isOnSwitchA() const {
95 return mSwitchCtrl->isOnSwitchA();
96}
97
98bool AreaObj::isOnSwitchB() const {
99 return mSwitchCtrl->isOnSwitchB();
100}
101
102bool AreaObj::isValidSwitchA() const {
103 return mSwitchCtrl->isOnSwitchA();
104}
105
106bool AreaObj::isValidSwitchB() const {
107 return mSwitchCtrl->isOnSwitchB();
108}
109
110void AreaObj::setFollowMtx(const TPos3f *pMtx) {
111 mForm->_4 = (TPos3f*)pMtx;
112}
113
114TPos3f* AreaObj::getFollowMtx() const {
115 return mForm->_4;
116}
117
118AreaObjMgr::AreaObjMgr(s32 count, const char* pName) : NameObj(pName), mArray() {
119 mArray.mCount = 0;
120 _18 = count;
121}
122
123void AreaObjMgr::entry(AreaObj *pAreaObj) {
124 if (!mArray.mCount) {
125 u32 cnt = _18;
126 mArray.mArray.mArr = new AreaObj*[cnt];
127 mArray.mArray.mMaxSize = cnt;
128 }
129
130 u32 count = mArray.mCount;
131 mArray.mCount = count + 1;
132 mArray.mArray.mArr[count] = pAreaObj;
133}
134
135// AreaObjMgr::find_in
136
137void AreaObj::validate() {
138 mValid = true;
139}
140
141void AreaObj::invalidate() {
142 mValid = false;
143}
144
145const char* AreaObj::getManagerName() const {
146 return mName;
147}
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition AreaObj.cpp:41
The most basic form of an object.
Definition NameObj.hpp:11
void setName(const char *pName)
Sets the NameObj's mName.
Definition NameObj.cpp:48
const char * mName
A string to identify the NameObj.
Definition NameObj.hpp:38