From 32531ba067bf90753a7d1218183fbec001ce4865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Wed, 29 Dec 2021 17:58:17 +0100 Subject: [PATCH] ksys/phys: Add RigidContactPoints allocation functions --- data/uking_functions.csv | 16 ++++++++-------- src/KingSystem/Physics/System/physContactMgr.cpp | 14 ++++++++++++-- src/KingSystem/Physics/System/physContactMgr.h | 10 +++++++--- src/KingSystem/Physics/System/physMemSystem.cpp | 7 +++++++ src/KingSystem/Physics/System/physMemSystem.h | 4 ++++ .../Physics/System/physRigidContactPoints.cpp | 10 ++++++++++ .../Physics/System/physRigidContactPoints.h | 3 ++- .../Physics/System/physRigidContactPointsEx.cpp | 10 ++++++++++ .../Physics/System/physRigidContactPointsEx.h | 5 +++-- 9 files changed, 63 insertions(+), 16 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index ee6349e3..43e53939 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -83728,11 +83728,11 @@ Address,Quality,Size,Name 0x0000007100fb24e8,O,000316,_ZN4ksys4phys10ContactMgr20loadContactInfoTableEPN4sead4HeapEN3agl3utl19ResParameterArchiveENS0_16ContactLayerTypeE 0x0000007100fb2624,O,000688,_ZN4ksys4phys10ContactMgr22doLoadContactInfoTableEN3agl3utl19ResParameterArchiveENS0_16ContactLayerTypeEb 0x0000007100fb28d4,O,000136,_ZN4ksys4phys10ContactMgr18allocContactPointsEPN4sead4HeapEiRKNS2_14SafeStringBaseIcEEiii -0x0000007100fb295c,U,000220, -0x0000007100fb2a38,O,000100,_ZN4ksys4phys10ContactMgr21registerContactPointsEPNS0_18RigidContactPointsE +0x0000007100fb295c,O,000220,_ZN4ksys4phys10ContactMgr20allocContactPointsExEPN4sead4HeapEiiRKNS2_14SafeStringBaseIcEEiii +0x0000007100fb2a38,O,000100,_ZN4ksys4phys10ContactMgr21registerContactPointsEPNS0_19IRigidContactPointsE 0x0000007100fb2a9c,U,000056, 0x0000007100fb2ad4,U,000156, -0x0000007100fb2b70,O,000148,_ZN4ksys4phys10ContactMgr17freeContactPointsEPNS0_18RigidContactPointsE +0x0000007100fb2b70,O,000148,_ZN4ksys4phys10ContactMgr17freeContactPointsEPNS0_19IRigidContactPointsE 0x0000007100fb2c04,U,000144, 0x0000007100fb2c94,U,000216, 0x0000007100fb2d6c,U,000136, @@ -84086,8 +84086,8 @@ Address,Quality,Size,Name 0x0000007100fc75a8,U,000076, 0x0000007100fc75f4,U,000020, 0x0000007100fc7608,U,000052, -0x0000007100fc763c,U,000064, -0x0000007100fc767c,U,000024, +0x0000007100fc763c,O,000064,_ZN4ksys4phys18RigidContactPoints4makeEPN4sead4HeapEiRKNS2_14SafeStringBaseIcEEiii +0x0000007100fc767c,O,000024,_ZN4ksys4phys18RigidContactPoints4freeEPS1_ 0x0000007100fc7694,O,000076,_ZN4ksys4phys18RigidContactPointsC1ERKN4sead14SafeStringBaseIcEEiii 0x0000007100fc76e0,O,000004,_ZN4ksys4phys18RigidContactPointsD1Ev 0x0000007100fc76e4,O,000004,_ZN4ksys4phys18RigidContactPointsD0Ev @@ -84300,9 +84300,9 @@ Address,Quality,Size,Name 0x0000007100fcf854,U,000092, 0x0000007100fcf8b0,U,000004,nullsub_4257 0x0000007100fcf8b4,U,000008, -0x0000007100fcf8bc,U,000072, +0x0000007100fcf8bc,O,000072,_ZN4ksys4phys20RigidContactPointsEx4makeEPN4sead4HeapEiiRKNS2_14SafeStringBaseIcEEiii 0x0000007100fcf904,O,000348,_ZN4ksys4phys20RigidContactPointsEx17registerLayerPairENS0_12ContactLayerES2_b -0x0000007100fcfa60,U,000024, +0x0000007100fcfa60,O,000024,_ZN4ksys4phys20RigidContactPointsEx4freeEPS1_ 0x0000007100fcfa78,O,000096,_ZN4ksys4phys20RigidContactPointsExC1ERKN4sead14SafeStringBaseIcEEiii 0x0000007100fcfad8,O,000004,_ZN4ksys4phys20RigidContactPointsExD1Ev 0x0000007100fcfadc,O,000004,_ZN4ksys4phys20RigidContactPointsExD0Ev @@ -93427,7 +93427,7 @@ Address,Quality,Size,Name 0x00000071012168c8,U,000052, 0x00000071012168fc,O,000008,_ZNK4ksys4phys9MemSystem18allocContactPointsEPN4sead4HeapEiRKNS2_14SafeStringBaseIcEEiii 0x0000007101216904,O,000008,_ZNK4ksys4phys9MemSystem17freeContactPointsEPNS0_18RigidContactPointsE -0x000000710121690c,U,000008, +0x000000710121690c,O,000008,_ZNK4ksys4phys9MemSystem20allocContactPointsExEPN4sead4HeapEiiRKNS2_14SafeStringBaseIcEEiii 0x0000007101216914,U,000080, 0x0000007101216964,O,000008,_ZNK4ksys4phys9MemSystem21registerContactPointsEPNS0_18RigidContactPointsE 0x000000710121696c,U,000008, diff --git a/src/KingSystem/Physics/System/physContactMgr.cpp b/src/KingSystem/Physics/System/physContactMgr.cpp index dfbf294e..6c2402c9 100644 --- a/src/KingSystem/Physics/System/physContactMgr.cpp +++ b/src/KingSystem/Physics/System/physContactMgr.cpp @@ -4,6 +4,7 @@ #include "KingSystem/Physics/System/physGroupFilter.h" #include "KingSystem/Physics/System/physMemSystem.h" #include "KingSystem/Physics/System/physRigidContactPoints.h" +#include "KingSystem/Physics/System/physRigidContactPointsEx.h" namespace ksys::phys { @@ -72,13 +73,22 @@ RigidContactPoints* ContactMgr::allocContactPoints(sead::Heap* heap, int num, return points; } -void ContactMgr::registerContactPoints(RigidContactPoints* points) { +RigidContactPointsEx* ContactMgr::allocContactPointsEx(sead::Heap* heap, int num, int num2, + const sead::SafeString& name, int a, int b, + int c) { + auto* points = new (heap) RigidContactPointsEx(name, a, b, c); + points->allocPoints(heap, num, num2); + registerContactPoints(points); + return points; +} + +void ContactMgr::registerContactPoints(IRigidContactPoints* points) { auto lock = sead::makeScopedLock(mMutex1); if (!points->isLinked()) mRigidContactPoints.pushBack(points); } -void ContactMgr::freeContactPoints(RigidContactPoints* points) { +void ContactMgr::freeContactPoints(IRigidContactPoints* points) { if (!points) return; diff --git a/src/KingSystem/Physics/System/physContactMgr.h b/src/KingSystem/Physics/System/physContactMgr.h index 4eb5f4ff..3420f882 100644 --- a/src/KingSystem/Physics/System/physContactMgr.h +++ b/src/KingSystem/Physics/System/physContactMgr.h @@ -20,7 +20,9 @@ class Heap; namespace ksys::phys { +class IRigidContactPoints; class RigidContactPoints; +class RigidContactPointsEx; struct ContactInfoTable { struct Receiver : agl::utl::ParameterObj { @@ -54,8 +56,10 @@ public: RigidContactPoints* allocContactPoints(sead::Heap* heap, int num, const sead::SafeString& name, int a, int b, int c); - void registerContactPoints(RigidContactPoints* points); - void freeContactPoints(RigidContactPoints* points); + RigidContactPointsEx* allocContactPointsEx(sead::Heap* heap, int num, int num2, + const sead::SafeString& name, int a, int b, int c); + void registerContactPoints(IRigidContactPoints* points); + void freeContactPoints(IRigidContactPoints* points); private: void doLoadContactInfoTable(agl::utl::ResParameterArchive archive, ContactLayerType type, @@ -66,7 +70,7 @@ private: sead::OffsetList mList0; int mList0Size = 0; sead::Atomic _34 = 0; - sead::OffsetList mRigidContactPoints; + sead::OffsetList mRigidContactPoints; sead::OffsetList mList2; sead::OffsetList mList3; sead::OffsetList mList4; diff --git a/src/KingSystem/Physics/System/physMemSystem.cpp b/src/KingSystem/Physics/System/physMemSystem.cpp index a8193a33..834d6e2e 100644 --- a/src/KingSystem/Physics/System/physMemSystem.cpp +++ b/src/KingSystem/Physics/System/physMemSystem.cpp @@ -1,5 +1,6 @@ #include "KingSystem/Physics/System/physMemSystem.h" #include "KingSystem/Physics/System/physContactMgr.h" +#include "KingSystem/Physics/System/physRigidContactPoints.h" namespace ksys::phys { @@ -15,6 +16,12 @@ void MemSystem::freeContactPoints(RigidContactPoints* points) const { mContactMgr->freeContactPoints(points); } +RigidContactPointsEx* MemSystem::allocContactPointsEx(sead::Heap* heap, int num, int num2, + const sead::SafeString& name, int a, int b, + int c) const { + return mContactMgr->allocContactPointsEx(heap, num, num2, name, a, b, c); +} + void MemSystem::registerContactPoints(RigidContactPoints* points) const { mContactMgr->registerContactPoints(points); } diff --git a/src/KingSystem/Physics/System/physMemSystem.h b/src/KingSystem/Physics/System/physMemSystem.h index 92eec883..4b2d3dca 100644 --- a/src/KingSystem/Physics/System/physMemSystem.h +++ b/src/KingSystem/Physics/System/physMemSystem.h @@ -32,6 +32,10 @@ public: RigidContactPoints* allocContactPoints(sead::Heap* heap, int num, const sead::SafeString& name, int a, int b, int c) const; void freeContactPoints(RigidContactPoints* points) const; + RigidContactPointsEx* allocContactPointsEx(sead::Heap* heap, int num, int num2, + const sead::SafeString& name, int a, int b, + int c) const; + void freeContactPointsEx(RigidContactPointsEx* points) const; void registerContactPoints(RigidContactPoints* points) const; void registerContactPointLayerPair(RigidContactPointsEx* points, ContactLayer layer1, ContactLayer layer2, bool enabled); diff --git a/src/KingSystem/Physics/System/physRigidContactPoints.cpp b/src/KingSystem/Physics/System/physRigidContactPoints.cpp index 2e1c6ed9..9170491a 100644 --- a/src/KingSystem/Physics/System/physRigidContactPoints.cpp +++ b/src/KingSystem/Physics/System/physRigidContactPoints.cpp @@ -1,7 +1,17 @@ #include "KingSystem/Physics/System/physRigidContactPoints.h" +#include "KingSystem/Physics/System/physMemSystem.h" namespace ksys::phys { +RigidContactPoints* RigidContactPoints::make(sead::Heap* heap, int num, + const sead::SafeString& name, int a, int b, int c) { + return MemSystem::instance()->allocContactPoints(heap, num, name, a, b, c); +} + +void RigidContactPoints::free(RigidContactPoints* instance) { + MemSystem::instance()->freeContactPoints(instance); +} + RigidContactPoints::RigidContactPoints(const sead::SafeString& name, int a, int b, int c) : IRigidContactPoints(name, a, b, c) {} diff --git a/src/KingSystem/Physics/System/physRigidContactPoints.h b/src/KingSystem/Physics/System/physRigidContactPoints.h index 21165243..499391e5 100644 --- a/src/KingSystem/Physics/System/physRigidContactPoints.h +++ b/src/KingSystem/Physics/System/physRigidContactPoints.h @@ -19,6 +19,7 @@ public: IRigidContactPoints(const sead::SafeString& name, int a, int b, int c) : sead::INamable(name), _2c(a), _30(b), _34(c) {} virtual ~IRigidContactPoints() = default; + virtual void freePoints() = 0; bool isLinked() const { return mListNode.isLinked(); } static constexpr size_t getListNodeOffset() { return offsetof(IRigidContactPoints, mListNode); } @@ -41,7 +42,7 @@ public: RigidContactPoints(const sead::SafeString& name, int a, int b, int c); ~RigidContactPoints() override; - virtual void freePoints(); + void freePoints() override; virtual void allocPoints(sead::Heap* heap, int num); private: diff --git a/src/KingSystem/Physics/System/physRigidContactPointsEx.cpp b/src/KingSystem/Physics/System/physRigidContactPointsEx.cpp index fd718ca0..98aabe5f 100644 --- a/src/KingSystem/Physics/System/physRigidContactPointsEx.cpp +++ b/src/KingSystem/Physics/System/physRigidContactPointsEx.cpp @@ -3,6 +3,16 @@ namespace ksys::phys { +RigidContactPointsEx* RigidContactPointsEx::make(sead::Heap* heap, int num, int num2, + const sead::SafeString& name, int a, int b, + int c) { + return MemSystem::instance()->allocContactPointsEx(heap, num, num2, name, a, b, c); +} + +void RigidContactPointsEx::free(RigidContactPointsEx* instance) { + MemSystem::instance()->freeContactPointsEx(instance); +} + bool RigidContactPointsEx::registerLayerPair(ContactLayer layer1, ContactLayer layer2, bool enabled) { if (mLayerType == ContactLayerType::Invalid) diff --git a/src/KingSystem/Physics/System/physRigidContactPointsEx.h b/src/KingSystem/Physics/System/physRigidContactPointsEx.h index d399c61a..1fd53db2 100644 --- a/src/KingSystem/Physics/System/physRigidContactPointsEx.h +++ b/src/KingSystem/Physics/System/physRigidContactPointsEx.h @@ -100,12 +100,13 @@ public: const Point* const* mPointsStart = nullptr; }; - static RigidContactPointsEx* make(); + static RigidContactPointsEx* make(sead::Heap* heap, int num, int num2, + const sead::SafeString& name, int a, int b, int c); static void free(RigidContactPointsEx* instance); RigidContactPointsEx(const sead::SafeString& name, int a, int b, int c); ~RigidContactPointsEx() override; - virtual void freePoints(); + void freePoints() override; virtual void allocPoints(sead::Heap* heap, int num, int num2); bool registerLayerPair(ContactLayer layer1, ContactLayer layer2, bool enabled);