summaryrefslogtreecommitdiff
path: root/src/KingSystem/ActorSystem/actActorLinkConstDataAccess.h
blob: 4c67c686d001bac947569309730468bc61150ed3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include <basis/seadTypes.h>
#include <math/seadMatrix.h>
#include <prim/seadSafeString.h>

namespace ksys {
struct MesTransceiverId;
namespace act {

class Actor;
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();

    ActorLinkConstDataAccess(const ActorLinkConstDataAccess&) = delete;
    ActorLinkConstDataAccess& operator=(const ActorLinkConstDataAccess&) = delete;
    ActorLinkConstDataAccess(ActorLinkConstDataAccess&& other) noexcept {
        *this = std::move(other);
    }
    ActorLinkConstDataAccess& operator=(ActorLinkConstDataAccess&& other) noexcept {
        std::swap(mAcquired, other.mAcquired);
        std::swap(mProc, other.mProc);
        return *this;
    }

    /// Acquire a BaseProc. This increments its reference count.
    /// If an actor was already acquired, it is released.
    bool acquire(BaseProc* proc);

    void release() { acquire(nullptr); }

    bool hasProc() const { return mProc != nullptr; }

    const MesTransceiverId* getMessageTransceiverId() const;
    const Actor* getActor() const;
    const sead::Matrix34f& getActorMtx();

protected:
    friend class ActorConstDataAccess;
    friend class BaseProc;
    friend class BaseProcHandle;
    friend class BaseProcUnit;

    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,
                 s32 = 2);

}  // namespace act

}  // namespace ksys