mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
- Refine the Cache_Get callback, to use a void * instead of a char *
- Switch alias models over to Cache_Get/Cache_Release
This commit is contained in:
parent
f54ef94fd0
commit
f1a016c8a5
13 changed files with 82 additions and 68 deletions
|
@ -120,12 +120,12 @@ void Hunk_Check (void);
|
|||
|
||||
struct cache_user_s;
|
||||
typedef void * (*cache_allocator_t) (struct cache_user_s *c, int size, const char *name);
|
||||
typedef void (*cache_loader_t) (struct cache_user_s *cache, cache_allocator_t allocator);
|
||||
typedef void (*cache_loader_t) (void *object, cache_allocator_t allocator);
|
||||
|
||||
typedef struct cache_user_s
|
||||
{
|
||||
void *data;
|
||||
char *filename;
|
||||
void *object;
|
||||
cache_loader_t loader;
|
||||
} cache_user_t;
|
||||
|
||||
|
@ -143,7 +143,7 @@ void *Cache_Alloc (cache_user_t *c, int size, const char *name);
|
|||
|
||||
void Cache_Report (void);
|
||||
|
||||
void Cache_Add (cache_user_t *c, const char *filename, cache_loader_t loader);
|
||||
void Cache_Add (cache_user_t *c, void *object, cache_loader_t loader);
|
||||
void Cache_Remove (cache_user_t *c);
|
||||
void *Cache_Get (cache_user_t *c);
|
||||
void *Cache_TryGet (cache_user_t *c);
|
||||
|
|
|
@ -61,7 +61,7 @@ void SND_Update_ (void);
|
|||
sfx_t *SND_PrecacheSound (const char *name);
|
||||
void SND_ClearBuffer (void);
|
||||
void SND_PaintChannels (int endtime);
|
||||
void SND_CallbackLoad (struct cache_user_s *cache, cache_allocator_t allocator);
|
||||
void SND_CallbackLoad (void *object, cache_allocator_t allocator);
|
||||
|
||||
void SND_Init_Cvars ();
|
||||
|
||||
|
@ -330,7 +330,7 @@ SND_FindName (const char *name)
|
|||
|
||||
sfx = &known_sfx[i];
|
||||
strcpy (sfx->name, name);
|
||||
Cache_Add (&sfx->cache, name, SND_CallbackLoad);
|
||||
Cache_Add (&sfx->cache, sfx, SND_CallbackLoad);
|
||||
|
||||
num_sfx++;
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ int cache_full_cycle;
|
|||
|
||||
byte *SND_Alloc (int size);
|
||||
wavinfo_t SND_GetWavinfo (const char *name, byte * wav, int wavlength);
|
||||
sfxcache_t *SND_LoadSound (cache_user_t *cache, const char *name, cache_allocator_t allocator);
|
||||
sfxcache_t *SND_LoadSound (sfx_t *sfx, cache_allocator_t allocator);
|
||||
|
||||
|
||||
void
|
||||
|
@ -157,7 +157,7 @@ SND_ResampleSfx (sfxcache_t *sc, int inrate, int inwidth, byte * data)
|
|||
//=============================================================================
|
||||
|
||||
sfxcache_t *
|
||||
SND_LoadSound (cache_user_t *cache, const char *name, cache_allocator_t allocator)
|
||||
SND_LoadSound (sfx_t *sfx, cache_allocator_t allocator)
|
||||
{
|
||||
char namebuffer[256];
|
||||
byte *data;
|
||||
|
@ -169,7 +169,7 @@ SND_LoadSound (cache_user_t *cache, const char *name, cache_allocator_t allocato
|
|||
|
||||
// load it in
|
||||
strcpy (namebuffer, "sound/");
|
||||
strncat (namebuffer, name, sizeof (namebuffer) - strlen (namebuffer));
|
||||
strncat (namebuffer, sfx->name, sizeof (namebuffer) - strlen (namebuffer));
|
||||
|
||||
data = COM_LoadStackFile (namebuffer, stackbuf, sizeof (stackbuf));
|
||||
|
||||
|
@ -178,9 +178,9 @@ SND_LoadSound (cache_user_t *cache, const char *name, cache_allocator_t allocato
|
|||
return NULL;
|
||||
}
|
||||
|
||||
info = SND_GetWavinfo (name, data, com_filesize);
|
||||
info = SND_GetWavinfo (sfx->name, data, com_filesize);
|
||||
if (info.channels != 1) {
|
||||
Con_Printf ("%s is a stereo sample\n", name);
|
||||
Con_Printf ("%s is a stereo sample\n", sfx->name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ SND_LoadSound (cache_user_t *cache, const char *name, cache_allocator_t allocato
|
|||
len = len * 2 * info.channels;
|
||||
}
|
||||
|
||||
sc = allocator (cache, len + sizeof (sfxcache_t), name);
|
||||
sc = allocator (&sfx->cache, len + sizeof (sfxcache_t), sfx->name);
|
||||
|
||||
if (!sc)
|
||||
return NULL;
|
||||
|
@ -210,9 +210,9 @@ SND_LoadSound (cache_user_t *cache, const char *name, cache_allocator_t allocato
|
|||
}
|
||||
|
||||
void
|
||||
SND_CallbackLoad (struct cache_user_s *cache, cache_allocator_t allocator)
|
||||
SND_CallbackLoad (void *object, cache_allocator_t allocator)
|
||||
{
|
||||
SND_LoadSound (cache, cache->filename, allocator);
|
||||
SND_LoadSound (object, allocator);
|
||||
}
|
||||
|
||||
/* WAV loading */
|
||||
|
|
|
@ -356,7 +356,7 @@ GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s)
|
|||
qboolean do_cache = false;
|
||||
|
||||
aliasmodel = m;
|
||||
paliashdr = hdr; // (aliashdr_t *)Mod_Extradata (m);
|
||||
paliashdr = hdr;
|
||||
|
||||
if (gl_mesh_cache->int_val
|
||||
&& gl_mesh_cache->int_val <= paliashdr->mdl.numtris) {
|
||||
|
|
|
@ -80,7 +80,7 @@ void *Mod_LoadAliasGroup (void *pin, maliasframedesc_t *frame);
|
|||
//=========================================================================
|
||||
|
||||
void
|
||||
Mod_LoadAliasModel (model_t *mod, void *buffer)
|
||||
Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
|
||||
{
|
||||
int i, j;
|
||||
mdl_t *pinmodel, *pmodel;
|
||||
|
@ -94,6 +94,7 @@ Mod_LoadAliasModel (model_t *mod, void *buffer)
|
|||
byte *p;
|
||||
int len;
|
||||
unsigned short crc;
|
||||
void *mem;
|
||||
|
||||
CRC_Init (&crc);
|
||||
for (len = com_filesize, p = buffer; len; len--, p++)
|
||||
|
@ -218,10 +219,10 @@ Mod_LoadAliasModel (model_t *mod, void *buffer)
|
|||
end = Hunk_LowMark ();
|
||||
total = end - start;
|
||||
|
||||
Cache_Alloc (&mod->cache, total, loadname);
|
||||
if (!mod->cache.data)
|
||||
return;
|
||||
memcpy (mod->cache.data, pheader, total);
|
||||
mem = allocator (&mod->cache, total, loadname);
|
||||
if (!mem)
|
||||
return; // FIXME: shouldn't this call Hunk_FreeToLowMark too?!?!
|
||||
memcpy (mem, pheader, total);
|
||||
|
||||
Hunk_FreeToLowMark (start);
|
||||
}
|
||||
|
|
|
@ -48,9 +48,11 @@
|
|||
#include "QF/sys.h"
|
||||
#include "QF/vfs.h"
|
||||
|
||||
void Mod_LoadAliasModel (model_t *mod, void *buf);
|
||||
void Mod_LoadAliasModel (model_t *mod, void *buf, cache_allocator_t allocator);
|
||||
void Mod_LoadSpriteModel (model_t *mod, void *buf);
|
||||
void Mod_LoadBrushModel (model_t *mod, void *buf);
|
||||
model_t *Mod_RealLoadModel (model_t *mod, qboolean crash, cache_allocator_t allocator);
|
||||
void Mod_CallbackLoad (void *object, cache_allocator_t allocator);
|
||||
|
||||
model_t *loadmodel;
|
||||
char loadname[32]; // for hunk tags
|
||||
|
@ -143,6 +145,7 @@ Mod_FindName (const char *name)
|
|||
strcpy (mod->name, name);
|
||||
mod->needload = true;
|
||||
mod_numknown++;
|
||||
Cache_Add (&mod->cache, mod, Mod_CallbackLoad);
|
||||
}
|
||||
|
||||
return mod;
|
||||
|
@ -156,19 +159,21 @@ Mod_FindName (const char *name)
|
|||
model_t *
|
||||
Mod_LoadModel (model_t *mod, qboolean crash)
|
||||
{
|
||||
void *d;
|
||||
unsigned int *buf;
|
||||
byte stackbuf[1024]; // avoid dirtying the cache heap
|
||||
|
||||
if (!mod->needload) {
|
||||
if (mod->type == mod_alias) {
|
||||
d = Cache_Check (&mod->cache);
|
||||
if (d)
|
||||
if (Cache_Check (&mod->cache))
|
||||
return mod;
|
||||
} else
|
||||
return mod; // not cached at all
|
||||
}
|
||||
return Mod_RealLoadModel (mod, crash, Cache_Alloc);
|
||||
}
|
||||
|
||||
model_t *
|
||||
Mod_RealLoadModel (model_t *mod, qboolean crash, cache_allocator_t allocator)
|
||||
{
|
||||
unsigned int *buf;
|
||||
byte stackbuf[1024]; // avoid dirtying the cache heap
|
||||
// load the file
|
||||
buf =
|
||||
(unsigned int *) COM_LoadStackFile (mod->name, stackbuf,
|
||||
|
@ -192,7 +197,7 @@ Mod_LoadModel (model_t *mod, qboolean crash)
|
|||
|
||||
switch (LittleLong (*(unsigned int *) buf)) {
|
||||
case IDPOLYHEADER:
|
||||
Mod_LoadAliasModel (mod, buf);
|
||||
Mod_LoadAliasModel (mod, buf, allocator);
|
||||
break;
|
||||
|
||||
case IDSPRITEHEADER:
|
||||
|
@ -207,6 +212,20 @@ Mod_LoadModel (model_t *mod, qboolean crash)
|
|||
return mod;
|
||||
}
|
||||
|
||||
/*
|
||||
Mod_CallbackLoad
|
||||
|
||||
Callback used to load model automatically
|
||||
*/
|
||||
void
|
||||
Mod_CallbackLoad (void *object, cache_allocator_t allocator)
|
||||
{
|
||||
if (((model_t *)object)->type != mod_alias)
|
||||
Sys_Error ("Mod_CallbackLoad for non-alias model? FIXME!\n");
|
||||
// FIXME: do we want crash set to true?
|
||||
Mod_RealLoadModel (object, true, allocator);
|
||||
}
|
||||
|
||||
/*
|
||||
Mod_ForName
|
||||
|
||||
|
@ -223,27 +242,6 @@ Mod_ForName (const char *name, qboolean crash)
|
|||
return Mod_LoadModel (mod, crash);
|
||||
}
|
||||
|
||||
/*
|
||||
Mod_Extradata
|
||||
|
||||
Caches the data if needed
|
||||
*/
|
||||
void *
|
||||
Mod_Extradata (model_t *mod)
|
||||
{
|
||||
void *r;
|
||||
|
||||
r = Cache_Check (&mod->cache);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
Mod_LoadModel (mod, true);
|
||||
|
||||
if (!mod->cache.data)
|
||||
Sys_Error ("Mod_Extradata: caching failed");
|
||||
return mod->cache.data;
|
||||
}
|
||||
|
||||
void
|
||||
Mod_TouchModel (const char *name)
|
||||
{
|
||||
|
|
|
@ -963,16 +963,14 @@ Cache_Profile (void)
|
|||
}
|
||||
|
||||
void
|
||||
Cache_Add (cache_user_t *c, const char *filename, cache_loader_t loader)
|
||||
Cache_Add (cache_user_t *c, void *object, cache_loader_t loader)
|
||||
{
|
||||
CACHE_WRITE_LOCK;
|
||||
|
||||
if (c->data || c->filename || c->loader)
|
||||
if (c->data || c->object || c->loader)
|
||||
Sys_Error ("Cache_Add: cache item already exists!\n");
|
||||
|
||||
c->filename = strdup (filename);
|
||||
if (!c->filename)
|
||||
Sys_Error ("Cache_Add: strdup failed!\n");
|
||||
c->object = object;
|
||||
c->loader = loader;
|
||||
|
||||
// c->loader (c, Cache_RealAlloc); // for debugging
|
||||
|
@ -985,14 +983,13 @@ Cache_Remove (cache_user_t *c)
|
|||
{
|
||||
CACHE_WRITE_LOCK;
|
||||
|
||||
if (!c->filename || !c->loader)
|
||||
if (!c->object || !c->loader)
|
||||
Sys_Error ("Cache_Remove: already removed!\n");
|
||||
|
||||
if (Cache_RealCheck (c))
|
||||
Cache_RealFree (c);
|
||||
|
||||
free (c->filename);
|
||||
c->filename = 0;
|
||||
c->object = 0;
|
||||
c->loader = 0;
|
||||
|
||||
CACHE_WRITE_UNLOCK;
|
||||
|
@ -1006,7 +1003,7 @@ Cache_TryGet (cache_user_t *c)
|
|||
|
||||
mem = Cache_RealCheck (c);
|
||||
if (!mem) {
|
||||
c->loader (c, Cache_RealAlloc);
|
||||
c->loader (c->object, Cache_RealAlloc);
|
||||
mem = Cache_RealCheck (c);
|
||||
}
|
||||
if (mem)
|
||||
|
|
|
@ -624,7 +624,7 @@ R_DrawAliasModel (entity_t *e, qboolean cull)
|
|||
VectorNormalize (shadevector);
|
||||
|
||||
// locate the proper data
|
||||
paliashdr = (aliashdr_t *) Mod_Extradata (currententity->model);
|
||||
paliashdr = Cache_Get (¤tentity->model->cache);
|
||||
c_alias_polys += paliashdr->mdl.numtris;
|
||||
|
||||
// draw all the triangles
|
||||
|
@ -714,6 +714,8 @@ R_DrawAliasModel (entity_t *e, qboolean cull)
|
|||
qfglEnable (GL_TEXTURE_2D);
|
||||
qfglPopMatrix ();
|
||||
}
|
||||
|
||||
Cache_Release (¤tentity->model->cache);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -207,7 +207,7 @@ Skin_Do_Translation_Model (model_t *model, int skinnum, int slot, skin_t *skin)
|
|||
if (model->type != mod_alias) // only translate skins on alias models
|
||||
return;
|
||||
|
||||
paliashdr = (aliashdr_t *) Mod_Extradata (model);
|
||||
paliashdr = Cache_Get (&model->cache);
|
||||
if (skinnum < 0
|
||||
|| skinnum >= paliashdr->mdl.numskins) {
|
||||
Con_Printf ("(%d): Invalid player skin #%d\n", slot,
|
||||
|
@ -222,6 +222,8 @@ Skin_Do_Translation_Model (model_t *model, int skinnum, int slot, skin_t *skin)
|
|||
inheight = paliashdr->mdl.skinheight;
|
||||
|
||||
build_skin (texnum, original, inwidth, inheight, inwidth, inheight, false);
|
||||
|
||||
Cache_Release (&model->cache);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -113,7 +113,7 @@ R_AliasCheckBBox (void)
|
|||
// expand, rotate, and translate points into worldspace
|
||||
currententity->trivial_accept = 0;
|
||||
pmodel = currententity->model;
|
||||
pahdr = Mod_Extradata (pmodel);
|
||||
pahdr = Cache_Get (&pmodel->cache);
|
||||
pmdl = (mdl_t *) ((byte *) pahdr + pahdr->model);
|
||||
|
||||
R_AliasSetUpTransform (0);
|
||||
|
@ -166,6 +166,7 @@ R_AliasCheckBBox (void)
|
|||
}
|
||||
|
||||
if (zfullyclipped) {
|
||||
Cache_Release (&pmodel->cache);
|
||||
return false; // everything was near-z-clipped
|
||||
}
|
||||
|
||||
|
@ -226,8 +227,10 @@ R_AliasCheckBBox (void)
|
|||
allclip &= flags;
|
||||
}
|
||||
|
||||
if (allclip)
|
||||
if (allclip) {
|
||||
Cache_Release (&pmodel->cache);
|
||||
return false; // trivial reject off one side
|
||||
}
|
||||
|
||||
currententity->trivial_accept = !anyclip & !zclipped;
|
||||
|
||||
|
@ -237,6 +240,7 @@ R_AliasCheckBBox (void)
|
|||
}
|
||||
}
|
||||
|
||||
Cache_Release (&pmodel->cache);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -664,7 +668,7 @@ R_AliasDrawModel (alight_t *plighting)
|
|||
(((long) &finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
|
||||
pauxverts = &auxverts[0];
|
||||
|
||||
paliashdr = (aliashdr_t *) Mod_Extradata (currententity->model);
|
||||
paliashdr = Cache_Get (¤tentity->model->cache);
|
||||
pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model);
|
||||
|
||||
R_AliasSetupSkin ();
|
||||
|
@ -697,4 +701,6 @@ R_AliasDrawModel (alight_t *plighting)
|
|||
R_AliasPrepareUnclippedPoints ();
|
||||
else
|
||||
R_AliasPreparePoints ();
|
||||
|
||||
Cache_Release (¤tentity->model->cache);
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ R_AliasCheckBBox (void)
|
|||
// expand, rotate, and translate points into worldspace
|
||||
currententity->trivial_accept = 0;
|
||||
pmodel = currententity->model;
|
||||
pahdr = Mod_Extradata (pmodel);
|
||||
pahdr = Cache_Get (&pmodel->cache);
|
||||
pmdl = (mdl_t *) ((byte *) pahdr + pahdr->model);
|
||||
|
||||
R_AliasSetUpTransform (0);
|
||||
|
@ -166,6 +166,7 @@ R_AliasCheckBBox (void)
|
|||
}
|
||||
|
||||
if (zfullyclipped) {
|
||||
Cache_Release (&pmodel->cache);
|
||||
return false; // everything was near-z-clipped
|
||||
}
|
||||
|
||||
|
@ -226,8 +227,10 @@ R_AliasCheckBBox (void)
|
|||
allclip &= flags;
|
||||
}
|
||||
|
||||
if (allclip)
|
||||
if (allclip) {
|
||||
Cache_Release (&pmodel->cache);
|
||||
return false; // trivial reject off one side
|
||||
}
|
||||
|
||||
currententity->trivial_accept = !anyclip & !zclipped;
|
||||
|
||||
|
@ -237,6 +240,7 @@ R_AliasCheckBBox (void)
|
|||
}
|
||||
}
|
||||
|
||||
Cache_Release (&pmodel->cache);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -651,7 +655,7 @@ R_AliasDrawModel (alight_t *plighting)
|
|||
(((long) &finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
|
||||
pauxverts = &auxverts[0];
|
||||
|
||||
paliashdr = (aliashdr_t *) Mod_Extradata (currententity->model);
|
||||
paliashdr = Cache_Get (¤tentity->model->cache);
|
||||
pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model);
|
||||
|
||||
R_AliasSetupSkin ();
|
||||
|
@ -683,4 +687,6 @@ R_AliasDrawModel (alight_t *plighting)
|
|||
R_AliasPrepareUnclippedPoints ();
|
||||
else
|
||||
R_AliasPreparePoints ();
|
||||
|
||||
Cache_Release (¤tentity->model->cache);
|
||||
}
|
||||
|
|
|
@ -1373,12 +1373,13 @@ PrintFrameName (model_t *m, int frame)
|
|||
aliashdr_t *hdr;
|
||||
maliasframedesc_t *pframedesc;
|
||||
|
||||
hdr = (aliashdr_t *) Mod_Extradata (m);
|
||||
hdr = Cache_TryGet (&m->cache);
|
||||
if (!hdr)
|
||||
return;
|
||||
pframedesc = &hdr->frames[frame];
|
||||
|
||||
Con_Printf ("frame %i: %s\n", frame, pframedesc->name);
|
||||
Cache_Release (&m->cache);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -296,13 +296,14 @@ Model_NextDownload (void)
|
|||
info_key = emodel_name;
|
||||
|
||||
if (info_key && cl_model_crcs->int_val) {
|
||||
aliashdr_t *ahdr = (aliashdr_t *) Mod_Extradata
|
||||
(cl.model_precache[i]);
|
||||
aliashdr_t *ahdr = Cache_Get
|
||||
(&cl.model_precache[i]->cache);
|
||||
Info_SetValueForKey (cls.userinfo, info_key, va ("%d", ahdr->crc),
|
||||
MAX_INFO_STRING, 0);
|
||||
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
|
||||
SZ_Print (&cls.netchan.message, va ("setinfo %s %d", info_key,
|
||||
ahdr->crc));
|
||||
Cache_Release (&cl.model_precache[i]->cache);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue