mirror of https://github.com/zeldaret/botw.git
ksys/act: Add ActorLinkConstDataAccess (incomplete)
Also moves from functions from ActorLinkConstDataAccess (the base class for BaseProc) into the Actor-specific ActorConstDataAccess
This commit is contained in:
parent
1cc0b1e6be
commit
7226150ed7
|
@ -22,6 +22,8 @@ add_executable(uking
|
|||
src/Game/DLC/aoc2.h
|
||||
|
||||
src/KingSystem/ActorSystem/actActor.h
|
||||
src/KingSystem/ActorSystem/actActorConstDataAccess.cpp
|
||||
src/KingSystem/ActorSystem/actActorConstDataAccess.h
|
||||
src/KingSystem/ActorSystem/actActorCreator.cpp
|
||||
src/KingSystem/ActorSystem/actActorCreator.h
|
||||
src/KingSystem/ActorSystem/actActorFactory.cpp
|
||||
|
|
|
@ -181,7 +181,7 @@
|
|||
0x0000007100003140,BeamBase::reflectMaybe,852,
|
||||
0x0000007100003494,sub_7100003494,880,
|
||||
0x0000007100003804,sub_7100003804,96,
|
||||
0x0000007100003864,BaseProcLink::getActor,248,
|
||||
0x0000007100003864,BaseProcLink::getActor,248,_ZN4ksys3act12acquireActorEPNS0_12BaseProcLinkEPNS0_20ActorConstDataAccessE
|
||||
0x000000710000395c,sub_710000395C,132,
|
||||
0x00000071000039e0,sub_71000039E0,316,
|
||||
0x0000007100003b1c,sub_7100003B1C,280,
|
||||
|
@ -71173,11 +71173,11 @@
|
|||
0x0000007100d0da88,Account::init,96,
|
||||
0x0000007100d0dae8,Account::__auto0,8,
|
||||
0x0000007100d0daf0,Account::getUserId,28,
|
||||
0x0000007100d0db0c,ActorAccessor::ctorCopy,144,
|
||||
0x0000007100d0db9c,ActorAccessor::hasActor,16,_ZNK4ksys3act24ActorLinkConstDataAccess7hasProcEPNS0_8BaseProcE
|
||||
0x0000007100d0dbac,act::fieldx8IsEqualToActorFieldx60,144,
|
||||
0x0000007100d0dc3c,sub_7100D0DC3C,168,
|
||||
0x0000007100d0dce4,act::acc::Actor::baseProcLinkFromActor,168,
|
||||
0x0000007100d0db0c,ActorAccessor::ctorCopy,144,_ZN4ksys3act20ActorConstDataAccess12acquireActorERKNS0_24ActorLinkConstDataAccessE
|
||||
0x0000007100d0db9c,ActorAccessor::hasActor,16,_ZNK4ksys3act20ActorConstDataAccess7hasProcEPNS0_8BaseProcE
|
||||
0x0000007100d0dbac,act::fieldx8IsEqualToActorFieldx60,144,_ZNK4ksys3act20ActorConstDataAccess7hasProcERKNS0_12BaseProcLinkE
|
||||
0x0000007100d0dc3c,sub_7100D0DC3C,168,_ZNK4ksys3act20ActorConstDataAccess11linkAcquireEPNS0_12BaseProcLinkE
|
||||
0x0000007100d0dce4,act::acc::Actor::baseProcLinkFromActor,168,_ZNK4ksys3act20ActorConstDataAccess22linkAcquireImmediatelyEPNS0_12BaseProcLinkE
|
||||
0x0000007100d0dd8c,act::acc::Actor::getMessageTransceiverId,160,
|
||||
0x0000007100d0de2c,ActorAccessor::isPlayerClass,136,
|
||||
0x0000007100d0deb4,act::acc::Actor::isWeaponActorProfile,136,
|
||||
|
@ -71240,7 +71240,7 @@
|
|||
0x0000007100d105a8,sub_7100D105A8,188,
|
||||
0x0000007100d10664,sub_7100D10664,156,
|
||||
0x0000007100d10700,act::acc::getActorMtx,156,
|
||||
0x0000007100d1079c,ActorAccessor::debugLog,4,_ZN4ksys3act24ActorLinkConstDataAccess8debugLogEiRKN4sead14SafeStringBaseIcEE
|
||||
0x0000007100d1079c,ActorAccessor::debugLog,4,_ZNK4ksys3act20ActorConstDataAccess8debugLogEiRKN4sead14SafeStringBaseIcEE
|
||||
0x0000007100d107a0,ActorAccessor::getPosition2,148,
|
||||
0x0000007100d10834,act::acc::getPreviousPos2,156,
|
||||
0x0000007100d108d0,act::acc::getField440_Vec3,156,
|
||||
|
|
Can't render this file because it is too large.
|
|
@ -0,0 +1,58 @@
|
|||
#include "KingSystem/ActorSystem/actActorConstDataAccess.h"
|
||||
#include <prim/seadRuntimeTypeInfo.h>
|
||||
#include "KingSystem/ActorSystem/actActor.h"
|
||||
|
||||
namespace ksys::act {
|
||||
|
||||
static BaseProc* getProcIfActor(BaseProc* proc) {
|
||||
if (proc && sead::IsDerivedFrom<Actor>(proc))
|
||||
return proc;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ActorConstDataAccess::acquireActor(const ActorLinkConstDataAccess& other) {
|
||||
return acquire(getProcIfActor(other.mProc));
|
||||
}
|
||||
|
||||
bool ActorConstDataAccess::hasProc(BaseProc* proc) const {
|
||||
return mProc == proc;
|
||||
}
|
||||
|
||||
bool ActorConstDataAccess::hasProc(const BaseProcLink& link) const {
|
||||
return link.hasProcById(getProcIfActor(mProc));
|
||||
}
|
||||
|
||||
bool ActorConstDataAccess::linkAcquire(BaseProcLink* link) const {
|
||||
auto* proc = getProcIfActor(mProc);
|
||||
if (proc)
|
||||
return link->acquire(proc, false);
|
||||
|
||||
link->reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ActorConstDataAccess::linkAcquireImmediately(BaseProcLink* link) const {
|
||||
auto* proc = getProcIfActor(mProc);
|
||||
if (proc)
|
||||
return link->acquire(proc, true);
|
||||
|
||||
link->reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
void ActorConstDataAccess::debugLog(s32, const sead::SafeString&) const {
|
||||
// Intentionally left empty.
|
||||
}
|
||||
|
||||
bool acquireActor(BaseProcLink* link, ActorConstDataAccess* accessor) {
|
||||
return link->getProcInContext([accessor](BaseProc* proc, bool valid) {
|
||||
if (!proc) {
|
||||
if (!valid)
|
||||
accessor->acquire(nullptr);
|
||||
return false;
|
||||
}
|
||||
return accessor->acquire(sead::DynamicCast<Actor>(proc));
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace ksys::act
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include "KingSystem/ActorSystem/actActorLinkConstDataAccess.h"
|
||||
#include "KingSystem/ActorSystem/actBaseProcLink.h"
|
||||
|
||||
namespace ksys::act {
|
||||
|
||||
class ActorConstDataAccess : public ActorLinkConstDataAccess {
|
||||
public:
|
||||
bool acquireActor(const ActorLinkConstDataAccess& other);
|
||||
|
||||
/// Checks whether the acquired BaseProc is `proc`.
|
||||
bool hasProc(BaseProc* proc) const;
|
||||
|
||||
/// Checks whether the acquired BaseProc and the BaseProcLink's actor are the same
|
||||
/// by comparing the IDs.
|
||||
bool hasProc(const BaseProcLink& link) const;
|
||||
|
||||
bool linkAcquire(BaseProcLink* link) const;
|
||||
bool linkAcquireImmediately(BaseProcLink* link) const;
|
||||
|
||||
void debugLog(s32, const sead::SafeString& method_name) const;
|
||||
};
|
||||
|
||||
bool acquireActor(BaseProcLink* link, ActorConstDataAccess* accessor);
|
||||
|
||||
} // namespace ksys::act
|
|
@ -25,14 +25,6 @@ bool ActorLinkConstDataAccess::acquire(BaseProc* proc) {
|
|||
return proc && proc->acquire(*this);
|
||||
}
|
||||
|
||||
bool ActorLinkConstDataAccess::hasProc(BaseProc* proc) const {
|
||||
return mProc == proc;
|
||||
}
|
||||
|
||||
void ActorLinkConstDataAccess::debugLog(s32, const sead::SafeString&) {
|
||||
// Intentionally left empty.
|
||||
}
|
||||
|
||||
bool acquireProc(ActorLinkConstDataAccess* accessor, BaseProc* proc, const sead::SafeString& from,
|
||||
s32) {
|
||||
bool acquired = false;
|
||||
|
|
|
@ -23,12 +23,9 @@ public:
|
|||
|
||||
void release() { acquire(nullptr); }
|
||||
|
||||
/// Checks whether the acquired BaseProc is `proc`.
|
||||
bool hasProc(BaseProc* proc) const;
|
||||
protected:
|
||||
friend class ActorConstDataAccess;
|
||||
|
||||
void debugLog(s32, const sead::SafeString& method_name);
|
||||
|
||||
private:
|
||||
bool mAcquired = false;
|
||||
BaseProc* mProc = nullptr;
|
||||
};
|
||||
|
|
|
@ -32,7 +32,7 @@ bool BaseProcLink::hasProc() const {
|
|||
|
||||
bool BaseProcLink::hasProcInCalcState() const {
|
||||
return getProcInContext(
|
||||
[](BaseProc* proc) { return proc && proc->getState() == BaseProc::State::Calc; });
|
||||
[](BaseProc* proc, bool) { return proc && proc->getState() == BaseProc::State::Calc; });
|
||||
}
|
||||
|
||||
bool BaseProcLink::hasProcById(BaseProc* proc) const {
|
||||
|
@ -40,7 +40,7 @@ bool BaseProcLink::hasProcById(BaseProc* proc) const {
|
|||
}
|
||||
|
||||
BaseProc* BaseProcLink::getProc(ActorLinkConstDataAccess* accessor, BaseProc* other_proc) const {
|
||||
return getProcInContext([&](BaseProc* proc) -> BaseProc* {
|
||||
return getProcInContext([&](BaseProc* proc, bool) -> BaseProc* {
|
||||
if (proc && acquireProc(accessor, proc, "frm::BaseProcLink") &&
|
||||
BaseProcMgr::instance()->isAccessingProcSafe(proc, other_proc)) {
|
||||
return proc;
|
||||
|
@ -50,7 +50,7 @@ BaseProc* BaseProcLink::getProc(ActorLinkConstDataAccess* accessor, BaseProc* ot
|
|||
}
|
||||
|
||||
BaseProc* BaseProcLink::getProc(ActorLinkConstDataAccess* accessor) const {
|
||||
return getProcInContext([&](BaseProc* proc) -> BaseProc* {
|
||||
return getProcInContext([&](BaseProc* proc, bool) -> BaseProc* {
|
||||
if (proc && acquireProc(accessor, proc, "frm::BaseProcLink"))
|
||||
return proc;
|
||||
return nullptr;
|
||||
|
@ -90,7 +90,7 @@ void BaseProcLink::reset() {
|
|||
}
|
||||
|
||||
bool BaseProcLink::isAccessingSpecifiedProcUnsafe(BaseProc* other) const {
|
||||
return getProcInContext([&](BaseProc* proc) {
|
||||
return getProcInContext([&](BaseProc* proc, bool) {
|
||||
return proc && !BaseProcMgr::instance()->isAccessingProcSafe(proc, other);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -43,14 +43,14 @@ public:
|
|||
|
||||
bool isAccessingSpecifiedProcUnsafe(BaseProc* other) const;
|
||||
|
||||
template <typename Function>
|
||||
auto getProcInContext(const Function& function) const;
|
||||
|
||||
private:
|
||||
static constexpr u32 cInvalidId = -1;
|
||||
|
||||
BaseProc* getProc() const;
|
||||
|
||||
template <typename Function>
|
||||
auto getProcInContext(const Function& function) const;
|
||||
|
||||
BaseProcLinkData* mData = nullptr;
|
||||
u32 mId = cInvalidId;
|
||||
bool mAcquired = false;
|
||||
|
@ -106,14 +106,14 @@ inline BaseProc* BaseProcLink::getProc() const {
|
|||
template <typename Function>
|
||||
inline auto BaseProcLink::getProcInContext(const Function& function) const {
|
||||
if (mId == cInvalidId)
|
||||
return function(nullptr);
|
||||
return function(nullptr, false);
|
||||
|
||||
const auto guard = sead::makeScopeGuard([crit_section = mData->lockIfNeeded()] {
|
||||
if (crit_section)
|
||||
crit_section->unlock();
|
||||
});
|
||||
|
||||
return function(getProc());
|
||||
return function(getProc(), true);
|
||||
}
|
||||
|
||||
} // namespace ksys::act
|
||||
|
|
Loading…
Reference in New Issue