From 0dc07525309ecc1d522fa4f18ecb09993b035f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 20 Aug 2020 01:26:10 +0200 Subject: [PATCH] ksys/act: Implement ActorLinkConstDataAccess --- data/uking_functions.csv | 8 ++--- lib/sead | 2 +- src/KingSystem/ActorSystem/actActor.h | 2 ++ .../actActorLinkConstDataAccess.cpp | 33 +++++++++++++++++++ .../ActorSystem/actActorLinkConstDataAccess.h | 15 +++++++++ 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 1453e4bf..621baf65 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -71172,7 +71172,7 @@ 0x0000007100d0dae8,Account::__auto0,8, 0x0000007100d0daf0,Account::getUserId,28, 0x0000007100d0db0c,ActorAccessor::ctorCopy,144, -0x0000007100d0db9c,ActorAccessor::hasActor,16, +0x0000007100d0db9c,ActorAccessor::hasActor,16,_ZNK4ksys3act24ActorLinkConstDataAccess7hasProcEPNS0_8BaseProcE 0x0000007100d0dbac,act::fieldx8IsEqualToActorFieldx60,144, 0x0000007100d0dc3c,sub_7100D0DC3C,168, 0x0000007100d0dce4,act::acc::Actor::baseProcLinkFromActor,168, @@ -71238,7 +71238,7 @@ 0x0000007100d105a8,sub_7100D105A8,188, 0x0000007100d10664,sub_7100D10664,156, 0x0000007100d10700,act::acc::getActorMtx,156, -0x0000007100d1079c,ActorAccessor::debugLog,4, +0x0000007100d1079c,ActorAccessor::debugLog,4,_ZN4ksys3act24ActorLinkConstDataAccess8debugLogEiRKN4sead14SafeStringBaseIcEE 0x0000007100d107a0,ActorAccessor::getPosition2,148, 0x0000007100d10834,act::acc::getPreviousPos2,156, 0x0000007100d108d0,act::acc::getField440_Vec3,156, @@ -74112,8 +74112,8 @@ 0x0000007100dca3b4,ActorInstParams::Buf::addInvoker,196, 0x0000007100dca478,ActorInstParams::Buf::pop,604, 0x0000007100dca6d4,_ZN15ActorInstParams3BufaSERS0_,56, -0x0000007100dca70c,_ZN13ActorAccessorD2Ev,56, -0x0000007100dca744,ActorAccessor::acquire,88, +0x0000007100dca70c,_ZN13ActorAccessorD2Ev,56,_ZN4ksys3act24ActorLinkConstDataAccessD1Ev +0x0000007100dca744,ActorAccessor::acquire,88,_ZN4ksys3act24ActorLinkConstDataAccess7acquireEPNS0_8BaseProcE 0x0000007100dca79c,act::acquireActorFromGameOrHavokThread,256, 0x0000007100dca89c,GameFramework::ctor,96, 0x0000007100dca8fc,GameFramework::dtor,64, diff --git a/lib/sead b/lib/sead index 2bf84562..c53aff46 160000 --- a/lib/sead +++ b/lib/sead @@ -1 +1 @@ -Subproject commit 2bf8456295d4640862e112fba66cb6bf2cc0ee93 +Subproject commit c53aff46fc42344958c42d0b69b27f992fc8d979 diff --git a/src/KingSystem/ActorSystem/actActor.h b/src/KingSystem/ActorSystem/actActor.h index cc51e126..39f41064 100644 --- a/src/KingSystem/ActorSystem/actActor.h +++ b/src/KingSystem/ActorSystem/actActor.h @@ -11,6 +11,8 @@ public: Actor(); // FIXME ~Actor() override; + SEAD_RTTI_OVERRIDE(Actor, BaseProc) + void emitBasicSigOn(); void emitBasicSigOff(); }; diff --git a/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.cpp b/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.cpp index e69de29b..476482ce 100644 --- a/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.cpp +++ b/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.cpp @@ -0,0 +1,33 @@ +#include "KingSystem/ActorSystem/actActorLinkConstDataAccess.h" +#include "KingSystem/ActorSystem/actBaseProc.h" + +namespace ksys::act { + +ActorLinkConstDataAccess::~ActorLinkConstDataAccess() { + if (mAcquired) + acquire(nullptr); +} + +bool ActorLinkConstDataAccess::acquire(BaseProc* proc) { + if (mProc) { + if (mAcquired) + mProc->release(); + + mAcquired = false; + mProc = nullptr; + } + + if (proc) + return proc->acquire(*this); + return false; +} + +bool ActorLinkConstDataAccess::hasProc(BaseProc* proc) const { + return mProc == proc; +} + +void ActorLinkConstDataAccess::debugLog(s32, const sead::SafeString&) { + // Intentionally left empty. +} + +} // namespace ksys::act diff --git a/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.h b/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.h index 628138b1..ff4258ec 100644 --- a/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.h +++ b/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.h @@ -1,5 +1,8 @@ #pragma once +#include +#include + namespace ksys { namespace act { @@ -9,9 +12,21 @@ class BaseProc; /// Provides read-only access to actor data for safe, multi-threaded access. class ActorLinkConstDataAccess { public: + ActorLinkConstDataAccess() = default; + explicit ActorLinkConstDataAccess(BaseProc* proc) { acquire(proc); } + /// Destructor that automatically releases any acquired BaseProc. ~ActorLinkConstDataAccess(); + /// Acquire a BaseProc. This increments its reference count. + /// If an actor was already acquired, it is released. + bool acquire(BaseProc* proc); + + /// Checks whether the acquired BaseProc is `proc`. + bool hasProc(BaseProc* proc) const; + private: + void debugLog(s32, const sead::SafeString& method_name); + bool mAcquired = false; BaseProc* mProc = nullptr; };