Skip to content

Commit c43e2cb

Browse files
committed
perf: reintroduce KeyValues cache with sv_pure support
InvalidCache every time we do a pure reload, technically we could be more selective but lots of other systems also do a similar full reload of files so I think it's fine this improves performance of mostly material queries but also some specific weapon data queries
1 parent 8b22356 commit c43e2cb

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/engine/cl_main.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ void CL_ReloadFilesInList( IFileList *pFilesToReload )
181181

182182
ResourceLocker crashPreventer;
183183

184+
// Handle KeyValues
185+
// TODO: only reload paths we need to reload
186+
// this is still better than completely disabling the KV cache...
187+
KeyValuesSystem()->InvalidateCache();
188+
184189
// Handle materials..
185190
materials->ReloadFilesInList( pFilesToReload );
186191

@@ -406,12 +411,12 @@ void WriteConfig_f( ConVar *var, const char *pOldString )
406411
void CL_CheckClientState( void )
407412
{
408413
// Setup the local network backdoor (we do this each frame so it can be toggled on and off).
409-
bool useBackdoor = cl_LocalNetworkBackdoor.GetInt() &&
414+
bool useBackdoor = cl_LocalNetworkBackdoor.GetInt() &&
415+
Host_IsSinglePlayerGame() &&
410416
(cl.m_NetChannel ? cl.m_NetChannel->IsLoopback() : false) &&
411417
sv.IsActive() &&
412418
!demorecorder->IsRecording() &&
413-
!demoplayer->IsPlayingBack() &&
414-
Host_IsSinglePlayerGame();
419+
!demoplayer->IsPlayingBack();
415420

416421
CL_SetupLocalNetworkBackDoor( useBackdoor );
417422
}

src/tier1/KeyValues.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ const char *KeyValues::GetName( void ) const
534534
//-----------------------------------------------------------------------------
535535
// Purpose: Read a single token from buffer (0 terminated)
536536
//-----------------------------------------------------------------------------
537+
#pragma warning( push )
537538
#pragma warning (disable:4706)
538539
const char *KeyValues::ReadToken( CUtlBuffer &buf, bool &wasQuoted, bool &wasConditional )
539540
{
@@ -618,7 +619,7 @@ const char *KeyValues::ReadToken( CUtlBuffer &buf, bool &wasQuoted, bool &wasCon
618619
s_pTokenBuf[ nCount ] = 0;
619620
return s_pTokenBuf;
620621
}
621-
#pragma warning (default:4706)
622+
#pragma warning( pop )
622623

623624

624625

@@ -681,7 +682,8 @@ bool KeyValues::LoadFromFile( IBaseFileSystem *filesystem, const char *resourceN
681682
So all vmt's files can bypass sv_pure 1. And I believe this mod is mostly
682683
made of vmt files, so valve's sv_pure 1 bull is pretty redundant.
683684
*/
684-
const bool bUseCache = false;
685+
// UNDONE: the above exploit is no longer relevant because the KeyValues cache is now invalidated for sv_pure
686+
const bool bUseCache = s_pfGetSymbolForString == KeyValues::GetSymbolForStringClassic;
685687
#endif
686688

687689
// If pathID is null, we cannot cache the result because that has a weird iterate-through-a-bunch-of-locations behavior.

0 commit comments

Comments
 (0)