NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_base_actor.cpp
1#include <dol/bases/d_base_actor.hpp>
2#include <dol/bases/d_reset.hpp>
3#include <dol/bases/d_scene.hpp>
4#include <dol/cLib/c_math.hpp>
6#include <lib/rvl/mtx/mtx.h>
7
11
12dBaseActor_c::dBaseActor_c() :
13mLinkActor(this),
14mPos(),
15mLastPos(),
16mAngle(),
17mLastAngle()
18{
19 // Append the actor to the list
20 m_actorManage.append(&mLinkActor);
21
22 // Copy position and angle if set
23 if (m_tmpCtPosP != nullptr) {
24 mPos = *m_tmpCtPosP;
25 mLastPos = *m_tmpCtPosP;
26 }
27
28 if (m_tmpCtAngleP != nullptr) {
29 mAngle = *m_tmpCtAngleP;
30 mLastAngle = *m_tmpCtAngleP;
31 }
32
33 // Initialize the rest
34 mVisible = true;
35
36 mCenterOffs.x = 0.0f;
37 mCenterOffs.y = 0.0f;
38 mCenterOffs.z = 0.0f;
39
40 mScale.x = 1.0f;
41 mScale.y = 1.0f;
42 mScale.z = 1.0f;
43
45 mActorProperties = profile->mActorProperties;
46}
47
48dBaseActor_c::~dBaseActor_c() {
50}
51
53 return (dBase_c::preCreate() != NOT_READY);
54}
55
57 dBase_c::postCreate(status);
58}
59
61 return (dBase_c::preDelete() != NOT_READY);
62}
63
65 dBase_c::postDelete(status);
66}
67
70 return NOT_READY;
71 } else {
72
73 // Make sure the game isn't being reset
75 return !(
80 );
81 }
82}
83
85 if (status == SUCCESS) {
87 mLastPos = mPos;
88 }
89
91}
92
94 if (dBase_c::preDraw() == NOT_READY) {
95 return NOT_READY;
96 } else {
97 return mVisible != 0;
98 }
99}
100
102 dBase_c::postDraw(status);
103}
104
106}
107
109}
110
111void dBaseActor_c::setTmpCtData(const mVec3_c *position, const mAng3_c *rotation) {
112 m_tmpCtPosP = position;
113 m_tmpCtAngleP = rotation;
114}
115
116dBaseActor_c *dBaseActor_c::construct(ProfileName profName, unsigned long param, const mVec3_c *position, const mAng3_c *rotation) {
117 setTmpCtData(position, rotation);
118
119 // Find the current scene actor and set it as parent
121 return (dBaseActor_c *)dBase_c::createBase(profName, parent, param, ACTOR);
122}
123
125 dBaseActor_c *currActor = nullptr;
126
127 while (currActor = (dBaseActor_c *)fManager_c::searchBaseByGroupType(fBase_c::ACTOR, currActor), currActor != nullptr) {
128 currActor->draw2D();
129 }
130}
131
133 dBaseActor_c *currActor = nullptr;
134
135 while (currActor = (dBaseActor_c *)fManager_c::searchBaseByGroupType(fBase_c::ACTOR, currActor), currActor != nullptr) {
136 currActor->draw2D_lyt2();
137 }
138}
139
140dBaseActor_c *dBaseActor_c::construct(ProfileName profName, dBase_c *parent, unsigned long param, const mVec3_c *position, const mAng3_c *rotation) {
141 setTmpCtData(position, rotation);
142 return (dBaseActor_c *)dBase_c::createBase(profName, parent, param, ACTOR);
143}
144
146 float sin = nw4r::math::SinS(mLastAngle.y);
147 float cos = nw4r::math::CosS(mLastAngle.y);
148
149 // Distribute mSpeedF on the X and Z axes according to the actor's rotation and use the regular Y speed
150 // [Defining newZ is required for matching]
151 float newZ = mSpeedF * cos;
153 mSpeed.x = mSpeedF * sin;
154 mSpeed.z = newZ;
155}
156
158 // [Loading the axes in this order is required for matching]
159 float z = mPos.z;
160 float y = mPos.y;
161 float x = mPos.x;
162 PSMTXTrans(mMatrix, x, y, z);
163 mAng rot = mAng((u16)mAngle.y);
164 mMatrix.YrotM(rot);
165}
166
168 mPos += delta;
169}
170
173}
174
176 calcSpeedF();
177 mSpeed.x = mSpeedF;
179}
180
182 float newSpeed = mSpeed.x;
183
184 // If the X speed hasn't reached the max, increase it until it reaches the limit
185 // Else decrease it until the limit
186 if (mSpeed.x < mSpeedMax.x) {
187 newSpeed += mAccelF;
188 if (newSpeed > mSpeedMax.x) {
189 newSpeed = mSpeedMax.x;
190 }
191 } else if (mSpeed.x > mSpeedMax.x) {
192 newSpeed -= mAccelF;
193 if (newSpeed < mSpeedMax.x) {
194 newSpeed = mSpeedMax.x;
195 }
196 }
197
198 mSpeed.x = newSpeed;
199}
200
202 // Note: All Y values are negative, so the comparison is the other way
203 float newSpeed = mSpeed.y + mAccelY;
204 if (newSpeed < mSpeedMax.y) {
205 newSpeed = mSpeedMax.y;
206 }
207
208 mSpeed.y = newSpeed;
209}
210
212 // If the speed hasn't exceeded the limit, increase it until the limit is reached
213 // Else decrease it until the limit
214 if (mSpeedF < mMaxSpeedF) {
216 } else if (mSpeedF > mMaxSpeedF) {
218 }
219}
220
222 // If the speed has exceeded the limit, decrease it until the limit is reached
223 // Else increase it until the limit
224 if (mSpeed.y < mMaxFallSpeed) {
226 } else if (mSpeed.y > mMaxFallSpeed) {
228 }
229}
230
232 return mPos + mCenterOffs;
233}
234
237}
bool remove(cListNd_c *node)
Removes a node from the list.
Definition c_list.cpp:30
Basic actor class, supporting positioning, rotation and movement/acceleration.
mAng3_c mLastAngle
The actor's rotation in the previous frame.
bool mVisible
Whether the actor should be visible or not. Defaults to true .
void calcSpeedXY()
Updates the actor's speed (2D actors).
int GetProfNameActorNum(ProfileName profile)
Counts the instances of the given actor profile.
mMtx_c mMatrix
The actor's world matrix.
virtual int preDraw()
Code to be executed before draw.
float mAccelF
The actor's horizontal acceleration.
mVec3_c mSpeed
The actor's speed.
mVec3_c mLastPos
The actor's position in the previous frame.
mVec3_c mPos
The actor's position (top-left corner).
virtual void draw2D_lyt2()
Alternate drawing function for drawing in front of 2D layouts (second draw pass).
mVec3_c mSpeedMax
The actor's maximum speed.
void makeMtx()
Updates the actor's world matrix.
virtual void postExecute(fBase_c::MAIN_STATE_e status)
Code to be executed after execute.
virtual void postDraw(fBase_c::MAIN_STATE_e status)
See dBase_c::postDraw.
static const mVec3_c * m_tmpCtPosP
Temporary storage for the next constructed actor's position. See mPos.
void calcSpeedX()
Applies mAccelF to the actor's X speed, using mSpeedMax as the speed limit.
mVec3_c mPosDelta
The actor's position delta since the previous frame.
mVec3_c mCenterOffs
The offset from the position to the center of the actor (defaults to 0).
void calcFallSpeed()
Applies mAccelY to the actor's Y speed, using mMaxFallSpeed as the speed limit.
fLiNdBa_c mLinkActor
The node in m_actorManage.
static void setTmpCtData(const mVec3_c *position, const mAng3_c *rotation)
Sets temporary data to be used for the next actor's construction.
static dBaseActor_c * construct(ProfileName profName, unsigned long param, const mVec3_c *position, const mAng3_c *rotation)
Creates an actor without a parent.
virtual int preDelete()
See dBase_c::preDelete.
float mSpeedF
The actor's horizontal speed.
virtual void postDelete(fBase_c::MAIN_STATE_e status)
See dBase_c::postDelete.
void posMove()
Moves the actor by its speed.
virtual void draw2D()
Alternate drawing function for drawing in front of 2D layouts (first draw pass).
float mMaxFallSpeed
The actor's maximum fall speed.
void calcSpeed()
Updates the actor's speed (3D actors).
mVec3_c getCenterPos() const
Gets the actor's center position.
static const mAng3_c * m_tmpCtAngleP
Temporary storage for the next constructed actor's rotation. See mAngle.
void calcSpeedF()
Applies mAccelF to mSpeedF, using mMaxSpeedF as the speed limit.
static fLiMgBa_c m_actorManage
A list of all the constructed actors.
mAng3_c mAngle
The actor's rotation.
static void draw2DActorOnLyt2()
Calls draw2D_lyt2 on every actor.
virtual void postCreate(fBase_c::MAIN_STATE_e status)
See dBase_c::postCreate.
float mAccelY
The actor's vertical acceleration.
float mMaxSpeedF
The actor's maximum horizontal speed.
void calcSpeedY()
Applies mAccelY to the actor's Y speed, using mSpeedMax as the speed limit.
virtual int preExecute()
Code to be executed before execute.
virtual int preCreate()
See dBase_c::preCreate.
static void draw2DActorOnLyt1()
Calls draw2D on every actor.
An extension of fBase_c with base kind and name strings.
Definition d_base.hpp:9
virtual int preDelete()
See fBase_c::preDelete.
Definition d_base.cpp:45
virtual void postExecute(fBase_c::MAIN_STATE_e status)
See fBase_c::postExecute.
Definition d_base.cpp:58
virtual void postDraw(fBase_c::MAIN_STATE_e status)
See fBase_c::postDraw.
Definition d_base.cpp:67
virtual void postCreate(fBase_c::MAIN_STATE_e status)
See fBase_c::postCreate.
Definition d_base.cpp:41
virtual int preDraw()
Code to be executed before draw.
Definition d_base.cpp:62
virtual void postDelete(fBase_c::MAIN_STATE_e status)
See fBase_c::postDelete.
Definition d_base.cpp:49
virtual int preExecute()
Code to be executed before execute.
Definition d_base.cpp:53
virtual int preCreate()
See fBase_c::preCreate.
Definition d_base.cpp:37
static dBase_c * createBase(ProfileName profName, dBase_c *parent, unsigned long param, u8 groupType)
See fBase_c::createChild.
Definition d_base.cpp:87
static dBase_c * searchBaseByProfName(ProfileName profile, const dBase_c *parent)
Searches for a base with a given profile name, optionally under a given parent.
Definition d_base.cpp:18
System reset management class.
Definition d_reset.hpp:10
static dReset::Manage_c * GetInstance()
Gets a pointer to the instance of this class.
int mModeProc
The game's current running state. See Mode_e.
Definition d_reset.hpp:41
@ SAFETY_WAIT
The game is about to execute the hard reset procedure indicated in mExecMode.
Definition d_reset.hpp:20
@ SOFT_RESET
The game is being soft reset (from the Home Menu).
Definition d_reset.hpp:16
int mModeInit
The running state the game's about to switch to. See Mode_e.
Definition d_reset.hpp:45
static ProfileName m_nowScene
The profile name of the current scene.
Definition d_scene.hpp:56
MAIN_STATE_e
The possible operation results.
Definition f_base.hpp:135
@ SUCCESS
The operation was completed successfully.
Definition f_base.hpp:138
@ ACTOR
The base is an actor.
Definition f_base.hpp:131
@ NOT_READY
The step could not completed at this time.
Definition f_base.hpp:144
A base list, made of fLiNdBa_c nodes.
Definition f_list_mg.hpp:13
int countNodeByProfName(ProfileName profName) const
Counts the number of bases using the given profile name.
Definition f_list.cpp:57
static fBase_c * searchBaseByGroupType(unsigned char groupType, const fBase_c *parent)
Searches for a base with a given group type, optionally under a given parent.
Definition f_manager.cpp:41
A three-dimensional short angle vector.
Definition m_angle.hpp:61
s16 y
The rotation on the Y axis.
Definition m_angle.hpp:113
void YrotM(mAng angle)
Rotates the matrix on the Y axis by the given angle.
Definition m_mtx.cpp:70
A three-dimensional floating point vector.
Definition m_vec.hpp:88
float y
The coordinates on the Y axis.
Definition m_vec.hpp:172
float x
The coordinates on the X axis.
Definition m_vec.hpp:171
float z
The coordinates on the Z axis.
Definition m_vec.hpp:173
void PSMTXTrans(Mtx *mtx, float x, float y, float z)
Sets a translation matrix with the given components.
u16 ProfileName
The name of a profile. Value is a fProfile::PROFILE_NAME_e.
Definition f_profile.hpp:32
const fBaseProfile_c *(* sProfileList)[PROFILE_COUNT]
A list of all profiles.
Definition f_profile.cpp:5
float fmin(float x, float y)
Gets the minimum float between x and y .
Definition c_math.hpp:21
float fmax(float x, float y)
Gets the maximum float between x and y .
Definition c_math.hpp:30
float CosS(short ang)
Computes the cosine value.
float SinS(short ang)
Computes the sine value.
A set of basic information needed to construct an actor base.
Definition f_profile.hpp:59
u32 mActorProperties
Various actor-related properties.
Definition f_profile.hpp:66
A one-dimensional short angle vector.
Definition m_angle.hpp:8