diff options
| author | Léo Lam <leo@leolam.fr> | 2021-12-22 16:23:22 +0100 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2021-12-24 21:48:41 +0100 |
| commit | a816125247419be2a3b581e136d88b9ecf8a8a09 (patch) | |
| tree | 0f1e9bb9f994aa83a8a480883293a7e1be1547bd /src/KingSystem/Physics/System/physSystemData.cpp | |
| parent | 19f019b0ffaccb850312dc172daad5957eaca1ef (diff) | |
ksys/phys: Finish SystemData and start implementing GroupFilter
Diffstat (limited to 'src/KingSystem/Physics/System/physSystemData.cpp')
| -rw-r--r-- | src/KingSystem/Physics/System/physSystemData.cpp | 64 |
1 files changed, 52 insertions, 12 deletions
diff --git a/src/KingSystem/Physics/System/physSystemData.cpp b/src/KingSystem/Physics/System/physSystemData.cpp index 41f3845e..319bb98e 100644 --- a/src/KingSystem/Physics/System/physSystemData.cpp +++ b/src/KingSystem/Physics/System/physSystemData.cpp @@ -1,5 +1,6 @@ #include "KingSystem/Physics/System/physSystemData.h" #include "KingSystem/Physics/System/physContactInfoTable.h" +#include "KingSystem/Physics/System/physGroupFilter.h" #include "KingSystem/Physics/System/physMaterialTable.h" #include "KingSystem/Physics/System/physRagdollControllerKeyList.h" #include "KingSystem/Resource/resHandle.h" @@ -21,10 +22,10 @@ SystemData::~SystemData() { deleteAndNull(mMaterialTableHandle); deleteAndNull(mSubMaterialTableHandle); - deleteAndNull(mLayerTableInfo[0].mResHandle); + deleteAndNull(mLayerMatrices[0].mResHandle); deleteAndNull(mContactInfoTableHandles[0]); - deleteAndNull(mLayerTableInfo[1].mResHandle); + deleteAndNull(mLayerMatrices[1].mResHandle); deleteAndNull(mContactInfoTableHandles[1]); deleteAndNull(mCharacterCtrlTable.mResHandle); @@ -36,11 +37,11 @@ SystemData::~SystemData() { } } -void SystemData::load(sead::Heap* heap, LayerTable* entity_layer_table, - LayerTable* sensor_layer_table, MaterialTable* material_table, +void SystemData::load(sead::Heap* heap, GroupFilter* entity_group_filter, + GroupFilter* sensor_group_filter, MaterialTable* material_table, ContactInfoTable* contact_info_table) { - loadLayerTable(heap, entity_layer_table, ContactLayerType::Entity); - loadLayerTable(heap, sensor_layer_table, ContactLayerType::Sensor); + loadLayerTable(heap, entity_group_filter, ContactLayerType::Entity); + loadLayerTable(heap, sensor_group_filter, ContactLayerType::Sensor); loadMaterialTable(heap, material_table); loadSubMaterialTable(heap, material_table); loadContactInfoTable(heap, contact_info_table, ContactLayerType::Entity); @@ -49,6 +50,34 @@ void SystemData::load(sead::Heap* heap, LayerTable* entity_layer_table, loadRagdollCtrlKeyList(heap); } +void SystemData::loadLayerTable(sead::Heap* heap, GroupFilter* filter, ContactLayerType type) { + auto& matrix = mLayerMatrices[int(type)]; + matrix.addList("LayerTable"); + + const int first = filter->getLayerFirst(); + const int last = filter->getLayerLast(); + const int num_layers = 1 + last - first; + + for (int i = 0; i < num_layers; ++i) { + auto& table = matrix.mTables[i]; + const ContactLayer layer = first + i; + table.num_layers = num_layers; + table.filter = filter; + table.layer = layer; + + matrix.mParamList.addObj(&table, contactLayerToText(layer)); + + for (int j = 0; j < num_layers; ++j) { + const char* other_layer_name = contactLayerToText(first + j); + table.layer_values[j].init(0, other_layer_name, other_layer_name, &table); + } + } + + matrix.mResHandle = new (heap) res::Handle; + const auto res = loadLayerTableRes(matrix, type); + matrix.mParamIO.applyResParameterArchive(res); +} + void SystemData::loadMaterialTable(sead::Heap* heap, MaterialTable* table) { mMaterialTableHandle = new (heap) res::Handle; const auto res = loadMaterialTableRes(); @@ -95,9 +124,8 @@ void SystemData::loadRagdollCtrlKeyList(sead::Heap* heap) { mRagdollCtrlKeyList = sead::DynamicCast<RagdollControllerKeyList>(res); } -agl::utl::ResParameterArchive -SystemData::loadLayerTableRes(const SystemData::LayerTableInfoContainer& container, - ContactLayerType type) { +agl::utl::ResParameterArchive SystemData::loadLayerTableRes(const SystemData::LayerMatrix& matrix, + ContactLayerType type) { res::LoadRequest request; request.mRequester = "physSystemData"; const char* path{}; @@ -109,7 +137,7 @@ SystemData::loadLayerTableRes(const SystemData::LayerTableInfoContainer& contain path = "Physics/System/SensorLayerTable.bphyslayer"; break; } - const auto& resource = *container.mResHandle->load(path, &request); + const auto& resource = *matrix.mResHandle->load(path, &request); auto* direct_resource = sead::DynamicCast<const sead::DirectResource>(&resource); return agl::utl::ResParameterArchive{direct_resource->getRawData()}; } @@ -159,8 +187,20 @@ agl::utl::ResParameterArchive SystemData::loadCharacterCtrlTableRes() { return agl::utl::ResParameterArchive{direct_resource->getRawData()}; } -void LayerTableInfo::postRead_() { - // FIXME +void LayerTable::postRead_() { + u32 collision_mask = 0; + u32 custom_mask = 0; + + for (int i = 0; i < num_layers; ++i) { + const int value = layer_values[i].ref(); + if (value & 1) + collision_mask |= 1 << i; + if (value & 2) + custom_mask |= 1 << i; + } + + filter->setLayerCollisionEnabledMask(layer, collision_mask); + filter->setLayerCustomMask(layer, custom_mask); } } // namespace ksys::phys |
