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