summaryrefslogtreecommitdiff
path: root/src/KingSystem/Physics/physHavokMemoryAllocator.cpp
blob: efe356cef1d265746437ff8c6e57535e7a29ce25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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