mirror of
https://github.com/aap/librw.git
synced 2025-04-07 02:18:15 +01:00
change to engine init; little fix
This commit is contained in:
parent
d9def88c46
commit
e8990d5b3d
@ -125,6 +125,15 @@ free_managed(void *p)
|
|||||||
free(mem->origPtr);
|
free(mem->origPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
printleaks(void)
|
||||||
|
{
|
||||||
|
FORLIST(lnk, allocations){
|
||||||
|
MemoryBlock *mem = LLLinkGetData(lnk, MemoryBlock, inAllocList);
|
||||||
|
printf("sz %d hint %X\n %s\n", mem->sz, mem->hint, mem->codeline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: make the debug out configurable
|
// TODO: make the debug out configurable
|
||||||
void *mustmalloc_h(size_t sz, uint32 hint)
|
void *mustmalloc_h(size_t sz, uint32 hint)
|
||||||
{
|
{
|
||||||
@ -147,11 +156,25 @@ void *mustrealloc_h(void *p, size_t sz, uint32 hint)
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
//#define TRACK_ALLOCATIONS
|
MemoryFunctions defaultMemfuncs = {
|
||||||
|
malloc_h,
|
||||||
|
realloc_h,
|
||||||
|
free,
|
||||||
|
nil,
|
||||||
|
nil
|
||||||
|
};
|
||||||
|
|
||||||
|
MemoryFunctions managedMemfuncs = {
|
||||||
|
malloc_managed,
|
||||||
|
realloc_managed,
|
||||||
|
free_managed,
|
||||||
|
nil,
|
||||||
|
nil
|
||||||
|
};
|
||||||
|
|
||||||
// This function mainly registers engine plugins
|
// This function mainly registers engine plugins
|
||||||
bool32
|
bool32
|
||||||
Engine::init(void)
|
Engine::init(MemoryFunctions *memfuncs)
|
||||||
{
|
{
|
||||||
if(engine || Engine::state != Dead){
|
if(engine || Engine::state != Dead){
|
||||||
RWERROR((ERR_ENGINEINIT));
|
RWERROR((ERR_ENGINEINIT));
|
||||||
@ -161,19 +184,15 @@ Engine::init(void)
|
|||||||
totalMemoryAllocated = 0;
|
totalMemoryAllocated = 0;
|
||||||
allocations.init();
|
allocations.init();
|
||||||
|
|
||||||
// TODO: make this an argument
|
if(memfuncs)
|
||||||
#ifdef TRACK_ALLOCATIONS
|
Engine::memfuncs = *memfuncs;
|
||||||
memfuncs.rwmalloc = malloc_managed;
|
else
|
||||||
memfuncs.rwrealloc = realloc_managed;
|
Engine::memfuncs = defaultMemfuncs;
|
||||||
memfuncs.rwfree = free_managed;
|
|
||||||
#else
|
|
||||||
memfuncs.rwmalloc = malloc_h;
|
|
||||||
memfuncs.rwrealloc = realloc_h;
|
|
||||||
memfuncs.rwfree = free;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
memfuncs.rwmustmalloc = mustmalloc_h;
|
if(Engine::memfuncs.rwmustmalloc == nil)
|
||||||
memfuncs.rwmustrealloc = mustrealloc_h;
|
Engine::memfuncs.rwmustmalloc = mustmalloc_h;
|
||||||
|
if(Engine::memfuncs.rwmustrealloc == nil)
|
||||||
|
Engine::memfuncs.rwmustrealloc = mustrealloc_h;
|
||||||
|
|
||||||
PluginList::open();
|
PluginList::open();
|
||||||
|
|
||||||
@ -303,13 +322,6 @@ Engine::term(void)
|
|||||||
// TODO: maybe reset more stuff here?
|
// TODO: maybe reset more stuff here?
|
||||||
d3d::nativeRasterOffset = 0;
|
d3d::nativeRasterOffset = 0;
|
||||||
|
|
||||||
#ifdef TRACK_ALLOCATIONS
|
|
||||||
FORLIST(lnk, allocations){
|
|
||||||
MemoryBlock *mem = LLLinkGetData(lnk, MemoryBlock, inAllocList);
|
|
||||||
printf("sz %d hint %X\n %s\n", mem->sz, mem->hint, mem->codeline);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Engine::state = Dead;
|
Engine::state = Dead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +83,9 @@ closeIm2D(void)
|
|||||||
{
|
{
|
||||||
glDeleteBuffers(1, &im2DIbo);
|
glDeleteBuffers(1, &im2DIbo);
|
||||||
glDeleteBuffers(1, &im2DVbo);
|
glDeleteBuffers(1, &im2DVbo);
|
||||||
|
#ifdef RW_GL_USE_VAOS
|
||||||
|
glDeleteVertexArrays(1, &im2DVao);
|
||||||
|
#endif
|
||||||
im2dShader->destroy();
|
im2dShader->destroy();
|
||||||
im2dShader = nil;
|
im2dShader = nil;
|
||||||
}
|
}
|
||||||
@ -238,6 +241,9 @@ closeIm3D(void)
|
|||||||
{
|
{
|
||||||
glDeleteBuffers(1, &im3DIbo);
|
glDeleteBuffers(1, &im3DIbo);
|
||||||
glDeleteBuffers(1, &im3DVbo);
|
glDeleteBuffers(1, &im3DVbo);
|
||||||
|
#ifdef RW_GL_USE_VAOS
|
||||||
|
glDeleteVertexArrays(1, &im3DVao);
|
||||||
|
#endif
|
||||||
im3dShader->destroy();
|
im3dShader->destroy();
|
||||||
im3dShader = nil;
|
im3dShader = nil;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ struct Engine
|
|||||||
static MemoryFunctions memfuncs;
|
static MemoryFunctions memfuncs;
|
||||||
static State state;
|
static State state;
|
||||||
|
|
||||||
static bool32 init(void);
|
static bool32 init(MemoryFunctions *memfuncs = nil);
|
||||||
static bool32 open(EngineOpenParams*);
|
static bool32 open(EngineOpenParams*);
|
||||||
static bool32 start(void);
|
static bool32 start(void);
|
||||||
static void term(void);
|
static void term(void);
|
||||||
@ -207,6 +207,10 @@ inline void *mustrealloc_LOC(void *p, size_t sz, uint32 hint, const char *here)
|
|||||||
#define rwResize(p, s, h) rw::mustrealloc_LOC(p,s,h,RWHERE)
|
#define rwResize(p, s, h) rw::mustrealloc_LOC(p,s,h,RWHERE)
|
||||||
#define rwResizeT(t, p, s, h) (t*)rw::mustrealloc_LOC(p,(s)*sizeof(t),h,RWHERE)
|
#define rwResizeT(t, p, s, h) (t*)rw::mustrealloc_LOC(p,(s)*sizeof(t),h,RWHERE)
|
||||||
|
|
||||||
|
extern MemoryFunctions defaultMemfuncs;
|
||||||
|
extern MemoryFunctions managedMemfuncs;
|
||||||
|
void printleaks(void); // when using managed mem funcs
|
||||||
|
|
||||||
namespace null {
|
namespace null {
|
||||||
void beginUpdate(Camera*);
|
void beginUpdate(Camera*);
|
||||||
void endUpdate(Camera*);
|
void endUpdate(Camera*);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user