New Super Mario Bros. U Headers
Loading...
Searching...
No Matches
ActorBase.h
Go to the documentation of this file.
1#pragma once
2
3#include <actor/ActorCreateParam.h>
4
5#include <container/seadOffsetList.h>
6#include <heap/seadHeap.h>
7#include <prim/seadBitFlag.h>
8#include <prim/seadRuntimeTypeInfo.h>
9
10class ActorMgr;
11
12/**
13 * @brief Base interface class for all actors in the game. Lifecycle is handled by @c ActorMgr.
14 * @par @c Size: 0x50
15 * @par @c vtable Address: 0x100006C0
16 */
18{
19 // getRuntimeTypeInfoStatic()::typeInfo initialization guard variable Address: 0x101E9CC4
20 // getRuntimeTypeInfoStatic()::typeInfo Address: 0x101E9CC8
22
23public:
24 /**
25 * @brief Represents the execution state of a main operation, and whether it was skipped.
26 * @details In the case of @c preX skipping the main callback, @c cState_None will be passed to @c postX. Otherwise, the signal is forwarded.
27 */
29 {
30 cState_None = 0, ///< The operation was skipped.
31 cState_Failed, ///< The operation was cancelled.
32 cState_Success, ///< The operation was successful.
33 cState_Wait ///< The operation was stalled.
34 };
35
36 /**
37 * @brief Defines signals to pass to ActorMgr when performing create and delete operations on the actor.
38 */
39 enum Result
40 {
41 cResult_Wait = 0, ///< Stall the operation, tries to call again the next frame.
42 cResult_Success, ///< The operation was successful, continue execution.
43 cResult_Failed ///< Cancel the operation. This deletes the actor.
44 };
45
46public:
48
49public:
50 /**
51 * @brief Whether this actor has been successfully created and is now active.
52 */
53 bool isActive() const
54 {
55 return mIsActive;
56 }
57
58 /**
59 * @brief Schedule this actor for deletion on the next frame.
60 */
62 {
63 mDeleteRequestFlag = true;
64 }
65
66 /**
67 * @brief Whether this actor has been scheduled for deletion on the next frame.
68 */
69 bool isRequestedDelete() const
70 {
71 return mDeleteRequestFlag;
72 }
73
74 /**
75 * @brief The unique identifier handle for this actor.
76 */
78 {
79 return mActorUniqueID;
80 }
81
82 /**
83 * @brief The specific profile ID which this actor was instantiated from.
84 * @par Address: 0x02002C80
85 */
87
88 /**
89 * @brief The specific profile which this actor was instantiated from.
90 */
92 {
93 return mActorProfile;
94 }
95
96 /**
97 * @brief Whether the actor was created with @c ActorMgr::createImmediately(), rather than deferred with @c ActorMgr::createLater().
98 */
100 {
101 return mCreatedImmediately;
102 }
103
104 /**
105 * @brief Whether the actor was spawned from the level with @c ActorCreateMgr, rather than dynamically spawned by another actor.
106 */
107 bool isMapActor() const
108 {
109 return mIsMapActor;
110 }
111
112 /**
113 * @brief Level designer configuration. Also known as "nybbles" or "spritedata".
114 */
116 {
117 return mParam0;
118 }
119
120 /**
121 * @brief Level designer configuration. Also known as "nybbles" or "spritedata".
122 */
124 {
125 return mParam1;
126 }
127
128 /**
129 * @brief Extra level designer configuration. Also known as "nybbles" or "spritedata".
130 */
132 {
133 return mParamEx;
134 }
135
136 /**
137 * @brief @c sead::OffsetList used for holding child actors spawned by this actor. Managed automatically if @c param.parent_id is set when spawning.
138 */
139 const List& getChildList() const
140 {
141 return mChildList;
142 }
143
144 /**
145 * @brief The personal heap for this actor.
146 */
148 {
149 return mActorHeap;
150 }
151
152 /**
153 * The parent actor pointer if this actor is a child, @c nullptr otherwise.
154 */
156 {
157 return mParent;
158 }
159
160 /**
161 * @brief The parent actor pointer if this actor is a child, @c nullptr otherwise.
162 * @tparam T The parent type to cast to, returns @c nullptr if the types are incompatible.
163 */
164 template <typename T>
165 T* getParent() const
166 {
167 return sead::DynamicCast<T>(mParent);
168 }
169
170 /**
171 * @brief Disconnects a child from this actor's family tree.
172 * @param child The target actor to orphan.
173 * @par Address: 0x02002C8C
174 */
175 void removeChild(ActorBase* child);
176
177protected:
178 /**
179 * @brief Constructs an actor from configuration data.
180 * @param param Parameters and user configuration to pass to the actor.
181 * @par Address: 0x02002CE0
182 */
183 ActorBase(const ActorCreateParam& param);
184 /**
185 * @brief Destroys the actor and orphans all of its children.
186 * @par Address: 0x02002E68
187 */
188 virtual ~ActorBase();
189
190protected:
191 /**
192 * @brief Callback invoked before the @c create operation.
193 * @return Whether to continue to the main @c create callback, rather than skip to @c postExecute().
194 * @details Returns @c true by default.
195 * @par Address: 0x02002F7C
196 */
197 virtual bool preCreate();
198 /**
199 * @brief Main initialization/setup callback for the actor.
200 * @return A signal for how to handle the operation.
201 * @details Returns @c cResult_Success by default.
202 * @par Address: 0x02002F84
203 */
204 virtual Result create();
205 /**
206 * @brief Callback invoked unconditionally after the @c create phase completes. It executes even if @c preCreate() bypassed the main @c create() operation.
207 * @param state The signal which @c create() returned, or @c cState_None if @c preCreate() skipped it.
208 * @par Address: 0x02002F00
209 */
210 virtual void postCreate(MainState state);
211
212 /**
213 * @brief Callback invoked before the @c execute operation.
214 * @return Whether to continue to the main @c execute callback, rather than skip to @c postExecute().
215 * @details Returns @c true by default unless the game is paused or frozen. See @c EventMgr::isJoin().
216 * @par Address: 0x02002F04
217 */
218 virtual bool preExecute();
219 /**
220 * @brief Main execution/logic callback for the actor. Called every frame (the game runs at exactly 60 FPS).
221 * @return A signal for how to handle the operation. @c true / @c false imply @c cState_Success / @c cState_Failed.
222 * @details Returns @c true by default.
223 * @par Address: 0x02002F8C
224 */
225 virtual bool execute();
226 /**
227 * @brief Callback invoked unconditionally after the @c execute phase completes. It executes even if @c preExecute() bypassed the main @c execute() operation.
228 * @param state The signal which @c execute() returned, or @c cState_None if @c preExecute() skipped it.
229 * @par Address: 0x02002F34
230 */
231 virtual void postExecute(MainState state);
232 /**
233 * @brief Callback which is called after all other actors have finished executing for this frame.
234 * @details The actor must subscribe to the @c finalUpdate signal on a per-frame basis via @c ActorMgr::addToFinalUpdate().
235 * @par Address: 0x02002F94
236 */
237 virtual void finalUpdate();
238
239 /**
240 * @brief Callback invoked before the @c draw operation.
241 * @return Whether to continue to the main @c draw callback, rather than skip to @c postDraw().
242 * @details Returns @c true by default.
243 */
244 virtual bool preDraw();
245 /**
246 * @brief Main rendering callback for the actor. Called every frame (the game runs at exactly 60 FPS).
247 * @note This is only for scheduling deferred render tasks; actual rendering may not be performed at this stage.
248 * @return A signal for how to handle the operation. @c true / @c false imply @c cState_Success / @c cState_Failed. However, signaling failure does not delete the actor.
249 * @details Returns @c true by default.
250 * @par Address 0x02002FA0
251 */
252 virtual bool draw();
253 /**
254 * @brief Callback invoked unconditionally after the @c draw phase completes. It executes even if @c preDraw() bypassed the main @c draw() operation.
255 * @param state The signal which @c draw() returned, or @c cState_None if @c preDraw() skipped it.
256 * @par Address 0x02002F38
257 */
258 virtual void postDraw(MainState state);
259
260 /**
261 * @brief Callback invoked before the @c delete operation.
262 * @return Whether to continue to the main @c doDelete callback.
263 * @details Returns @c true by default.
264 * @par Address: 0x02002FA8
265 */
266 virtual bool preDelete();
267 /**
268 * @brief Main deletion callback for the actor.
269 * @return A signal for how to handle the operation.
270 * @details @c Failure and @c Success both result in deletion. Only @c Wait results in a stall.
271 * @par Address: 0x02002FB0
272 */
273 virtual Result doDelete();
274 /**
275 * @brief Unconditionally called callback for after the @c delete operation.
276 * @param state The signal which @c doDelete() returned, or @c cState_None if @c preDelete() skipped it.
277 * @note The actor has still technically not been deleted yet at this point, that occurs right after this call.
278 * @par Address: 0x02002F3C
279 */
280 virtual void postDelete(MainState state);
281
282protected:
283 void setActive_(bool active)
284 {
285 mIsActive = active;
286 }
287
288protected:
289 sead::Heap* mActorHeap; ///< Personal heap for this actor of type @c sead::FrameHeap. Capacity of @c 0x20200, but profiles in the player whitelist get @c 0x1A0200.
290 ActorUniqueID mActorUniqueID; ///< The unique identifier handle for this actor.
291 Profile* mActorProfile; ///< The specific profile which this actor was instantiated from.
292 bool mCreatedImmediately; ///< Whether the actor was created with @c ActorMgr::createImmediately(), rather than deferred with @c ActorMgr::createLater().
293 bool mIsMapActor; ///< Whether the actor was spawned from the level with @c ActorCreateMgr, rather than dynamically spawned by another actor.
294 bool mIsActive; ///< Whether the @c create operation has completed and the actor is executing.
295 bool mDeleteRequestFlag; ///< Whether to delete this actor on the next frame.
296 u32 mParam0; ///< Level designer configuration. Also known as "nybbles" or "spritedata".
297 u32 mParam1; ///< Level designer configuration. Also known as "nybbles" or "spritedata".
298 ActorParamEx1 mParamEx; ///< Extra level designer configuration. Also known as "nybbles" or "spritedata".
299 List mChildList; ///< @c sead::OffsetList used for holding child actors spawned by this actor. Managed automatically if @c param.parent_id is set when spawning.
300 sead::ListNode mChildNode; ///< Implementation detail. Used to track our position in the parent's @c mChildList.
301 ActorBase* mParent; ///< The parent actor if this actor is a child. Automatically set to @c nullptr if orphaned.
302 sead::ListNode mExecuteNode; ///< Implementation detail. Used to track our position in @c ActorMgr lists.
303 sead::ListNode mDrawNode; ///< Implementation detail. Used to track our position in @c ActorMgr `mDrawManage` list.
305
306 friend class ActorMgr;
307};
308static_assert(sizeof(ActorBase) == 0x50);
309
310template <typename T>
311ActorBase* TActorFactory(const ActorCreateParam& param)
312{
313 return new T(param);
314}
ActorBase * TActorFactory(const ActorCreateParam &param)
Definition ActorBase.h:311
Base interface class for all actors in the game. Lifecycle is handled by ActorMgr.
Definition ActorBase.h:18
u32 getParam1() const
Level designer configuration. Also known as "nybbles" or "spritedata".
Definition ActorBase.h:123
ActorUniqueID getActorUniqueID() const
The unique identifier handle for this actor.
Definition ActorBase.h:77
bool mIsMapActor
Whether the actor was spawned from the level with ActorCreateMgr, rather than dynamically spawned by ...
Definition ActorBase.h:293
ActorParamEx1 mParamEx
Extra level designer configuration. Also known as "nybbles" or "spritedata".
Definition ActorBase.h:298
bool isCreatedImmediately() const
Whether the actor was created with ActorMgr::createImmediately(), rather than deferred with ActorMgr:...
Definition ActorBase.h:99
virtual void postExecute(MainState state)
Callback invoked unconditionally after the execute phase completes. It executes even if preExecute() ...
virtual Result doDelete()
Main deletion callback for the actor.
u32 mParam0
Level designer configuration. Also known as "nybbles" or "spritedata".
Definition ActorBase.h:296
virtual bool preCreate()
Callback invoked before the create operation.
virtual bool draw()
Main rendering callback for the actor. Called every frame (the game runs at exactly 60 FPS).
bool mCreatedImmediately
Whether the actor was created with ActorMgr::createImmediately(), rather than deferred with ActorMgr:...
Definition ActorBase.h:292
s32 getProfileID() const
The specific profile ID which this actor was instantiated from.
virtual void postCreate(MainState state)
Callback invoked unconditionally after the create phase completes. It executes even if preCreate() by...
ActorBase * getParent() const
Definition ActorBase.h:155
ActorParamEx1 getParamEx() const
Extra level designer configuration. Also known as "nybbles" or "spritedata".
Definition ActorBase.h:131
bool mDeleteRequestFlag
Whether to delete this actor on the next frame.
Definition ActorBase.h:295
virtual void postDelete(MainState state)
Unconditionally called callback for after the delete operation.
virtual bool execute()
Main execution/logic callback for the actor. Called every frame (the game runs at exactly 60 FPS).
const List & getChildList() const
sead::OffsetList used for holding child actors spawned by this actor. Managed automatically if param....
Definition ActorBase.h:139
ActorUniqueID mActorUniqueID
The unique identifier handle for this actor.
Definition ActorBase.h:290
bool isMapActor() const
Whether the actor was spawned from the level with ActorCreateMgr, rather than dynamically spawned by ...
Definition ActorBase.h:107
virtual bool preExecute()
Callback invoked before the execute operation.
u32 getParam0() const
Level designer configuration. Also known as "nybbles" or "spritedata".
Definition ActorBase.h:115
bool isActive() const
Whether this actor has been successfully created and is now active.
Definition ActorBase.h:53
sead::ListNode mChildNode
Implementation detail. Used to track our position in the parent's mChildList.
Definition ActorBase.h:300
bool isRequestedDelete() const
Whether this actor has been scheduled for deletion on the next frame.
Definition ActorBase.h:69
sead::ListNode mExecuteNode
Implementation detail. Used to track our position in ActorMgr lists.
Definition ActorBase.h:302
ActorBase * mParent
The parent actor if this actor is a child. Automatically set to nullptr if orphaned.
Definition ActorBase.h:301
List mChildList
sead::OffsetList used for holding child actors spawned by this actor. Managed automatically if param....
Definition ActorBase.h:299
virtual ~ActorBase()
Destroys the actor and orphans all of its children.
void removeChild(ActorBase *child)
Disconnects a child from this actor's family tree.
sead::Heap * mActorHeap
Personal heap for this actor of type sead::FrameHeap. Capacity of 0x20200, but profiles in the player...
Definition ActorBase.h:289
sead::Heap * getActorHeap() const
The personal heap for this actor.
Definition ActorBase.h:147
sead::OffsetList< ActorBase > List
Definition ActorBase.h:47
sead::ListNode mDrawNode
Implementation detail. Used to track our position in ActorMgr mDrawManage list.
Definition ActorBase.h:303
void setActive_(bool active)
Definition ActorBase.h:283
Profile * getProfile() const
The specific profile which this actor was instantiated from.
Definition ActorBase.h:91
T * getParent() const
The parent actor pointer if this actor is a child, nullptr otherwise.
Definition ActorBase.h:165
virtual bool preDelete()
Callback invoked before the delete operation.
sead::BitFlag32 mFlag
Definition ActorBase.h:304
ActorBase(const ActorCreateParam &param)
Constructs an actor from configuration data.
Profile * mActorProfile
The specific profile which this actor was instantiated from.
Definition ActorBase.h:291
virtual void finalUpdate()
Callback which is called after all other actors have finished executing for this frame.
bool mIsActive
Whether the create operation has completed and the actor is executing.
Definition ActorBase.h:294
virtual Result create()
Main initialization/setup callback for the actor.
u32 mParam1
Level designer configuration. Also known as "nybbles" or "spritedata".
Definition ActorBase.h:297
void deleteRequest()
Schedule this actor for deletion on the next frame.
Definition ActorBase.h:61
virtual void postDraw(MainState state)
Callback invoked unconditionally after the draw phase completes. It executes even if preDraw() bypass...
Result
Defines signals to pass to ActorMgr when performing create and delete operations on the actor.
Definition ActorBase.h:40
@ cResult_Success
The operation was successful, continue execution.
Definition ActorBase.h:42
@ cResult_Wait
Stall the operation, tries to call again the next frame.
Definition ActorBase.h:41
@ cResult_Failed
Cancel the operation. This deletes the actor.
Definition ActorBase.h:43
virtual bool preDraw()
Callback invoked before the draw operation.
Definition ActorMgr.h:13