2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-10 16:27:43 +00:00

some CMemory additions

This commit is contained in:
Jack Andersen
2015-08-23 08:53:43 -10:00
parent f3b5b9f49a
commit 5784759b62
8 changed files with 161 additions and 13 deletions

View File

@@ -1,33 +1,60 @@
#include "CMemory.hpp"
#include "CGameAllocator.hpp"
#include <LogVisor/LogVisor.hpp>
namespace Retro
{
static CGameAllocator GAME_ALLOCATOR;
static IAllocator* MEMORY_ALLOCATOR = &GAME_ALLOCATOR;
static bool MEMORY_ALLOCATOR_READY = false;
LogVisor::LogModule Log("CMemory");
static CGameAllocator g_gameAllocator;
static IAllocator* g_memoryAllocator = &g_gameAllocator;
static bool g_memoryAllocatorReady = false;
void CMemory::Startup(COsContext& cos)
{
MEMORY_ALLOCATOR_READY = MEMORY_ALLOCATOR->Initialize(cos);
g_memoryAllocatorReady = g_memoryAllocator->Initialize(cos);
}
void CMemory::Shutdown()
{
MEMORY_ALLOCATOR->Shutdown();
MEMORY_ALLOCATOR_READY = false;
g_memoryAllocator->Shutdown();
g_memoryAllocatorReady = false;
}
void CMemory::SetAllocator(COsContext& cos, IAllocator& alloc)
{
if (&alloc != MEMORY_ALLOCATOR)
if (&alloc != g_memoryAllocator)
{
MEMORY_ALLOCATOR = &alloc;
MEMORY_ALLOCATOR->Initialize(cos);
g_memoryAllocator = &alloc;
g_memoryAllocator->Initialize(cos);
}
}
void CMemory::OffsetFakeStatics(int val)
{
g_memoryAllocator->OffsetFakeStatics(val);
}
void CMemory::SetOutOfMemoryCallback(const IAllocator::TOutOfMemoryCallback cb, void* ctx)
{
g_memoryAllocator->SetOutOfMemoryCallback(cb, ctx);
}
void CMemory::Free(void* ptr)
{
g_memoryAllocator->Free(ptr);
}
void* CMemory::Alloc(u32 sz, IAllocator::EHint hint, IAllocator::EScope scope,
IAllocator::EType type, const CCallStack& cs)
{
void* newPtr = g_memoryAllocator->Alloc(sz, hint, scope, type, cs);
if (!newPtr)
Log.report(LogVisor::Error, "Alloc Failed! - Size %d", sz);
return newPtr;
}
CMemorySys::CMemorySys(COsContext& cos, IAllocator& alloc)
{
CMemory::Startup(cos);
@@ -39,6 +66,6 @@ CMemorySys::~CMemorySys()
CMemory::Shutdown();
}
IAllocator& CMemorySys::GetGameAllocator() {return GAME_ALLOCATOR;}
IAllocator& CMemorySys::GetGameAllocator() {return g_gameAllocator;}
}