summaryrefslogtreecommitdiff
path: root/src/KingSystem/Physics/System/physMaterialTable.h
blob: da0fb540f5f753a0d906fb2e3a4b7181b803b0a9 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once

#include <container/seadSafeArray.h>
#include <utility/aglParameter.h>
#include <utility/aglParameterIO.h>
#include <utility/aglParameterList.h>
#include <utility/aglParameterObj.h>
#include <utility/aglResParameter.h>
#include "KingSystem/Physics/physDefines.h"
#include "KingSystem/Utils/Types.h"

namespace ksys::phys {

class MaterialTable {
public:
    /// Properties for interactions between two materials.
    struct MaterialPairProperties {
        float friction;
        float restitution;
    };

    /// Parameter object that stores an entire row of InteractionProperties.
    struct Values : agl::utl::IParameterObj {
        sead::SafeArray<agl::utl::Parameter<sead::Vector2f>, Material::size()> values;
    };
    KSYS_CHECK_SIZE_NX150(Values, 0x4b0);

    struct SubValues : agl::utl::IParameterObj {
        sead::SafeArray<agl::utl::Parameter<sead::FixedSafeString<32>>, 12> values;
        int num_values;
    };
    KSYS_CHECK_SIZE_NX150(SubValues, 0x3f8);

    MaterialTable();
    virtual ~MaterialTable();

    void loadMaterialTable(sead::Heap* heap, agl::utl::ResParameterArchive archive);
    void loadSubMaterialTable(sead::Heap* heap, agl::utl::ResParameterArchive archive);

    MaterialPairProperties getPairProperties(Material mat_a, Material mat_b) const {
        auto& vec = mMaterialTable[mat_a].values[mat_b];
        return {vec->x, vec->y};
    }

    const sead::SafeString& getSubMaterial(Material material, int submat_idx) const;
    const sead::SafeString& getSoundMatchingSubMaterial(Material material, int submat_idx) const;

    int getSubMaterialIdx(Material material, const sead::SafeString& submat_name) const;
    int getSoundSubMaterialIdx(Material material, const sead::SafeString& submat_name) const;

    int getNumSubMaterials(Material material) const;
    bool subMaterialHasSound(Material material, int submat_idx) const;

private:
    void addMaterialTableList(const char* name) {
        mMaterialTablePIO.addList(&mMaterialTablePList, name);
    }

    void addSubMaterialTableList(const char* name) {
        mSubMaterialTablePIO.addList(&mSubMaterialTablePList, name);
    }

    agl::utl::IParameterIO mMaterialTablePIO;
    agl::utl::ParameterList mMaterialTablePList;
    sead::SafeArray<Values, Material::size()> mMaterialTable;

    agl::utl::IParameterIO mSubMaterialTablePIO;
    agl::utl::ParameterList mSubMaterialTablePList;
    sead::SafeArray<SubValues, Material::size()> mSubMaterialTable;

    agl::utl::ParameterList mSoundSubMaterialTablePList;
    sead::SafeArray<SubValues, Material::size()> mSoundSubMaterialTable;

    agl::utl::ParameterList mSoundMatchingSubMaterialTablePList;
    sead::SafeArray<SubValues, Material::size()> mSoundMatchingSubMaterialTable;
};
KSYS_CHECK_SIZE_NX150(MaterialTable, 0x25a28);

}  // namespace ksys::phys