From 5ea2e295c131c3bbb7f12514efff0bd72146b581 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 30 Jul 2024 15:22:32 +0300 Subject: [PATCH] engine: prevent rescanning filesystem when new player connects or on late precache By reusing a padding hole in resource_t structure, we put a bit indicating that this archive was already mounted by filesystem and skip it. Because we associate this with resource, theoretical use of late precache with archives will rescan filesystem and allow using newly downloaded assets. --- engine/client/cl_main.c | 17 ++++++++++++----- engine/custom.h | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 9a0f92dc..95e320e0 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -2830,19 +2830,26 @@ static void CL_Physinfo_f( void ) static qboolean CL_ShouldRescanFilesystem( void ) { resource_t *res; + qboolean retval = false; for( res = cl.resourcesonhand.pNext; res && res != &cl.resourcesonhand; res = res->pNext ) { if( res->type == t_generic ) { const char *ext = COM_FileExtension( res->szFileName ); - // TODO: query supported archives format from fs_stdio - // TODO: query if was already opened - if( !Q_stricmp( ext, "wad" ) || !Q_stricmp( ext, "pk3" ) || !Q_stricmp( ext, "pak" )) - return true; + + if( !g_fsapi.IsArchiveExtensionSupported( ext, IAES_ONLY_REAL_ARCHIVES )) + continue; + + if( FBitSet( res->ucExtraFlags, RES_EXTRA_ARCHIVE_CHECKED )) + continue; + + SetBits( res->ucExtraFlags, RES_EXTRA_ARCHIVE_CHECKED ); + retval = true; } } - return false; + + return retval; } qboolean CL_PrecacheResources( void ) diff --git a/engine/custom.h b/engine/custom.h index 04d84894..3c8a0818 100644 --- a/engine/custom.h +++ b/engine/custom.h @@ -53,6 +53,10 @@ typedef struct resourceinfo_s #define RES_ALWAYS (1<<5) // Download always even if available on client #define RES_CHECKFILE (1<<7) // Check file on client +// this archive was already mounted after rescan +// only makes sense for archives and on client +#define RES_EXTRA_ARCHIVE_CHECKED BIT( 0 ) + typedef struct resource_s { char szFileName[64]; // File name to download/precache. @@ -67,6 +71,7 @@ typedef struct resource_s // if it's a custom resource. unsigned char rguc_reserved[32]; // For future expansion + unsigned short ucExtraFlags; // fwgs extension, doesn't change the size of struct because of compiler padding struct resource_s *pNext; // Next in chain. struct resource_s *pPrev; } resource_t;