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