engine: add new needload flag specifically for cleaning up unused models and use unreferenced for free slots.

This commit is contained in:
Alibek Omarov
2026-01-17 06:07:21 +05:00
parent 742265c2c4
commit 5cb5e76872
4 changed files with 23 additions and 12 deletions

View File

@@ -1114,7 +1114,12 @@ void CL_ClearSpriteTextures( void )
int i;
for( i = 1; i < MAX_CLIENT_SPRITES; i++ )
clgame.sprites[i].needload = NL_UNREFERENCED;
{
if( clgame.sprites[i].needload == NL_UNREFERENCED )
continue;
clgame.sprites[i].needload = NL_FREE_UNUSED;
}
}
// it's a Valve default value for LoadMapSprite (probably must be power of two)
@@ -1348,7 +1353,7 @@ static model_t *CL_LoadSpriteModel( const char *filename, uint type, uint texFla
for( i = 0, mod = &clgame.sprites[start]; i < MAX_CLIENT_SPRITES / 2; i++, mod++ )
{
if( !mod->name[0] )
if( mod->needload == NL_UNREFERENCED )
break; // this is a valid spot
}

View File

@@ -1808,7 +1808,7 @@ void CL_RegisterResources( sizebuf_t *msg, connprotocol_t proto )
// release unused SpriteTextures
for( i = 1, mod = clgame.sprites; i < MAX_CLIENT_SPRITES; i++, mod++ )
{
if( mod->needload == NL_UNREFERENCED && COM_CheckString( mod->name ))
if( mod->needload == NL_FREE_UNUSED )
Mod_FreeModel( mod );
}

View File

@@ -57,9 +57,10 @@ typedef struct
} model_info_t;
// values for model_t's needload
#define NL_UNREFERENCED 0 // this model can be freed after sequence precaching is done
#define NL_NEEDS_LOADED 1
#define NL_PRESENT 2
#define NL_UNREFERENCED 0
#define NL_NEEDS_LOADED 1
#define NL_PRESENT 2
#define NL_FREE_UNUSED 3 // this model can be freed after sequence precaching is done
typedef struct hullnode_s
{

View File

@@ -55,7 +55,7 @@ static void Mod_Modellist_f( void )
for( i = nummodels = 0, mod = mod_known; i < mod_numknown; i++, mod++ )
{
if( !COM_CheckStringEmpty( mod->name ) )
if( mod->needload == NL_UNREFERENCED )
continue; // free slot
Con_Printf( "%s\n", mod->name );
nummodels++;
@@ -74,7 +74,7 @@ Mod_FreeUserData
static void Mod_FreeUserData( model_t *mod )
{
// ignore submodels and freed models
if( !COM_CheckStringEmpty( mod->name ) || mod->name[0] == '*' )
if( mod->needload == NL_UNREFERENCED || mod->name[0] == '*' )
return;
if( Host_IsDedicated() )
@@ -101,7 +101,7 @@ Mod_FreeModel
void Mod_FreeModel( model_t *mod )
{
// already freed?
if( !mod || !COM_CheckStringEmpty( mod->name ) )
if( !mod || mod->needload == NL_UNREFERENCED )
return;
if( mod->type != mod_brush || mod->name[0] != '*' )
@@ -230,7 +230,10 @@ model_t *Mod_FindName( const char *filename, qboolean trackCRC )
// find a free model slot spot
for( i = 0, mod = mod_known; i < mod_numknown; i++, mod++ )
if( !COM_CheckStringEmpty( mod->name ) ) break; // this is a valid spot
{
if( mod->needload == NL_UNREFERENCED )
break; // this is a valid spot
}
if( i == mod_numknown )
{
@@ -429,9 +432,11 @@ static void Mod_PurgeStudioCache( void )
{
if( mod_known[i].type == mod_studio )
mod_known[i].submodels = NULL;
if( mod_known[i].name[0] == '*' )
Mod_FreeModel( &mod_known[i] );
mod_known[i].needload = NL_UNREFERENCED;
mod_known[i].needload = NL_FREE_UNUSED;
}
Mem_EmptyPool( com_studiocache );
@@ -482,7 +487,7 @@ void Mod_FreeUnused( void )
// never tries to release worldmodel
for( i = 1, mod = &mod_known[1]; i < mod_numknown; i++, mod++ )
{
if( mod->needload == NL_UNREFERENCED && COM_CheckString( mod->name ))
if( mod->needload == NL_FREE_UNUSED )
Mod_FreeModel( mod );
}
}