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