summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-04-22 19:03:46 +0200
committerLéo Lam <leo@leolam.fr>2021-04-22 19:37:58 +0200
commit136f20427d6b346da488ec84f39b5c6aeaffd24e (patch)
treea8f5740cbc11c50dfd16a505b1f565997ae62267
parentf6e4643808bdec31d2e2bf1b3d3a0ce0b456e348 (diff)
ksys/phys: Implement ParamSet and res::Physics
-rw-r--r--data/uking_functions.csv48
m---------lib/agl0
-rw-r--r--src/KingSystem/Physics/System/physParamSet.cpp145
-rw-r--r--src/KingSystem/Physics/System/physParamSet.h19
-rw-r--r--src/KingSystem/Resource/resResourcePhysics.cpp14
-rw-r--r--src/KingSystem/Resource/resResourcePhysics.h13
6 files changed, 213 insertions, 26 deletions
diff --git a/data/uking_functions.csv b/data/uking_functions.csv
index a0743471..4673d227 100644
--- a/data/uking_functions.csv
+++ b/data/uking_functions.csv
@@ -83975,13 +83975,13 @@
0x0000007100fc2530,sub_7100FC2530,664,
0x0000007100fc27c8,sub_7100FC27C8,80,
0x0000007100fc2818,j__ZdlPv_1008,4,
-0x0000007100fc281c,Bphysics::ParamSet::ctor,660,
-0x0000007100fc2ab0,sub_7100FC2AB0,124,
-0x0000007100fc2b2c,Bphysics::ParamSet::cleanUp,264,
-0x0000007100fc2c34,sub_7100FC2C34,52,
-0x0000007100fc2c68,Bphysics::ParamSet::parse,64,
-0x0000007100fc2ca8,Bphysics::ParamSet::doParse,1508,
-0x0000007100fc328c,Bphysics::ParamSet::getRigidBody,28,
+0x0000007100fc281c,Bphysics::ParamSet::ctor,660,_ZN4ksys4phys8ParamSetC1Ev
+0x0000007100fc2ab0,sub_7100FC2AB0,124,_ZN4ksys4phys8ParamSetD1Ev
+0x0000007100fc2b2c,Bphysics::ParamSet::cleanUp,264,_ZN4ksys4phys8ParamSet8finalizeEv
+0x0000007100fc2c34,sub_7100FC2C34,52,_ZN4ksys4phys8ParamSetD0Ev
+0x0000007100fc2c68,Bphysics::ParamSet::parse,64,_ZN4ksys4phys8ParamSet5parseEPNS_3res7PhysicsEN3agl3utl19ResParameterArchiveEPN4sead4HeapE
+0x0000007100fc2ca8,Bphysics::ParamSet::doParse,1508,_ZN4ksys4phys8ParamSet7doParseEPNS_3res7PhysicsEN3agl3utl19ResParameterArchiveEPN4sead4HeapE
+0x0000007100fc328c,Bphysics::ParamSet::getRigidBody,28,_ZN4ksys4phys8ParamSet15getRigidBodySetEi
0x0000007100fc32a8,sub_7100FC32A8,136,
0x0000007100fc3330,sub_7100FC3330,68,
0x0000007100fc3374,j_nullsub_4247,4,
@@ -91563,23 +91563,23 @@
0x00000071011b1504,sub_71011B1504,92,_ZThn632_NK4ksys3res9ModelList18getRuntimeTypeInfoEv
0x00000071011b1560,sub_71011B1560,8,_ZThn632_NK4ksys3res9ModelList10needsParseEv
0x00000071011b1568,sub_71011B1568,372,_ZN4ksys3res9ModelList33checkDerivedRuntimeTypeInfoStaticEPKN4sead15RuntimeTypeInfo9InterfaceE
-0x00000071011b16dc,nullsub_4627,4,
-0x00000071011b16e0,ResourceBphysics::m5_null,4,
-0x00000071011b16e4,sub_71011B16E4,80,
-0x00000071011b1734,ResourceBphysics::parse,80,
-0x00000071011b1784,sub_71011B1784,104,
-0x00000071011b17ec,sub_71011B17EC,92,
-0x00000071011b1848,sub_71011B1848,8,
-0x00000071011b1850,sub_71011B1850,92,
-0x00000071011b18ac,sub_71011B18AC,8,
-0x00000071011b18b4,ResourceBphysics::m0,8,
-0x00000071011b18bc,ResourceBphysics::m1,92,
-0x00000071011b1918,ResourceBphysics::m2,104,
-0x00000071011b1980,ResourceBphysics::m3,92,
-0x00000071011b19dc,ResourceBphysics::m6,8,
-0x00000071011b19e4,sub_71011B19E4,100,
-0x00000071011b1a48,sub_71011B1A48,88,
-0x00000071011b1aa0,sub_71011B1AA0,372,
+0x00000071011b16dc,nullsub_4627,4,_ZN4ksys3res7Physics9doCreate_EPhjPN4sead4HeapE
+0x00000071011b16e0,ResourceBphysics::m5_null,4,_ZThn632_N4ksys3res7Physics9doCreate_EPhjPN4sead4HeapE
+0x00000071011b16e4,sub_71011B16E4,80,_ZN4ksys3res7Physics6parse_EPhmPN4sead4HeapE
+0x00000071011b1734,ResourceBphysics::parse,80,_ZThn632_N4ksys3res7Physics6parse_EPhmPN4sead4HeapE
+0x00000071011b1784,sub_71011B1784,104,_ZN4ksys3res7PhysicsD2Ev
+0x00000071011b17ec,sub_71011B17EC,92,_ZN4ksys3res7PhysicsD0Ev
+0x00000071011b1848,sub_71011B1848,8,_ZNK4ksys3res7Physics27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE
+0x00000071011b1850,sub_71011B1850,92,_ZNK4ksys3res7Physics18getRuntimeTypeInfoEv
+0x00000071011b18ac,sub_71011B18AC,8,_ZNK4ksys3res7Physics10needsParseEv
+0x00000071011b18b4,ResourceBphysics::m0,8,_ZThn632_NK4ksys3res7Physics27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE
+0x00000071011b18bc,ResourceBphysics::m1,92,_ZThn632_NK4ksys3res7Physics18getRuntimeTypeInfoEv
+0x00000071011b1918,ResourceBphysics::m2,104,_ZThn632_N4ksys3res7PhysicsD1Ev
+0x00000071011b1980,ResourceBphysics::m3,92,_ZThn632_N4ksys3res7PhysicsD0Ev
+0x00000071011b19dc,ResourceBphysics::m6,8,_ZThn632_NK4ksys3res7Physics10needsParseEv
+0x00000071011b19e4,sub_71011B19E4,100,_ZThn664_N4ksys3res7PhysicsD1Ev
+0x00000071011b1a48,sub_71011B1A48,88,_ZThn664_N4ksys3res7PhysicsD0Ev
+0x00000071011b1aa0,sub_71011B1AA0,372,_ZN4ksys3res7Physics33checkDerivedRuntimeTypeInfoStaticEPKN4sead15RuntimeTypeInfo9InterfaceE
0x00000071011b1c14,Effect::eventCreate,1392,
0x00000071011b2184,sub_71011B2184,8,
0x00000071011b218c,sub_71011B218C,104,
diff --git a/lib/agl b/lib/agl
-Subproject 69c2ac1c2180c9ce8e7446cc1b81919dfaf5be5
+Subproject 1ee52998fa0ca6d4c2ada8bef6dfd70aa2e63cb
diff --git a/src/KingSystem/Physics/System/physParamSet.cpp b/src/KingSystem/Physics/System/physParamSet.cpp
index 3155a3eb..3af09949 100644
--- a/src/KingSystem/Physics/System/physParamSet.cpp
+++ b/src/KingSystem/Physics/System/physParamSet.cpp
@@ -1 +1,146 @@
#include "KingSystem/Physics/System/physParamSet.h"
+#include "KingSystem/Physics/Cloth/physClothParam.h"
+#include "KingSystem/Physics/Ragdoll/physRagdollParam.h"
+#include "KingSystem/Physics/RigidBody/physEdgeRigidBodyParam.h"
+#include "KingSystem/Physics/RigidBody/physRigidBodyParam.h"
+#include "KingSystem/Physics/RigidBody/physRigidBodySetParam.h"
+#include "KingSystem/Physics/SupportBone/physSupportBoneParam.h"
+#include "KingSystem/Physics/System/physCharacterControllerParam.h"
+#include "KingSystem/Physics/System/physContactInfoParam.h"
+#include "KingSystem/Resource/resResourcePhysics.h"
+
+namespace ksys::phys {
+
+ParamSet::ParamSet()
+ : use_rigid_body_set_num(0, "use_rigid_body_set_num", &obj),
+ use_character_controller(false, "use_character_controller", &obj),
+ use_ragdoll(false, "use_ragdoll", &obj), use_support_bone(false, "use_support_bone", &obj),
+ use_cloth(false, "use_cloth", &obj), use_contact_info(false, "use_contact_info", &obj),
+ use_system_group_handler(true, "use_system_group_handler", &obj),
+ use_edge_rigid_body_num(false, "use_edge_rigid_body_num", &obj) {}
+
+ParamSet::~ParamSet() {
+ finalize();
+}
+
+bool ParamSet::parse(res::Physics* bphysics, agl::utl::ResParameterArchive archive,
+ sead::Heap* heap) {
+ if (!archive.isValid())
+ return false;
+
+ if (!doParse(bphysics, archive, heap)) {
+ finalize();
+ return false;
+ }
+
+ return true;
+}
+
+template <typename T>
+static void safeDelete(T*& ptr) {
+ if (!ptr)
+ return;
+ delete ptr;
+ ptr = nullptr;
+}
+
+void ParamSet::finalize() {
+ rigid_body_sets.freeBuffer();
+ safeDelete(character_controller);
+ safeDelete(contact_info);
+ safeDelete(cloth_set);
+ safeDelete(ragdoll);
+ safeDelete(support_bone);
+ safeDelete(edge_rigid_body_set);
+ *use_rigid_body_set_num = 0;
+ *use_ragdoll = false;
+ *use_cloth = false;
+ *use_support_bone = false;
+ *use_edge_rigid_body_num = 0;
+}
+
+bool ParamSet::doParse(res::Physics* bphysics, agl::utl::ResParameterArchive archive,
+ sead::Heap* heap) {
+ const auto ParamSet = archive.getRootList().getResParameterList(0);
+ if (ParamSet.getResParameterObjNum() < 1)
+ return false;
+
+ const auto header_obj = ParamSet.getResParameterObj(0);
+ obj.applyResParameterObj(header_obj);
+
+ const int num_rigid_body_sets = *use_rigid_body_set_num;
+ if (num_rigid_body_sets > 0) {
+ rigid_body_sets.allocBufferAssert(num_rigid_body_sets, heap);
+
+ const auto RigidBodySet = agl::utl::getResParameterList(ParamSet, "RigidBodySet");
+ if (!RigidBodySet)
+ return false;
+
+ for (auto it = RigidBodySet.listBegin(), end = RigidBodySet.listEnd(); it != end; ++it) {
+ if (!rigid_body_sets[it.getIndex()].parse(it.getList(), heap))
+ return false;
+ }
+ }
+
+ if (*use_character_controller) {
+ character_controller = new (heap) CharacterControllerParam;
+ if (!character_controller->parse(
+ agl::utl::getResParameterList(ParamSet, "CharacterController"), heap)) {
+ return false;
+ }
+ }
+
+ if (*use_contact_info) {
+ contact_info = new (heap) ContactInfoParam;
+ if (!contact_info->parse(agl::utl::getResParameterList(ParamSet, "RigidContactInfo"), heap))
+ return false;
+ }
+
+ if (*use_support_bone) {
+ support_bone = new (heap) SupportBoneParam;
+ addObj(support_bone, "SupportBone");
+ }
+
+ if (*use_ragdoll) {
+ ragdoll = new (heap) RagdollParam;
+ addObj(ragdoll, "Ragdoll");
+ }
+
+ if (*use_cloth) {
+ cloth_set = new (heap) ClothSetParam;
+ const auto list = agl::utl::getResParameterList(ParamSet, "Cloth");
+ if (list) {
+ addList(cloth_set, "Cloth");
+ if (!cloth_set->parse(list, heap))
+ return false;
+ }
+ }
+
+ if (*use_edge_rigid_body_num > 0) {
+ edge_rigid_body_set = new (heap) EdgeRigidBodySetParam;
+ edge_rigid_body_set->parse(*use_edge_rigid_body_num, heap);
+ addList(edge_rigid_body_set, "EdgeRigidBody");
+ }
+
+ applyResParameterList(ParamSet);
+
+ num_rigid_bodies_with_link_matrix = 0;
+ for (int set_idx = 0; set_idx < num_rigid_body_sets; ++set_idx) {
+ auto& set = rigid_body_sets[set_idx];
+
+ const int num_rigid_bodies = set.getNumRigidBodies();
+ for (int body_idx = 0; body_idx < num_rigid_bodies; ++body_idx) {
+ if (!set.rigid_bodies[body_idx].info.link_matrix->isEmpty())
+ ++num_rigid_bodies_with_link_matrix;
+ }
+ }
+
+ bphysics->addList(this, "ParamSet");
+ return true;
+}
+
+RigidBodySetParam& ParamSet::getRigidBodySet(int idx) {
+ return rigid_body_sets[idx];
+}
+
+} // namespace ksys::phys
diff --git a/src/KingSystem/Physics/System/physParamSet.h b/src/KingSystem/Physics/System/physParamSet.h
index b0f791a6..450a1cb1 100644
--- a/src/KingSystem/Physics/System/physParamSet.h
+++ b/src/KingSystem/Physics/System/physParamSet.h
@@ -5,6 +5,10 @@
#include <agl/Utils/aglParameterObj.h>
#include <container/seadBuffer.h>
+namespace ksys::res {
+class Physics;
+}
+
namespace ksys::phys {
struct RigidBodySetParam;
@@ -16,13 +20,22 @@ struct ContactInfoParam;
struct EdgeRigidBodySetParam;
struct ParamSet : public agl::utl::ParameterList {
+ ParamSet();
+ ~ParamSet() override;
+ ParamSet(const ParamSet&) = delete;
+ auto operator=(const ParamSet&) = delete;
+
+ bool parse(res::Physics* bphysics, agl::utl::ResParameterArchive archive, sead::Heap* heap);
+
+ RigidBodySetParam& getRigidBodySet(int idx);
+
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{};
+ EdgeRigidBodySetParam* edge_rigid_body_set{};
agl::utl::ParameterObj obj;
agl::utl::Parameter<int> use_rigid_body_set_num;
@@ -34,6 +47,10 @@ struct ParamSet : public agl::utl::ParameterList {
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;
+
+private:
+ void finalize();
+ bool doParse(res::Physics* bphysics, agl::utl::ResParameterArchive archive, sead::Heap* heap);
};
} // namespace ksys::phys
diff --git a/src/KingSystem/Resource/resResourcePhysics.cpp b/src/KingSystem/Resource/resResourcePhysics.cpp
index 89054e81..88591fb9 100644
--- a/src/KingSystem/Resource/resResourcePhysics.cpp
+++ b/src/KingSystem/Resource/resResourcePhysics.cpp
@@ -1 +1,15 @@
#include "KingSystem/Resource/resResourcePhysics.h"
+
+namespace ksys::res {
+
+void Physics::doCreate_(u8* buffer, u32 buffer_size, sead::Heap* heap) {}
+
+bool Physics::parse_(u8* data, size_t size, sead::Heap* heap) {
+ if (!data)
+ return true;
+
+ mParamSet.parse(this, agl::utl::ResParameterArchive{data}, heap);
+ return true;
+}
+
+} // namespace ksys::res
diff --git a/src/KingSystem/Resource/resResourcePhysics.h b/src/KingSystem/Resource/resResourcePhysics.h
index fb95e0c1..5eef2cfd 100644
--- a/src/KingSystem/Resource/resResourcePhysics.h
+++ b/src/KingSystem/Resource/resResourcePhysics.h
@@ -1,13 +1,24 @@
#pragma once
+#include "KingSystem/Physics/System/physParamSet.h"
#include "KingSystem/Resource/resResource.h"
#include "KingSystem/Utils/ParamIO.h"
namespace ksys::res {
-// TODO
class Physics : public ParamIO, public Resource {
SEAD_RTTI_OVERRIDE(Physics, Resource)
+public:
+ Physics() : ParamIO("physics", 0) {}
+
+ phys::ParamSet& getParamSet() { return mParamSet; }
+
+ void doCreate_(u8* buffer, u32 buffer_size, sead::Heap* heap) override;
+ bool parse_(u8* data, size_t size, sead::Heap* heap) override;
+ bool needsParse() const override { return true; }
+
+private:
+ phys::ParamSet mParamSet;
};
} // namespace ksys::res