summaryrefslogtreecommitdiff
path: root/src/KingSystem/Physics/Ragdoll/physRagdollInstanceMgr.cpp
blob: 92c3588615c19e2421057d71cd6d055e99dd6cf5 (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
#include "KingSystem/Physics/Ragdoll/physRagdollInstanceMgr.h"
#include <prim/seadScopedLock.h>
#include "KingSystem/Physics/Ragdoll/physRagdollInstance.h"
#include "KingSystem/Physics/System/physSystem.h"

namespace ksys::phys {

RagdollInstanceMgr::RagdollInstanceMgr() = default;

RagdollInstanceMgr::~RagdollInstanceMgr() {
    mInstances.freeBuffer();
}

void RagdollInstanceMgr::init(sead::Heap* heap) {
    mInstances.alloc(0x400, heap);
}

bool RagdollInstanceMgr::addInstance(RagdollInstance* instance) {
    return mInstances.push(instance);
}

void RagdollInstanceMgr::removeInstance(RagdollInstance* instance) {
    auto lock = sead::makeScopedLock(mCS);
    mInstances.erase(instance);
}

void RagdollInstanceMgr::calc() {
    ScopedWorldLock world_lock{ContactLayerType::Entity};
    auto lock = sead::makeScopedLock(mCS);

    RagdollInstance* first_processed = nullptr;

    while (auto* instance = mInstances.pop()) {
        mInstances.push(instance);

        // If we have processed the entire buffer and wrapped around, stop.
        if (first_processed == instance)
            break;

        instance->update();

        if (first_processed == nullptr)
            first_processed = instance;
    }
}

void RagdollInstanceMgr::calc1() {}

}  // namespace ksys::phys