mirror of
https://github.com/zeldaret/botw
synced 2026-06-10 20:58:31 -04:00
ksys/act: Implement ActorLinkConstDataAccess
This commit is contained in:
@@ -11,6 +11,8 @@ public:
|
||||
Actor(); // FIXME
|
||||
~Actor() override;
|
||||
|
||||
SEAD_RTTI_OVERRIDE(Actor, BaseProc)
|
||||
|
||||
void emitBasicSigOn();
|
||||
void emitBasicSigOff();
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <basis/seadTypes.h>
|
||||
#include <prim/seadSafeString.h>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user