NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_base_actor.cpp
1#include <game/bases/d_base_actor.hpp>
2#include <game/bases/d_reset.hpp>
3#include <game/bases/d_scene.hpp>
4#include <nw4r/math.h>
5#include <nw4r/ut.h>
6
10
12mLinkActor(this),
13mPos(),
14mLastPos(),
15mAngle(),
17{
18 // Append the actor to the list
20
21 // Copy position and angle if set
22 if (m_tmpCtPosP != nullptr) {
25 }
26
27 if (m_tmpCtAngleP != nullptr) {
30 }
31
32 // Initialize the rest
33 mVisible = true;
34
35 mCenterOffs.x = 0.0f;
36 mCenterOffs.y = 0.0f;
37 mCenterOffs.z = 0.0f;
38
39 mScale.x = 1.0f;
40 mScale.y = 1.0f;
41 mScale.z = 1.0f;
42
43 fProfile::fProfilePtr_c profile = (*fProfile::sProfileList)[mProfName];
45}
46
50
54
58
62
66
69 return NOT_READY;
70 } else {
71
72 // Make sure the game isn't being reset
74 return !(
79 );
80 }
81}
82
84 if (status == SUCCESS) {
86 mLastPos = mPos;
87 }
88
90}
91
93 if (dBase_c::preDraw() == NOT_READY) {
94 return NOT_READY;
95 } else {
96 return mVisible != 0;
97 }
98}
99
103
105
107
108void dBaseActor_c::setTmpCtData(const mVec3_c *position, const mAng3_c *rotation) {
109 m_tmpCtPosP = position;
110 m_tmpCtAngleP = rotation;
111}
112
113dBaseActor_c *dBaseActor_c::construct(ProfileName profName, unsigned long param, const mVec3_c *position, const mAng3_c *rotation) {
114 setTmpCtData(position, rotation);
115
116 // Find the current scene actor and set it as parent
118 return (dBaseActor_c *)dBase_c::createBase(profName, parent, param, ACTOR);
119}
120
122 dBaseActor_c *currActor = nullptr;
123
124 while (currActor = (dBaseActor_c *)fManager_c::searchBaseByGroupType(fBase_c::ACTOR, currActor), currActor != nullptr) {
125 currActor->draw2D();
126 }
127}
128
130 dBaseActor_c *currActor = nullptr;
131
132 while (currActor = (dBaseActor_c *)fManager_c::searchBaseByGroupType(fBase_c::ACTOR, currActor), currActor != nullptr) {
133 currActor->draw2D_lyt2();
134 }
135}
136
137dBaseActor_c *dBaseActor_c::construct(ProfileName profName, dBase_c *parent, unsigned long param, const mVec3_c *position, const mAng3_c *rotation) {
138 setTmpCtData(position, rotation);
139 return (dBaseActor_c *)dBase_c::createBase(profName, parent, param, ACTOR);
140}
141
143 float sin = mAngle3D.y.sin();
144 float cos = mAngle3D.y.cos();
145
146 // Distribute mSpeedF on the X and Z axes according to the actor's rotation and use the regular Y speed
147 // [Defining newZ is required for matching]
148 float newZ = mSpeedF * cos;
149 mSpeed.y = nw4r::ut::Max<float>(mSpeed.y + mAccelY, mMaxFallSpeed);
150 mSpeed.x = mSpeedF * sin;
151 mSpeed.z = newZ;
152}
153
155 mMatrix.trans(mPos.x, mPos.y, mPos.z);
156 mMatrix.YrotM(mAngle.y);
157}
158
160 mPos += delta;
161}
162
166
172
174 float newSpeed = mSpeed.x;
175
176 // If the X speed hasn't reached the max, increase it until it reaches the limit
177 // Else decrease it until the limit
178 if (mSpeed.x < mSpeedMax.x) {
179 newSpeed += mAccelF;
180 if (newSpeed > mSpeedMax.x) {
181 newSpeed = mSpeedMax.x;
182 }
183 } else if (mSpeed.x > mSpeedMax.x) {
184 newSpeed -= mAccelF;
185 if (newSpeed < mSpeedMax.x) {
186 newSpeed = mSpeedMax.x;
187 }
188 }
189
190 mSpeed.x = newSpeed;
191}
192
194 // [Since Y values are assumed negative, the comparison is the other way]
195 float newSpeed = mSpeed.y + mAccelY;
196 if (newSpeed < mSpeedMax.y) {
197 newSpeed = mSpeedMax.y;
198 }
199
200 mSpeed.y = newSpeed;
201}
202
204 // If the speed hasn't exceeded the limit, increase it until the limit is reached
205 // Else decrease it until the limit
206 if (mSpeedF < mMaxSpeedF) {
207 mSpeedF = nw4r::ut::Min<float>(mSpeedF + mAccelF, mMaxSpeedF);
208 } else if (mSpeedF > mMaxSpeedF) {
209 mSpeedF = nw4r::ut::Max<float>(mSpeedF - mAccelF, mMaxSpeedF);
210 }
211}
212
214 // If the speed has exceeded the limit, decrease it until the limit is reached
215 // Else increase it until the limit
216 if (mSpeed.y < mMaxFallSpeed) {
217 mSpeed.y = nw4r::ut::Min<float>(mSpeed.y - mAccelY, mMaxFallSpeed);
218 } else if (mSpeed.y > mMaxFallSpeed) {
219 mSpeed.y = nw4r::ut::Max<float>(mSpeed.y + mAccelY, mMaxFallSpeed);
220 }
221}
222
226
228 return dBaseActor_c::m_actorManage.countNodeByProfName(profile);
229}
bool mVisible
Whether the actor should be visible or not. Defaults to true .
mAng3_c mAngle3D
The actor's rotation (for 3D actors).
void calcSpeedXY()
Updates the actor's speed (2D actors). See here for details.
int GetProfNameActorNum(ProfileName profile)
Counts the instances of the given actor profile.
mMtx_c mMatrix
The actor's partial transformation matrix. See makeMtx for details.
virtual int preDraw()
pre method for the draw operation.
mVec3_c mScale
The actor's scale (defaults to 1).
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.
virtual void draw2D_lyt2()
Alternate drawing function used to draw 3D models in front of 2D graphics (second draw pass).
mVec3_c mSpeedMax
The actor's maximum speed.
void makeMtx()
Generates a partial transformation matrix for the actor and stores it in mMatrix.
virtual void postExecute(fBase_c::MAIN_STATE_e status)
post method for the execute operation.
virtual void postDraw(fBase_c::MAIN_STATE_e status)
post method for the draw operation.
static const mVec3_c * m_tmpCtPosP
Temporary storage for the next constructed actor's position. See mPos.
void calcSpeedX()
Updates the actor's X speed. See here for details.
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()
Updates the actor's falling speed. See here for details.
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()
pre method for the delete operation.
float mSpeedF
The actor's horizontal speed.
virtual void postDelete(fBase_c::MAIN_STATE_e status)
post method for the delete operation.
void posMove()
Moves the actor by its speed.
virtual void draw2D()
Alternate drawing function used to draw 3D models in front of 2D graphics (first draw pass).
float mMaxFallSpeed
The actor's maximum fall speed.
void calcSpeed()
Updates the actor's speed (3D actors). See here for details.
mVec3_c getCenterPos() const
Gets the actor's centered position.
static const mAng3_c * m_tmpCtAngleP
Temporary storage for the next constructed actor's rotation. See mAngle.
void calcSpeedF()
Updates the actor's forward speed. See here for details.
static fLiMgBa_c m_actorManage
A list of all actor bases.
mAng3_c mAngle
The actor's rotation (for 2D actors).
static void draw2DActorOnLyt2()
Calls draw2D_lyt2 on every actor.
virtual ~dBaseActor_c()
Destroys the actor.
virtual void postCreate(fBase_c::MAIN_STATE_e status)
post method for the create operation.
u32 mActorProperties
The actor's properties. See fProfile::fActorProfile_c::mActorProperties.
float mAccelY
The actor's vertical acceleration.
float mMaxSpeedF
The actor's maximum horizontal speed.
void calcSpeedY()
Updates the actor's Y speed. See here for details.
virtual int preExecute()
pre method for the execute operation.
virtual int preCreate()
pre method for the create operation.
static void draw2DActorOnLyt1()
Calls draw2D on every actor.
dBaseActor_c()
Constructs a new actor.
dBase_c()
Constructs a new base.
Definition d_base.cpp:13
virtual int preDelete()
pre method for the delete operation.
Definition d_base.cpp:46
virtual void postExecute(fBase_c::MAIN_STATE_e status)
post method for the execute operation.
Definition d_base.cpp:59
virtual void postDraw(fBase_c::MAIN_STATE_e status)
post method for the draw operation.
Definition d_base.cpp:68
virtual void postCreate(fBase_c::MAIN_STATE_e status)
post method for the create operation.
Definition d_base.cpp:42
virtual int preDraw()
pre method for the draw operation.
Definition d_base.cpp:63
virtual void postDelete(fBase_c::MAIN_STATE_e status)
post method for the delete operation.
Definition d_base.cpp:50
virtual int preExecute()
pre method for the execute operation.
Definition d_base.cpp:54
virtual int preCreate()
pre method for the create operation.
Definition d_base.cpp:38
static dBase_c * createBase(ProfileName profName, dBase_c *parent, unsigned long param, u8 groupType)
Creates a child base under the given parent.
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:19
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:33
@ SUCCESS
The operation was completed successfully.
Definition f_base.hpp:36
@ ACTOR
The base is an actor.
Definition f_base.hpp:29
ProfileName mProfName
The base's profile name.
Definition f_base.hpp:60
@ NOT_READY
The step could not completed at this time.
Definition f_base.hpp:42
A base list, made of fLiNdBa_c nodes.
Definition f_list_mg.hpp:13
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:59
A three-dimensional floating point vector.
Definition m_vec.hpp:100
u16 ProfileName
The name of a profile. Value is a fProfile::PROFILE_NAME_e.
Definition f_profile.hpp:32
u32 mActorProperties
Various actor-related properties.
Definition f_profile.hpp:70
const fActorProfile_c * mActorProfile
An actor profile.
Definition f_profile.hpp:75