NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
f_base.hpp
1#pragma once
2#include <types.h>
3#include <lib/egg/core/eggFrmHeap.h>
6#include <game/framework/f_helper_unk.hpp>
7#include <game/framework/f_manager.hpp>
8#include <game/framework/f_list_mg.hpp>
9
10#define ACTOR_PARAM_CONFIG(name, offset, size) static const u16 PARAM_##name = ((offset << 8) | size)
11#define ACTOR_PARAM_LOCAL(param, name) ((param >> (PARAM_##name >> 8)) & ((1 << (PARAM_##name & 0xff)) - 1))
12#define ACTOR_PARAM(name) ACTOR_PARAM_LOCAL(mParam, name)
13
14/// @brief The base class for all scenes, actors and various other processes.
15/// @ingroup framework
16class fBase_c {
17public:
18
19 /// @brief The possible lifecycle states.
21 CREATING, ///< The base's @p create operation has yet to conclude.
22 ACTIVE, ///< The base is in the main execution cycle.
23 DELETING, ///< The base's @p delete operation is about to run.
24 };
25
26 /// @brief The possible group types.
28 OTHER, ///< The base is a @ref dBase_c "generic process".
29 SCENE, ///< The base is a @ref dScene_c "scene".
30 ACTOR, ///< The base is an @ref dBaseActor_c "actor".
31 ENEMY ///< The base is an @ref dEn_c "enemy".
32 };
33
34 /// @brief The possible operation results.
36 CANCELED, ///< The operation was canceled early.
37 ERROR, ///< The operation could not be completed.
38 SUCCESS, ///< The operation was completed successfully.
39 WAITING ///< The operation is waiting for something and cannot be completed yet.
40 };
41
42 /// @brief The possible operation step results.
44 NOT_READY, ///< The step could not completed at this time.
45 SUCCEEDED, ///< The step was completed successfully.
46 FAILED, ///< The step could not be completed.
47 };
48
49 /// @brief Controls if the @p execute and @p draw operations should be skipped.
51 ROOT_DISABLE_EXECUTE = BIT_FLAG(0), ///< Execution is disabled, and this is a root base.
52 DISABLE_EXECUTE = BIT_FLAG(1), ///< Execution is disabled.
53 ROOT_DISABLE_DRAW = BIT_FLAG(2), ///< Drawing is disabled, and this is a root base.
54 DISABLE_DRAW = BIT_FLAG(3) ///< Drawing is disabled.
55 };
56
57 /// @brief The base's unique identifier.
58 /// @details This value is incremented for every created base. Should it reach @ref fBaseID_e::BASE_ID_MAX,
59 /// the game will intentionally stall.
61 u32 mParam; ///< A bitfield that configures the base's behaviour. Its usage varies from profile to profile.
62 ProfileName mProfName; ///< The base's profile name.
63
64protected:
65 u8 mLifecycleState; ///< The base's lifecycle state. Value is a LIFECYCLE_e.
66
67 /// @brief If deletion of the base was requested, but the @p delete operation has not been
68 /// scheduled yet.
70
71 /// @brief If the @p create operation was completed, but scheduling the @p execute and @p draw
72 /// operations isn't possible at this time.
73 /// @details If true, scheduling will be deferred to the next @p connect operation.
75
76 /// @brief If the @p create operation has not been completed, and rescheduling it isn't possible at
77 /// this time.
78 /// @details If true, rescheduling will be deferred to the next @p connect operation.
80
81 u8 mGroupType; ///< The base's group type. Value is a GROUP_TYPE_e.
82 u8 mProcControl; ///< The operations to be skipped. Value is a PROC_DISABLE_e.
83
84 /// @brief Checks if a flag is set in #mProcControl.
85 bool isProcControlFlag(u8 flag) const { return (mProcControl & flag) != 0; }
86 /// @brief Sets a flag in #mProcControl.
87 void setProcControlFlag(u8 flag) { mProcControl |= flag; }
88 /// @brief Clears a flag in #mProcControl.
89 void clearProcControlFlag(u8 flag) { mProcControl &= ~flag; }
90
91 fManager_c mMng; ///< The base's process manager.
92
93 fBaHelper_c *mpUnusedHelper; ///< See [Unused Content](#unused-content). @unused
94 fLiMgBa_c mUnusedList; ///< See [Unused Content](#unused-content). @unused
95
96 // [No p because of the string "fBase_c::mHeap"]
97 EGG::FrmHeap *mHeap; ///< The base's dedicated heap. @unused
98
99public:
100 fBase_c(); ///< Constructs a new base.
101
102 /// @brief @p new operator override for all bases.
103 /// @details Bases are allocated in mHeap::g_gameHeaps[0] in a top-down direction, and are
104 /// zero-initialized.
105 static void *operator new(size_t);
106 static void operator delete(void *); ///< @p delete operator override for all bases.
107
108protected:
109 /// @brief @p do method for the @p create operation.
110 /// @return A PACK_RESULT_e value.
111 virtual int create();
112
113 /// @brief @p pre method for the @p create operation.
114 /// @return A PACK_RESULT_e value.
115 virtual int preCreate();
116
117 /// @brief @p post method for the @p create operation.
118 virtual void postCreate(MAIN_STATE_e state);
119
120 /// @brief @p do method for the @p delete operation.
121 /// @details This method was renamed due to conflict with the @p delete C++ keyword.
122 /// @return A PACK_RESULT_e value.
123 virtual int doDelete();
124
125 /// @brief @p pre method for the @p delete operation.
126 /// @return A PACK_RESULT_e value.
127 virtual int preDelete();
128
129 /// @brief @p post method for the @p delete operation.
130 virtual void postDelete(MAIN_STATE_e state);
131
132 /// @brief @p do method for the @p execute operation.
133 /// @return A PACK_RESULT_e value.
134 virtual int execute();
135
136 /// @brief @p pre method for the @p execute operation.
137 /// @return A PACK_RESULT_e value.
138 virtual int preExecute();
139
140 /// @brief @p post method for the @p execute operation.
141 virtual void postExecute(MAIN_STATE_e state);
142
143 /// @brief @p do method for the @p draw operation.
144 /// @return A PACK_RESULT_e value.
145 virtual int draw();
146
147 /// @brief @p pre method for the @p draw operation.
148 /// @return A PACK_RESULT_e value.
149 virtual int preDraw();
150
151 /// @brief @p post method for the @p draw operation.
152 virtual void postDraw(MAIN_STATE_e state);
153
154 /// @brief Informs the base that it's about to be deleted.
155 virtual void deleteReady();
156
157 /**
158 * @brief Creates a heap of the given size for the base.
159 * @unused
160 * @details If the requested heap space is not available, the heap is adjusted to allocate all the
161 * available memory. If that also fails, the base is deleted.
162 * @param size The heap's size, or @p -1 to allocate all available space.
163 * @param parentHeap The parent heap, or @p nullptr to use the current heap.
164 * @return If the heap creation was successful.
165 */
166 virtual bool entryFrmHeap(unsigned long size, EGG::Heap *parentHeap);
167
168 /**
169 * @brief Creates a heap of the given size for the base.
170 * @unused
171 * @details Unlike entryFrmHeap(), the base is immediately deleted if the requested space is not
172 * available.
173 * @param size The heap's size, or @p -1 to allocate all available space.
174 * @param parentHeap The parent heap, or @p nullptr to use the current heap.
175 * @return If the heap creation was successful.
176 */
177 virtual bool entryFrmHeapNonAdjust(unsigned long size, EGG::Heap *parentHeap);
178 virtual bool createHeap(); ///< [Does nothing]. @unused
179
180 virtual ~fBase_c(); ///< Destroys the base.
181
182public:
183 /// @brief Requests deletion of the base.
184 /// @details Calling this function multiple times has no effect.
185 void deleteRequest();
186
187 fBase_c *getConnectParent() const; ///< Gets the base's parent.
188 fBase_c *getConnectChild() const; ///< Gets the base's first child.
189 fBase_c *getConnectBrNext() const; ///< Gets the base's next sibling.
190
191 /// @brief Checks if the base has at least one child in the @ref LIFECYCLE_e::CREATING "CREATING" state.
192 /// @return If such a child base exists.
193 bool checkChildProcessCreateState() const;
194
195private:
196 int createPack(); ///< Executes the @p create operation. See commonPack().
197 int deletePack(); ///< Executes the @p delete operation. See commonPack().
198 int executePack(); ///< Executes the @p execute operation. See commonPack().
199 int drawPack(); ///< Executes the @p draw operation. See commonPack().
200
201 /**
202 * @brief Executes an operation. See [here](#operation-flow) for more details.
203 *
204 * @param doFunc The operation's @p do method.
205 * @param preFunc The operation's @p pre method.
206 * @param postFunc The operation's @p post method.
207 * @return A PACK_RESULT_e value returned from doFunc, or preFunc if doFunc was not executed.
208 */
209 int commonPack(int (fBase_c::*doFunc)(), int (fBase_c::*preFunc)(), void (fBase_c::*postFunc)(MAIN_STATE_e));
210
211 /**
212 * @brief Executes the @p connect operation.
213 * @details This operation carries out the following tasks:
214 * - Schedule the base (and its children) for deletion if deletion was requested (see #mDeleteRequested)
215 * - Propagate updates to the root base's #mProcControl field down the tree
216 * - Update the base's position in the @p execute and @p draw lists on priority changes
217 * - Process any deferred schedule requests (see #mDeferExecute and #mDeferRetryCreate)
218 * @return The operation always returns #SUCCEEDED.
219 */
220 int connectProc();
221
222 /// @brief Kickstarts the base's lifecycle by running the @p create operation.
223 void runCreate();
224
225 /// @brief Gets a child of the base in the @ref LIFECYCLE_e::CREATING "CREATING" state.
226 /// @return The first child satisfying this condition, or @p nullptr if none is found.
228
229public:
230 /**
231 * @brief Creates a child base under the given parent.
232 *
233 * @param profName The base's profile name.
234 * @param parent The base's parent. Must not be @p nullptr .
235 * @param param The base's parameters.
236 * @param groupType The base's group type.
237 * @return A pointer to the instantiated base, or @p nullptr .
238 */
239 static fBase_c *createChild(ProfileName profName, fBase_c *parent, unsigned long param, u8 groupType);
240
241 /**
242 * @brief Creates a root base.
243 *
244 * @param profName The base's profile name.
245 * @param param The base's parameters.
246 * @param groupType The base's group type.
247 * @return A pointer to the instantiated base, or @p nullptr .
248 */
249 static fBase_c *createRoot(ProfileName profName, unsigned long param, u8 groupType);
250
251private:
252 /**
253 * @brief Sets temporary data to be used for the next base's construction.
254 *
255 * @param profName The base's profile name.
256 * @param connectParent The connect node of the base's parent, or @p nullptr .
257 * @param param The base's parameters.
258 * @param groupType The base's group type.
259 */
260 static void setTmpCtData(ProfileName profName, fTrNdBa_c *connectParent, unsigned long param, u8 groupType);
261
262 /**
263 * @brief Internal function for base construction.
264 *
265 * @param profName The base's profile name.
266 * @param connectParent The parent base's connect node.
267 * @param param The base's parameters.
268 * @param groupType The base's group type.
269 * @return A pointer to the instantiated base, or @p nullptr .
270 */
271 static fBase_c *fBase_make(ProfileName profName, fTrNdBa_c *connectParent, unsigned long param, u8 groupType);
272
273protected:
274 static int (*sLoadAsyncCallback)(); ///< See [Unused Content](#unused-content). @unused
275 static void (*sUnloadCallback)(); ///< See [Unused Content](#unused-content). @unused
276
277private:
278 static fBaseID_e m_rootUniqueID; ///< Unique ID counter for base construction. See #mUniqueID.
279 static u32 m_tmpCtParam; ///< Temporary storage for the next constructed base's params. See #mParam.
280 static ProfileName m_tmpCtProfName; ///< Temporary storage for the next constructed base's profile name. See #mProfName.
281 static u8 m_tmpCtGroupType; ///< Temporary storage for the next constructed base's group type. See #mGroupType.
282 static fTrNdBa_c *m_tmpCtConnectParent; ///< Temporary storage for the next constructed base's parent connect node.
283
284 friend class fManager_c;
285 friend class fLiNdBa_c;
286 friend class fTrMgBa_c;
287};
[A helper class for fBase_c with unknown purpose].
int commonPack(int(fBase_c::*doFunc)(), int(fBase_c::*preFunc)(), void(fBase_c::*postFunc)(MAIN_STATE_e))
Executes an operation. See here for more details.
Definition f_base.cpp:66
u8 mGroupType
The base's group type. Value is a GROUP_TYPE_e.
Definition f_base.hpp:81
fBase_c * getChildProcessCreateState() const
Gets a child of the base in the CREATING state.
Definition f_base.cpp:465
MAIN_STATE_e
The possible operation results.
Definition f_base.hpp:35
@ ERROR
The operation could not be completed.
Definition f_base.hpp:37
@ SUCCESS
The operation was completed successfully.
Definition f_base.hpp:38
@ CANCELED
The operation was canceled early.
Definition f_base.hpp:36
@ WAITING
The operation is waiting for something and cannot be completed yet.
Definition f_base.hpp:39
static ProfileName m_tmpCtProfName
Temporary storage for the next constructed base's profile name. See mProfName.
Definition f_base.hpp:280
virtual int preCreate()
pre method for the create operation.
Definition f_base.cpp:92
static int(* sLoadAsyncCallback)()
See Unused Content.
Definition f_base.hpp:274
virtual int draw()
do method for the draw operation.
Definition f_base.cpp:188
virtual int preDelete()
pre method for the delete operation.
Definition f_base.cpp:126
fLiMgBa_c mUnusedList
See Unused Content.
Definition f_base.hpp:94
bool mDeferExecute
If the create operation was completed, but scheduling the execute and draw operations isn't possible ...
Definition f_base.hpp:74
static fBase_c * createChild(ProfileName profName, fBase_c *parent, unsigned long param, u8 groupType)
Creates a child base under the given parent.
Definition f_base.cpp:511
static fBaseID_e m_rootUniqueID
Unique ID counter for base construction. See mUniqueID.
Definition f_base.hpp:278
EGG::FrmHeap * mHeap
The base's dedicated heap.
Definition f_base.hpp:97
int createPack()
Executes the create operation. See commonPack().
Definition f_base.cpp:122
void runCreate()
Kickstarts the base's lifecycle by running the create operation.
Definition f_base.cpp:450
virtual ~fBase_c()
Destroys the base.
Definition f_base.cpp:57
fBase_c * getConnectChild() const
Gets the base's first child.
Definition f_base.cpp:310
fBase_c * getConnectBrNext() const
Gets the base's next sibling.
Definition f_base.cpp:317
void deleteRequest()
Requests deletion of the base.
Definition f_base.cpp:289
int connectProc()
Executes the connect operation.
Definition f_base.cpp:212
virtual int create()
do method for the create operation.
Definition f_base.cpp:88
static fBase_c * fBase_make(ProfileName profName, fTrNdBa_c *connectParent, unsigned long param, u8 groupType)
Internal function for base construction.
Definition f_base.cpp:490
GROUP_TYPE_e
The possible group types.
Definition f_base.hpp:27
@ ENEMY
The base is an enemy.
Definition f_base.hpp:31
@ SCENE
The base is a scene.
Definition f_base.hpp:29
@ OTHER
The base is a generic process.
Definition f_base.hpp:28
@ ACTOR
The base is an actor.
Definition f_base.hpp:30
virtual int preExecute()
pre method for the execute operation.
Definition f_base.cpp:172
fManager_c mMng
The base's process manager.
Definition f_base.hpp:91
static u8 m_tmpCtGroupType
Temporary storage for the next constructed base's group type. See mGroupType.
Definition f_base.hpp:281
virtual bool entryFrmHeap(unsigned long size, EGG::Heap *parentHeap)
Creates a heap of the given size for the base.
Definition f_base.cpp:324
virtual bool createHeap()
[Does nothing].
Definition f_base.cpp:434
virtual void postCreate(MAIN_STATE_e state)
post method for the create operation.
Definition f_base.cpp:96
static u32 m_tmpCtParam
Temporary storage for the next constructed base's params. See mParam.
Definition f_base.hpp:279
ProfileName mProfName
The base's profile name.
Definition f_base.hpp:62
bool checkChildProcessCreateState() const
Checks if the base has at least one child in the CREATING state.
Definition f_base.cpp:479
bool mDeferRetryCreate
If the create operation has not been completed, and rescheduling it isn't possible at this time.
Definition f_base.hpp:79
fBaHelper_c * mpUnusedHelper
See Unused Content.
Definition f_base.hpp:93
LIFECYCLE_e
The possible lifecycle states.
Definition f_base.hpp:20
@ CREATING
The base's create operation has yet to conclude.
Definition f_base.hpp:21
@ DELETING
The base's delete operation is about to run.
Definition f_base.hpp:23
@ ACTIVE
The base is in the main execution cycle.
Definition f_base.hpp:22
u32 mParam
A bitfield that configures the base's behaviour. Its usage varies from profile to profile.
Definition f_base.hpp:61
bool mDeleteRequested
If deletion of the base was requested, but the delete operation has not been scheduled yet.
Definition f_base.hpp:69
virtual void postExecute(MAIN_STATE_e state)
post method for the execute operation.
Definition f_base.cpp:180
virtual int preDraw()
pre method for the draw operation.
Definition f_base.cpp:192
void clearProcControlFlag(u8 flag)
Clears a flag in mProcControl.
Definition f_base.hpp:89
int deletePack()
Executes the delete operation. See commonPack().
Definition f_base.cpp:164
virtual int execute()
do method for the execute operation.
Definition f_base.cpp:168
void setProcControlFlag(u8 flag)
Sets a flag in mProcControl.
Definition f_base.hpp:87
int executePack()
Executes the execute operation. See commonPack().
Definition f_base.cpp:184
static fBase_c * createRoot(ProfileName profName, unsigned long param, u8 groupType)
Creates a root base.
Definition f_base.cpp:518
PROC_DISABLE_e
Controls if the execute and draw operations should be skipped.
Definition f_base.hpp:50
@ DISABLE_DRAW
Drawing is disabled.
Definition f_base.hpp:54
@ ROOT_DISABLE_EXECUTE
Execution is disabled, and this is a root base.
Definition f_base.hpp:51
@ DISABLE_EXECUTE
Execution is disabled.
Definition f_base.hpp:52
@ ROOT_DISABLE_DRAW
Drawing is disabled, and this is a root base.
Definition f_base.hpp:53
virtual bool entryFrmHeapNonAdjust(unsigned long size, EGG::Heap *parentHeap)
Creates a heap of the given size for the base.
Definition f_base.cpp:408
u8 mLifecycleState
The base's lifecycle state. Value is a LIFECYCLE_e.
Definition f_base.hpp:65
virtual void postDraw(MAIN_STATE_e state)
post method for the draw operation.
Definition f_base.cpp:200
virtual void postDelete(MAIN_STATE_e state)
post method for the delete operation.
Definition f_base.cpp:142
fBase_c * getConnectParent() const
Gets the base's parent.
Definition f_base.cpp:303
PACK_RESULT_e
The possible operation step results.
Definition f_base.hpp:43
@ NOT_READY
The step could not completed at this time.
Definition f_base.hpp:44
@ SUCCEEDED
The step was completed successfully.
Definition f_base.hpp:45
@ FAILED
The step could not be completed.
Definition f_base.hpp:46
int drawPack()
Executes the draw operation. See commonPack().
Definition f_base.cpp:204
u8 mProcControl
The operations to be skipped. Value is a PROC_DISABLE_e.
Definition f_base.hpp:82
static void setTmpCtData(ProfileName profName, fTrNdBa_c *connectParent, unsigned long param, u8 groupType)
Sets temporary data to be used for the next base's construction.
Definition f_base.cpp:483
virtual void deleteReady()
Informs the base that it's about to be deleted.
Definition f_base.cpp:208
static fTrNdBa_c * m_tmpCtConnectParent
Temporary storage for the next constructed base's parent connect node.
Definition f_base.hpp:282
virtual int doDelete()
do method for the delete operation.
Definition f_base.cpp:118
static void(* sUnloadCallback)()
See Unused Content.
Definition f_base.hpp:275
fBaseID_e mUniqueID
The base's unique identifier.
Definition f_base.hpp:60
bool isProcControlFlag(u8 flag) const
Checks if a flag is set in mProcControl.
Definition f_base.hpp:85
fBase_c()
Constructs a new base.
Definition f_base.cpp:15
A base list, made of fLiNdBa_c nodes.
Definition f_list_mg.hpp:13
A base tree node.
Definition f_tree_nd.hpp:12
fBaseID_e
A unique identifier for each base.
Definition f_base_id.hpp:6
u16 ProfileName
The name of a profile. Value is a fProfile::PROFILE_NAME_e.
Definition f_profile.hpp:32