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