mirror of https://github.com/PrimeDecomp/prime.git
parent
67e861c0f0
commit
ec593c79e5
|
@ -9,15 +9,15 @@ struct SMediumAllocPuddle {
|
||||||
~SMediumAllocPuddle();
|
~SMediumAllocPuddle();
|
||||||
void* FindFree(uint blockCount);
|
void* FindFree(uint blockCount);
|
||||||
void* FindFreeEntry(uint blockCount);
|
void* FindFreeEntry(uint blockCount);
|
||||||
bool Free(const void* ptr);
|
void Free(const void* ptr);
|
||||||
|
|
||||||
uint GetUnkx10() const { return x10_; }
|
const uint GetUnkx10() const { return x10_; }
|
||||||
uint GetNumBlocks() const { return x14_numBlocks; }
|
const uint GetNumBlocks() const { return x14_numBlocks; }
|
||||||
uint GetNumAllocs() const { return x18_numAllocs; }
|
const uint GetNumAllocs() const { return x18_numAllocs; }
|
||||||
uint GetNumEntries() const { return x1c_numEntries; }
|
const uint GetNumEntries() const { return x1c_numEntries; }
|
||||||
bool GetUnk2() const { return x20_unk2; }
|
const bool GetUnk2() const { return x20_unk2; }
|
||||||
|
const uint GetPtrOffset(const void* ptr) const { return (uchar*)ptr - x0_mainData.get(); }
|
||||||
static uint GetBlockOffset(const void* ptrA, const void* ptrB);
|
static ushort GetBlockOffset(const void* ptrA, const void* ptrB);
|
||||||
static void InitBookKeeping(uchar* bookKeepingPtr, const ushort blockCount);
|
static void InitBookKeeping(uchar* bookKeepingPtr, const ushort blockCount);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -38,7 +38,7 @@ public:
|
||||||
CMediumAllocPool();
|
CMediumAllocPool();
|
||||||
void* Alloc(uint size);
|
void* Alloc(uint size);
|
||||||
bool HasPuddles() const;
|
bool HasPuddles() const;
|
||||||
void AddPuddle(uint, void*, bool);
|
void AddPuddle(const uint, void*, const bool);
|
||||||
void ClearPuddles();
|
void ClearPuddles();
|
||||||
|
|
||||||
int Free(const void* ptr);
|
int Free(const void* ptr);
|
||||||
|
|
|
@ -12,7 +12,7 @@ class list {
|
||||||
public:
|
public:
|
||||||
class iterator;
|
class iterator;
|
||||||
class const_iterator;
|
class const_iterator;
|
||||||
iterator erase(const iterator& item);
|
iterator erase(const iterator& item) { return do_erase(item.get_node()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct node;
|
struct node;
|
||||||
|
@ -33,9 +33,7 @@ public:
|
||||||
size_t size() const { return x14_count; }
|
size_t size() const { return x14_count; }
|
||||||
bool empty() const { return x14_count == 0; }
|
bool empty() const { return x14_count == 0; }
|
||||||
|
|
||||||
void pop_front() {
|
void pop_front() { erase(x4_start); }
|
||||||
erase(x4_start);
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator begin() { return iterator(x4_start); }
|
iterator begin() { return iterator(x4_start); }
|
||||||
const_iterator begin() const { return const_iterator(x4_start); }
|
const_iterator begin() const { return const_iterator(x4_start); }
|
||||||
|
@ -166,7 +164,6 @@ list< T, Alloc >::~list() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template < typename T, typename Alloc >
|
template < typename T, typename Alloc >
|
||||||
typename list< T, Alloc >::node* list< T, Alloc >::do_erase(node* node) {
|
typename list< T, Alloc >::node* list< T, Alloc >::do_erase(node* node) {
|
||||||
typename list< T, Alloc >::node* result = node->get_next();
|
typename list< T, Alloc >::node* result = node->get_next();
|
||||||
|
|
|
@ -43,7 +43,25 @@ void* CMediumAllocPool::Alloc(uint len) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CMediumAllocPool::Free(const void* ptr) {}
|
int CMediumAllocPool::Free(const void* ptr) {
|
||||||
|
rstl::list<SMediumAllocPuddle>::node* node = x0_list.begin().get_node();
|
||||||
|
for (; node != x0_list.end().get_node(); node = node->get_next()) {
|
||||||
|
SMediumAllocPuddle* puddle = node->get_value();
|
||||||
|
if (puddle->GetPtrOffset(ptr) < puddle->GetNumEntries() * 32) {
|
||||||
|
puddle->Free(ptr);
|
||||||
|
if (node->get_value()->GetNumAllocs() == 0 && node->get_value()->GetUnk2()) {
|
||||||
|
if (x18_lastNodePrev == node ) {
|
||||||
|
x18_lastNodePrev = x0_list.begin().get_node();
|
||||||
|
}
|
||||||
|
|
||||||
|
x0_list.erase(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
uint CMediumAllocPool::GetNumAllocs() {
|
uint CMediumAllocPool::GetNumAllocs() {
|
||||||
uint ret = 0;
|
uint ret = 0;
|
||||||
|
@ -72,7 +90,7 @@ uint CMediumAllocPool::GetNumBlocksAvailable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this is such a hack... */
|
/* this is such a hack... */
|
||||||
#pragma inline_max_size(250)
|
#pragma inline_max_size(325)
|
||||||
void CMediumAllocPool::AddPuddle(uint len, void* data, const bool unk) {
|
void CMediumAllocPool::AddPuddle(uint len, void* data, const bool unk) {
|
||||||
x0_list.push_back(SMediumAllocPuddle(len, data, unk));
|
x0_list.push_back(SMediumAllocPuddle(len, data, unk));
|
||||||
x18_lastNodePrev = x0_list.end().get_node();
|
x18_lastNodePrev = x0_list.end().get_node();
|
||||||
|
@ -115,9 +133,17 @@ void* SMediumAllocPuddle::FindFree(uint blockCount) {
|
||||||
|
|
||||||
void* SMediumAllocPuddle::FindFreeEntry(uint numBlocks) { return nullptr; }
|
void* SMediumAllocPuddle::FindFreeEntry(uint numBlocks) { return nullptr; }
|
||||||
|
|
||||||
bool SMediumAllocPuddle::Free(const void* ptr) {}
|
void SMediumAllocPuddle::Free(const void* ptr) {}
|
||||||
|
|
||||||
uint SMediumAllocPuddle::GetBlockOffset(const void* ptrA, const void* ptrB) { return 0; }
|
ushort SMediumAllocPuddle::GetBlockOffset(const void* ptr1, const void* ptr2) {
|
||||||
|
unsigned char tmp = (uchar*)ptr2 - (uchar*)ptr1 > 1 ? ((uchar*)ptr1)[1] : 0;
|
||||||
|
|
||||||
|
ushort x = tmp + (*(uchar*)(ptr1) & 0x7f) * 0x100;
|
||||||
|
if ((x & 0x6000) == 0) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
return (x & 0x6000u) == 0x6000u ? 3 : (((x & 0x6000u) != 0x4000) ? 0 : 1) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
void SMediumAllocPuddle::InitBookKeeping(uchar* bookKeepingPtr, ushort blockCount) {
|
void SMediumAllocPuddle::InitBookKeeping(uchar* bookKeepingPtr, ushort blockCount) {
|
||||||
if (blockCount < 4) {
|
if (blockCount < 4) {
|
||||||
|
|
Loading…
Reference in New Issue