summaryrefslogtreecommitdiff
path: root/src/KingSystem/Physics/System/physHavokMemoryAllocator.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2026-09-28 03:39:31 +0200
committerLéo Lam <leo@leolam.fr>2026-10-13 02:55:29 +0200
commit89322a8d0cb0c1aaab509ab653a9368a2ae5dea9 (patch)
tree32eb8a0aaa2dd4b25343643ac61b0808f6562d4e /src/KingSystem/Physics/System/physHavokMemoryAllocator.cpp
parent0ee30415f78a5edc870c0947ca19292f01152205 (diff)
ksys/phys: rearrange the folder layout to match link order
A folder's files are linked before its subfolders, and the rigid body files are linked as one flat sequence. ListShape is the one file that does not fit this order. | Old | New | |---|---| | RigidBody/Shape/<Kind>/phys<Kind>Shape.cpp | RigidBody/Shape/phys<Kind>Shape.cpp | | RigidBody/Shape/<Kind>/phys<Kind>RigidBody.cpp | RigidBody/physRigidBody<Kind>.cpp | | RigidBody/Shape/List/physListShapeRigidBody.cpp | RigidBody/physRigidBodyListShape.cpp | | physHavokMemoryAllocator.cpp | System/physHavokMemoryAllocator.cpp | | StaticCompound/physStaticCompound{,Mgr,RigidBodyGroup,Util}.cpp | System/ | | StaticCompound/physStaticCompound{Info,Autogen}.cpp | System/physStaticCompoundInfo.cpp | The original has the type infos' cleanup functions just before StaticCompoundInfo's functions, so the merged file defines the reflection data first, with plain static cleanup functions as in Havok's generated reflection code. Template instantiations would be emitted after the rest of the file. (AI assisted using Claude Fable 5.1 and Claude Opus 5.5)
Diffstat (limited to 'src/KingSystem/Physics/System/physHavokMemoryAllocator.cpp')
-rw-r--r--src/KingSystem/Physics/System/physHavokMemoryAllocator.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/KingSystem/Physics/System/physHavokMemoryAllocator.cpp b/src/KingSystem/Physics/System/physHavokMemoryAllocator.cpp
new file mode 100644
index 00000000..dfa76401
--- /dev/null
+++ b/src/KingSystem/Physics/System/physHavokMemoryAllocator.cpp
@@ -0,0 +1,37 @@
+#include "KingSystem/Physics/System/physHavokMemoryAllocator.h"
+#include "KingSystem/Utils/HeapUtil.h"
+
+namespace ksys::phys {
+
+HavokMemoryAllocator::HavokMemoryAllocator(int align) : hkMallocAllocator(align) {}
+
+HavokMemoryAllocator::~HavokMemoryAllocator() = default;
+
+void HavokMemoryAllocator::initDualHeap(sead::Heap* heap1, sead::Heap* heap2, u32 size,
+ const sead::SafeString& name) {
+ mHeap = util::DualHeap::create(size, name, heap1, heap2, alignof(void*),
+ sead::Heap::cHeapDirection_Forward, true);
+}
+
+void* HavokMemoryAllocator::blockAlloc(int numBytes) {
+ return mHeap->tryAlloc(numBytes, m_align);
+}
+
+void HavokMemoryAllocator::blockFree(void* p, int numBytes) {
+ mHeap->free(p);
+}
+
+size_t HavokMemoryAllocator::getHeapSize() const {
+ return mHeap->getSize();
+}
+
+size_t HavokMemoryAllocator::getHeapFreeSize() const {
+ return sead::DynamicCast<util::DualHeap>(mHeap)->getFreeSize();
+}
+
+int HavokMemoryAllocator::getAllocatedSize(const void* obj, int nbytes) const {
+ // sead::ExpHeap::getAllocatedSize isn't const-correct :/
+ return static_cast<int>(mHeap->getAllocatedSize(const_cast<void*>(obj)));
+}
+
+} // namespace ksys::phys