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