diff options
author | aap <aap@papnet.eu> | 2020-11-25 22:49:50 +0100 |
---|---|---|
committer | aap <aap@papnet.eu> | 2020-11-25 22:49:50 +0100 |
commit | 4ddc35634160da5779c46ab63a5b3d351af50b83 (patch) | |
tree | 9e38a65296bb049d0292948c135ef8f3a939df9b /src/fakerw/fake.cpp | |
parent | implemented CMemoryHeap, not used or tested yet (diff) | |
download | re3-4ddc35634160da5779c46ab63a5b3d351af50b83.tar re3-4ddc35634160da5779c46ab63a5b3d351af50b83.tar.gz re3-4ddc35634160da5779c46ab63a5b3d351af50b83.tar.bz2 re3-4ddc35634160da5779c46ab63a5b3d351af50b83.tar.lz re3-4ddc35634160da5779c46ab63a5b3d351af50b83.tar.xz re3-4ddc35634160da5779c46ab63a5b3d351af50b83.tar.zst re3-4ddc35634160da5779c46ab63a5b3d351af50b83.zip |
Diffstat (limited to 'src/fakerw/fake.cpp')
-rw-r--r-- | src/fakerw/fake.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/fakerw/fake.cpp b/src/fakerw/fake.cpp index 64a37421..39606335 100644 --- a/src/fakerw/fake.cpp +++ b/src/fakerw/fake.cpp @@ -16,9 +16,14 @@ using namespace rw; RwUInt8 RwObjectGetType(const RwObject *obj) { return obj->type; } -void *RwMalloc(size_t size) { return malloc(size); } -void *RwCalloc(size_t numObj, size_t sizeObj) { return calloc(numObj, sizeObj); } -void RwFree(void *mem) { free(mem); } +void *RwMalloc(size_t size) { return engine->memfuncs.rwmalloc(size, 0); } +void *RwCalloc(size_t numObj, size_t sizeObj) { + void *mem = RwMalloc(numObj*sizeObj); + if(mem) + memset(mem, 0, numObj*sizeObj); + return mem; +} +void RwFree(void *mem) { engine->memfuncs.rwfree(mem); } //RwReal RwV3dNormalize(RwV3d * out, const RwV3d * in); @@ -536,8 +541,27 @@ RwBool RwRenderStateSet(RwRenderState state, void *value) } } +static rw::MemoryFunctions gMemfuncs; +static void *(*real_malloc)(size_t size); +static void *(*real_realloc)(void *mem, size_t newSize); +static void *mallocWrap(size_t sz, uint32 hint) { if(sz == 0) return nil; return real_malloc(sz); } +static void *reallocWrap(void *p, size_t sz, uint32 hint) { return real_realloc(p, sz); } + + // WARNING: unused parameters -RwBool RwEngineInit(RwMemoryFunctions *memFuncs, RwUInt32 initFlags, RwUInt32 resArenaSize) { Engine::init(); return true; } +RwBool RwEngineInit(RwMemoryFunctions *memFuncs, RwUInt32 initFlags, RwUInt32 resArenaSize) { + if(memFuncs){ + real_malloc = memFuncs->rwmalloc; + real_realloc = memFuncs->rwrealloc; + gMemfuncs.rwmalloc = mallocWrap; + gMemfuncs.rwrealloc = reallocWrap; + gMemfuncs.rwfree = memFuncs->rwfree; + Engine::init(&gMemfuncs); + }else{ + Engine::init(nil); + } + return true; +} // TODO: this is platform dependent RwBool RwEngineOpen(RwEngineOpenParams *initParams) { static EngineOpenParams openParams; |