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>
5#include <lib/nw4r/ut/inlines.hpp>
6#include <lib/rvl/mtx/mtx.h>
7
11
13mLinkActor(this),
14mPos(),
15mLastPos(),
16mAngle(),
17mAngle3D()
18{
19 // Append the actor to the list
21
22 // Copy position and angle if set
23 if (m_tmpCtPosP != nullptr) {
26 }
27
28 if (m_tmpCtAngleP != nullptr) {
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
46}
47
51
55
59
63
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
104
106
108
109void dBaseActor_c::setTmpCtData(const mVec3_c *position, const mAng3_c *rotation) {
110 m_tmpCtPosP = position;
111 m_tmpCtAngleP = rotation;
112}
113
114dBaseActor_c *dBaseActor_c::construct(ProfileName profName, unsigned long param, const mVec3_c *position, const mAng3_c *rotation) {
115 setTmpCtData(position, rotation);
116
117 // Find the current scene actor and set it as parent
119 return (dBaseActor_c *)dBase_c::createBase(profName, parent, param, ACTOR);
120}
121
123 dBaseActor_c *currActor = nullptr;
124
125 while (currActor = (dBaseActor_c *)fManager_c::searchBaseByGroupType(fBase_c::ACTOR, currActor), currActor != nullptr) {
126 currActor->draw2D();
127 }
128}
129
131 dBaseActor_c *currActor = nullptr;
132
133 while (currActor = (dBaseActor_c *)fManager_c::searchBaseByGroupType(fBase_c::ACTOR, currActor), currActor != nullptr) {
134 currActor->draw2D_lyt2();
135 }
136}
137
138dBaseActor_c *dBaseActor_c::construct(ProfileName profName, dBase_c *parent, unsigned long param, const mVec3_c *position, const mAng3_c *rotation) {
139 setTmpCtData(position, rotation);
140 return (dBaseActor_c *)dBase_c::createBase(profName, parent, param, ACTOR);
141}
142
144 float sin = nw4r::math::SinS(mAngle3D.y);
145 float cos = nw4r::math::CosS(mAngle3D.y);
146
147 // Distribute mSpeedF on the X and Z axes according to the actor's rotation and use the regular Y speed
148 // [Defining newZ is required for matching]
149 float newZ = mSpeedF * cos;
151 mSpeed.x = mSpeedF * sin;
152 mSpeed.z = newZ;
153}
154
156 // [Loading the axes in this order is required for matching]
157 float z = mPos.z;
158 float y = mPos.y;
159 float x = mPos.x;
160 PSMTXTrans(mMatrix, x, y, z);
161 mAng rot = mAng((u16)mAngle.y);
162 mMatrix.YrotM(rot);
163}
164
166 mPos += delta;
167}
168
172
178
180 float newSpeed = mSpeed.x;
181
182 // If the X speed hasn't reached the max, increase it until it reaches the limit
183 // Else decrease it until the limit
184 if (mSpeed.x < mSpeedMax.x) {
185 newSpeed += mAccelF;
186 if (newSpeed > mSpeedMax.x) {
187 newSpeed = mSpeedMax.x;
188 }
189 } else if (mSpeed.x > mSpeedMax.x) {
190 newSpeed -= mAccelF;
191 if (newSpeed < mSpeedMax.x) {
192 newSpeed = mSpeedMax.x;
193 }
194 }
195
196 mSpeed.x = newSpeed;
197}
198
200 // [Since Y values are assumed negative, the comparison is the other way]
201 float newSpeed = mSpeed.y + mAccelY;
202 if (newSpeed < mSpeedMax.y) {
203 newSpeed = mSpeedMax.y;
204 }
205
206 mSpeed.y = newSpeed;
207}
208
210 // If the speed hasn't exceeded the limit, increase it until the limit is reached
211 // Else decrease it until the limit
212 if (mSpeedF < mMaxSpeedF) {
214 } else if (mSpeedF > mMaxSpeedF) {
216 }
217}
218
220 // If the speed has exceeded the limit, decrease it until the limit is reached
221 // Else increase it until the limit
222 if (mSpeed.y < mMaxFallSpeed) {
224 } else if (mSpeed.y > mMaxFallSpeed) {
226 }
227}
228
232
bool append(cListNd_c *node)
Adds a node to the end of the list.
Definition c_list.cpp:60
bool remove(cListNd_c *node)
Removes a node from the list.
Definition c_list.cpp:30
The minimum required implementation for an actor base.
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.
The minimum required implementation for a base.
Definition d_base.hpp:41
virtual int preDelete()
pre method for the delete operation.
Definition d_base.cpp:45
virtual void postExecute(fBase_c::MAIN_STATE_e status)
post method for the execute operation.
Definition d_base.cpp:58
virtual void postDraw(fBase_c::MAIN_STATE_e status)
post method for the draw operation.
Definition d_base.cpp:67
virtual void postCreate(fBase_c::MAIN_STATE_e status)
post method for the create operation.
Definition d_base.cpp:41
virtual int preDraw()
pre method for the draw operation.
Definition d_base.cpp:62
virtual void postDelete(fBase_c::MAIN_STATE_e status)
post method for the delete operation.
Definition d_base.cpp:49
virtual int preExecute()
pre method for the execute operation.
Definition d_base.cpp:53
virtual int preCreate()
pre method for the create operation.
Definition d_base.cpp:37
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:86
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:137
@ SUCCESS
The operation was completed successfully.
Definition f_base.hpp:140
@ ACTOR
The base is an actor.
Definition f_base.hpp:133
ProfileName mProfName
The base's profile name.
Definition f_base.hpp:164
@ NOT_READY
The step could not completed at this time.
Definition f_base.hpp:146
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:62
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:60
s16 y
The rotation on the Y axis.
Definition m_angle.hpp:112
void YrotM(mAng angle)
Rotates the matrix on the Y axis by the given angle.
Definition m_mtx.cpp:69
A three-dimensional floating point vector.
Definition m_vec.hpp:100
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 CosS(short ang)
Computes the cosine value.
float SinS(short ang)
Computes the sine value.
T Min(T a, T b)
Gets the smaller of the two given values.
Definition inlines.hpp:9
T Max(T a, T b)
Gets the larger of the two given values.
Definition inlines.hpp:15
A set of basic information needed to construct an actor base.
Definition f_profile.hpp:60
u32 mActorProperties
Various actor-related properties.
Definition f_profile.hpp:67
A one-dimensional short angle vector.
Definition m_angle.hpp:8