mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-27 05:40:25 +00:00
Merge branch 'detour_alloc' into 'master'
Use RecastGlobalAllocator for Detour See merge request OpenMW/openmw!3678
This commit is contained in:
commit
c3dfc8c213
2 changed files with 12 additions and 4 deletions
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "recasttempallocator.hpp"
|
#include "recasttempallocator.hpp"
|
||||||
|
|
||||||
|
#include <DetourAlloc.h>
|
||||||
#include <RecastAlloc.h>
|
#include <RecastAlloc.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -14,10 +15,14 @@ namespace DetourNavigator
|
||||||
public:
|
public:
|
||||||
static void init() { instance(); }
|
static void init() { instance(); }
|
||||||
|
|
||||||
static void* alloc(size_t size, rcAllocHint hint)
|
static void* recastAlloc(size_t size, rcAllocHint hint) { return alloc(size, hint == RC_ALLOC_TEMP); }
|
||||||
|
|
||||||
|
static void* detourAlloc(size_t size, dtAllocHint hint) { return alloc(size, hint == DT_ALLOC_TEMP); }
|
||||||
|
|
||||||
|
static void* alloc(size_t size, bool temp)
|
||||||
{
|
{
|
||||||
void* result = nullptr;
|
void* result = nullptr;
|
||||||
if (rcLikely(hint == RC_ALLOC_TEMP))
|
if (rcLikely(temp))
|
||||||
result = tempAllocator().alloc(size);
|
result = tempAllocator().alloc(size);
|
||||||
if (rcUnlikely(!result))
|
if (rcUnlikely(!result))
|
||||||
result = allocPerm(size);
|
result = allocPerm(size);
|
||||||
|
@ -38,7 +43,11 @@ namespace DetourNavigator
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RecastGlobalAllocator() { rcAllocSetCustom(&RecastGlobalAllocator::alloc, &RecastGlobalAllocator::free); }
|
RecastGlobalAllocator()
|
||||||
|
{
|
||||||
|
rcAllocSetCustom(&RecastGlobalAllocator::recastAlloc, &RecastGlobalAllocator::free);
|
||||||
|
dtAllocSetCustom(&RecastGlobalAllocator::detourAlloc, &RecastGlobalAllocator::free);
|
||||||
|
}
|
||||||
|
|
||||||
static RecastGlobalAllocator& instance()
|
static RecastGlobalAllocator& instance()
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,7 +52,6 @@ namespace DetourNavigator
|
||||||
mTop = mPrev;
|
mTop = mPrev;
|
||||||
mPrev = getTempPtrPrev(mTop);
|
mPrev = getTempPtrPrev(mTop);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue