res reload callback interface change: now also receives handle of object being reloaded. simplifies tex reload code
This was SVN commit r602.
This commit is contained in:
parent
766a0b4077
commit
ddd7821425
@ -761,9 +761,10 @@ static void IO_dtor(IO* io)
|
||||
// i don't think it's possible anyway, without controlling the AIO
|
||||
// implementation: when we cancel, we can't prevent the app from calling
|
||||
// aio_result, which would terminate the read.
|
||||
static int IO_reload(IO* io, const char* fn)
|
||||
static int IO_reload(IO* io, const char* fn, Handle h)
|
||||
{
|
||||
UNUSED(fn);
|
||||
UNUSED(h);
|
||||
|
||||
return io->cb? 0 : ERR_NO_MEM;
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ static void Font_dtor(Font* f)
|
||||
}
|
||||
|
||||
|
||||
static int Font_reload(Font* f, const char* fn)
|
||||
static int Font_reload(Font* f, const char* fn, Handle)
|
||||
{
|
||||
// we pass the loaded file to sscanf. the data needs to be 0-terminated,
|
||||
// so we read, and then copy into a 0-terminated buffer. ugh.
|
||||
|
@ -471,7 +471,7 @@ if(!(flags & RES_KEY))
|
||||
// catch exception to simplify reload funcs - let them use new()
|
||||
try
|
||||
{
|
||||
err = vtbl->reload(hd->user, fn);
|
||||
err = vtbl->reload(hd->user, fn, h);
|
||||
}
|
||||
catch(std::bad_alloc)
|
||||
{
|
||||
@ -536,11 +536,12 @@ int h_reload(const char* fn)
|
||||
if(!hd || hd->key != key)
|
||||
continue;
|
||||
|
||||
int err = hd->type->reload(hd->user, hd->fn);
|
||||
Handle h = handle(i, hd->tag);
|
||||
|
||||
int err = hd->type->reload(hd->user, hd->fn, h);
|
||||
// don't stop if an error is encountered - try to reload them all.
|
||||
if(err < 0)
|
||||
{
|
||||
Handle h = handle(i, hd->tag);
|
||||
h_free(h, hd->type);
|
||||
ret = err;
|
||||
}
|
||||
|
@ -25,6 +25,15 @@
|
||||
#include "lib.h"
|
||||
|
||||
|
||||
// 0 = invalid handle value; < 0 is an error code.
|
||||
// 64 bits, because we want tags to remain unique: tag overflow may
|
||||
// let handle use errors slip through, or worse, cause spurious errors.
|
||||
// with 32 bits, we'd need >= 12 for the index, leaving < 512K tags -
|
||||
// not a lot.
|
||||
typedef i64 Handle;
|
||||
|
||||
|
||||
|
||||
// handle type (for 'type safety' - can't use a texture handle as a sound)
|
||||
|
||||
|
||||
@ -86,7 +95,7 @@ but- has to handle variable params, a bit ugly
|
||||
struct H_VTbl
|
||||
{
|
||||
void(*init)(void* user, va_list);
|
||||
int(*reload)(void* user, const char* fn);
|
||||
int(*reload)(void* user, const char* fn, Handle);
|
||||
void(*dtor)(void* user);
|
||||
size_t user_size;
|
||||
const char* name;
|
||||
@ -97,12 +106,12 @@ typedef H_VTbl* H_Type;
|
||||
#define H_TYPE_DEFINE(type)\
|
||||
/* forward decls */\
|
||||
static void type##_init(type*, va_list);\
|
||||
static int type##_reload(type*, const char*);\
|
||||
static int type##_reload(type*, const char*, Handle);\
|
||||
static void type##_dtor(type*);\
|
||||
static H_VTbl V_##type =\
|
||||
{\
|
||||
(void(*)(void*, va_list))type##_init,\
|
||||
(int(*)(void*, const char*))type##_reload,\
|
||||
(int(*)(void*, const char*, Handle))type##_reload,\
|
||||
(void(*)(void*))type##_dtor,\
|
||||
sizeof(type), /* control block size */\
|
||||
#type /* name */\
|
||||
@ -129,14 +138,6 @@ typedef H_VTbl* H_Type;
|
||||
return ERR_INVALID_HANDLE;
|
||||
|
||||
|
||||
// 0 = invalid handle value; < 0 is an error code.
|
||||
// 64 bits, because we want tags to remain unique: tag overflow may
|
||||
// let handle use errors slip through, or worse, cause spurious errors.
|
||||
// with 32 bits, we'd need >= 12 for the index, leaving < 512K tags -
|
||||
// not a lot.
|
||||
typedef i64 Handle;
|
||||
|
||||
|
||||
// all functions check the passed tag (part of the handle) and type against
|
||||
// the internal values. if they differ, an error is returned.
|
||||
|
||||
@ -296,7 +297,7 @@ guide to defining and using resources
|
||||
does all initialization of the resource that requires its source file.
|
||||
called after init; also after dtor every time the file is reloaded.
|
||||
|
||||
static int Type_reload(Res1* r, const char* filename);
|
||||
static int Type_reload(Res1* r, const char* filename, Handle);
|
||||
{
|
||||
// somehow load stuff from filename, and store it in r->data1.
|
||||
return 0;
|
||||
|
@ -183,10 +183,11 @@ static void Mem_dtor(Mem* m)
|
||||
|
||||
// can't alloc here, because h_alloc needs the key when called
|
||||
// (key == pointer we allocate)
|
||||
static int Mem_reload(Mem* m, const char* fn)
|
||||
static int Mem_reload(Mem* m, const char* fn, Handle h)
|
||||
{
|
||||
UNUSED(m);
|
||||
UNUSED(fn);
|
||||
UNUSED(h);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "res/h_mgr.h"
|
||||
#include "res/vfs.h"
|
||||
#include "res/tex.h"
|
||||
#include "res/ogl_tex.h"
|
||||
#include "res/mem.h"
|
||||
#include "res/font.h"
|
||||
#include "res/unifont.h"
|
||||
|
@ -36,7 +36,7 @@ static void Sound_init(Sound* s, va_list args)
|
||||
s->channel = -1;
|
||||
}
|
||||
|
||||
static int Sound_reload(Sound* s, const char* filename)
|
||||
static int Sound_reload(Sound* s, const char* filename, Handle)
|
||||
{
|
||||
//only load if clip is empty
|
||||
if(s->clip == NULL)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
$Id: unifont.cpp,v 1.3 2004/06/21 12:49:37 janwas Exp $
|
||||
$Id: unifont.cpp,v 1.4 2004/06/25 22:19:19 janwas Exp $
|
||||
|
||||
Unicode OpenGL texture font
|
||||
|
||||
@ -51,7 +51,7 @@ static void UniFont_dtor(UniFont* f)
|
||||
}
|
||||
|
||||
|
||||
static int UniFont_reload(UniFont* f, const char* fn)
|
||||
static int UniFont_reload(UniFont* f, const char* fn, Handle h)
|
||||
{
|
||||
// fn is the base filename, like "fonts/console"
|
||||
// The font definition file is fn+".fnt" and the texture is fn+".tga"
|
||||
|
@ -892,7 +892,7 @@ static void VDir_dtor(VDir* vd)
|
||||
delete vd->files;
|
||||
}
|
||||
|
||||
static int VDir_reload(VDir* vd, const char* path)
|
||||
static int VDir_reload(VDir* vd, const char* path, Handle)
|
||||
{
|
||||
if(vd->subdirs)
|
||||
{
|
||||
@ -1141,7 +1141,7 @@ static void VFile_dtor(VFile* vf)
|
||||
|
||||
|
||||
|
||||
static int VFile_reload(VFile* vf, const char* path)
|
||||
static int VFile_reload(VFile* vf, const char* path, Handle)
|
||||
{
|
||||
uint& flags = vf_flags(vf);
|
||||
|
||||
|
@ -553,8 +553,10 @@ static void ZArchive_dtor(ZArchive* za)
|
||||
}
|
||||
|
||||
|
||||
static int ZArchive_reload(ZArchive* za, const char* fn)
|
||||
static int ZArchive_reload(ZArchive* za, const char* fn, Handle h)
|
||||
{
|
||||
UNUSED(h);
|
||||
|
||||
int err;
|
||||
|
||||
err = file_open(fn, 0, &za->f);
|
||||
|
Loading…
Reference in New Issue
Block a user