2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-25 19:30:08 +01:00

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

This commit is contained in:
Alibek Omarov 2023-10-28 15:38:40 +03:00
parent cff276db71
commit c5e91f299b
4 changed files with 28 additions and 27 deletions

View File

@ -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 },
};
static model_t *loadmodel;
/*
===============================================================================
@ -3151,6 +3153,8 @@ void Mod_LoadBrushModel( model_t *mod, const void *buffer, qboolean *loaded )
{
char poolname[MAX_VA_STRING];
loadmodel = mod;
Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", loadmodel->name );
if( loaded ) *loaded = false;

View File

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

View File

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

View File

@ -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_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" );
model_t *loadmodel;
/*
===============================================================================
@ -287,7 +286,6 @@ model_t *Mod_LoadModel( model_t *mod, qboolean crash )
Con_Reportf( "loading %s\n", mod->name );
mod->needload = NL_PRESENT;
mod->type = mod_bad;
loadmodel = mod;
// call the apropriate loader
switch( *(uint *)buf )