From 5cb5e76872a052ac2c373d74377d41baf202c4c5 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 17 Jan 2026 06:07:21 +0500 Subject: [PATCH] engine: add new needload flag specifically for cleaning up unused models and use unreferenced for free slots. --- engine/client/cl_game.c | 9 +++++++-- engine/client/cl_parse.c | 2 +- engine/common/mod_local.h | 7 ++++--- engine/common/model.c | 17 +++++++++++------ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index f1c97085..215cef9c 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -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 } diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 2375cc2e..990b56d1 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -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 ); } diff --git a/engine/common/mod_local.h b/engine/common/mod_local.h index 0f1778aa..735b77d6 100644 --- a/engine/common/mod_local.h +++ b/engine/common/mod_local.h @@ -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 { diff --git a/engine/common/model.c b/engine/common/model.c index 1829c6ff..b7190e40 100644 --- a/engine/common/model.c +++ b/engine/common/model.c @@ -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 ); } }