Browse Source

engine: mod_studio: reduce dependency on global loadmodel pointer, make it private for brush model loader

pull/2/head
Alibek Omarov 1 year ago
parent
commit
c5e91f299b
  1. 4
      engine/common/mod_bmodel.c
  2. 1
      engine/common/mod_local.h
  3. 48
      engine/common/mod_studio.c
  4. 2
      engine/common/model.c

4
engine/common/mod_bmodel.c

@ -210,6 +210,8 @@ static mlumpinfo_t extlumps[EXTRA_LUMPS] =
{ LUMP_SHADOWMAP, 0, MAX_MAP_LIGHTING / 3, sizeof( byte ), -1, "shadowmap", USE_EXTRAHEADER, (const void **)&srcmodel.shadowdata, &srcmodel.shadowdatasize }, { LUMP_SHADOWMAP, 0, MAX_MAP_LIGHTING / 3, sizeof( byte ), -1, "shadowmap", USE_EXTRAHEADER, (const void **)&srcmodel.shadowdata, &srcmodel.shadowdatasize },
}; };
static model_t *loadmodel;
/* /*
=============================================================================== ===============================================================================
@ -3151,6 +3153,8 @@ void Mod_LoadBrushModel( model_t *mod, const void *buffer, qboolean *loaded )
{ {
char poolname[MAX_VA_STRING]; char poolname[MAX_VA_STRING];
loadmodel = mod;
Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", loadmodel->name ); Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", loadmodel->name );
if( loaded ) *loaded = false; if( loaded ) *loaded = false;

1
engine/common/mod_local.h

@ -118,7 +118,6 @@ typedef struct world_static_s
#ifndef REF_DLL #ifndef REF_DLL
extern world_static_t world; extern world_static_t world;
extern poolhandle_t com_studiocache; extern poolhandle_t com_studiocache;
extern model_t *loadmodel;
extern convar_t mod_studiocache; extern convar_t mod_studiocache;
extern convar_t r_wadtextures; extern convar_t r_wadtextures;
extern convar_t r_showhull; extern convar_t r_showhull;

48
engine/common/mod_studio.c

@ -851,11 +851,11 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded )
char poolname[MAX_VA_STRING]; char poolname[MAX_VA_STRING];
studiohdr_t *phdr; studiohdr_t *phdr;
Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", loadmodel->name ); Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", mod->name );
if( loaded ) *loaded = false; if( loaded ) *loaded = false;
loadmodel->mempool = Mem_AllocPool( poolname ); mod->mempool = Mem_AllocPool( poolname );
loadmodel->type = mod_studio; mod->type = mod_studio;
phdr = R_StudioLoadHeader( mod, buffer ); phdr = R_StudioLoadHeader( mod, buffer );
if( !phdr ) return; // bad model if( !phdr ) return; // bad model
@ -886,9 +886,9 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded )
// give space for textures and skinrefs // give space for textures and skinrefs
size1 = thdr->numtextures * sizeof( mstudiotexture_t ); size1 = thdr->numtextures * sizeof( mstudiotexture_t );
size2 = thdr->numskinfamilies * thdr->numskinref * sizeof( short ); size2 = thdr->numskinfamilies * thdr->numskinref * sizeof( short );
mod->cache.data = Mem_Calloc( loadmodel->mempool, phdr->length + size1 + size2 ); mod->cache.data = Mem_Calloc( mod->mempool, phdr->length + size1 + size2 );
memcpy( loadmodel->cache.data, buffer, phdr->length ); // copy main mdl buffer memcpy( mod->cache.data, buffer, phdr->length ); // copy main mdl buffer
phdr = (studiohdr_t *)loadmodel->cache.data; // get the new pointer on studiohdr phdr = (studiohdr_t *)mod->cache.data; // get the new pointer on studiohdr
phdr->numskinfamilies = thdr->numskinfamilies; phdr->numskinfamilies = thdr->numskinfamilies;
phdr->numtextures = thdr->numtextures; phdr->numtextures = thdr->numtextures;
phdr->numskinref = thdr->numskinref; phdr->numskinref = thdr->numskinref;
@ -905,52 +905,52 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded )
else else
{ {
// NOTE: don't modify source buffer because it's used for CRC computing // NOTE: don't modify source buffer because it's used for CRC computing
loadmodel->cache.data = Mem_Calloc( loadmodel->mempool, phdr->length ); mod->cache.data = Mem_Calloc( mod->mempool, phdr->length );
memcpy( loadmodel->cache.data, buffer, phdr->length ); memcpy( mod->cache.data, buffer, phdr->length );
phdr = (studiohdr_t *)loadmodel->cache.data; // get the new pointer on studiohdr phdr = (studiohdr_t *)mod->cache.data; // get the new pointer on studiohdr
#if !XASH_DEDICATED #if !XASH_DEDICATED
ref.dllFuncs.Mod_StudioLoadTextures( mod, phdr ); ref.dllFuncs.Mod_StudioLoadTextures( mod, phdr );
#endif #endif
// NOTE: we wan't keep raw textures in memory. just cutoff model pointer above texture base // NOTE: we wan't keep raw textures in memory. just cutoff model pointer above texture base
loadmodel->cache.data = Mem_Realloc( loadmodel->mempool, loadmodel->cache.data, phdr->texturedataindex ); mod->cache.data = Mem_Realloc( mod->mempool, mod->cache.data, phdr->texturedataindex );
phdr = (studiohdr_t *)loadmodel->cache.data; // get the new pointer on studiohdr phdr = (studiohdr_t *)mod->cache.data; // get the new pointer on studiohdr
phdr->length = phdr->texturedataindex; // update model size phdr->length = phdr->texturedataindex; // update model size
} }
} }
else else
{ {
// just copy model into memory // just copy model into memory
loadmodel->cache.data = Mem_Calloc( loadmodel->mempool, phdr->length ); mod->cache.data = Mem_Calloc( mod->mempool, phdr->length );
memcpy( loadmodel->cache.data, buffer, phdr->length ); memcpy( mod->cache.data, buffer, phdr->length );
phdr = loadmodel->cache.data; phdr = mod->cache.data;
} }
// setup bounding box // setup bounding box
if( !VectorCompare( vec3_origin, phdr->bbmin )) if( !VectorCompare( vec3_origin, phdr->bbmin ))
{ {
// clipping bounding box // clipping bounding box
VectorCopy( phdr->bbmin, loadmodel->mins ); VectorCopy( phdr->bbmin, mod->mins );
VectorCopy( phdr->bbmax, loadmodel->maxs ); VectorCopy( phdr->bbmax, mod->maxs );
} }
else if( !VectorCompare( vec3_origin, phdr->min )) else if( !VectorCompare( vec3_origin, phdr->min ))
{ {
// movement bounding box // movement bounding box
VectorCopy( phdr->min, loadmodel->mins ); VectorCopy( phdr->min, mod->mins );
VectorCopy( phdr->max, loadmodel->maxs ); VectorCopy( phdr->max, mod->maxs );
} }
else else
{ {
// well compute bounds from vertices and round to nearest even values // well compute bounds from vertices and round to nearest even values
Mod_StudioComputeBounds( phdr, loadmodel->mins, loadmodel->maxs, true ); Mod_StudioComputeBounds( phdr, mod->mins, mod->maxs, true );
RoundUpHullSize( loadmodel->mins ); RoundUpHullSize( mod->mins );
RoundUpHullSize( loadmodel->maxs ); RoundUpHullSize( mod->maxs );
} }
loadmodel->numframes = Mod_StudioBodyVariations( loadmodel ); mod->numframes = Mod_StudioBodyVariations( mod );
loadmodel->radius = RadiusFromBounds( loadmodel->mins, loadmodel->maxs ); mod->radius = RadiusFromBounds( mod->mins, mod->maxs );
loadmodel->flags = phdr->flags; // copy header flags mod->flags = phdr->flags; // copy header flags
if( loaded ) *loaded = true; if( loaded ) *loaded = true;
} }

2
engine/common/model.c

@ -31,7 +31,6 @@ poolhandle_t com_studiocache; // cache for submodels
CVAR_DEFINE( mod_studiocache, "r_studiocache", "1", FCVAR_ARCHIVE, "enables studio cache for speedup tracing hitboxes" ); CVAR_DEFINE( mod_studiocache, "r_studiocache", "1", FCVAR_ARCHIVE, "enables studio cache for speedup tracing hitboxes" );
CVAR_DEFINE_AUTO( r_wadtextures, "0", 0, "completely ignore textures in the bsp-file if enabled" ); CVAR_DEFINE_AUTO( r_wadtextures, "0", 0, "completely ignore textures in the bsp-file if enabled" );
CVAR_DEFINE_AUTO( r_showhull, "0", 0, "draw collision hulls 1-3" ); CVAR_DEFINE_AUTO( r_showhull, "0", 0, "draw collision hulls 1-3" );
model_t *loadmodel;
/* /*
=============================================================================== ===============================================================================
@ -287,7 +286,6 @@ model_t *Mod_LoadModel( model_t *mod, qboolean crash )
Con_Reportf( "loading %s\n", mod->name ); Con_Reportf( "loading %s\n", mod->name );
mod->needload = NL_PRESENT; mod->needload = NL_PRESENT;
mod->type = mod_bad; mod->type = mod_bad;
loadmodel = mod;
// call the apropriate loader // call the apropriate loader
switch( *(uint *)buf ) switch( *(uint *)buf )

Loading…
Cancel
Save