From 384dfb7b66c616b758b6dc1b2257a219c16375b1 Mon Sep 17 00:00:00 2001 From: Adam Olsen Date: Fri, 31 Aug 2001 15:32:11 +0000 Subject: [PATCH] - partial work for putting sprites in the cache. doesn't currently build. --- libs/models/model.c | 14 ++++++++------ libs/models/sprite/model_sprite.c | 6 ++---- libs/video/renderer/gl/gl_rmain.c | 10 +++++----- libs/video/renderer/sw/sw_rsprite.c | 4 +++- libs/video/renderer/sw32/sw32_rsprite.c | 4 +++- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/libs/models/model.c b/libs/models/model.c index b2edb7322..849f7d6ed 100644 --- a/libs/models/model.c +++ b/libs/models/model.c @@ -49,7 +49,7 @@ #include "QF/vfs.h" void Mod_LoadAliasModel (model_t *mod, void *buf, cache_allocator_t allocator); -void Mod_LoadSpriteModel (model_t *mod, void *buf); +void Mod_LoadSpriteModel (model_t *mod, void *buf, cache_allocator_t allocator); 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); @@ -160,12 +160,14 @@ model_t * Mod_LoadModel (model_t *mod, qboolean crash) { if (!mod->needload) { - if (mod->type == mod_alias) { + if (mod->type == mod_alias || mod->type == mod_sprite) { if (Cache_Check (&mod->cache)) return mod; } else return mod; // not cached at all } + if (Cache_Check (&mod->cache)) + Cache_Free (&mod->cache); return Mod_RealLoadModel (mod, crash, Cache_Alloc); } @@ -201,7 +203,7 @@ Mod_RealLoadModel (model_t *mod, qboolean crash, cache_allocator_t allocator) break; case IDSPRITEHEADER: - Mod_LoadSpriteModel (mod, buf); + Mod_LoadSpriteModel (mod, buf, allocator); break; default: @@ -220,8 +222,8 @@ Mod_RealLoadModel (model_t *mod, qboolean crash, cache_allocator_t allocator) 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"); + if (((model_t *)object)->type == mod_brush) + Sys_Error ("Mod_CallbackLoad for mod_brush not yet supported. FIXME!\n"); // FIXME: do we want crash set to true? Mod_RealLoadModel (object, true, allocator); } @@ -263,6 +265,6 @@ Mod_Print (void) Con_Printf ("Cached models:\n"); for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) { - Con_Printf ("%8p : %s\n", mod->cache.data, mod->name); + Con_Printf ("%8p : %s\n", Cache_Check (&mod->cache), mod->name); } } diff --git a/libs/models/sprite/model_sprite.c b/libs/models/sprite/model_sprite.c index 7ee30bdd5..096158b30 100644 --- a/libs/models/sprite/model_sprite.c +++ b/libs/models/sprite/model_sprite.c @@ -90,7 +90,7 @@ Mod_LoadSpriteGroup (void *pin, mspriteframe_t **ppframe, int framenum) } void -Mod_LoadSpriteModel (model_t *mod, void *buffer) +Mod_LoadSpriteModel (model_t *mod, void *buffer, cache_allocator_t allocator) { int i; int version; @@ -111,9 +111,7 @@ Mod_LoadSpriteModel (model_t *mod, void *buffer) size = field_offset (msprite_t, frames[numframes]); - psprite = Hunk_AllocName (size, loadname); - - mod->cache.data = psprite; + psprite = allocator (&mod->cache, size, loadname); psprite->type = LittleLong (pin->type); psprite->maxwidth = LittleLong (pin->width); diff --git a/libs/video/renderer/gl/gl_rmain.c b/libs/video/renderer/gl/gl_rmain.c index 5d009b751..c52c8a9f8 100644 --- a/libs/video/renderer/gl/gl_rmain.c +++ b/libs/video/renderer/gl/gl_rmain.c @@ -133,15 +133,13 @@ R_RotateForEntity (entity_t *e) } static mspriteframe_t * -R_GetSpriteFrame (entity_t *currententity) +R_GetSpriteFrame (entity_t *currententity, msprite_t *psprite) { - msprite_t *psprite; mspritegroup_t *pspritegroup; mspriteframe_t *pspriteframe; int i, numframes, frame; float *pintervals, fullinterval, targettime, time; - psprite = currententity->model->cache.data; frame = currententity->frame; if ((frame >= psprite->numframes) || (frame < 0)) { @@ -186,8 +184,8 @@ R_DrawSpriteModel (entity_t *e) // don't even bother culling, because it's just a single // polygon without a surface cache - frame = R_GetSpriteFrame (e); - psprite = currententity->model->cache.data; + psprite = Cache_Get (¤tentity->model->cache); + frame = R_GetSpriteFrame (e, psprite); if (psprite->type == SPR_ORIENTED) { // bullet marks on walls AngleVectors (currententity->angles, v_forward, v_right, v_up); @@ -226,6 +224,8 @@ R_DrawSpriteModel (entity_t *e) qfglEnd (); qfglDisable (GL_ALPHA_TEST); + + Cache_Release (¤tentity->model->cache); } /* diff --git a/libs/video/renderer/sw/sw_rsprite.c b/libs/video/renderer/sw/sw_rsprite.c index 316598c7a..3eb03ceed 100644 --- a/libs/video/renderer/sw/sw_rsprite.c +++ b/libs/video/renderer/sw/sw_rsprite.c @@ -282,7 +282,7 @@ R_DrawSprite (void) vec3_t tvec; float dot, angle, sr, cr; - psprite = currententity->model->cache.data; + psprite = Cache_Get (¤tentity->model->cache); r_spritedesc.pspriteframe = R_GetSpriteframe (psprite); @@ -378,4 +378,6 @@ R_DrawSprite (void) R_RotateSprite (psprite->beamlength); R_SetupAndDrawSprite (); + + Cache_Release (¤tentity->model->cache); } diff --git a/libs/video/renderer/sw32/sw32_rsprite.c b/libs/video/renderer/sw32/sw32_rsprite.c index ba697da67..f7985b141 100644 --- a/libs/video/renderer/sw32/sw32_rsprite.c +++ b/libs/video/renderer/sw32/sw32_rsprite.c @@ -282,7 +282,7 @@ R_DrawSprite (void) vec3_t tvec; float dot, angle, sr, cr; - psprite = currententity->model->cache.data; + psprite = Cache_Get (¤tentity->model->cache); r_spritedesc.pspriteframe = R_GetSpriteframe (psprite); @@ -378,4 +378,6 @@ R_DrawSprite (void) R_RotateSprite (psprite->beamlength); R_SetupAndDrawSprite (); + + Cache_Release (¤tentity->model->cache); }