Compare commits

..

No commits in common. "def0513800eb5a1ab378327b233e93a376eca3e4" and "94dcf8ca7782730b389af08ef6ac73325b6ecc15" have entirely different histories.

6 changed files with 8 additions and 88 deletions

View file

@ -62,21 +62,6 @@ uint32_t ObjectAllocUsage(uint32_t heapId) {
return result;
}
void* ObjectPtr(uint32_t heapId, uint32_t memHandle) {
auto globals = GetObjAllocGlobals();
STORM_ASSERT(heapId < globals->objects.Count());
auto result = globals->objects[heapId].Ptr(memHandle);
ReleaseObjAllocGlobals();
return result;
}
void ObjectFree(uint32_t heapId, uint32_t memHandle) {
auto globals = GetObjAllocGlobals();
STORM_ASSERT(heapId < globals->objects.Count());
globals->objects[heapId].Delete(memHandle);
ReleaseObjAllocGlobals();
}
void ObjectAllocDestroy() {
// NOTICE: It seems like sub_4D2F90 does nothing useful
auto globals = GetObjAllocGlobals();

View file

@ -9,10 +9,6 @@ uint32_t ObjectAllocAddHeap(uint32_t objectSize, uint32_t objsPerBlock, const ch
uint32_t ObjectAllocUsage(uint32_t heapId);
void* ObjectPtr(uint32_t heapId, uint32_t memHandle);
void ObjectFree(uint32_t heapId, uint32_t memHandle);
void ObjectAllocDestroy();
#endif

View file

@ -4,20 +4,10 @@
#include <bc/Memory.hpp>
#include <storm/Error.hpp>
CObjectHeap::CObjectHeap(const CObjectHeap& heap) {
if (this == &heap) {
return;
}
this->m_obj = heap.m_obj;
this->m_indexStack = heap.m_indexStack;
this->m_allocated = heap.m_allocated;
heap.m_obj = nullptr;
heap.m_indexStack = nullptr;
heap.m_allocated = 0;
}
CObjectHeap::~CObjectHeap() {
this->Free();
if (this->m_obj) {
SMemFree(this->m_obj, __FILE__, __LINE__, 0);
}
}
int32_t CObjectHeap::Allocate(uint32_t objSize, uint32_t heapObjects, const char* heapName) {
@ -137,12 +127,3 @@ void CObjectHeap::Delete(uint32_t index, uint32_t objSize, uint32_t heapObjects)
this->m_indexStack[--this->m_allocated] = index;
}
void CObjectHeap::Free() {
if (this->m_obj) {
SMemFree(this->m_obj, __FILE__, __LINE__, 0);
}
this->m_obj = nullptr;
this->m_indexStack = nullptr;
this->m_allocated = 0;
}

View file

@ -6,21 +6,18 @@
class CObjectHeap {
public:
// Member variables
mutable void* m_obj = nullptr;
mutable uint32_t* m_indexStack = nullptr;
mutable uint32_t m_allocated = 0;
void* m_obj = nullptr;
uint32_t* m_indexStack = nullptr;
uint32_t m_allocated = 0;
// Member functions
CObjectHeap() = default;
CObjectHeap(const CObjectHeap& heap);
CObjectHeap& operator=(const CObjectHeap& heap) = delete;
~CObjectHeap();
int32_t Allocate(uint32_t objSize, uint32_t heapObjects, const char* heapName);
int32_t New(uint32_t objSize, uint32_t heapObjects, uint32_t* index, const char* heapName, void** obj, bool zero);
void* Ptr(uint32_t index, uint32_t objSize, uint32_t heapObjects);
void Delete(uint32_t index, uint32_t objSize, uint32_t heapObjects);
void Free();
};
#endif

View file

@ -1,26 +1,6 @@
#include "common/objectalloc/CObjectHeapList.hpp"
#include <storm/Error.hpp>
CObjectHeapList::CObjectHeapList(const CObjectHeapList& list) {
if (this == &list) {
return;
}
this->m_heaps.Set(list.m_heaps.Count(), list.m_heaps.Ptr());
this->m_objSize = list.m_objSize;
this->m_objsPerBlock = list.m_objsPerBlock;
this->m_numFullHeaps = list.m_numFullHeaps;
this->m_hasEmptyHeaps = list.m_hasEmptyHeaps;
this->uint20 = list.uint20;
this->m_fullestHeap = list.m_fullestHeap;
memcpy(this->m_heapName, list.m_heapName, sizeof(this->m_heapName));
this->uint78 = list.uint78;
this->uint7C = list.uint7C;
this->uint80 = list.uint80;
this->m_freeEmptyHeaps = list.m_freeEmptyHeaps;
}
int32_t CObjectHeapList::New(uint32_t* index, void** obj, bool zero) {
STORM_ASSERT(index);
@ -70,19 +50,10 @@ int32_t CObjectHeapList::New(uint32_t* index, void** obj, bool zero) {
return 1;
}
void* CObjectHeapList::Ptr(uint32_t index) {
uint32_t heapId = index / this->m_objsPerBlock;
uint32_t stackId = index % this->m_objsPerBlock;
STORM_ASSERT(heapId < this->m_heaps.Count());
return this->m_heaps[heapId].Ptr(stackId, this->m_objSize, this->m_objsPerBlock);
}
void CObjectHeapList::Delete(uint32_t index) {
uint32_t heapId = index / this->m_objsPerBlock;
uint32_t stackId = index % this->m_objsPerBlock;
STORM_ASSERT(heapId < this->m_heaps.Count());
auto& heap = this->m_heaps[heapId];
if (heap.m_allocated == this->m_objsPerBlock) {
this->m_numFullHeaps--;
@ -137,13 +108,7 @@ void CObjectHeapList::FreeEmptyHeaps() {
uint32_t count = this->m_heaps.Count();
while (count > 0 && totalAllocated < totalObjsPerBlock && !totalEmptyHeaps) {
auto& heap = this->m_heaps[count - 1];
if (heap.m_obj && !heap.m_allocated) {
heap.Free();
totalObjsPerBlock -= this->m_objsPerBlock;
totalEmptyHeaps--;
this->uint20 = 0;
}
// TODO: Remove last element from this->m_heaps
count--;
}

View file

@ -14,18 +14,14 @@ class CObjectHeapList {
uint32_t m_hasEmptyHeaps = 0;
uint32_t uint20 = 0;
uint32_t m_fullestHeap = 0;
char m_heapName[80] = {};
char m_heapName[80];
uint32_t uint78 = 0;
uint32_t uint7C = 0;
uint32_t uint80 = 0;
uint8_t m_freeEmptyHeaps = 1;
// Member functions
CObjectHeapList() = default;
CObjectHeapList(const CObjectHeapList& list);
CObjectHeapList& operator=(const CObjectHeapList& list) = delete;
int32_t New(uint32_t* index, void** obj, bool zero);
void* Ptr(uint32_t index);
void Delete(uint32_t index);
void FreeEmptyHeaps();
uint32_t BlocksAllocated();