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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
#include "KingSystem/Physics/System/physSystemData.h"
#include "KingSystem/Physics/System/physContactInfoTable.h"
#include "KingSystem/Physics/System/physMaterialTable.h"
#include "KingSystem/Physics/System/physRagdollControllerKeyList.h"
#include "KingSystem/Resource/resHandle.h"
#include "KingSystem/Resource/resLoadRequest.h"
namespace ksys::phys {
SystemData::SystemData() = default;
template <typename T>
static void deleteAndNull(T*& ptr) {
if (ptr) {
delete ptr;
ptr = nullptr;
}
}
SystemData::~SystemData() {
deleteAndNull(mMaterialTableHandle);
deleteAndNull(mSubMaterialTableHandle);
deleteAndNull(mLayerTableInfo[0].mResHandle);
deleteAndNull(mContactInfoTableHandles[0]);
deleteAndNull(mLayerTableInfo[1].mResHandle);
deleteAndNull(mContactInfoTableHandles[1]);
deleteAndNull(mCharacterCtrlTable.mResHandle);
if (auto*& handle = mRagdollCtrlKeyListHandle) {
delete handle;
handle = nullptr;
mRagdollCtrlKeyList = nullptr;
}
}
void SystemData::load(sead::Heap* heap, LayerTable* entity_layer_table,
LayerTable* sensor_layer_table, MaterialTable* material_table,
ContactInfoTable* contact_info_table) {
loadLayerTable(heap, entity_layer_table, ContactLayerType::Entity);
loadLayerTable(heap, sensor_layer_table, ContactLayerType::Sensor);
loadMaterialTable(heap, material_table);
loadSubMaterialTable(heap, material_table);
loadContactInfoTable(heap, contact_info_table, ContactLayerType::Entity);
loadContactInfoTable(heap, contact_info_table, ContactLayerType::Sensor);
loadCharacterCtrlTable(heap);
loadRagdollCtrlKeyList(heap);
}
void SystemData::loadMaterialTable(sead::Heap* heap, MaterialTable* table) {
mMaterialTableHandle = new (heap) res::Handle;
const auto res = loadMaterialTableRes();
table->loadMaterialTable(heap, res);
}
void SystemData::loadSubMaterialTable(sead::Heap* heap, MaterialTable* table) {
mSubMaterialTableHandle = new (heap) res::Handle;
const auto res = loadSubMaterialTableRes();
table->loadSubMaterialTable(heap, res);
}
void SystemData::loadContactInfoTable(sead::Heap* heap, ContactInfoTable* table,
ContactLayerType type) {
mContactInfoTableHandles[int(type)] = new (heap) res::Handle;
const auto res = loadContactInfoTableRes(type);
table->load(heap, res, type);
}
void SystemData::loadCharacterCtrlTable(sead::Heap* heap) {
mCharacterCtrlTable.addList("CharacterControllerTable");
auto& obj = mCharacterCtrlTable.mTables[0];
mCharacterCtrlTable.mParamList.addObj(
&obj, CharacterControllerTable::Type(CharacterControllerTable::Type::Default).text());
for (int i = 0; i < Material::size(); ++i) {
const char* material_text = materialToText(i);
obj.params[i].init(0.0, material_text, material_text, &obj);
}
mCharacterCtrlTable.mResHandle = new (heap) res::Handle;
const auto res = loadCharacterCtrlTableRes();
mCharacterCtrlTable.mParamIO.applyResParameterArchive(res);
}
void SystemData::loadRagdollCtrlKeyList(sead::Heap* heap) {
mRagdollCtrlKeyListHandle = new (heap) res::Handle;
res::LoadRequest request;
request.mRequester = "physSystemData";
const char* path = "Physics/System/RagdollControllerKeyList.brgcon";
auto* res = mRagdollCtrlKeyListHandle->load(path, &request);
mRagdollCtrlKeyList = sead::DynamicCast<RagdollControllerKeyList>(res);
}
agl::utl::ResParameterArchive
SystemData::loadLayerTableRes(const SystemData::LayerTableInfoContainer& container,
ContactLayerType type) {
res::LoadRequest request;
request.mRequester = "physSystemData";
const char* path{};
switch (type) {
case ContactLayerType::Entity:
path = "Physics/System/EntityLayerTable.bphyslayer";
break;
case ContactLayerType::Sensor:
path = "Physics/System/SensorLayerTable.bphyslayer";
break;
}
const auto& resource = *container.mResHandle->load(path, &request);
auto* direct_resource = sead::DynamicCast<const sead::DirectResource>(&resource);
return agl::utl::ResParameterArchive{direct_resource->getRawData()};
}
agl::utl::ResParameterArchive SystemData::loadMaterialTableRes() {
res::LoadRequest request;
request.mRequester = "physSystemData";
const char* path = "Physics/System/PhysicsMaterialTable.bphysmaterial";
const auto& resource = *mMaterialTableHandle->load(path, &request);
auto* direct_resource = sead::DynamicCast<const sead::DirectResource>(&resource);
return agl::utl::ResParameterArchive{direct_resource->getRawData()};
}
agl::utl::ResParameterArchive SystemData::loadSubMaterialTableRes() {
res::LoadRequest request;
request.mRequester = "physSystemData";
const char* path = "Physics/System/PhysicsSubMaterialTable.bphyssubmat";
const auto& resource = *mSubMaterialTableHandle->load(path, &request);
auto* direct_resource = sead::DynamicCast<const sead::DirectResource>(&resource);
return agl::utl::ResParameterArchive{direct_resource->getRawData()};
}
agl::utl::ResParameterArchive SystemData::loadContactInfoTableRes(ContactLayerType type) {
res::LoadRequest request;
request.mRequester = "physSystemData";
const char* path{};
switch (type) {
case ContactLayerType::Entity:
path = "Physics/System/EntityContactInfoTable.bphyscontact";
break;
case ContactLayerType::Sensor:
path = "Physics/System/SensorContactInfoTable.bphyscontact";
break;
}
/// @bug Possible bug? The request is never used.
const auto& resource = *mContactInfoTableHandles[int(type)]->load(path, nullptr);
auto* direct_resource = sead::DynamicCast<const sead::DirectResource>(&resource);
return agl::utl::ResParameterArchive{direct_resource->getRawData()};
}
agl::utl::ResParameterArchive SystemData::loadCharacterCtrlTableRes() {
res::LoadRequest request;
request.mRequester = "physSystemData";
const char* path = "Physics/System/CharacterControllerTable.bphyscharcon";
const auto& resource = *mCharacterCtrlTable.mResHandle->load(path, &request);
auto* direct_resource = sead::DynamicCast<const sead::DirectResource>(&resource);
return agl::utl::ResParameterArchive{direct_resource->getRawData()};
}
void LayerTableInfo::postRead_() {
// FIXME
}
} // namespace ksys::phys
|