ksys/phys: Start adding physics parameter structs

* SupportBoneParam
* RagdollParam
* ClothSetParam, ClothSubWindParam, ClothParam
* EdgeRigidBodySetParam, EdgeRigidBody
* ParamSet (only the header for now)
This commit is contained in:
Léo Lam
2021-04-20 23:16:53 +02:00
parent 63472349c7
commit f9d6eedc9f
14 changed files with 311 additions and 27 deletions
+10
View File
@@ -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
)
@@ -0,0 +1,60 @@
#include "KingSystem/Physics/Cloth/physClothParam.h"
#include <filedevice/seadPath.h>
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
@@ -0,0 +1,51 @@
#pragma once
#include <agl/Utils/aglParameter.h>
#include <agl/Utils/aglParameterList.h>
#include <agl/Utils/aglParameterObj.h>
#include <container/seadBuffer.h>
#include <prim/seadSafeString.h>
namespace ksys::phys {
struct ClothSubWindParam : agl::utl::ParameterObj {
ClothSubWindParam();
agl::utl::Parameter<sead::Vector3f> sub_wind_direction;
agl::utl::Parameter<float> sub_wind_frequency;
agl::utl::Parameter<float> sub_wind_speed;
};
struct ClothParam : agl::utl::ParameterObj {
ClothParam();
agl::utl::Parameter<float> wind_drag;
agl::utl::Parameter<float> wind_frequency;
agl::utl::Parameter<float> wind_min_speed;
agl::utl::Parameter<float> wind_max_speed;
agl::utl::Parameter<float> sub_wind_factor_main;
agl::utl::Parameter<float> sub_wind_factor_add;
agl::utl::Parameter<bool> wind_enable;
agl::utl::Parameter<bool> writeback_to_local;
agl::utl::Parameter<sead::SafeString> name;
agl::utl::Parameter<sead::SafeString> 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<sead::SafeString> cloth_setup_file_path;
agl::utl::Parameter<int> cloth_num;
sead::FixedSafeString<64> cloth_setup_file_name;
ClothSubWindParam sub_wind;
sead::Buffer<ClothParam> cloths;
};
} // namespace ksys::phys
@@ -0,0 +1,18 @@
#include "KingSystem/Physics/Ragdoll/physRagdollParam.h"
#include <filedevice/seadPath.h>
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
@@ -0,0 +1,23 @@
#pragma once
#include <agl/Utils/aglParameter.h>
#include <agl/Utils/aglParameterList.h>
#include <agl/Utils/aglParameterObj.h>
#include <prim/seadSafeString.h>
namespace ksys::phys {
struct RagdollParam : agl::utl::ParameterObj {
RagdollParam();
~RagdollParam() override;
agl::utl::Parameter<sead::SafeString> contact_point_info;
agl::utl::Parameter<sead::SafeString> collision_info;
agl::utl::Parameter<sead::SafeString> ragdoll_setup_file_path;
sead::FixedSafeString<32> ragdoll_setup_file_stem;
protected:
void postRead_() override;
};
} // namespace ksys::phys
@@ -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
@@ -0,0 +1,30 @@
#pragma once
#include <agl/Utils/aglParameter.h>
#include <agl/Utils/aglParameterList.h>
#include <agl/Utils/aglParameterObj.h>
#include <container/seadBuffer.h>
namespace ksys::phys {
struct EdgeRigidBodyParam : agl::utl::ParameterObj {
EdgeRigidBodyParam();
~EdgeRigidBodyParam() override;
agl::utl::Parameter<sead::SafeString> set_name;
agl::utl::Parameter<sead::SafeString> body_name;
agl::utl::Parameter<sead::SafeString> 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<EdgeRigidBodyParam> edge_rigid_bodies;
};
} // namespace ksys::phys
@@ -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
@@ -0,0 +1,15 @@
#pragma once
#include <agl/Utils/aglParameter.h>
#include <agl/Utils/aglParameterObj.h>
#include <hostio/seadHostIONode.h>
namespace ksys::phys {
struct SupportBoneParam : agl::utl::ParameterObj, sead::hostio::Node {
SupportBoneParam();
agl::utl::Parameter<sead::SafeString> support_bone_setup_file_path;
};
} // namespace ksys::phys
@@ -0,0 +1 @@
#include "KingSystem/Physics/System/physParamSet.h"
@@ -0,0 +1,39 @@
#pragma once
#include <agl/Utils/aglParameter.h>
#include <agl/Utils/aglParameterList.h>
#include <agl/Utils/aglParameterObj.h>
#include <container/seadBuffer.h>
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<RigidBodySetParam> 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<int> use_rigid_body_set_num;
agl::utl::Parameter<bool> use_character_controller;
agl::utl::Parameter<bool> use_ragdoll;
agl::utl::Parameter<bool> use_support_bone;
agl::utl::Parameter<bool> use_cloth;
agl::utl::Parameter<bool> use_contact_info;
agl::utl::Parameter<bool> use_system_group_handler;
agl::utl::Parameter<int> use_edge_rigid_body_num;
int num_rigid_bodies_with_link_matrix = 0;
};
} // namespace ksys::phys