mirror of
https://github.com/zeldaret/botw
synced 2026-07-11 14:38:41 -04:00
ksys/phys: Add HavokMemoryAllocator
This commit is contained in:
@@ -174,9 +174,11 @@ target_sources(uking PRIVATE
|
||||
System/physUserTag.cpp
|
||||
System/physUserTag.h
|
||||
|
||||
physConversions.h
|
||||
physDefines.cpp
|
||||
physDefines.h
|
||||
physConversions.h
|
||||
physHavokMemoryAllocator.cpp
|
||||
physHavokMemoryAllocator.h
|
||||
physHeapUtil.h
|
||||
physLayerMaskBuilder.h
|
||||
physMaterialMask.cpp
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "KingSystem/Physics/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
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <Havok/Common/Base/Memory/Allocator/Malloc/hkMallocAllocator.h>
|
||||
#include <basis/seadTypes.h>
|
||||
#include <hostio/seadHostIONode.h>
|
||||
#include <prim/seadSafeString.h>
|
||||
|
||||
namespace sead {
|
||||
class ExpHeap;
|
||||
}
|
||||
|
||||
namespace ksys::phys {
|
||||
|
||||
class HavokMemoryAllocator : public hkMallocAllocator, public sead::hostio::Node {
|
||||
public:
|
||||
explicit HavokMemoryAllocator(int align = HK_REAL_ALIGNMENT);
|
||||
~HavokMemoryAllocator() override;
|
||||
|
||||
void initDualHeap(sead::Heap* heap1, sead::Heap* heap2, u32 size, const sead::SafeString& name);
|
||||
|
||||
void* blockAlloc(int numBytes) override;
|
||||
void blockFree(void* p, int numBytes) override;
|
||||
int getAllocatedSize(const void* obj, int nbytes) const override;
|
||||
|
||||
size_t getHeapSize() const;
|
||||
size_t getHeapFreeSize() const;
|
||||
|
||||
private:
|
||||
sead::ExpHeap* mHeap{};
|
||||
};
|
||||
|
||||
} // namespace ksys::phys
|
||||
Reference in New Issue
Block a user