From 4d7d592918786e5db951cec4067f447d605c8bc5 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 28 Oct 2023 16:06:00 +0300 Subject: [PATCH] engine: mod_bmodel: completely get rid of global loadmodel pointer --- engine/common/mod_bmodel.c | 418 ++++++++++++++++++------------------- 1 file changed, 206 insertions(+), 212 deletions(-) diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index 50ab2d78..283d0d2b 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -210,8 +210,6 @@ 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; - /* =============================================================================== @@ -267,7 +265,7 @@ static fs_offset_t Mod_CalculateMipTexSize( mip_t *mt, qboolean palette ) ( palette ? MIPTEX_CUSTOM_PALETTE_SIZE_BYTES : 0 ); } -static qboolean Mod_CalcMipTexUsesCustomPalette( dbspmodel_t *bmod, int textureIndex ) +static qboolean Mod_CalcMipTexUsesCustomPalette( model_t *mod, dbspmodel_t *bmod, int textureIndex ) { int nextTextureIndex = 0; mip_t *mipTex; @@ -282,7 +280,7 @@ static qboolean Mod_CalcMipTexUsesCustomPalette( dbspmodel_t *bmod, int textureI size = Mod_CalculateMipTexSize( mipTex, false ); // Compute next data offset to determine allocated miptex space - for( nextTextureIndex = textureIndex + 1; nextTextureIndex < loadmodel->numtextures; nextTextureIndex++ ) + for( nextTextureIndex = textureIndex + 1; nextTextureIndex < mod->numtextures; nextTextureIndex++ ) { int nextOffset = bmod->textures->dataofs[nextTextureIndex]; @@ -319,7 +317,7 @@ static qboolean Mod_NameImpliesTextureIsAnimated( texture_t *tex ) return true; } -static void Mod_CreateDefaultTexture( texture_t **texture ) +static void Mod_CreateDefaultTexture( model_t *mod, texture_t **texture ) { texture_t *tex; @@ -327,7 +325,7 @@ static void Mod_CreateDefaultTexture( texture_t **texture ) if( !texture || *texture != NULL ) return; - *texture = tex = Mem_Calloc( loadmodel->mempool, sizeof( *tex )); + *texture = tex = Mem_Calloc( mod->mempool, sizeof( *tex )); Q_strncpy( tex->name, REF_DEFAULT_TEXTURE, sizeof( tex->name )); #if !XASH_DEDICATED @@ -947,7 +945,7 @@ converted maps potential may don't support water transparency ================== */ -static qboolean Mod_CheckWaterAlphaSupport( dbspmodel_t *bmod ) +static qboolean Mod_CheckWaterAlphaSupport( model_t *mod, dbspmodel_t *bmod ) { mleaf_t *leaf; int i, j; @@ -958,15 +956,15 @@ static qboolean Mod_CheckWaterAlphaSupport( dbspmodel_t *bmod ) // check all liquid leafs to see if they can see into empty leafs, if any // can we can assume this map supports r_wateralpha - for( i = 0, leaf = loadmodel->leafs; i < loadmodel->numleafs; i++, leaf++ ) + for( i = 0, leaf = mod->leafs; i < mod->numleafs; i++, leaf++ ) { if(( leaf->contents == CONTENTS_WATER || leaf->contents == CONTENTS_SLIME ) && leaf->cluster >= 0 ) { pvs = Mod_DecompressPVS( leaf->compressed_vis, world.visbytes ); - for( j = 0; j < loadmodel->numleafs; j++ ) + for( j = 0; j < mod->numleafs; j++ ) { - if( CHECKVISBIT( pvs, loadmodel->leafs[j].cluster ) && loadmodel->leafs[j].contents == CONTENTS_EMPTY ) + if( CHECKVISBIT( pvs, mod->leafs[j].cluster ) && mod->leafs[j].contents == CONTENTS_EMPTY ) return true; } } @@ -1134,7 +1132,7 @@ Mod_CalcSurfaceExtents Fills in surf->texturemins[] and surf->extents[] ================= */ -static void Mod_CalcSurfaceExtents( msurface_t *surf ) +static void Mod_CalcSurfaceExtents( model_t *mod, msurface_t *surf ) { // this place is VERY critical to precision // keep it as float, don't use double, because it causes issues with lightmap @@ -1143,7 +1141,7 @@ static void Mod_CalcSurfaceExtents( msurface_t *surf ) int bmins[2], bmaxs[2]; int i, j, e, sample_size; mextrasurf_t *info = surf->info; - int facenum = surf - loadmodel->surfaces; + int facenum = surf - mod->surfaces; mtexinfo_t *tex; mvertex_t *v; @@ -1157,13 +1155,13 @@ static void Mod_CalcSurfaceExtents( msurface_t *surf ) for( i = 0; i < surf->numedges; i++ ) { - e = loadmodel->surfedges[surf->firstedge + i]; + e = mod->surfedges[surf->firstedge + i]; - if( e >= loadmodel->numedges || e <= -loadmodel->numedges ) + if( e >= mod->numedges || e <= -mod->numedges ) Host_Error( "Mod_CalcSurfaceExtents: bad edge\n" ); - if( e >= 0 ) v = &loadmodel->vertexes[loadmodel->edges[e].v[0]]; - else v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]]; + if( e >= 0 ) v = &mod->vertexes[mod->edges[e].v[0]]; + else v = &mod->vertexes[mod->edges[-e].v[1]]; for( j = 0; j < 2; j++ ) { @@ -1217,7 +1215,7 @@ Mod_CalcSurfaceBounds fills in surf->mins and surf->maxs ================= */ -static void Mod_CalcSurfaceBounds( msurface_t *surf ) +static void Mod_CalcSurfaceBounds( model_t *mod, msurface_t *surf ) { int i, e; mvertex_t *v; @@ -1226,13 +1224,13 @@ static void Mod_CalcSurfaceBounds( msurface_t *surf ) for( i = 0; i < surf->numedges; i++ ) { - e = loadmodel->surfedges[surf->firstedge + i]; + e = mod->surfedges[surf->firstedge + i]; - if( e >= loadmodel->numedges || e <= -loadmodel->numedges ) + if( e >= mod->numedges || e <= -mod->numedges ) Host_Error( "Mod_CalcSurfaceBounds: bad edge\n" ); - if( e >= 0 ) v = &loadmodel->vertexes[loadmodel->edges[e].v[0]]; - else v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]]; + if( e >= 0 ) v = &mod->vertexes[mod->edges[e].v[0]]; + else v = &mod->vertexes[mod->edges[-e].v[1]]; AddPointToBounds( v->position, surf->info->mins, surf->info->maxs ); } @@ -1244,7 +1242,7 @@ static void Mod_CalcSurfaceBounds( msurface_t *surf ) Mod_CreateFaceBevels ================= */ -static void Mod_CreateFaceBevels( msurface_t *surf ) +static void Mod_CreateFaceBevels( model_t *mod, msurface_t *surf ) { vec3_t delta, edgevec; byte *facebevel; @@ -1260,7 +1258,7 @@ static void Mod_CreateFaceBevels( msurface_t *surf ) else contents = CONTENTS_SOLID; size = sizeof( mfacebevel_t ) + surf->numedges * sizeof( mplane_t ); - facebevel = (byte *)Mem_Calloc( loadmodel->mempool, size ); + facebevel = (byte *)Mem_Calloc( mod->mempool, size ); fb = (mfacebevel_t *)facebevel; facebevel += sizeof( mfacebevel_t ); fb->edges = (mplane_t *)facebevel; @@ -1277,8 +1275,8 @@ static void Mod_CreateFaceBevels( msurface_t *surf ) { mplane_t *dest = &fb->edges[i]; - v0 = Mod_GetVertexByNumber( loadmodel, surf->firstedge + i ); - v1 = Mod_GetVertexByNumber( loadmodel, surf->firstedge + (i + 1) % surf->numedges ); + v0 = Mod_GetVertexByNumber( mod, surf->firstedge + i ); + v1 = Mod_GetVertexByNumber( mod, surf->firstedge + (i + 1) % surf->numedges ); VectorSubtract( v1->position, v0->position, edgevec ); CrossProduct( faceNormal, edgevec, dest->normal ); VectorNormalize( dest->normal ); @@ -1292,7 +1290,7 @@ static void Mod_CreateFaceBevels( msurface_t *surf ) // compute face radius for( i = 0; i < surf->numedges; i++ ) { - v0 = Mod_GetVertexByNumber( loadmodel, surf->firstedge + i ); + v0 = Mod_GetVertexByNumber( mod, surf->firstedge + i ); VectorSubtract( v0->position, fb->origin, delta ); radius = DotProduct( delta, delta ); fb->radius = Q_max( radius, fb->radius ); @@ -1388,24 +1386,24 @@ Mod_MakeHull0 Duplicate the drawing hull structure as a clipping hull ================= */ -static void Mod_MakeHull0( void ) +static void Mod_MakeHull0( model_t *mod ) { mnode_t *in, *child; mclipnode_t *out; hull_t *hull; int i, j; - hull = &loadmodel->hulls[0]; - hull->clipnodes = out = Mem_Malloc( loadmodel->mempool, loadmodel->numnodes * sizeof( *out )); - in = loadmodel->nodes; + hull = &mod->hulls[0]; + hull->clipnodes = out = Mem_Malloc( mod->mempool, mod->numnodes * sizeof( *out )); + in = mod->nodes; hull->firstclipnode = 0; - hull->lastclipnode = loadmodel->numnodes - 1; - hull->planes = loadmodel->planes; + hull->lastclipnode = mod->numnodes - 1; + hull->planes = mod->planes; - for( i = 0; i < loadmodel->numnodes; i++, out++, in++ ) + for( i = 0; i < mod->numnodes; i++, out++, in++ ) { - out->planenum = in->plane - loadmodel->planes; + out->planenum = in->plane - mod->planes; for( j = 0; j < 2; j++ ) { @@ -1413,7 +1411,7 @@ static void Mod_MakeHull0( void ) if( child->contents < 0 ) out->children[j] = child->contents; - else out->children[j] = child - loadmodel->nodes; + else out->children[j] = child - mod->nodes; } } } @@ -1477,7 +1475,7 @@ static void Mod_SetupHull( dbspmodel_t *bmod, model_t *mod, poolhandle_t mempool Mod_LoadColoredLighting ================= */ -static qboolean Mod_LoadColoredLighting( dbspmodel_t *bmod ) +static qboolean Mod_LoadColoredLighting( model_t *mod, dbspmodel_t *bmod ) { char modelname[64]; char path[64]; @@ -1485,11 +1483,11 @@ static qboolean Mod_LoadColoredLighting( dbspmodel_t *bmod ) fs_offset_t litdatasize; byte *in; - COM_FileBase( loadmodel->name, modelname, sizeof( modelname )); + COM_FileBase( mod->name, modelname, sizeof( modelname )); Q_snprintf( path, sizeof( path ), "maps/%s.lit", modelname ); // make sure what deluxemap is actual - if( !COM_CompareFileTime( path, loadmodel->name, &iCompare )) + if( !COM_CompareFileTime( path, mod->name, &iCompare )) return false; if( iCompare < 0 ) // this may happens if level-designer used -onlyents key for hlcsg @@ -1515,9 +1513,9 @@ static qboolean Mod_LoadColoredLighting( dbspmodel_t *bmod ) return false; } - loadmodel->lightdata = Mem_Malloc( loadmodel->mempool, litdatasize ); - memcpy( loadmodel->lightdata, in + 8, litdatasize ); - SetBits( loadmodel->flags, MODEL_COLORED_LIGHTING ); + mod->lightdata = Mem_Malloc( mod->mempool, litdatasize ); + memcpy( mod->lightdata, in + 8, litdatasize ); + SetBits( mod->flags, MODEL_COLORED_LIGHTING ); bmod->lightdatasize = litdatasize; Mem_Free( in ); @@ -1529,7 +1527,7 @@ static qboolean Mod_LoadColoredLighting( dbspmodel_t *bmod ) Mod_LoadDeluxemap ================= */ -static void Mod_LoadDeluxemap( dbspmodel_t *bmod ) +static void Mod_LoadDeluxemap( model_t *mod, dbspmodel_t *bmod ) { char modelname[64]; fs_offset_t deluxdatasize; @@ -1540,11 +1538,11 @@ static void Mod_LoadDeluxemap( dbspmodel_t *bmod ) if( !FBitSet( host.features, ENGINE_LOAD_DELUXEDATA )) return; - COM_FileBase( loadmodel->name, modelname, sizeof( modelname )); + COM_FileBase( mod->name, modelname, sizeof( modelname )); Q_snprintf( path, sizeof( path ), "maps/%s.dlit", modelname ); // make sure what deluxemap is actual - if( !COM_CompareFileTime( path, loadmodel->name, &iCompare )) + if( !COM_CompareFileTime( path, mod->name, &iCompare )) return; if( iCompare < 0 ) // this may happens if level-designer used -onlyents key for hlcsg @@ -1570,7 +1568,7 @@ static void Mod_LoadDeluxemap( dbspmodel_t *bmod ) return; } - bmod->deluxedata_out = Mem_Malloc( loadmodel->mempool, deluxdatasize ); + bmod->deluxedata_out = Mem_Malloc( mod->mempool, deluxdatasize ); memcpy( bmod->deluxedata_out, in + 8, deluxdatasize ); bmod->deluxdatasize = deluxdatasize; Mem_Free( in ); @@ -1584,22 +1582,21 @@ duplicate the basic information for embedded submodels ================= */ -static void Mod_SetupSubmodels( dbspmodel_t *bmod ) +static void Mod_SetupSubmodels( model_t *mod, dbspmodel_t *bmod ) { qboolean colored = false; poolhandle_t mempool; char *ents; - model_t *mod; dmodel_t *bm; + const char *name = mod->name; int i, j; - ents = loadmodel->entities; - mempool = loadmodel->mempool; - if( FBitSet( loadmodel->flags, MODEL_COLORED_LIGHTING )) + ents = mod->entities; + mempool = mod->mempool; + if( FBitSet( mod->flags, MODEL_COLORED_LIGHTING )) colored = true; - mod = loadmodel; - loadmodel->numframes = 2; // regular and alternate animation + mod->numframes = 2; // regular and alternate animation // set up the submodels for( i = 0; i < mod->numsubmodels; i++ ) @@ -1642,7 +1639,7 @@ static void Mod_SetupSubmodels( dbspmodel_t *bmod ) SetBits( mod->flags, MODEL_HAS_ORIGIN ); #ifdef HACKS_RELATED_HLMODS // c2a1 doesn't have origin brush it's just placed at center of the level - if( !Q_stricmp( loadmodel->name, "maps/c2a1.bsp" ) && ( i == 11 )) + if( !Q_stricmp( name, "maps/c2a1.bsp" ) && ( i == 11 )) SetBits( mod->flags, MODEL_HAS_ORIGIN ); #endif } @@ -1665,14 +1662,15 @@ static void Mod_SetupSubmodels( dbspmodel_t *bmod ) if( i < mod->numsubmodels - 1 ) { char name[8]; + model_t *submod; // duplicate the basic information Q_snprintf( name, sizeof( name ), "*%i", i + 1 ); - loadmodel = Mod_FindName( name, true ); - *loadmodel = *mod; - Q_strncpy( loadmodel->name, name, sizeof( loadmodel->name )); - loadmodel->mempool = 0; - mod = loadmodel; + submod = Mod_FindName( name, true ); + *submod = *mod; + Q_strncpy( submod->name, name, sizeof( submod->name )); + submod->mempool = 0; + mod = submod; } } @@ -1692,17 +1690,17 @@ static void Mod_SetupSubmodels( dbspmodel_t *bmod ) Mod_LoadSubmodels ================= */ -static void Mod_LoadSubmodels( dbspmodel_t *bmod ) +static void Mod_LoadSubmodels( model_t *mod, dbspmodel_t *bmod ) { dmodel_t *in, *out; int oldmaxfaces; int i, j; // allocate extradata for each dmodel_t - out = Mem_Malloc( loadmodel->mempool, bmod->numsubmodels * sizeof( *out )); + out = Mem_Malloc( mod->mempool, bmod->numsubmodels * sizeof( *out )); - loadmodel->numsubmodels = bmod->numsubmodels; - loadmodel->submodels = out; + mod->numsubmodels = bmod->numsubmodels; + mod->submodels = out; in = bmod->submodels; if( bmod->isworld ) @@ -1750,7 +1748,7 @@ static void Mod_LoadSubmodels( dbspmodel_t *bmod ) Mod_LoadEntities ================= */ -static void Mod_LoadEntities( dbspmodel_t *bmod ) +static void Mod_LoadEntities( model_t *mod, dbspmodel_t *bmod ) { byte *entpatch = NULL; char token[MAX_TOKEN]; @@ -1765,11 +1763,11 @@ static void Mod_LoadEntities( dbspmodel_t *bmod ) size_t ft1, ft2; // world is check for entfile too - Q_strncpy( entfilename, loadmodel->name, sizeof( entfilename )); + Q_strncpy( entfilename, mod->name, sizeof( entfilename )); COM_ReplaceExtension( entfilename, ".ent", sizeof( entfilename )); // make sure what entity patch is never than bsp - ft1 = FS_FileTime( loadmodel->name, false ); + ft1 = FS_FileTime( mod->name, false ); ft2 = FS_FileTime( entfilename, true ); if( ft2 != -1 ) @@ -1788,12 +1786,12 @@ static void Mod_LoadEntities( dbspmodel_t *bmod ) } // make sure what we really has terminator - loadmodel->entities = Mem_Calloc( loadmodel->mempool, bmod->entdatasize + 1 ); - memcpy( loadmodel->entities, bmod->entdata, bmod->entdatasize ); // moving to private model pool + mod->entities = Mem_Calloc( mod->mempool, bmod->entdatasize + 1 ); + memcpy( mod->entities, bmod->entdata, bmod->entdatasize ); // moving to private model pool if( entpatch ) Mem_Free( entpatch ); // release entpatch if present if( !bmod->isworld ) return; - pfile = (char *)loadmodel->entities; + pfile = (char *)mod->entities; world.generator[0] = '\0'; world.compiler[0] = '\0'; world.message[0] = '\0'; @@ -1865,15 +1863,15 @@ static void Mod_LoadEntities( dbspmodel_t *bmod ) Mod_LoadPlanes ================= */ -static void Mod_LoadPlanes( dbspmodel_t *bmod ) +static void Mod_LoadPlanes( model_t *mod, dbspmodel_t *bmod ) { dplane_t *in; mplane_t *out; int i, j; in = bmod->planes; - loadmodel->planes = out = Mem_Malloc( loadmodel->mempool, bmod->numplanes * sizeof( *out )); - loadmodel->numplanes = bmod->numplanes; + mod->planes = out = Mem_Malloc( mod->mempool, bmod->numplanes * sizeof( *out )); + mod->numplanes = bmod->numplanes; for( i = 0; i < bmod->numplanes; i++, in++, out++ ) { @@ -1899,15 +1897,15 @@ static void Mod_LoadPlanes( dbspmodel_t *bmod ) Mod_LoadVertexes ================= */ -static void Mod_LoadVertexes( dbspmodel_t *bmod ) +static void Mod_LoadVertexes( model_t *mod, dbspmodel_t *bmod ) { dvertex_t *in; mvertex_t *out; int i; in = bmod->vertexes; - out = loadmodel->vertexes = Mem_Malloc( loadmodel->mempool, bmod->numvertexes * sizeof( mvertex_t )); - loadmodel->numvertexes = bmod->numvertexes; + out = mod->vertexes = Mem_Malloc( mod->mempool, bmod->numvertexes * sizeof( mvertex_t )); + mod->numvertexes = bmod->numvertexes; if( bmod->isworld ) ClearBounds( world.mins, world.maxs ); @@ -1935,13 +1933,13 @@ static void Mod_LoadVertexes( dbspmodel_t *bmod ) Mod_LoadEdges ================= */ -static void Mod_LoadEdges( dbspmodel_t *bmod ) +static void Mod_LoadEdges( model_t *mod, dbspmodel_t *bmod ) { medge_t *out; int i; - loadmodel->edges = out = Mem_Malloc( loadmodel->mempool, bmod->numedges * sizeof( medge_t )); - loadmodel->numedges = bmod->numedges; + mod->edges = out = Mem_Malloc( mod->mempool, bmod->numedges * sizeof( medge_t )); + mod->numedges = bmod->numedges; if( bmod->version == QBSP2_VERSION ) { @@ -1970,11 +1968,11 @@ static void Mod_LoadEdges( dbspmodel_t *bmod ) Mod_LoadSurfEdges ================= */ -static void Mod_LoadSurfEdges( dbspmodel_t *bmod ) +static void Mod_LoadSurfEdges( model_t *mod, dbspmodel_t *bmod ) { - loadmodel->surfedges = Mem_Malloc( loadmodel->mempool, bmod->numsurfedges * sizeof( dsurfedge_t )); - memcpy( loadmodel->surfedges, bmod->surfedges, bmod->numsurfedges * sizeof( dsurfedge_t )); - loadmodel->numsurfedges = bmod->numsurfedges; + mod->surfedges = Mem_Malloc( mod->mempool, bmod->numsurfedges * sizeof( dsurfedge_t )); + memcpy( mod->surfedges, bmod->surfedges, bmod->numsurfedges * sizeof( dsurfedge_t )); + mod->numsurfedges = bmod->numsurfedges; } /* @@ -1982,13 +1980,13 @@ static void Mod_LoadSurfEdges( dbspmodel_t *bmod ) Mod_LoadMarkSurfaces ================= */ -static void Mod_LoadMarkSurfaces( dbspmodel_t *bmod ) +static void Mod_LoadMarkSurfaces( model_t *mod, dbspmodel_t *bmod ) { msurface_t **out; int i; - loadmodel->marksurfaces = out = Mem_Malloc( loadmodel->mempool, bmod->nummarkfaces * sizeof( *out )); - loadmodel->nummarksurfaces = bmod->nummarkfaces; + mod->marksurfaces = out = Mem_Malloc( mod->mempool, bmod->nummarkfaces * sizeof( *out )); + mod->nummarksurfaces = bmod->nummarkfaces; if( bmod->version == QBSP2_VERSION ) { @@ -1996,9 +1994,9 @@ static void Mod_LoadMarkSurfaces( dbspmodel_t *bmod ) for( i = 0; i < bmod->nummarkfaces; i++, in++ ) { - if( *in < 0 || *in >= loadmodel->numsurfaces ) - Host_Error( "Mod_LoadMarkFaces: bad surface number in '%s'\n", loadmodel->name ); - out[i] = loadmodel->surfaces + *in; + if( *in < 0 || *in >= mod->numsurfaces ) + Host_Error( "Mod_LoadMarkFaces: bad surface number in '%s'\n", mod->name ); + out[i] = mod->surfaces + *in; } } else @@ -2007,14 +2005,14 @@ static void Mod_LoadMarkSurfaces( dbspmodel_t *bmod ) for( i = 0; i < bmod->nummarkfaces; i++, in++ ) { - if( *in < 0 || *in >= loadmodel->numsurfaces ) - Host_Error( "Mod_LoadMarkFaces: bad surface number in '%s'\n", loadmodel->name ); - out[i] = loadmodel->surfaces + *in; + if( *in < 0 || *in >= mod->numsurfaces ) + Host_Error( "Mod_LoadMarkFaces: bad surface number in '%s'\n", mod->name ); + out[i] = mod->surfaces + *in; } } } -static void Mod_LoadTextureData( dbspmodel_t *bmod, int textureIndex ) +static void Mod_LoadTextureData( model_t *mod, dbspmodel_t *bmod, int textureIndex ) { #if !XASH_DEDICATED texture_t *texture = NULL; @@ -2028,13 +2026,13 @@ static void Mod_LoadTextureData( dbspmodel_t *bmod, int textureIndex ) if( Host_IsDedicated( )) return; - texture = loadmodel->textures[textureIndex]; + texture = mod->textures[textureIndex]; mipTex = Mod_GetMipTexForTexture( bmod, textureIndex ); if( FBitSet( host.features, ENGINE_IMPROVED_LINETRACE ) && mipTex->name[0] == '{' ) SetBits( txFlags, TF_KEEP_SOURCE ); // Paranoia2 texture alpha-tracing - usesCustomPalette = Mod_CalcMipTexUsesCustomPalette( bmod, textureIndex ); + usesCustomPalette = Mod_CalcMipTexUsesCustomPalette( mod, bmod, textureIndex ); // check for multi-layered sky texture (quake1 specific) if( bmod->isworld && Q_strncmp( mipTex->name, "sky", 3 ) == 0 && ( mipTex->width / mipTex->height ) == 2 ) @@ -2122,12 +2120,12 @@ static void Mod_LoadTextureData( dbspmodel_t *bmod, int textureIndex ) #endif // !XASH_DEDICATED } -static void Mod_LoadTexture( dbspmodel_t *bmod, int textureIndex ) +static void Mod_LoadTexture( model_t *mod, dbspmodel_t *bmod, int textureIndex ) { texture_t *texture; mip_t *mipTex; - if( textureIndex < 0 || textureIndex >= loadmodel->numtextures ) + if( textureIndex < 0 || textureIndex >= mod->numtextures ) return; mipTex = Mod_GetMipTexForTexture( bmod, textureIndex ); @@ -2136,15 +2134,15 @@ static void Mod_LoadTexture( dbspmodel_t *bmod, int textureIndex ) { // No data for this texture. // Create default texture (some mods require this). - Mod_CreateDefaultTexture( &loadmodel->textures[textureIndex] ); + Mod_CreateDefaultTexture( mod, &mod->textures[textureIndex] ); return; } if( mipTex->name[0] == '\0' ) Q_snprintf( mipTex->name, sizeof( mipTex->name ), "miptex_%i", textureIndex ); - texture = (texture_t *)Mem_Calloc( loadmodel->mempool, sizeof( *texture )); - loadmodel->textures[textureIndex] = texture; + texture = (texture_t *)Mem_Calloc( mod->mempool, sizeof( *texture )); + mod->textures[textureIndex] = texture; // Ensure texture name is lowercase. Q_strnlwr( mipTex->name, texture->name, sizeof( texture->name )); @@ -2152,18 +2150,18 @@ static void Mod_LoadTexture( dbspmodel_t *bmod, int textureIndex ) texture->width = mipTex->width; texture->height = mipTex->height; - Mod_LoadTextureData( bmod, textureIndex ); + Mod_LoadTextureData( mod, bmod, textureIndex ); } -static void Mod_LoadAllTextures( dbspmodel_t *bmod ) +static void Mod_LoadAllTextures( model_t *mod, dbspmodel_t *bmod ) { int i; - for( i = 0; i < loadmodel->numtextures; i++ ) - Mod_LoadTexture( bmod, i ); + for( i = 0; i < mod->numtextures; i++ ) + Mod_LoadTexture( mod, bmod, i ); } -static void Mod_SequenceAnimatedTexture( int baseTextureIndex ) +static void Mod_SequenceAnimatedTexture( model_t *mod, int baseTextureIndex ) { texture_t *anims[10]; texture_t *altanims[10]; @@ -2172,10 +2170,10 @@ static void Mod_SequenceAnimatedTexture( int baseTextureIndex ) int altmax = 0; int candidateIndex; - if( baseTextureIndex < 0 || baseTextureIndex >= loadmodel->numtextures ) + if( baseTextureIndex < 0 || baseTextureIndex >= mod->numtextures ) return; - baseTexture = loadmodel->textures[baseTextureIndex]; + baseTexture = mod->textures[baseTextureIndex]; if( !Mod_NameImpliesTextureIsAnimated( baseTexture )) return; @@ -2206,9 +2204,9 @@ static void Mod_SequenceAnimatedTexture( int baseTextureIndex ) } // Now search the rest of the textures to find all other frames. - for( candidateIndex = baseTextureIndex + 1; candidateIndex < loadmodel->numtextures; candidateIndex++ ) + for( candidateIndex = baseTextureIndex + 1; candidateIndex < mod->numtextures; candidateIndex++ ) { - texture_t *altTexture = loadmodel->textures[candidateIndex]; + texture_t *altTexture = mod->textures[candidateIndex]; if( !Mod_NameImpliesTextureIsAnimated( altTexture )) continue; @@ -2289,12 +2287,12 @@ static void Mod_SequenceAnimatedTexture( int baseTextureIndex ) } } -static void Mod_SequenceAllAnimatedTextures( void ) +static void Mod_SequenceAllAnimatedTextures( model_t *mod ) { int i; - for( i = 0; i < loadmodel->numtextures; i++ ) - Mod_SequenceAnimatedTexture( i ); + for( i = 0; i < mod->numtextures; i++ ) + Mod_SequenceAnimatedTexture( mod, i ); } /* @@ -2302,7 +2300,7 @@ static void Mod_SequenceAllAnimatedTextures( void ) Mod_LoadTextures ================= */ -static void Mod_LoadTextures( dbspmodel_t *bmod ) +static void Mod_LoadTextures( model_t *mod, dbspmodel_t *bmod ) { dmiptexlump_t *lump; @@ -2320,15 +2318,15 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) if( bmod->texdatasize < 1 || !lump || lump->nummiptex < 1 ) { // no textures - loadmodel->textures = NULL; + mod->textures = NULL; return; } - loadmodel->textures = (texture_t **)Mem_Calloc( loadmodel->mempool, lump->nummiptex * sizeof( texture_t * )); - loadmodel->numtextures = lump->nummiptex; + mod->textures = (texture_t **)Mem_Calloc( mod->mempool, lump->nummiptex * sizeof( texture_t * )); + mod->numtextures = lump->nummiptex; - Mod_LoadAllTextures( bmod ); - Mod_SequenceAllAnimatedTextures(); + Mod_LoadAllTextures( mod, bmod ); + Mod_SequenceAllAnimatedTextures( mod ); } /* @@ -2336,7 +2334,7 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) Mod_LoadTexInfo ================= */ -static void Mod_LoadTexInfo( dbspmodel_t *bmod ) +static void Mod_LoadTexInfo( model_t *mod, dbspmodel_t *bmod ) { mfaceinfo_t *fout, *faceinfo; int i, j, k, miptex; @@ -2345,7 +2343,7 @@ static void Mod_LoadTexInfo( dbspmodel_t *bmod ) dtexinfo_t *in; // trying to load faceinfo - faceinfo = fout = Mem_Calloc( loadmodel->mempool, bmod->numfaceinfo * sizeof( *fout )); + faceinfo = fout = Mem_Calloc( mod->mempool, bmod->numfaceinfo * sizeof( *fout )); fin = bmod->faceinfo; for( i = 0; i < bmod->numfaceinfo; i++, fin++, fout++ ) @@ -2356,8 +2354,8 @@ static void Mod_LoadTexInfo( dbspmodel_t *bmod ) fout->groupid = fin->groupid; } - loadmodel->texinfo = out = Mem_Calloc( loadmodel->mempool, bmod->numtexinfo * sizeof( *out )); - loadmodel->numtexinfo = bmod->numtexinfo; + mod->texinfo = out = Mem_Calloc( mod->mempool, bmod->numtexinfo * sizeof( *out )); + mod->numtexinfo = bmod->numtexinfo; in = bmod->texinfo; for( i = 0; i < bmod->numtexinfo; i++, in++, out++ ) @@ -2367,9 +2365,9 @@ static void Mod_LoadTexInfo( dbspmodel_t *bmod ) out->vecs[j][k] = in->vecs[j][k]; miptex = in->miptex; - if( miptex < 0 || miptex > loadmodel->numtextures ) + if( miptex < 0 || miptex > mod->numtextures ) miptex = 0; // this is possible? - out->texture = loadmodel->textures[miptex]; + out->texture = mod->textures[miptex]; out->flags = in->flags; // make sure what faceinfo is really exist @@ -2383,7 +2381,7 @@ static void Mod_LoadTexInfo( dbspmodel_t *bmod ) Mod_LoadSurfaces ================= */ -static void Mod_LoadSurfaces( dbspmodel_t *bmod ) +static void Mod_LoadSurfaces( model_t *mod, dbspmodel_t *bmod ) { int test_lightsize = -1; int next_lightofs = -1; @@ -2392,9 +2390,9 @@ static void Mod_LoadSurfaces( dbspmodel_t *bmod ) mextrasurf_t *info; msurface_t *out; - loadmodel->surfaces = out = Mem_Calloc( loadmodel->mempool, bmod->numsurfaces * sizeof( msurface_t )); - info = Mem_Calloc( loadmodel->mempool, bmod->numsurfaces * sizeof( mextrasurf_t )); - loadmodel->numsurfaces = bmod->numsurfaces; + mod->surfaces = out = Mem_Calloc( mod->mempool, bmod->numsurfaces * sizeof( msurface_t )); + info = Mem_Calloc( mod->mempool, bmod->numsurfaces * sizeof( mextrasurf_t )); + mod->numsurfaces = bmod->numsurfaces; // predict samplecount based on bspversion if( bmod->version == Q1BSP_VERSION || bmod->version == QBSP2_VERSION ) @@ -2413,13 +2411,13 @@ static void Mod_LoadSurfaces( dbspmodel_t *bmod ) { dface32_t *in = &bmod->surfaces32[i]; - if(( in->firstedge + in->numedges ) > loadmodel->numsurfedges ) + if(( in->firstedge + in->numedges ) > mod->numsurfedges ) continue; // corrupted level? out->firstedge = in->firstedge; out->numedges = in->numedges; if( in->side ) SetBits( out->flags, SURF_PLANEBACK ); - out->plane = loadmodel->planes + in->planenum; - out->texinfo = loadmodel->texinfo + in->texinfo; + out->plane = mod->planes + in->planenum; + out->texinfo = mod->texinfo + in->texinfo; for( j = 0; j < MAXLIGHTMAPS; j++ ) out->styles[j] = in->styles[j]; @@ -2429,7 +2427,7 @@ static void Mod_LoadSurfaces( dbspmodel_t *bmod ) { dface_t *in = &bmod->surfaces[i]; - if(( in->firstedge + in->numedges ) > loadmodel->numsurfedges ) + if(( in->firstedge + in->numedges ) > mod->numsurfedges ) { Con_Reportf( S_ERROR "bad surface %i from %zu\n", i, bmod->numsurfaces ); continue; @@ -2438,8 +2436,8 @@ static void Mod_LoadSurfaces( dbspmodel_t *bmod ) out->firstedge = in->firstedge; out->numedges = in->numedges; if( in->side ) SetBits( out->flags, SURF_PLANEBACK ); - out->plane = loadmodel->planes + in->planenum; - out->texinfo = loadmodel->texinfo + in->texinfo; + out->plane = mod->planes + in->planenum; + out->texinfo = mod->texinfo + in->texinfo; for( j = 0; j < MAXLIGHTMAPS; j++ ) out->styles[j] = in->styles[j]; @@ -2476,9 +2474,9 @@ static void Mod_LoadSurfaces( dbspmodel_t *bmod ) if( FBitSet( out->texinfo->flags, TEX_SPECIAL )) SetBits( out->flags, SURF_DRAWTILED ); - Mod_CalcSurfaceBounds( out ); - Mod_CalcSurfaceExtents( out ); - Mod_CreateFaceBevels( out ); + Mod_CalcSurfaceBounds( mod, out ); + Mod_CalcSurfaceExtents( mod, out ); + Mod_CreateFaceBevels( mod, out ); // grab the second sample to detect colored lighting if( test_lightsize > 0 && lightofs != -1 ) @@ -2507,7 +2505,7 @@ static void Mod_LoadSurfaces( dbspmodel_t *bmod ) #if !XASH_DEDICATED // TODO: Do we need subdivide on server? if( FBitSet( out->flags, SURF_DRAWTURB ) && !Host_IsDedicated() ) - ref.dllFuncs.GL_SubdivideSurface( loadmodel, out ); // cut up polygon for warps + ref.dllFuncs.GL_SubdivideSurface( mod, out ); // cut up polygon for warps #endif } @@ -2537,15 +2535,15 @@ static void Mod_LoadSurfaces( dbspmodel_t *bmod ) Mod_LoadNodes ================= */ -static void Mod_LoadNodes( dbspmodel_t *bmod ) +static void Mod_LoadNodes( model_t *mod, dbspmodel_t *bmod ) { mnode_t *out; int i, j, p; - loadmodel->nodes = out = (mnode_t *)Mem_Calloc( loadmodel->mempool, bmod->numnodes * sizeof( *out )); - loadmodel->numnodes = bmod->numnodes; + mod->nodes = out = (mnode_t *)Mem_Calloc( mod->mempool, bmod->numnodes * sizeof( *out )); + mod->numnodes = bmod->numnodes; - for( i = 0; i < loadmodel->numnodes; i++, out++ ) + for( i = 0; i < mod->numnodes; i++, out++ ) { if( bmod->version == QBSP2_VERSION ) { @@ -2558,15 +2556,15 @@ static void Mod_LoadNodes( dbspmodel_t *bmod ) } p = in->planenum; - out->plane = loadmodel->planes + p; + out->plane = mod->planes + p; out->firstsurface = in->firstface; out->numsurfaces = in->numfaces; for( j = 0; j < 2; j++ ) { p = in->children[j]; - if( p >= 0 ) out->children[j] = loadmodel->nodes + p; - else out->children[j] = (mnode_t *)(loadmodel->leafs + ( -1 - p )); + if( p >= 0 ) out->children[j] = mod->nodes + p; + else out->children[j] = (mnode_t *)(mod->leafs + ( -1 - p )); } } else @@ -2580,21 +2578,21 @@ static void Mod_LoadNodes( dbspmodel_t *bmod ) } p = in->planenum; - out->plane = loadmodel->planes + p; + out->plane = mod->planes + p; out->firstsurface = in->firstface; out->numsurfaces = in->numfaces; for( j = 0; j < 2; j++ ) { p = in->children[j]; - if( p >= 0 ) out->children[j] = loadmodel->nodes + p; - else out->children[j] = (mnode_t *)(loadmodel->leafs + ( -1 - p )); + if( p >= 0 ) out->children[j] = mod->nodes + p; + else out->children[j] = (mnode_t *)(mod->leafs + ( -1 - p )); } } } // sets nodes and leafs - Mod_SetParent( loadmodel->nodes, NULL ); + Mod_SetParent( mod->nodes, NULL ); } /* @@ -2602,18 +2600,18 @@ static void Mod_LoadNodes( dbspmodel_t *bmod ) Mod_LoadLeafs ================= */ -static void Mod_LoadLeafs( dbspmodel_t *bmod ) +static void Mod_LoadLeafs( model_t *mod, dbspmodel_t *bmod ) { mleaf_t *out; int i, j, p; int visclusters = 0; - loadmodel->leafs = out = (mleaf_t *)Mem_Calloc( loadmodel->mempool, bmod->numleafs * sizeof( *out )); - loadmodel->numleafs = bmod->numleafs; + mod->leafs = out = (mleaf_t *)Mem_Calloc( mod->mempool, bmod->numleafs * sizeof( *out )); + mod->numleafs = bmod->numleafs; if( bmod->isworld ) { - visclusters = loadmodel->submodels[0].visleafs; + visclusters = mod->submodels[0].visleafs; world.visbytes = (visclusters + 7) >> 3; world.fatbytes = (visclusters + 31) >> 3; refState.visbytes = world.visbytes; @@ -2637,7 +2635,7 @@ static void Mod_LoadLeafs( dbspmodel_t *bmod ) for( j = 0; j < 4; j++ ) out->ambient_sound_level[j] = in->ambient_level[j]; - out->firstmarksurface = loadmodel->marksurfaces + in->firstmarksurface; + out->firstmarksurface = mod->marksurfaces + in->firstmarksurface; out->nummarksurfaces = in->nummarksurfaces; } else @@ -2656,7 +2654,7 @@ static void Mod_LoadLeafs( dbspmodel_t *bmod ) for( j = 0; j < 4; j++ ) out->ambient_sound_level[j] = in->ambient_level[j]; - out->firstmarksurface = loadmodel->marksurfaces + in->firstmarksurface; + out->firstmarksurface = mod->marksurfaces + in->firstmarksurface; out->nummarksurfaces = in->nummarksurfaces; } @@ -2668,17 +2666,17 @@ static void Mod_LoadLeafs( dbspmodel_t *bmod ) out->cluster = -1; // ignore visofs errors on leaf 0 (solid) - if( p >= 0 && out->cluster >= 0 && loadmodel->visdata ) + if( p >= 0 && out->cluster >= 0 && mod->visdata ) { if( p < bmod->visdatasize ) - out->compressed_vis = loadmodel->visdata + p; + out->compressed_vis = mod->visdata + p; else Con_Reportf( S_WARN "Mod_LoadLeafs: invalid visofs for leaf #%i\n", i ); } } else out->cluster = -1; // no visclusters on bmodels if( p == -1 ) out->compressed_vis = NULL; - else out->compressed_vis = loadmodel->visdata + p; + else out->compressed_vis = mod->visdata + p; // gl underwater warp if( out->contents != CONTENTS_EMPTY ) @@ -2691,11 +2689,11 @@ static void Mod_LoadLeafs( dbspmodel_t *bmod ) } } - if( bmod->isworld && loadmodel->leafs[0].contents != CONTENTS_SOLID ) - Host_Error( "Mod_LoadLeafs: Map %s has leaf 0 is not CONTENTS_SOLID\n", loadmodel->name ); + if( bmod->isworld && mod->leafs[0].contents != CONTENTS_SOLID ) + Host_Error( "Mod_LoadLeafs: Map %s has leaf 0 is not CONTENTS_SOLID\n", mod->name ); // do some final things for world - if( bmod->isworld && Mod_CheckWaterAlphaSupport( bmod )) + if( bmod->isworld && Mod_CheckWaterAlphaSupport( mod, bmod )) SetBits( world.flags, FWORLD_WATERALPHA ); } @@ -2704,12 +2702,12 @@ static void Mod_LoadLeafs( dbspmodel_t *bmod ) Mod_LoadClipnodes ================= */ -static void Mod_LoadClipnodes( dbspmodel_t *bmod ) +static void Mod_LoadClipnodes( model_t *mod, dbspmodel_t *bmod ) { dclipnode32_t *out; int i; - bmod->clipnodes_out = out = (dclipnode32_t *)Mem_Malloc( loadmodel->mempool, bmod->numclipnodes * sizeof( *out )); + bmod->clipnodes_out = out = (dclipnode32_t *)Mem_Malloc( mod->mempool, bmod->numclipnodes * sizeof( *out )); if(( bmod->version == QBSP2_VERSION ) || ( bmod->version == HLBSP_VERSION && bmod->isbsp30ext && bmod->numclipnodes >= MAX_MAP_CLIPNODES_HLBSP )) { @@ -2741,8 +2739,8 @@ static void Mod_LoadClipnodes( dbspmodel_t *bmod ) } } - // FIXME: fill loadmodel->clipnodes? - loadmodel->numclipnodes = bmod->numclipnodes; + // FIXME: fill mod->clipnodes? + mod->numclipnodes = bmod->numclipnodes; } /* @@ -2750,10 +2748,10 @@ static void Mod_LoadClipnodes( dbspmodel_t *bmod ) Mod_LoadVisibility ================= */ -static void Mod_LoadVisibility( dbspmodel_t *bmod ) +static void Mod_LoadVisibility( model_t *mod, dbspmodel_t *bmod ) { - loadmodel->visdata = Mem_Malloc( loadmodel->mempool, bmod->visdatasize ); - memcpy( loadmodel->visdata, bmod->visdata, bmod->visdatasize ); + mod->visdata = Mem_Malloc( mod->mempool, bmod->visdatasize ); + memcpy( mod->visdata, bmod->visdata, bmod->visdatasize ); } /* @@ -2761,17 +2759,17 @@ static void Mod_LoadVisibility( dbspmodel_t *bmod ) Mod_LoadLightVecs ================= */ -static void Mod_LoadLightVecs( dbspmodel_t *bmod ) +static void Mod_LoadLightVecs( model_t *mod, dbspmodel_t *bmod ) { if( bmod->deluxdatasize != bmod->lightdatasize ) { if( bmod->deluxdatasize > 0 ) Con_Printf( S_ERROR "Mod_LoadLightVecs: has mismatched size (%zu should be %zu)\n", bmod->deluxdatasize, bmod->lightdatasize ); - else Mod_LoadDeluxemap( bmod ); // old method + else Mod_LoadDeluxemap( mod, bmod ); // old method return; } - bmod->deluxedata_out = Mem_Malloc( loadmodel->mempool, bmod->deluxdatasize ); + bmod->deluxedata_out = Mem_Malloc( mod->mempool, bmod->deluxdatasize ); memcpy( bmod->deluxedata_out, bmod->deluxdata, bmod->deluxdatasize ); } @@ -2780,7 +2778,7 @@ static void Mod_LoadLightVecs( dbspmodel_t *bmod ) Mod_LoadShadowmap ================= */ -static void Mod_LoadShadowmap( dbspmodel_t *bmod ) +static void Mod_LoadShadowmap( model_t *mod, dbspmodel_t *bmod ) { if( bmod->shadowdatasize != ( bmod->lightdatasize / 3 )) { @@ -2789,7 +2787,7 @@ static void Mod_LoadShadowmap( dbspmodel_t *bmod ) return; } - bmod->shadowdata_out = Mem_Malloc( loadmodel->mempool, bmod->shadowdatasize ); + bmod->shadowdata_out = Mem_Malloc( mod->mempool, bmod->shadowdatasize ); memcpy( bmod->shadowdata_out, bmod->shadowdata, bmod->shadowdatasize ); } @@ -2798,7 +2796,7 @@ static void Mod_LoadShadowmap( dbspmodel_t *bmod ) Mod_LoadLighting ================= */ -static void Mod_LoadLighting( dbspmodel_t *bmod ) +static void Mod_LoadLighting( model_t *mod, dbspmodel_t *bmod ) { int i, lightofs; msurface_t *surf; @@ -2811,9 +2809,9 @@ static void Mod_LoadLighting( dbspmodel_t *bmod ) switch( bmod->lightmap_samples ) { case 1: - if( !Mod_LoadColoredLighting( bmod )) + if( !Mod_LoadColoredLighting( mod, bmod )) { - loadmodel->lightdata = out = (color24 *)Mem_Malloc( loadmodel->mempool, bmod->lightdatasize * sizeof( color24 )); + mod->lightdata = out = (color24 *)Mem_Malloc( mod->mempool, bmod->lightdatasize * sizeof( color24 )); in = bmod->lightdata; // expand the white lighting data @@ -2822,9 +2820,9 @@ static void Mod_LoadLighting( dbspmodel_t *bmod ) } break; case 3: // load colored lighting - loadmodel->lightdata = Mem_Malloc( loadmodel->mempool, bmod->lightdatasize ); - memcpy( loadmodel->lightdata, bmod->lightdata, bmod->lightdatasize ); - SetBits( loadmodel->flags, MODEL_COLORED_LIGHTING ); + mod->lightdata = Mem_Malloc( mod->mempool, bmod->lightdatasize ); + memcpy( mod->lightdata, bmod->lightdata, bmod->lightdatasize ); + SetBits( mod->flags, MODEL_COLORED_LIGHTING ); break; default: Host_Error( "Mod_LoadLighting: bad lightmap sample count %i\n", bmod->lightmap_samples ); @@ -2834,29 +2832,29 @@ static void Mod_LoadLighting( dbspmodel_t *bmod ) // not supposed to be load ? if( FBitSet( host.features, ENGINE_LOAD_DELUXEDATA )) { - Mod_LoadLightVecs( bmod ); - Mod_LoadShadowmap( bmod ); + Mod_LoadLightVecs( mod, bmod ); + Mod_LoadShadowmap( mod, bmod ); if( bmod->isworld && bmod->deluxdatasize ) SetBits( world.flags, FWORLD_HAS_DELUXEMAP ); } - surf = loadmodel->surfaces; + surf = mod->surfaces; // setup lightdata pointers - for( i = 0; i < loadmodel->numsurfaces; i++, surf++ ) + for( i = 0; i < mod->numsurfaces; i++, surf++ ) { if( bmod->version == QBSP2_VERSION ) lightofs = bmod->surfaces32[i].lightofs; else lightofs = bmod->surfaces[i].lightofs; - if( loadmodel->lightdata && lightofs != -1 ) + if( mod->lightdata && lightofs != -1 ) { int offset = (lightofs / bmod->lightmap_samples); // NOTE: we divide offset by three because lighting and deluxemap keep their pointers // into three-bytes structs and shadowmap just monochrome - surf->samples = loadmodel->lightdata + offset; + surf->samples = mod->lightdata + offset; // if deluxemap is present setup it too if( bmod->deluxedata_out ) @@ -2888,12 +2886,11 @@ Mod_LoadBmodelLumps loading and processing bmodel ================= */ -qboolean Mod_LoadBmodelLumps( const byte *mod_base, qboolean isworld ) +static qboolean Mod_LoadBmodelLumps( model_t *mod, const byte *mod_base, qboolean isworld ) { const dheader_t *header = (const dheader_t *)mod_base; const dextrahdr_t *extrahdr = (const dextrahdr_t *)(mod_base + sizeof( dheader_t )); dbspmodel_t *bmod = &srcmodel; - model_t *mod = loadmodel; char wadvalue[2048]; size_t len = 0; int i, ret, flags = 0; @@ -2902,13 +2899,13 @@ qboolean Mod_LoadBmodelLumps( const byte *mod_base, qboolean isworld ) memset( bmod, 0, sizeof( dbspmodel_t )); memset( &loadstat, 0, sizeof( loadstat_t )); - Q_strncpy( loadstat.name, loadmodel->name, sizeof( loadstat.name )); + Q_strncpy( loadstat.name, mod->name, sizeof( loadstat.name )); wadvalue[0] = '\0'; #ifndef SUPPORT_BSP2_FORMAT if( header->version == QBSP2_VERSION ) { - Con_Printf( S_ERROR DEFAULT_BSP_BUILD_ERROR, loadmodel->name ); + Con_Printf( S_ERROR DEFAULT_BSP_BUILD_ERROR, mod->name ); return false; } #endif @@ -2936,7 +2933,7 @@ qboolean Mod_LoadBmodelLumps( const byte *mod_base, qboolean isworld ) srclumps[1].lumpnumber = LUMP_PLANES; break; default: - Con_Printf( S_ERROR "%s has wrong version number (%i should be %i)\n", loadmodel->name, header->version, HLBSP_VERSION ); + Con_Printf( S_ERROR "%s has wrong version number (%i should be %i)\n", mod->name, header->version, HLBSP_VERSION ); loadstat.numerrors++; return false; } @@ -2967,29 +2964,28 @@ qboolean Mod_LoadBmodelLumps( const byte *mod_base, qboolean isworld ) Con_DPrintf( "Mod_Load%s: %i warning(s)\n", isworld ? "World" : "Brush", loadstat.numwarnings ); // load into heap - Mod_LoadEntities( bmod ); - Mod_LoadPlanes( bmod ); - Mod_LoadSubmodels( bmod ); - Mod_LoadVertexes( bmod ); - Mod_LoadEdges( bmod ); - Mod_LoadSurfEdges( bmod ); - Mod_LoadTextures( bmod ); - Mod_LoadVisibility( bmod ); - Mod_LoadTexInfo( bmod ); - Mod_LoadSurfaces( bmod ); - Mod_LoadLighting( bmod ); - Mod_LoadMarkSurfaces( bmod ); - Mod_LoadLeafs( bmod ); - Mod_LoadNodes( bmod ); - Mod_LoadClipnodes( bmod ); + Mod_LoadEntities( mod, bmod ); + Mod_LoadPlanes( mod, bmod ); + Mod_LoadSubmodels( mod, bmod ); + Mod_LoadVertexes( mod, bmod ); + Mod_LoadEdges( mod, bmod ); + Mod_LoadSurfEdges( mod, bmod ); + Mod_LoadTextures( mod, bmod ); + Mod_LoadVisibility( mod, bmod ); + Mod_LoadTexInfo( mod, bmod ); + Mod_LoadSurfaces( mod, bmod ); + Mod_LoadLighting( mod, bmod ); + Mod_LoadMarkSurfaces( mod, bmod ); + Mod_LoadLeafs( mod, bmod ); + Mod_LoadNodes( mod, bmod ); + Mod_LoadClipnodes( mod, bmod ); // preform some post-initalization - Mod_MakeHull0 (); - Mod_SetupSubmodels( bmod ); + Mod_MakeHull0( mod ); + Mod_SetupSubmodels( mod, bmod ); if( isworld ) { - loadmodel = mod; // restore pointer to world #if !XASH_DEDICATED Mod_InitDebugHulls( mod ); // FIXME: build hulls for separate bmodels (shells, medkits etc) world.deluxedata = bmod->deluxedata_out; // deluxemap data pointer @@ -3153,17 +3149,15 @@ 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 ); + Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", mod->name ); if( loaded ) *loaded = false; - loadmodel->mempool = Mem_AllocPool( poolname ); - loadmodel->type = mod_brush; + mod->mempool = Mem_AllocPool( poolname ); + mod->type = mod_brush; // loading all the lumps into heap - if( !Mod_LoadBmodelLumps( buffer, world.loading )) + if( !Mod_LoadBmodelLumps( mod, buffer, world.loading )) return; // there were errors if( world.loading ) worldmodel = mod;