diff --git a/data/uking_functions.csv b/data/uking_functions.csv index dded5f3a..22875bca 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -89516,10 +89516,10 @@ 0x00000071011bbc0c,BaseProcHandle::wakeUpActorAndReleaseUnit,184, 0x00000071011bbcc4,BaseProcHandle::getBaseProcEvent,48, 0x00000071011bbcf4,BaseProcHandle::allocUnit,228, -0x00000071011bbdd8,BaseProcUnit::setActor,540, +0x00000071011bbdd8,BaseProcUnit::setActor,540,_ZN4ksys3act12BaseProcUnit7setProcEPNS0_8BaseProcE 0x00000071011bbff4,BaseProcUnit::cleanUp,512, 0x00000071011bc1f4,BaseProcUnit::unlinkActor,412, -0x00000071011bc390,BaseProcUnit::isParentHandleDefault,24, +0x00000071011bc390,BaseProcUnit::isParentHandleDefault,24,_ZNK4ksys3act12BaseProcUnit21isParentHandleDefaultEv 0x00000071011bc3a8,sub_71011BC3A8,132, 0x00000071011bc42c,sub_71011BC42C,56, 0x00000071011bc464,sinitBaseProcHandle,172, diff --git a/src/KingSystem/ActorSystem/actBaseProc.h b/src/KingSystem/ActorSystem/actBaseProc.h index 1c9aa7cc..0411b834 100644 --- a/src/KingSystem/ActorSystem/actBaseProc.h +++ b/src/KingSystem/ActorSystem/actBaseProc.h @@ -11,6 +11,7 @@ #include #include "KingSystem/ActorSystem/actBaseProcJob.h" #include "KingSystem/ActorSystem/actBaseProcMap.h" +#include "KingSystem/ActorSystem/actBaseProcHandle.h" #include "KingSystem/Utils/StrTreeMap.h" #include "KingSystem/Utils/Types.h" @@ -23,17 +24,7 @@ class BaseProc; class BaseProcLinkData; class BaseProcJobHandler; class BaseProcUnit; - -class BaseProcHandle { -public: - BaseProcHandle(); - ~BaseProcHandle(); - -private: - BaseProcUnit* mUnit; - u8 mFlag; -}; -KSYS_CHECK_SIZE_NX150(BaseProcHandle, 0x10); +class BaseProcHandle; /// Actor base class that encapsulates all the low-level actor lifetime logic. class BaseProc { @@ -100,6 +91,7 @@ public: return mState == State::Delete || mStateFlags.isOn(StateFlags::RequestDelete); } + bool isInitialized() const { return mFlags.isOn(Flags::Initialized); } /// For BaseProcLink or ActorLinkConstDataAccess. bool acquire(ActorLinkConstDataAccess& accessor); BaseProcLinkData* getBaseProcLinkData() const { return mBaseProcLinkData; } diff --git a/src/KingSystem/ActorSystem/actBaseProcHandle.cpp b/src/KingSystem/ActorSystem/actBaseProcHandle.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/KingSystem/ActorSystem/actBaseProcHandle.h b/src/KingSystem/ActorSystem/actBaseProcHandle.h new file mode 100644 index 00000000..031e9923 --- /dev/null +++ b/src/KingSystem/ActorSystem/actBaseProcHandle.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include "actBaseProcUnit.h" +#include "KingSystem/Utils/Types.h" + +namespace ksys::act { + +class BaseProcUnit; + +class BaseProcHandle { +public: + BaseProcHandle(); + ~BaseProcHandle(); + + static BaseProcHandle sDummyBaseProcHandle; +private: + BaseProcUnit* mUnit; + u8 mFlag; +}; +KSYS_CHECK_SIZE_NX150(BaseProcHandle, 0x10); + +} // namespace ksys::act \ No newline at end of file diff --git a/src/KingSystem/ActorSystem/actBaseProcUnit.cpp b/src/KingSystem/ActorSystem/actBaseProcUnit.cpp index e69de29b..8f8b3919 100644 --- a/src/KingSystem/ActorSystem/actBaseProcUnit.cpp +++ b/src/KingSystem/ActorSystem/actBaseProcUnit.cpp @@ -0,0 +1,57 @@ +#include "KingSystem/ActorSystem/actBaseProcUnit.h" +#include +#include +#include "KingSystem/ActorSystem/actActorLinkConstDataAccess.h" +#include "KingSystem/ActorSystem/actBaseProc.h" +#include "KingSystem/Utils/Debug.h" +namespace ksys::act { + +// NON_MATCHING: Equivalent but branches are off. +bool BaseProcUnit::setProc(BaseProc* proc) { + bool ret; + static constexpr const char* sStateNames[] = {"Init", "Calc", "Sleep", "Delete"}; + + auto lock = sead::makeScopedLock(mCS); + if (mProc) + mProc = nullptr; + + if (mHandle == &BaseProcHandle::sDummyBaseProcHandle) + return false; + + if (mHandle) { + if (mFlags != 1) { + sead::FixedSafeString<64> message; + + if (proc) + message.format("%s, %d, %d, %s, ( %p:%p )", proc->getName().cstr(), mFlags, + proc->isInitialized(), sStateNames[u8(proc->getState())], this, + mHandle.load()); + else + message.format("なし, %d, ?, ?, ( %p:%p )", mFlags, this, mHandle.load()); + + util::PrintDebug(message); + } + mProc = proc; + mFlags = 2; + ret = true; + } else { + sead::FixedSafeString<64> message; + + if (proc) + message.format("%s, %d, %d, %s, ( %p:%p )", proc->getName().cstr(), mFlags, + proc->isInitialized(), sStateNames[u8(proc->getState())], this, + mHandle.load()); + else + message.format("なし, %d, ?, ?, ( %p:%p )", mFlags, this, mHandle.load()); + + util::PrintDebug(message); + ret = false; + } + return ret; +} + +bool BaseProcUnit::isParentHandleDefault() const { + return mHandle == &BaseProcHandle::sDummyBaseProcHandle; +} + +} // namespace ksys::act \ No newline at end of file diff --git a/src/KingSystem/ActorSystem/actBaseProcUnit.h b/src/KingSystem/ActorSystem/actBaseProcUnit.h index 7bfe7e28..81d8ec4b 100644 --- a/src/KingSystem/ActorSystem/actBaseProcUnit.h +++ b/src/KingSystem/ActorSystem/actBaseProcUnit.h @@ -2,7 +2,8 @@ #include #include - +#include "KingSystem/ActorSystem/actBaseProcHandle.h" +#include namespace ksys::act { class BaseProc; @@ -18,7 +19,7 @@ public: private: u32 mFlags; - BaseProcHandle* mHandle; + sead::Atomic mHandle; BaseProc* mProc; // FIXME: // BaseProcRequest mRequest;