diff --git a/CMakeLists.txt b/CMakeLists.txt index 7215e92d..7a1aa8ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ add_executable(uking src/KingSystem/Terrain/teraSystem.h + src/KingSystem/Utils/Debug.h src/KingSystem/Utils/StrTreeMap.h src/KingSystem/Utils/Types.h ) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 621baf65..8d61ee6f 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -74114,7 +74114,7 @@ 0x0000007100dca6d4,_ZN15ActorInstParams3BufaSERS0_,56, 0x0000007100dca70c,_ZN13ActorAccessorD2Ev,56,_ZN4ksys3act24ActorLinkConstDataAccessD1Ev 0x0000007100dca744,ActorAccessor::acquire,88,_ZN4ksys3act24ActorLinkConstDataAccess7acquireEPNS0_8BaseProcE -0x0000007100dca79c,act::acquireActorFromGameOrHavokThread,256, +0x0000007100dca79c,act::acquireActorFromGameOrHavokThread,256,_ZN4ksys3act11acquireProcEPNS0_24ActorLinkConstDataAccessEPNS0_8BaseProcERKN4sead14SafeStringBaseIcEE 0x0000007100dca89c,GameFramework::ctor,96, 0x0000007100dca8fc,GameFramework::dtor,64, 0x0000007100dca93c,GameFramework::dtorDelete,72, diff --git a/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.cpp b/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.cpp index 3eda6bcd..91a3c860 100644 --- a/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.cpp +++ b/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.cpp @@ -1,5 +1,7 @@ #include "KingSystem/ActorSystem/actActorLinkConstDataAccess.h" #include "KingSystem/ActorSystem/actBaseProc.h" +#include "KingSystem/ActorSystem/actBaseProcMgr.h" +#include "KingSystem/Utils/Debug.h" namespace ksys::act { @@ -20,9 +22,7 @@ bool ActorLinkConstDataAccess::acquire(BaseProc* proc) { mProc = nullptr; } - if (proc) - return proc->acquire(*this); - return false; + return proc && proc->acquire(*this); } bool ActorLinkConstDataAccess::hasProc(BaseProc* proc) const { @@ -33,4 +33,24 @@ void ActorLinkConstDataAccess::debugLog(s32, const sead::SafeString&) { // Intentionally left empty. } +bool acquireProc(ActorLinkConstDataAccess* accessor, BaseProc* proc, const sead::SafeString& from) { + bool acquired = false; + + if (accessor) { + acquired = accessor->acquire(proc); + if (!acquired) + return false; + } + + if (acquired || BaseProcMgr::instance()->isHighPriorityThread()) + return true; + + sead::FixedSafeString<256> message; + // (%s)Acquiring from a low priority thread. Please change via ActorLinkConstDataAccess + message.format("(%s)低スレッドからの取得です。ActorLinkConstDataAccess経由に変更お願いします", + from.cstr()); + util::PrintDebug(message); + return false; +} + } // namespace ksys::act diff --git a/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.h b/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.h index ff4258ec..6727adfb 100644 --- a/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.h +++ b/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.h @@ -21,16 +21,22 @@ public: /// If an actor was already acquired, it is released. bool acquire(BaseProc* proc); + void release() { acquire(nullptr); } + /// Checks whether the acquired BaseProc is `proc`. bool hasProc(BaseProc* proc) const; -private: void debugLog(s32, const sead::SafeString& method_name); +private: bool mAcquired = false; BaseProc* mProc = nullptr; }; +/// Acquire the specified BaseProc using `accessor`. Using ActorLinkConstDataAccess is mandatory +/// when acquiring from a low priority thread (see BaseProcMgr for a definition). +bool acquireProc(ActorLinkConstDataAccess* accessor, BaseProc* proc, const sead::SafeString& from); + } // namespace act } // namespace ksys diff --git a/src/KingSystem/Utils/Debug.h b/src/KingSystem/Utils/Debug.h new file mode 100644 index 00000000..a80b02d0 --- /dev/null +++ b/src/KingSystem/Utils/Debug.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace ksys::util { + +inline void PrintDebug([[maybe_unused]] const sead::SafeString& message) {} + +}