From 3f33ba5d59bdbc6474daddf1971b79f1f12ec523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Tue, 4 Jan 2022 18:51:27 +0100 Subject: [PATCH] ksys/phys: Implement ContactMgr contact point pool functions --- data/uking_functions.csv | 4 ++-- .../Physics/System/physContactMgr.cpp | 11 +++++++++++ src/KingSystem/Physics/System/physContactMgr.h | 17 +++++++++-------- src/KingSystem/Physics/System/physMemSystem.h | 5 +++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 86c9a4c4..ffbbb214 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -83723,8 +83723,8 @@ Address,Quality,Size,Name 0x0000007100fb2230,U,000180, 0x0000007100fb22e4,U,000036, 0x0000007100fb2308,U,000212, -0x0000007100fb23dc,U,000152, -0x0000007100fb2474,U,000116, +0x0000007100fb23dc,O,000152,_ZN4ksys4phys10ContactMgr20initContactPointPoolEPN4sead4HeapENS0_13IsIndoorStageE +0x0000007100fb2474,O,000116,_ZN4ksys4phys10ContactMgr20freeContactPointPoolEv 0x0000007100fb24e8,O,000316,_ZN4ksys4phys10ContactMgr20loadContactInfoTableEPN4sead4HeapEN3agl3utl19ResParameterArchiveENS0_16ContactLayerTypeE 0x0000007100fb2624,O,000688,_ZN4ksys4phys10ContactMgr22doLoadContactInfoTableEN3agl3utl19ResParameterArchiveENS0_16ContactLayerTypeEb 0x0000007100fb28d4,O,000136,_ZN4ksys4phys10ContactMgr18allocContactPointsEPN4sead4HeapEiRKNS2_14SafeStringBaseIcEEiii diff --git a/src/KingSystem/Physics/System/physContactMgr.cpp b/src/KingSystem/Physics/System/physContactMgr.cpp index 6c2402c9..7af57a4f 100644 --- a/src/KingSystem/Physics/System/physContactMgr.cpp +++ b/src/KingSystem/Physics/System/physContactMgr.cpp @@ -18,6 +18,17 @@ ContactMgr::ContactMgr() { mList5.initOffset(0x48); } +void ContactMgr::initContactPointPool(sead::Heap* heap, IsIndoorStage indoor) { + int count = 0x1000; + if (indoor == IsIndoorStage::Yes) + count = 0x2000; + mContactPointPool.allocBufferAssert(count, heap); +} + +void ContactMgr::freeContactPointPool() { + mContactPointPool.freeBuffer(); +} + void ContactMgr::loadContactInfoTable(sead::Heap* heap, agl::utl::ResParameterArchive archive, ContactLayerType type) { auto& table = mContactInfoTables[int(type)]; diff --git a/src/KingSystem/Physics/System/physContactMgr.h b/src/KingSystem/Physics/System/physContactMgr.h index b96e46a2..24971513 100644 --- a/src/KingSystem/Physics/System/physContactMgr.h +++ b/src/KingSystem/Physics/System/physContactMgr.h @@ -13,6 +13,7 @@ #include #include #include "KingSystem/Physics/System/physDefines.h" +#include "KingSystem/Physics/System/physMaterialMask.h" #include "KingSystem/Utils/Types.h" namespace sead { @@ -21,6 +22,7 @@ class Heap; namespace ksys::phys { +enum class IsIndoorStage; class IRigidContactPoints; class RigidContactPoints; class RigidContactPointsEx; @@ -55,12 +57,8 @@ struct ContactPoint { sead::Vector3f _10; sead::Vector3f _1c; float scale; - void* _30; - void* _38; - void* _40; - void* _48; - void* _50; - void* _58; + MaterialMask material_mask1; + MaterialMask material_mask2; void* _60; sead::TypedBitFlag flags; }; @@ -73,6 +71,9 @@ public: void init(sead::Heap* heap); + void initContactPointPool(sead::Heap* heap, IsIndoorStage indoor); + void freeContactPointPool(); + void loadContactInfoTable(sead::Heap* heap, agl::utl::ResParameterArchive archive, ContactLayerType type); @@ -89,8 +90,8 @@ private: void doLoadContactInfoTable(agl::utl::ResParameterArchive archive, ContactLayerType type, bool skip_params); - // FIXME: type, name - sead::Buffer mBuffer; + // Used to optimise ContactPoint allocations. + sead::Buffer mContactPointPool; sead::OffsetList mList0; int mList0Size = 0; sead::Atomic _34 = 0; diff --git a/src/KingSystem/Physics/System/physMemSystem.h b/src/KingSystem/Physics/System/physMemSystem.h index cdaaba5e..a6a12625 100644 --- a/src/KingSystem/Physics/System/physMemSystem.h +++ b/src/KingSystem/Physics/System/physMemSystem.h @@ -21,6 +21,11 @@ struct RigidBodyRequestMgr { void sub_7100FA6C8C(bool, RigidBody*); }; +enum class IsIndoorStage { + No, + Yes, +}; + class MemSystem { SEAD_SINGLETON_DISPOSER(MemSystem) MemSystem();