From 96deb88e277ffadc5b550583733f571a1b74154b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 6 Sep 2020 22:51:43 +0200 Subject: [PATCH] ksys/Utils: Add DualFrameHeap --- lib/sead | 2 +- src/KingSystem/Utils/HeapUtil.h | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/sead b/lib/sead index 57301b4c..8a00c624 160000 --- a/lib/sead +++ b/lib/sead @@ -1 +1 @@ -Subproject commit 57301b4c5c6aa257e63860e2f6ae5872ef8d2af4 +Subproject commit 8a00c624536738a26fc087d478db025e2752fc12 diff --git a/src/KingSystem/Utils/HeapUtil.h b/src/KingSystem/Utils/HeapUtil.h index a803db85..54183f95 100644 --- a/src/KingSystem/Utils/HeapUtil.h +++ b/src/KingSystem/Utils/HeapUtil.h @@ -2,6 +2,7 @@ #include #include +#include #include #include "KingSystem/Utils/Types.h" @@ -42,8 +43,48 @@ protected: u8 _120; void* _128; }; +KSYS_CHECK_SIZE_NX150(sead::ExpHeap, 0x110); KSYS_CHECK_SIZE_NX150(DualHeap, 0x130); +class DualFrameHeap : public sead::FrameHeap { + SEAD_RTTI_OVERRIDE(DualFrameHeap, sead::FrameHeap) + +public: + static DualFrameHeap* tryCreate(size_t size, const sead::SafeString& name, Heap* parent1, + Heap* parent2, s32 alignment, HeapDirection direction, bool b); + static DualFrameHeap* create(size_t size, const sead::SafeString& name, Heap* parent1, + Heap* parent2, s32 alignment, HeapDirection direction, bool b); + + size_t adjust() override; + void* tryAlloc(size_t size, s32 alignment) override; + void free(void* ptr) override; + size_t getFreeSize() const override; + size_t getMaxAllocatableSize(int alignment) const override; + bool isInclude(const void* p_void) const override; + bool isEmpty() const override; + bool isAdjustable() const override; + void genInformation_(sead::hostio::Context* context) override; + void makeMetaString_(sead::BufferedSafeString* string) override; + +protected: + DualFrameHeap(size_t size, const sead::SafeString& name, Heap* parent1, Heap* parent2, + s32 alignment, HeapDirection direction, bool b); + ~DualFrameHeap() override; + + sead::Heap* mHeap2; + void* _f8; + u8 _100; +}; +KSYS_CHECK_SIZE_NX150(sead::FrameHeap, 0xf0); +KSYS_CHECK_SIZE_NX150(DualFrameHeap, 0x108); + +sead::Heap* tryCreateDualHeap(size_t size, const sead::SafeString& name, sead::Heap* heap1, + sead::Heap* heap2, sead::Heap::HeapDirection direction); + +/// Same as tryCreateDualHeap, but asserts on failure. +sead::Heap* createDualHeap(size_t size, const sead::SafeString& name, sead::Heap* heap1, + sead::Heap* heap2, sead::Heap::HeapDirection direction); + /// Returns the specified heap if it is not null. Otherwise, this returns the current heap. sead::Heap* getHeapOrCurrentHeap(sead::Heap* heap);