From f92ab2f5598789d9531bfe93e9abcc3dc4cc938d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 20 Aug 2020 12:19:00 +0200 Subject: [PATCH] ksys/act: Finish BaseProcLinkData --- data/uking_functions.csv | 4 ++-- .../ActorSystem/actBaseProcLinkDataMgr.cpp | 19 +++++++++++++++++++ .../ActorSystem/actBaseProcLinkDataMgr.h | 13 ++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 8d61ee6f..a65a8bbb 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -89524,8 +89524,8 @@ 0x00000071011bc464,sinitBaseProcHandle,172, 0x00000071011bc510,_ZN12BaseProcLinkC2Ev,20,_ZN4ksys3act12BaseProcLinkC1Ev 0x00000071011bc524,_ZN12BaseProcLink12acquireActorER13ActorAccessorP9ActorBase,308, -0x00000071011bc658,BaseProcLinkData::lockCritSectionOnGameThreadOrHavokThread,68, -0x00000071011bc69c,BaseProcLinkData::checkIdAndEngaged,52, +0x00000071011bc658,BaseProcLinkData::lockCritSectionOnGameThreadOrHavokThread,68,_ZN4ksys3act16BaseProcLinkData12lockIfNeededEv +0x00000071011bc69c,BaseProcLinkData::checkIdAndEngaged,52,_ZNK4ksys3act16BaseProcLinkData7getProcEjb 0x00000071011bc6d0,_ZN12BaseProcLink12fromAccessorER13ActorAccessor,276, 0x00000071011bc7e4,BaseProcLink::checkHasActorById,40, 0x00000071011bc80c,_ZN12BaseProcLinkeqERS_,152, diff --git a/src/KingSystem/ActorSystem/actBaseProcLinkDataMgr.cpp b/src/KingSystem/ActorSystem/actBaseProcLinkDataMgr.cpp index cc986835..8479ae09 100644 --- a/src/KingSystem/ActorSystem/actBaseProcLinkDataMgr.cpp +++ b/src/KingSystem/ActorSystem/actBaseProcLinkDataMgr.cpp @@ -2,11 +2,30 @@ #include #include #include "KingSystem/ActorSystem/actBaseProc.h" +#include "KingSystem/ActorSystem/actBaseProcMgr.h" namespace ksys::act { SEAD_SINGLETON_DISPOSER_IMPL(BaseProcLinkDataMgr) +BaseProc* BaseProcLinkData::getProc(u32 id, bool allow_deleted) const { + if (id == u32(-1) || mId != id) + return nullptr; + + if (!allow_deleted && mProc && mProc->getState() == BaseProc::State::Delete) + return nullptr; + + return mProc; +} + +sead::CriticalSection* BaseProcLinkData::lockIfNeeded() { + if (BaseProcMgr::instance()->isHighPriorityThread()) + return nullptr; + + mCS.lock(); + return &mCS; +} + bool BaseProcLinkDataMgr::acquireLink(BaseProc* proc) { auto lock = sead::makeScopedLock(mCS); s32 index = mIndex; diff --git a/src/KingSystem/ActorSystem/actBaseProcLinkDataMgr.h b/src/KingSystem/ActorSystem/actBaseProcLinkDataMgr.h index b7f19f81..7ce56373 100644 --- a/src/KingSystem/ActorSystem/actBaseProcLinkDataMgr.h +++ b/src/KingSystem/ActorSystem/actBaseProcLinkDataMgr.h @@ -13,9 +13,20 @@ class BaseProc; class BaseProcLinkData { public: u32 id() const { return mId; } - BaseProc* proc() const { return mProc; } s32 refCount() const { return mRefCount; } + /// Get the stored BaseProc. + BaseProc* getProc() const { return mProc; } + /// Get the stored BaseProc or nullptr if its ID or state are unexpected. + /// @param id The expected ID. + /// @param allow_deleted Whether to allow the BaseProc to be in the Delete state. + BaseProc* getProc(u32 id, bool allow_deleted) const; + + /// Locks the critical section if on a low priority thread and returns it; + /// unlocking it is the responsibility of the caller. + /// Returns nullptr if on a high priority thread. In that case, nothing needs to be done. + sead::CriticalSection* lockIfNeeded(); + private: friend class BaseProcLinkDataMgr;