From f9d6eedc9f8128ba0765a6b01da9e2fbb4a25341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Tue, 20 Apr 2021 23:16:53 +0200 Subject: [PATCH] ksys/phys: Start adding physics parameter structs * SupportBoneParam * RagdollParam * ClothSetParam, ClothSubWindParam, ClothParam * EdgeRigidBodySetParam, EdgeRigidBody * ParamSet (only the header for now) --- data/uking_functions.csv | 50 ++++++++-------- lib/agl | 2 +- lib/sead | 2 +- src/KingSystem/Physics/CMakeLists.txt | 10 ++++ .../Physics/Cloth/physClothParam.cpp | 60 +++++++++++++++++++ src/KingSystem/Physics/Cloth/physClothParam.h | 51 ++++++++++++++++ .../Physics/Ragdoll/physRagdollParam.cpp | 18 ++++++ .../Physics/Ragdoll/physRagdollParam.h | 23 +++++++ .../RigidBody/physEdgeRigidBodyParam.cpp | 28 +++++++++ .../RigidBody/physEdgeRigidBodyParam.h | 30 ++++++++++ .../SupportBone/physSupportBoneParam.cpp | 9 +++ .../SupportBone/physSupportBoneParam.h | 15 +++++ .../Physics/System/physParamSet.cpp | 1 + src/KingSystem/Physics/System/physParamSet.h | 39 ++++++++++++ 14 files changed, 311 insertions(+), 27 deletions(-) create mode 100644 src/KingSystem/Physics/Cloth/physClothParam.cpp create mode 100644 src/KingSystem/Physics/Cloth/physClothParam.h create mode 100644 src/KingSystem/Physics/Ragdoll/physRagdollParam.cpp create mode 100644 src/KingSystem/Physics/Ragdoll/physRagdollParam.h create mode 100644 src/KingSystem/Physics/RigidBody/physEdgeRigidBodyParam.cpp create mode 100644 src/KingSystem/Physics/RigidBody/physEdgeRigidBodyParam.h create mode 100644 src/KingSystem/Physics/SupportBone/physSupportBoneParam.cpp create mode 100644 src/KingSystem/Physics/SupportBone/physSupportBoneParam.h create mode 100644 src/KingSystem/Physics/System/physParamSet.cpp create mode 100644 src/KingSystem/Physics/System/physParamSet.h diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 28a23ec8..12fececd 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -93530,17 +93530,17 @@ 0x000000710121b3d8,sub_710121B3D8,444, 0x000000710121b594,sub_710121B594,3288, 0x000000710121c26c,sub_710121C26C,76, -0x000000710121c2b8,sub_710121C2B8,468, -0x000000710121c48c,sub_710121C48C,72, -0x000000710121c4d4,sub_710121C4D4,44, -0x000000710121c500,j__ZdlPv_1243,4, -0x000000710121c504,sub_710121C504,340, -0x000000710121c658,sub_710121C658,352, -0x000000710121c7b8,sub_710121C7B8,812, -0x000000710121cae4,sub_710121CAE4,332, -0x000000710121cc30,sub_710121CC30,72, -0x000000710121cc78,j__ZdlPv_1244,4, -0x000000710121cc7c,j__ZdlPv_1245,4, +0x000000710121c2b8,sub_710121C2B8,468,_ZN4ksys4phys13ClothSetParamC1Ev +0x000000710121c48c,sub_710121C48C,72,_ZN4ksys4phys13ClothSetParamD1Ev +0x000000710121c4d4,sub_710121C4D4,44,_ZN4ksys4phys17ClothSubWindParamD2Ev +0x000000710121c500,j__ZdlPv_1243,4,_ZN4ksys4phys13ClothSetParamD0Ev +0x000000710121c504,sub_710121C504,340,_ZN4ksys4phys13ClothSetParam5parseERKN3agl3utl16ResParameterListEPN4sead4HeapE +0x000000710121c658,sub_710121C658,352,_ZNK4ksys4phys13ClothSetParam8getClothERKN4sead14SafeStringBaseIcEE +0x000000710121c7b8,sub_710121C7B8,812,_ZN4ksys4phys10ClothParamC1Ev +0x000000710121cae4,sub_710121CAE4,332,_ZN4ksys4phys17ClothSubWindParamC1Ev +0x000000710121cc30,sub_710121CC30,72,_ZN4ksys4phys10ClothParamD2Ev +0x000000710121cc78,j__ZdlPv_1244,4,_ZN4ksys4phys10ClothParamD0Ev +0x000000710121cc7c,j__ZdlPv_1245,4,_ZN4ksys4phys17ClothSubWindParamD0Ev 0x000000710121cc80,sub_710121CC80,152, 0x000000710121cd18,sub_710121CD18,356, 0x000000710121ce7c,sub_710121CE7C,36, @@ -93607,10 +93607,10 @@ 0x0000007101223230,sub_7101223230,32, 0x0000007101223250,sub_7101223250,208, 0x0000007101223320,sub_7101223320,536, -0x0000007101223538,sub_7101223538,440, -0x00000071012236f0,sub_71012236F0,44, -0x000000710122371c,j__ZdlPv_1246,4, -0x0000007101223720,sub_7101223720,324, +0x0000007101223538,sub_7101223538,440,_ZN4ksys4phys12RagdollParamC1Ev +0x00000071012236f0,sub_71012236F0,44,_ZN4ksys4phys12RagdollParamD1Ev +0x000000710122371c,j__ZdlPv_1246,4,_ZN4ksys4phys12RagdollParamD0Ev +0x0000007101223720,sub_7101223720,324,_ZN4ksys4phys12RagdollParam9postRead_Ev 0x0000007101223864,sub_7101223864,128, 0x00000071012238e4,sub_71012238E4,1504, 0x0000007101223ec4,xxxxx,52, @@ -93667,9 +93667,9 @@ 0x00000071012283a4,sub_71012283A4,592, 0x00000071012285f4,sub_71012285F4,692, 0x00000071012288a8,sub_71012288A8,380, -0x0000007101228a24,sub_7101228A24,208, -0x0000007101228af4,sub_7101228AF4,48, -0x0000007101228b24,j__ZdlPv_1247,4, +0x0000007101228a24,sub_7101228A24,208,_ZN4ksys4phys16SupportBoneParamC1Ev +0x0000007101228af4,sub_7101228AF4,48,_ZN4ksys4phys16SupportBoneParamD2Ev +0x0000007101228b24,j__ZdlPv_1247,4,_ZN4ksys4phys16SupportBoneParamD0Ev 0x0000007101228b28,sub_7101228B28,876, 0x0000007101228e94,sub_7101228E94,164, 0x0000007101228f38,sub_7101228F38,688, @@ -95335,13 +95335,13 @@ 0x00000071012ad4f0,sub_71012AD4F0,112, 0x00000071012ad560,sub_71012AD560,92, 0x00000071012ad5bc,nullsub_4774,4, -0x00000071012ad5c0,sub_71012AD5C0,368, -0x00000071012ad730,sub_71012AD730,44, -0x00000071012ad75c,j__ZdlPv_1289,4, -0x00000071012ad760,sub_71012AD760,56, -0x00000071012ad798,sub_71012AD798,152, -0x00000071012ad830,sub_71012AD830,132, -0x00000071012ad8b4,sub_71012AD8B4,280, +0x00000071012ad5c0,sub_71012AD5C0,368,_ZN4ksys4phys18EdgeRigidBodyParamC1Ev +0x00000071012ad730,sub_71012AD730,44,_ZN4ksys4phys18EdgeRigidBodyParamD1Ev +0x00000071012ad75c,j__ZdlPv_1289,4,_ZN4ksys4phys18EdgeRigidBodyParamD0Ev +0x00000071012ad760,sub_71012AD760,56,_ZN4ksys4phys21EdgeRigidBodySetParamC1Ev +0x00000071012ad798,sub_71012AD798,152,_ZN4ksys4phys21EdgeRigidBodySetParamD1Ev +0x00000071012ad830,sub_71012AD830,132,_ZN4ksys4phys21EdgeRigidBodySetParamD0Ev +0x00000071012ad8b4,sub_71012AD8B4,280,_ZN4ksys4phys21EdgeRigidBodySetParam5parseEiPN4sead4HeapE 0x00000071012ad9cc,sub_71012AD9CC,1924, 0x00000071012ae150,sub_71012AE150,436, 0x00000071012ae304,sub_71012AE304,1324, diff --git a/lib/agl b/lib/agl index 24e9d779..69c2ac1c 160000 --- a/lib/agl +++ b/lib/agl @@ -1 +1 @@ -Subproject commit 24e9d779f586bb9ba37aa8b901d458a5e5721b24 +Subproject commit 69c2ac1c2180c9ce8e7446cc1b81919dfaf5be56 diff --git a/lib/sead b/lib/sead index 207bf6c8..7b9f11e3 160000 --- a/lib/sead +++ b/lib/sead @@ -1 +1 @@ -Subproject commit 207bf6c8cf91148a629d666637ca84ac311e9ff6 +Subproject commit 7b9f11e3880789dff46aa834c0f42c5c2328fb8e diff --git a/src/KingSystem/Physics/CMakeLists.txt b/src/KingSystem/Physics/CMakeLists.txt index 0b27d301..a887c606 100644 --- a/src/KingSystem/Physics/CMakeLists.txt +++ b/src/KingSystem/Physics/CMakeLists.txt @@ -1,4 +1,14 @@ target_sources(uking PRIVATE + Cloth/physClothParam.cpp + Cloth/physClothParam.h Ragdoll/physRagdollConfig.cpp Ragdoll/physRagdollConfig.h + Ragdoll/physRagdollParam.cpp + Ragdoll/physRagdollParam.h + RigidBody/physEdgeRigidBodyParam.cpp + RigidBody/physEdgeRigidBodyParam.h + SupportBone/physSupportBoneParam.cpp + SupportBone/physSupportBoneParam.h + System/physParamSet.cpp + System/physParamSet.h ) diff --git a/src/KingSystem/Physics/Cloth/physClothParam.cpp b/src/KingSystem/Physics/Cloth/physClothParam.cpp new file mode 100644 index 00000000..f8ec69aa --- /dev/null +++ b/src/KingSystem/Physics/Cloth/physClothParam.cpp @@ -0,0 +1,60 @@ +#include "KingSystem/Physics/Cloth/physClothParam.h" +#include + +namespace ksys::phys { + +ClothSetParam::ClothSetParam() + : cloth_setup_file_path(sead::SafeString::cEmptyString, "cloth_setup_file_path", + "Clothセットアップファイル(.hkt)", &cloth_header_obj), + cloth_num(0, "cloth_num", "cloth_num", &cloth_header_obj) { + addObj(&cloth_header_obj, "ClothHeader"); + addObj(&sub_wind, "ClothSubWind"); +} + +ClothSetParam::~ClothSetParam() = default; + +bool ClothSetParam::parse(const agl::utl::ResParameterList& res_list, sead::Heap* heap) { + if (!res_list) + return false; + + cloth_header_obj.applyResParameterObj(res_list.getResParameterObj(0), nullptr); + + const int num_cloths = cloth_num.ref(); + if (num_cloths <= 0) + return false; + + cloths.allocBufferAssert(num_cloths, heap); + for (int i = 0; i < num_cloths; ++i) { + addObj(&cloths[i], sead::FormatFixedSafeString<32>("Cloth_%d", i)); + } + + sead::Path::getFileName(&cloth_setup_file_name, cloth_setup_file_path.ref()); + + return true; +} + +const ClothParam* ClothSetParam::getCloth(const sead::SafeString& name) const { + int index = -1; + for (int i = 0, n = *cloth_num; i < n; ++i) { + if (name == *cloths[i].name) { + index = i; + break; + } + } + return index >= 0 && index < *cloth_num ? &cloths[index] : nullptr; +} + +ClothParam::ClothParam() + : wind_drag(5.0, "wind_drag", this), wind_frequency(5.0, "wind_frequency", this), + wind_min_speed(-4.0, "wind_mind_speed", this), wind_max_speed(10.0, "wind_max_speed", this), + sub_wind_factor_main(1.0, "sub_wind_factor_main", this), + sub_wind_factor_add(0.0, "sub_wind_factor_add", this), wind_enable(true, "wind_enable", this), + writeback_to_local(false, "writeback_to_local", this), + name(sead::SafeString::cEmptyString, "name", this), base_bone("Root", "base_bone", this) {} + +ClothSubWindParam::ClothSubWindParam() + : sub_wind_direction(sead::Vector3f::ey, "sub_wind_direction", this), + sub_wind_frequency(0.2, "sub_wind_frequency", this), + sub_wind_speed(0.0, "sub_wind_speed", this) {} + +} // namespace ksys::phys diff --git a/src/KingSystem/Physics/Cloth/physClothParam.h b/src/KingSystem/Physics/Cloth/physClothParam.h new file mode 100644 index 00000000..8aae4158 --- /dev/null +++ b/src/KingSystem/Physics/Cloth/physClothParam.h @@ -0,0 +1,51 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace ksys::phys { + +struct ClothSubWindParam : agl::utl::ParameterObj { + ClothSubWindParam(); + + agl::utl::Parameter sub_wind_direction; + agl::utl::Parameter sub_wind_frequency; + agl::utl::Parameter sub_wind_speed; +}; + +struct ClothParam : agl::utl::ParameterObj { + ClothParam(); + + agl::utl::Parameter wind_drag; + agl::utl::Parameter wind_frequency; + agl::utl::Parameter wind_min_speed; + agl::utl::Parameter wind_max_speed; + agl::utl::Parameter sub_wind_factor_main; + agl::utl::Parameter sub_wind_factor_add; + agl::utl::Parameter wind_enable; + agl::utl::Parameter writeback_to_local; + agl::utl::Parameter name; + agl::utl::Parameter base_bone; +}; + +struct ClothSetParam : agl::utl::ParameterList { + ClothSetParam(); + ~ClothSetParam() override; + ClothSetParam(const ClothSetParam&) = delete; + auto operator=(const ClothSetParam&) = delete; + + bool parse(const agl::utl::ResParameterList& res_list, sead::Heap* heap); + const ClothParam* getCloth(const sead::SafeString& name) const; + + agl::utl::ParameterObj cloth_header_obj; + agl::utl::Parameter cloth_setup_file_path; + agl::utl::Parameter cloth_num; + sead::FixedSafeString<64> cloth_setup_file_name; + ClothSubWindParam sub_wind; + sead::Buffer cloths; +}; + +} // namespace ksys::phys diff --git a/src/KingSystem/Physics/Ragdoll/physRagdollParam.cpp b/src/KingSystem/Physics/Ragdoll/physRagdollParam.cpp new file mode 100644 index 00000000..ac4ff17e --- /dev/null +++ b/src/KingSystem/Physics/Ragdoll/physRagdollParam.cpp @@ -0,0 +1,18 @@ +#include "KingSystem/Physics/Ragdoll/physRagdollParam.h" +#include + +namespace ksys::phys { + +RagdollParam::RagdollParam() + : contact_point_info(sead::SafeString::cEmptyString, "contact_point_info", this), + collision_info(sead::SafeString::cEmptyString, "collision_info", this), + ragdoll_setup_file_path(sead::SafeString::cEmptyString, "ragdoll_setup_file_path", this) {} + +RagdollParam::~RagdollParam() = default; + +void RagdollParam::postRead_() { + sead::Path::getFileName(&ragdoll_setup_file_stem, ragdoll_setup_file_path.ref()); + ragdoll_setup_file_stem.removeSuffix(".hkrg"); +} + +} // namespace ksys::phys diff --git a/src/KingSystem/Physics/Ragdoll/physRagdollParam.h b/src/KingSystem/Physics/Ragdoll/physRagdollParam.h new file mode 100644 index 00000000..7d2bb935 --- /dev/null +++ b/src/KingSystem/Physics/Ragdoll/physRagdollParam.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include +#include + +namespace ksys::phys { + +struct RagdollParam : agl::utl::ParameterObj { + RagdollParam(); + ~RagdollParam() override; + + agl::utl::Parameter contact_point_info; + agl::utl::Parameter collision_info; + agl::utl::Parameter ragdoll_setup_file_path; + sead::FixedSafeString<32> ragdoll_setup_file_stem; + +protected: + void postRead_() override; +}; + +} // namespace ksys::phys diff --git a/src/KingSystem/Physics/RigidBody/physEdgeRigidBodyParam.cpp b/src/KingSystem/Physics/RigidBody/physEdgeRigidBodyParam.cpp new file mode 100644 index 00000000..42f1895d --- /dev/null +++ b/src/KingSystem/Physics/RigidBody/physEdgeRigidBodyParam.cpp @@ -0,0 +1,28 @@ +#include "KingSystem/Physics/RigidBody/physEdgeRigidBodyParam.h" + +namespace ksys::phys { + +EdgeRigidBodyParam::EdgeRigidBodyParam() + : set_name(sead::SafeString::cEmptyString, "set_name", this), + body_name(sead::SafeString::cEmptyString, "body_name", this), + edge_type(sead::SafeString::cEmptyString, "edge_type", this) {} + +EdgeRigidBodyParam::~EdgeRigidBodyParam() = default; + +EdgeRigidBodySetParam::EdgeRigidBodySetParam() = default; + +EdgeRigidBodySetParam::~EdgeRigidBodySetParam() { + edge_rigid_bodies.freeBuffer(); +} + +void EdgeRigidBodySetParam::parse(int num, sead::Heap* heap) { + if (num <= 0) + return; + + edge_rigid_bodies.allocBufferAssert(num, heap); + for (int i = 0; i < num; ++i) { + addObj(&edge_rigid_bodies[i], sead::FormatFixedSafeString<32>("EdgeRigidBody_%d", i)); + } +} + +} // namespace ksys::phys diff --git a/src/KingSystem/Physics/RigidBody/physEdgeRigidBodyParam.h b/src/KingSystem/Physics/RigidBody/physEdgeRigidBodyParam.h new file mode 100644 index 00000000..b2dcde84 --- /dev/null +++ b/src/KingSystem/Physics/RigidBody/physEdgeRigidBodyParam.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + +namespace ksys::phys { + +struct EdgeRigidBodyParam : agl::utl::ParameterObj { + EdgeRigidBodyParam(); + ~EdgeRigidBodyParam() override; + + agl::utl::Parameter set_name; + agl::utl::Parameter body_name; + agl::utl::Parameter edge_type; +}; + +struct EdgeRigidBodySetParam : agl::utl::ParameterList { + EdgeRigidBodySetParam(); + ~EdgeRigidBodySetParam() override; + EdgeRigidBodySetParam(const EdgeRigidBodySetParam&) = delete; + auto operator=(const EdgeRigidBodySetParam&) = delete; + + void parse(int num, sead::Heap* heap); + + sead::Buffer edge_rigid_bodies; +}; + +} // namespace ksys::phys diff --git a/src/KingSystem/Physics/SupportBone/physSupportBoneParam.cpp b/src/KingSystem/Physics/SupportBone/physSupportBoneParam.cpp new file mode 100644 index 00000000..736191dd --- /dev/null +++ b/src/KingSystem/Physics/SupportBone/physSupportBoneParam.cpp @@ -0,0 +1,9 @@ +#include "KingSystem/Physics/SupportBone/physSupportBoneParam.h" + +namespace ksys::phys { + +SupportBoneParam::SupportBoneParam() + : support_bone_setup_file_path(sead::SafeString::cEmptyString, "support_bone_setup_file_path", + "補助骨セットアップファイル(.psb)", this) {} + +} // namespace ksys::phys diff --git a/src/KingSystem/Physics/SupportBone/physSupportBoneParam.h b/src/KingSystem/Physics/SupportBone/physSupportBoneParam.h new file mode 100644 index 00000000..54832016 --- /dev/null +++ b/src/KingSystem/Physics/SupportBone/physSupportBoneParam.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include +#include + +namespace ksys::phys { + +struct SupportBoneParam : agl::utl::ParameterObj, sead::hostio::Node { + SupportBoneParam(); + + agl::utl::Parameter support_bone_setup_file_path; +}; + +} // namespace ksys::phys diff --git a/src/KingSystem/Physics/System/physParamSet.cpp b/src/KingSystem/Physics/System/physParamSet.cpp new file mode 100644 index 00000000..3155a3eb --- /dev/null +++ b/src/KingSystem/Physics/System/physParamSet.cpp @@ -0,0 +1 @@ +#include "KingSystem/Physics/System/physParamSet.h" diff --git a/src/KingSystem/Physics/System/physParamSet.h b/src/KingSystem/Physics/System/physParamSet.h new file mode 100644 index 00000000..b0f791a6 --- /dev/null +++ b/src/KingSystem/Physics/System/physParamSet.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include +#include +#include + +namespace ksys::phys { + +struct RigidBodySetParam; +struct CharacterControllerParam; +struct ClothSetParam; +struct RagdollParam; +struct SupportBoneParam; +struct ContactInfoParam; +struct EdgeRigidBodySetParam; + +struct ParamSet : public agl::utl::ParameterList { + sead::Buffer rigid_body_sets{}; + CharacterControllerParam* character_controller{}; + ClothSetParam* cloth_set{}; + RagdollParam* ragdoll{}; + SupportBoneParam* support_bone{}; + ContactInfoParam* contact_info{}; + EdgeRigidBodySetParam* edge_rigid_body_sets{}; + + agl::utl::ParameterObj obj; + agl::utl::Parameter use_rigid_body_set_num; + agl::utl::Parameter use_character_controller; + agl::utl::Parameter use_ragdoll; + agl::utl::Parameter use_support_bone; + agl::utl::Parameter use_cloth; + agl::utl::Parameter use_contact_info; + agl::utl::Parameter use_system_group_handler; + agl::utl::Parameter use_edge_rigid_body_num; + int num_rigid_bodies_with_link_matrix = 0; +}; + +} // namespace ksys::phys