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