summaryrefslogtreecommitdiff
path: root/src/KingSystem/Physics/Ragdoll/physRagdollControllerKeyList.cpp
blob: 462734236612bef3f7433391f229ea35761820b5 (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
#include "KingSystem/Physics/Ragdoll/physRagdollControllerKeyList.h"

namespace ksys::phys {

RagdollControllerKeyList::RagdollControllerKey::RagdollControllerKey()
    : key(sead::SafeString::cEmptyString, "key", this), hierarchy_gain(0, "hierarchy_gain", this),
      velocity_damping(0, "velocity_damping", this),
      acceleration_gain(0, "acceleration_gain", this), velocity_gain(0, "velocity_gain", this),
      position_gain(0, "position_gain", this),
      position_max_linear_velocity(0, "position_max_linear_velocity", this),
      position_max_angular_velocity(0, "position_max_angular_velocity", this),
      snap_gain(0, "snap_gain", this),
      snap_max_linear_velocity(0, "snap_max_linear_velocity", this),
      snap_max_angular_velocity(0, "snap_max_angular_velocity", this),
      snap_max_linear_distance(0, "snap_max_linear_distance", this),
      snap_max_angular_distance(0, "snap_max_angular_distance", this) {}

RagdollControllerKeyList::RagdollControllerKeyList() = default;
RagdollControllerKeyList::~RagdollControllerKeyList() {
    buffer.freeBuffer();
}

RagdollControllerKeyList::RagdollControllerKey*
RagdollControllerKeyList::getControllerKeyByKey(const sead::SafeString& key) {
    int buffer_size = buffer.size();
    for (int i = 0; i < buffer_size; i++) {
        if (buffer[i].key.ref() == key) {
            return &buffer[i];
        }
    }
    return nullptr;
}

bool RagdollControllerKeyList::parse_(u8* data, size_t actualFileSize, sead::Heap* heap) {
    if (!data)
        return false;

    auto archive = agl::utl::ResParameterArchive(data);
    auto key_list = agl::utl::getResParameterList(archive.getRootList(), "RagCtrlKeyList");
    if (!key_list)
        return false;

    int key_count = key_list.getResParameterObjNum();
    if (key_count == 0)
        return false;

    buffer.allocBufferAssert(key_count, heap);

    for (int i = 0; i < key_count; i++) {
        buffer[i].applyResParameterObj(key_list.getResParameterObj(i));
    }

    return true;
}

}  // namespace ksys::phys