1#include <game/framework/f_base.hpp>
2#include <game/mLib/m_heap.hpp>
3#include <lib/MSL_C/string.h>
4#include <constants/sjis_constants.h>
16 mUniqueID(m_rootUniqueID),
18 mProfName(m_tmpCtProfName),
19 mGroupType(m_tmpCtGroupType),
35 if (prof !=
nullptr) {
36 u16 executeOrder = prof->mExecuteOrder;
40 u16 drawOrder = prof->mDrawOrder;
47 if (parent !=
nullptr) {
60 while (curr !=
nullptr) {
69 int result = (this->*preFunc)();
71 result = (this->*doFunc)();
84 (this->*postFunc)(state);
113 }
else if (state ==
ERROR) {
136 if (child !=
nullptr) {
150 if (
mHeap !=
nullptr) {
230 curr->mpOwner->deleteRequest();
236 if (parent !=
nullptr) {
298 curr->mpOwner->deleteRequest();
327 if (
mHeap !=
nullptr) {
331 unsigned long heapSize = 0;
336 newHeap = mHeap::makeFrmHeapAndUpdate(size, parentHeap, F_BASE_HEAP_NAME, 0x20, 0);
338 if (newHeap !=
nullptr) {
340 mHeap::restoreCurrentHeap();
342 if (!createSuccess) {
343 mHeap::destroyFrmHeap(newHeap);
346 heapSize = mHeap::adjustFrmHeap(newHeap);
347 if (size == heapSize) {
356 if (newHeap ==
nullptr) {
357 newHeap = mHeap::makeFrmHeapAndUpdate(-1, parentHeap, F_BASE_HEAP_NAME, 0x20, 0);
359 if (newHeap !=
nullptr) {
361 mHeap::restoreCurrentHeap();
363 if (!createSuccess) {
364 mHeap::destroyFrmHeap(newHeap);
367 heapSize = mHeap::adjustFrmHeap(newHeap);
373 if (newHeap !=
nullptr) {
374 EGG::FrmHeap *largerHeap = mHeap::makeFrmHeapAndUpdate(heapSize, parentHeap, F_BASE_HEAP_NAME, 0x20, 0);
376 if (largerHeap !=
nullptr) {
377 if (largerHeap < newHeap) {
378 mHeap::destroyFrmHeap(newHeap);
381 mHeap::restoreCurrentHeap();
383 if (!createSuccess) {
384 mHeap::destroyFrmHeap(largerHeap);
386 mHeap::adjustFrmHeap(largerHeap);
392 mHeap::restoreCurrentHeap();
393 mHeap::destroyFrmHeap(largerHeap);
398 if (newHeap !=
nullptr) {
411 if (
mHeap !=
nullptr) {
416 EGG::FrmHeap *newHeap = mHeap::makeFrmHeapAndUpdate(size, parentHeap, F_BASE_HEAP_NAME, 0x20, 0);
417 if (newHeap !=
nullptr) {
419 mHeap::restoreCurrentHeap();
421 if (!createSuccess) {
422 mHeap::destroyFrmHeap(newHeap);
438void *fBase_c::operator
new(
size_t size) {
439 void *mem = EGG::Heap::alloc(size, -4, mHeap::g_gameHeaps[0]);
440 if (mem !=
nullptr) {
441 memset(mem, 0, size);
446void fBase_c::operator
delete(
void *mem) {
447 EGG::Heap::free(mem, mHeap::g_gameHeaps[0]);
468 fTrNdBa_c *curr = connectNode->getChild();
470 while (curr !=
nullptr && curr != end) {
498 setTmpCtData(profName, connectParent, param, groupType);
505 if (res !=
nullptr) {
512 if (connectParent ==
nullptr) {
519 return fBase_make(profName,
nullptr, param, groupType);
bool append(cListNd_c *node)
Adds a node to the end of the list.
bool remove(cListNd_c *node)
Removes a node from the list.
bool prepend(cListNd_c *node)
Adds a node to the beginning of the list.
bool addTreeNode(cTreeNd_c *node, cTreeNd_c *parent)
Adds a node to the tree, either to the root node or to a specified parent node.
bool removeTreeNode(cTreeNd_c *node)
Removes a node from the tree.
bool LoadOnlyOne()
[Unused].
The base class for all scenes, actors and various other processes.
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.
fBase_c * getChildProcessCreateState() const
Gets a child of the base in the CREATING state.
MAIN_STATE_e
The possible operation results.
@ ERROR
The operation could not be completed.
@ SUCCESS
The operation was completed successfully.
@ CANCELED
The operation was canceled early.
@ WAITING
The operation is waiting for something and cannot be completed yet.
static ProfileName m_tmpCtProfName
Temporary storage for the next constructed base's profile name. See mProfName.
virtual int preCreate()
pre method for the create operation.
static int(* sLoadAsyncCallback)()
[Unused]. See Unused Content.
virtual int draw()
do method for the draw operation.
virtual int preDelete()
pre method for the delete operation.
fLiMgBa_c mUnusedList
[Unused]. See Unused Content.
bool mDeferExecute
If the create operation was completed, but scheduling the execute and draw operations isn't possible ...
static fBase_c * createChild(ProfileName profName, fBase_c *parent, unsigned long param, u8 groupType)
Creates a child base under the given parent.
static fBaseID_e m_rootUniqueID
Unique ID counter for base construction. See mUniqueID.
EGG::FrmHeap * mHeap
[Unused]. The base's dedicated heap.
int createPack()
Executes the create operation. See commonPack.
void runCreate()
Kickstarts the base's lifecycle by running the create operation.
virtual ~fBase_c()
Destroys the base.
fBase_c * getConnectChild() const
Gets the base's first child.
fBase_c * getConnectBrNext() const
Gets the base's next sibling.
void deleteRequest()
Requests deletion of the base.
int connectProc()
Executes the connect operation.
virtual int create()
do method for the create operation.
static fBase_c * fBase_make(ProfileName profName, fTrNdBa_c *connectParent, unsigned long param, u8 groupType)
Internal function for base construction.
virtual int preExecute()
pre method for the execute operation.
fManager_c mMng
The base's process manager.
static u8 m_tmpCtGroupType
Temporary storage for the next constructed base's group type. See mGroupType.
virtual bool entryFrmHeap(unsigned long size, EGG::Heap *parentHeap)
[Unused]. Creates a heap of the given size for the base.
virtual bool createHeap()
[Unused]. [Does nothing].
virtual void postCreate(MAIN_STATE_e state)
post method for the create operation.
static u32 m_tmpCtParam
Temporary storage for the next constructed base's params. See mParam.
ProfileName mProfName
The base's profile name.
bool checkChildProcessCreateState() const
Checks if the base has at least one child in the CREATING state.
bool mDeferRetryCreate
If the create operation has not been completed, and rescheduling it isn't possible at this time.
fBaHelper_c * mpUnusedHelper
[Unused]. See Unused Content.
@ CREATING
The base's create operation has yet to conclude.
@ DELETING
The base's delete operation is about to run.
@ ACTIVE
The base is in the main execution cycle.
bool mDeleteRequested
If deletion of the base was requested, but the delete operation has not been scheduled yet.
virtual void postExecute(MAIN_STATE_e state)
post method for the execute operation.
virtual int preDraw()
pre method for the draw operation.
void clearProcControlFlag(u8 flag)
Clears a flag in mProcControl.
int deletePack()
Executes the delete operation. See commonPack.
virtual int execute()
do method for the execute operation.
void setProcControlFlag(u8 flag)
Sets a flag in mProcControl.
int executePack()
Executes the execute operation. See commonPack.
static fBase_c * createRoot(ProfileName profName, unsigned long param, u8 groupType)
Creates a root base.
@ DISABLE_DRAW
Drawing is disabled.
@ ROOT_DISABLE_EXECUTE
Execution is disabled, and this is a root base.
@ DISABLE_EXECUTE
Execution is disabled.
@ ROOT_DISABLE_DRAW
Drawing is disabled, and this is a root base.
virtual bool entryFrmHeapNonAdjust(unsigned long size, EGG::Heap *parentHeap)
[Unused]. Creates a heap of the given size for the base.
u8 mLifecycleState
The base's lifecycle state. Value is a LIFECYCLE_e.
virtual void postDraw(MAIN_STATE_e state)
post method for the draw operation.
virtual void postDelete(MAIN_STATE_e state)
post method for the delete operation.
fBase_c * getConnectParent() const
Gets the base's parent.
@ NOT_READY
The step could not completed at this time.
@ SUCCEEDED
The step was completed successfully.
int drawPack()
Executes the draw operation. See commonPack.
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.
virtual void deleteReady()
Informs the base that it's about to be deleted.
static fTrNdBa_c * m_tmpCtConnectParent
Temporary storage for the next constructed base's parent connect node.
virtual int doDelete()
do method for the delete operation.
static void(* sUnloadCallback)()
[Unused]. See Unused Content.
bool isProcControlFlag(u8 flag) const
Checks if a flag is set in mProcControl.
fBase_c()
Constructs a new base.
bool addNode(fLiNdPrio_c *node)
Adds a node to the list, according to its priority.
void removeSelf()
Removes this node from the owner's mUnusedList.
A base list node, with priority fields for reordering.
u16 mNewOrder
The priority the node should change to if it differs from mOrder.
u16 mOrder
The priority of this node. Lower values mean higher priority.
static fLiMgPTMF_c m_drawManage
A list of all the bases scheduled for drawing.
static fTrMgPTMF_c m_connectManage
A tree that connects all loaded bases.
static fLiMgBa_c m_searchManage[8]
An array of lists used for base lookup.
static LOOP_PROC_e m_nowLoopProc
The current operation being globally executed. See mainLoop.
static fLiMgPTMF_c m_executeManage
A list of all the bases scheduled for execution.
int getSearchTableNum()
Gets the index of the search list the owning base was added to. See m_searchManage.
static fLiMgPTMF_c m_deleteManage
A list of all the bases scheduled for deletion.
fLiNdPrio_c mDrawNode
The node in the draw list.
fTrNdBa_c mConnectNode
The node in the connect tree.
static fLiMgPTMF_c m_createManage
A list of all the bases scheduled for creation.
fLiNdBa_c mSearchNode
The node in the search lists.
fLiNdPrio_c mMainNode
The node in the create, execute or delete list.
fBase_c * mpOwner
The owner of this node.
fTrNdBa_c * getTreeNextNotChild() const
Gets the next node in preorder traversal order, excluding the node's children.
fTrNdBa_c * getTreeNext() const
Gets the next node in preorder traversal order.
fBaseID_e
A unique identifier for each base.
@ BASE_ID_MAX
The maximum identifier value.
@ BASE_ID_FIRST
The starting identifier value.
u16 ProfileName
The name of a profile. Value is a fProfile::PROFILE_NAME_e.
const fBaseProfile_c *(* sProfileList)[PROFILE_COUNT]
A list of all profiles.
A set of basic information needed to construct a generic base.