From b4bbaf141f871352fe4eac1eb1ef9c7522ca8154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Fri, 7 Jan 2022 01:30:35 +0100 Subject: [PATCH] ksys/phys: Add MemSystem::initSystemData --- data/uking_functions.csv | 100 +++++++++--------- src/KingSystem/Physics/CMakeLists.txt | 2 + .../Physics/System/physMemSystem.cpp | 42 ++++++++ src/KingSystem/Physics/System/physMemSystem.h | 24 ++++- .../Physics/System/physSensorGroupFilter.cpp | 1 + .../Physics/System/physSensorGroupFilter.h | 14 +++ src/KingSystem/Resource/resEntryFactory.h | 3 +- 7 files changed, 133 insertions(+), 53 deletions(-) create mode 100644 src/KingSystem/Physics/System/physSensorGroupFilter.cpp create mode 100644 src/KingSystem/Physics/System/physSensorGroupFilter.h diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 82688b2a..3b44e44e 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -93390,7 +93390,7 @@ Address,Quality,Size,Name 0x0000007101214b04,U,000016,PhysicsMemSys::waitForResourceCreation 0x0000007101214b14,U,000136, 0x0000007101214b9c,U,000564,PhysicsMemSys::initHeaps -0x0000007101214dd0,U,001416,PhysicsMemSys::loadSysData +0x0000007101214dd0,O,001416,_ZN4ksys4phys9MemSystem14initSystemDataEPN4sead4HeapE 0x0000007101215358,U,000092, 0x00000071012153b4,U,000120, 0x000000710121542c,U,000276, @@ -93456,55 +93456,55 @@ Address,Quality,Size,Name 0x0000007101216df0,U,000152,PhysicsMemSys::__auto9 0x0000007101216e88,U,000076, 0x0000007101216ed4,U,000004,nullsub_4712 -0x0000007101216ed8,U,000068, -0x0000007101216f1c,U,000076, -0x0000007101216f68,U,000132, -0x0000007101216fec,U,000092, -0x0000007101217048,U,000152, -0x00000071012170e0,U,000008, -0x00000071012170e8,U,000008, -0x00000071012170f0,U,000068, -0x0000007101217134,U,000076, -0x0000007101217180,U,000132, -0x0000007101217204,U,000092, -0x0000007101217260,U,000152, -0x00000071012172f8,U,000008, -0x0000007101217300,U,000008, -0x0000007101217308,U,000068, -0x000000710121734c,U,000076, -0x0000007101217398,U,000132, -0x000000710121741c,U,000092, -0x0000007101217478,U,000152, -0x0000007101217510,U,000008, -0x0000007101217518,U,000008, -0x0000007101217520,U,000068, -0x0000007101217564,U,000076, -0x00000071012175b0,U,000132, -0x0000007101217634,U,000092, -0x0000007101217690,U,000152, -0x0000007101217728,U,000008, -0x0000007101217730,U,000008, -0x0000007101217738,U,000068,EntryFactoryHksc::m0 -0x000000710121777c,U,000076,EntryFactoryHksc::m1 -0x00000071012177c8,U,000132,EntryFactoryHksc::m2 -0x000000710121784c,U,000092,EntryFactoryHksc::m3 -0x00000071012178a8,U,000152,EntryFactoryHksc::newResource -0x0000007101217940,U,000008,EntryFactoryHksc::getResourceSize -0x0000007101217948,U,000008,EntryFactoryHksc::getLoadDataAlignment -0x0000007101217950,U,000068, -0x0000007101217994,U,000076, -0x00000071012179e0,U,000132, -0x0000007101217a64,U,000092, -0x0000007101217ac0,U,000180, -0x0000007101217b74,U,000008, -0x0000007101217b7c,U,000008, -0x0000007101217b84,U,000068, -0x0000007101217bc8,U,000076, -0x0000007101217c14,U,000132, -0x0000007101217c98,U,000092, -0x0000007101217cf4,U,000152, -0x0000007101217d8c,U,000008, -0x0000007101217d94,U,000008, +0x0000007101216ed8,O,000068,_ZN4ksys3res12EntryFactoryINS_4phys17RigidBodyResourceEED2Ev +0x0000007101216f1c,O,000076,_ZN4ksys3res12EntryFactoryINS_4phys17RigidBodyResourceEED0Ev +0x0000007101216f68,O,000132,_ZNK4ksys3res12EntryFactoryINS_4phys17RigidBodyResourceEE27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE +0x0000007101216fec,O,000092,_ZNK4ksys3res12EntryFactoryINS_4phys17RigidBodyResourceEE18getRuntimeTypeInfoEv +0x0000007101217048,O,000152,_ZN4ksys3res12EntryFactoryINS_4phys17RigidBodyResourceEE12newResource_EPN4sead4HeapEi +0x00000071012170e0,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys17RigidBodyResourceEE15getResourceSizeEv +0x00000071012170e8,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys17RigidBodyResourceEE20getLoadDataAlignmentEv +0x00000071012170f0,O,000068,_ZN4ksys3res12EntryFactoryINS_4phys15RagdollResourceEED2Ev +0x0000007101217134,O,000076,_ZN4ksys3res12EntryFactoryINS_4phys15RagdollResourceEED0Ev +0x0000007101217180,O,000132,_ZNK4ksys3res12EntryFactoryINS_4phys15RagdollResourceEE27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE +0x0000007101217204,O,000092,_ZNK4ksys3res12EntryFactoryINS_4phys15RagdollResourceEE18getRuntimeTypeInfoEv +0x0000007101217260,O,000152,_ZN4ksys3res12EntryFactoryINS_4phys15RagdollResourceEE12newResource_EPN4sead4HeapEi +0x00000071012172f8,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys15RagdollResourceEE15getResourceSizeEv +0x0000007101217300,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys15RagdollResourceEE20getLoadDataAlignmentEv +0x0000007101217308,O,000068,_ZN4ksys3res12EntryFactoryINS_4phys19SupportBoneResourceEED2Ev +0x000000710121734c,O,000076,_ZN4ksys3res12EntryFactoryINS_4phys19SupportBoneResourceEED0Ev +0x0000007101217398,O,000132,_ZNK4ksys3res12EntryFactoryINS_4phys19SupportBoneResourceEE27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE +0x000000710121741c,O,000092,_ZNK4ksys3res12EntryFactoryINS_4phys19SupportBoneResourceEE18getRuntimeTypeInfoEv +0x0000007101217478,O,000152,_ZN4ksys3res12EntryFactoryINS_4phys19SupportBoneResourceEE12newResource_EPN4sead4HeapEi +0x0000007101217510,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys19SupportBoneResourceEE15getResourceSizeEv +0x0000007101217518,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys19SupportBoneResourceEE20getLoadDataAlignmentEv +0x0000007101217520,O,000068,_ZN4ksys3res12EntryFactoryINS_4phys13ClothResourceEED2Ev +0x0000007101217564,O,000076,_ZN4ksys3res12EntryFactoryINS_4phys13ClothResourceEED0Ev +0x00000071012175b0,O,000132,_ZNK4ksys3res12EntryFactoryINS_4phys13ClothResourceEE27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE +0x0000007101217634,O,000092,_ZNK4ksys3res12EntryFactoryINS_4phys13ClothResourceEE18getRuntimeTypeInfoEv +0x0000007101217690,O,000152,_ZN4ksys3res12EntryFactoryINS_4phys13ClothResourceEE12newResource_EPN4sead4HeapEi +0x0000007101217728,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys13ClothResourceEE15getResourceSizeEv +0x0000007101217730,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys13ClothResourceEE20getLoadDataAlignmentEv +0x0000007101217738,O,000068,_ZN4ksys3res12EntryFactoryINS_4phys14StaticCompoundEED2Ev +0x000000710121777c,O,000076,_ZN4ksys3res12EntryFactoryINS_4phys14StaticCompoundEED0Ev +0x00000071012177c8,O,000132,_ZNK4ksys3res12EntryFactoryINS_4phys14StaticCompoundEE27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE +0x000000710121784c,O,000092,_ZNK4ksys3res12EntryFactoryINS_4phys14StaticCompoundEE18getRuntimeTypeInfoEv +0x00000071012178a8,O,000152,_ZN4ksys3res12EntryFactoryINS_4phys14StaticCompoundEE12newResource_EPN4sead4HeapEi +0x0000007101217940,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys14StaticCompoundEE15getResourceSizeEv +0x0000007101217948,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys14StaticCompoundEE20getLoadDataAlignmentEv +0x0000007101217950,O,000068,_ZN4ksys3res12EntryFactoryINS_4phys25TeraMeshRigidBodyResourceEED2Ev +0x0000007101217994,O,000076,_ZN4ksys3res12EntryFactoryINS_4phys25TeraMeshRigidBodyResourceEED0Ev +0x00000071012179e0,O,000132,_ZNK4ksys3res12EntryFactoryINS_4phys25TeraMeshRigidBodyResourceEE27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE +0x0000007101217a64,O,000092,_ZNK4ksys3res12EntryFactoryINS_4phys25TeraMeshRigidBodyResourceEE18getRuntimeTypeInfoEv +0x0000007101217ac0,O,000180,_ZN4ksys3res12EntryFactoryINS_4phys25TeraMeshRigidBodyResourceEE12newResource_EPN4sead4HeapEi +0x0000007101217b74,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys25TeraMeshRigidBodyResourceEE15getResourceSizeEv +0x0000007101217b7c,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys25TeraMeshRigidBodyResourceEE20getLoadDataAlignmentEv +0x0000007101217b84,O,000068,_ZN4ksys3res12EntryFactoryINS_4phys24RagdollControllerKeyListEED2Ev +0x0000007101217bc8,O,000076,_ZN4ksys3res12EntryFactoryINS_4phys24RagdollControllerKeyListEED0Ev +0x0000007101217c14,O,000132,_ZNK4ksys3res12EntryFactoryINS_4phys24RagdollControllerKeyListEE27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE +0x0000007101217c98,O,000092,_ZNK4ksys3res12EntryFactoryINS_4phys24RagdollControllerKeyListEE18getRuntimeTypeInfoEv +0x0000007101217cf4,O,000152,_ZN4ksys3res12EntryFactoryINS_4phys24RagdollControllerKeyListEE12newResource_EPN4sead4HeapEi +0x0000007101217d8c,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys24RagdollControllerKeyListEE15getResourceSizeEv +0x0000007101217d94,O,000008,_ZNK4ksys3res12EntryFactoryINS_4phys24RagdollControllerKeyListEE20getLoadDataAlignmentEv 0x0000007101217d9c,U,000044, 0x0000007101217dc8,U,000204, 0x0000007101217e94,U,000144, diff --git a/src/KingSystem/Physics/CMakeLists.txt b/src/KingSystem/Physics/CMakeLists.txt index fa1eb647..194fb98b 100644 --- a/src/KingSystem/Physics/CMakeLists.txt +++ b/src/KingSystem/Physics/CMakeLists.txt @@ -84,6 +84,8 @@ target_sources(uking PRIVATE System/physRigidContactPoints.h System/physRigidContactPointsEx.cpp System/physRigidContactPointsEx.h + System/physSensorGroupFilter.cpp + System/physSensorGroupFilter.h System/physShapeParam.cpp System/physShapeParam.h System/physSystemData.cpp diff --git a/src/KingSystem/Physics/System/physMemSystem.cpp b/src/KingSystem/Physics/System/physMemSystem.cpp index 834d6e2e..9bf4af62 100644 --- a/src/KingSystem/Physics/System/physMemSystem.cpp +++ b/src/KingSystem/Physics/System/physMemSystem.cpp @@ -1,11 +1,53 @@ #include "KingSystem/Physics/System/physMemSystem.h" +#include "KingSystem/Physics/Cloth/physClothResource.h" +#include "KingSystem/Physics/Ragdoll/physRagdollControllerKeyList.h" +#include "KingSystem/Physics/Ragdoll/physRagdollResource.h" +#include "KingSystem/Physics/RigidBody/TeraMesh/physTeraMeshRigidBodyResource.h" +#include "KingSystem/Physics/RigidBody/physRigidBodyResource.h" +#include "KingSystem/Physics/StaticCompound/physStaticCompound.h" +#include "KingSystem/Physics/SupportBone/physSupportBoneResource.h" #include "KingSystem/Physics/System/physContactMgr.h" +#include "KingSystem/Physics/System/physEntityGroupFilter.h" +#include "KingSystem/Physics/System/physMaterialTable.h" #include "KingSystem/Physics/System/physRigidContactPoints.h" +#include "KingSystem/Physics/System/physSensorGroupFilter.h" +#include "KingSystem/Physics/System/physSystemData.h" +#include "KingSystem/Resource/resEntryFactory.h" +#include "KingSystem/Resource/resSystem.h" namespace ksys::phys { SEAD_SINGLETON_DISPOSER_IMPL(MemSystem) +void MemSystem::initSystemData(sead::Heap* heap) { + res::registerEntryFactory(new (heap) res::EntryFactory(1.0, 0x400), "hkrb"); + res::registerEntryFactory(new (heap) res::EntryFactory(1.0, 0x400), "hkrg"); + res::registerEntryFactory(new (heap) res::EntryFactory(1.0, 0x100000), + "bphyssb"); + res::registerEntryFactory(new (heap) res::EntryFactory(2.0, 0x2800), "hkcl"); + res::registerEntryFactory(new (heap) res::EntryFactory(1.3, 0x40000), "hksc"); + res::registerEntryFactory(new (heap) res::EntryFactory(1.0, 0x800), + "hktmrb"); + res::registerEntryFactory(new (heap) res::EntryFactory(1.0, 0x4000), + "brgcon"); + + mEntityGroupFilter = EntityGroupFilter::make(ContactLayer::EntityObject, + ContactLayer::EntityMeshVisualizer, heap); + mSensorGroupFilter = SensorGroupFilter::make(ContactLayer::SensorCustomReceiver, heap); + mGroupFilters.pushBack(mEntityGroupFilter); + mGroupFilters.pushBack(mSensorGroupFilter); + + mContactMgr = new (heap) ContactMgr; + if (mContactMgr) + mContactMgr->init(heap); + + mMaterialTable = new (heap) MaterialTable; + + mSystemData = new (heap) SystemData; + mSystemData->load(mPhysicsSystemHeap, mEntityGroupFilter, mSensorGroupFilter, mMaterialTable, + mContactMgr); +} + RigidContactPoints* MemSystem::allocContactPoints(sead::Heap* heap, int num, const sead::SafeString& name, int a, int b, int c) const { diff --git a/src/KingSystem/Physics/System/physMemSystem.h b/src/KingSystem/Physics/System/physMemSystem.h index a6a12625..908940f1 100644 --- a/src/KingSystem/Physics/System/physMemSystem.h +++ b/src/KingSystem/Physics/System/physMemSystem.h @@ -1,7 +1,9 @@ #pragma once #include +#include #include +#include #include "KingSystem/Physics/System/physDefines.h" #include "KingSystem/Utils/Types.h" @@ -38,6 +40,8 @@ public: SystemData* getSystemData() const { return mSystemData; } MaterialTable* getMaterialTable() const { return mMaterialTable; } + void initSystemData(sead::Heap* heap); + RigidContactPoints* allocContactPoints(sead::Heap* heap, int num, const sead::SafeString& name, int a, int b, int c) const; void freeContactPoints(RigidContactPoints* points) const; @@ -52,7 +56,15 @@ public: void removeSystemGroupHandler(SystemGroupHandler* handler); private: - u8 _28[0x148 - 0x28]; + u8 _28[0xa8 - 0x28]; + sead::CriticalSection mCS; + void* _e8{}; + void* _f0{}; + GroupFilter* mEntityGroupFilter{}; + GroupFilter* mSensorGroupFilter{}; + sead::FixedPtrArray mGroupFilters; + // FIXME: type + sead::FixedPtrArray _128; ContactMgr* mContactMgr; void* _150; void* _158; @@ -61,7 +73,15 @@ private: void* mRigidBodyDividedMeshShapeMgr; SystemData* mSystemData; MaterialTable* mMaterialTable; - u8 _188[0x480 - 0x188]; + void* _188{}; + void* _190{}; + void* _198{}; + void* _1a0{}; + sead::Heap* mPhysicsSystemHeap{}; + sead::Heap* mDebugHeap{}; + sead::Heap* mPhysicsTempDefaultHeap{}; + sead::Heap* mPhysicsTempLowHeap{}; + u8 _1c8[0x480 - 0x1c8]; }; KSYS_CHECK_SIZE_NX150(MemSystem, 0x480); diff --git a/src/KingSystem/Physics/System/physSensorGroupFilter.cpp b/src/KingSystem/Physics/System/physSensorGroupFilter.cpp new file mode 100644 index 00000000..2ec514d0 --- /dev/null +++ b/src/KingSystem/Physics/System/physSensorGroupFilter.cpp @@ -0,0 +1 @@ +#include "KingSystem/Physics/System/physSensorGroupFilter.h" diff --git a/src/KingSystem/Physics/System/physSensorGroupFilter.h b/src/KingSystem/Physics/System/physSensorGroupFilter.h new file mode 100644 index 00000000..867cbd40 --- /dev/null +++ b/src/KingSystem/Physics/System/physSensorGroupFilter.h @@ -0,0 +1,14 @@ +#pragma once + +#include "KingSystem/Physics/System/physGroupFilter.h" + +namespace ksys::phys { + +// FIXME +class SensorGroupFilter : public GroupFilter { + SEAD_RTTI_OVERRIDE(SensorGroupFilter, GroupFilter) +public: + static SensorGroupFilter* make(ContactLayer::ValueType last, sead::Heap* heap); +}; + +} // namespace ksys::phys diff --git a/src/KingSystem/Resource/resEntryFactory.h b/src/KingSystem/Resource/resEntryFactory.h index 1ac243f2..071f70e3 100644 --- a/src/KingSystem/Resource/resEntryFactory.h +++ b/src/KingSystem/Resource/resEntryFactory.h @@ -32,7 +32,8 @@ template class EntryFactory : public EntryFactoryBase { SEAD_RTTI_OVERRIDE(EntryFactory, EntryFactoryBase) public: - using EntryFactoryBase::EntryFactoryBase; + explicit EntryFactory(f32 size_multiplier = 1.0, u32 size_constant = 0) + : EntryFactoryBase(size_multiplier, size_constant) {} u32 getResourceSize() const override { return sizeof(T); } u32 getLoadDataAlignment() const override { return T::cLoadDataAlignment; }