2023-10-03 14:23:56 +00:00
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
2020-04-22 16:56:21 +00:00
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
# include "cbase.h"
2023-10-03 14:23:56 +00:00
# include "stringpool.h"
2020-04-22 16:56:21 +00:00
# include "igamesystem.h"
# include "gamestringpool.h"
// memdbgon must be the last include file in a .cpp file!!!
# include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Purpose: The actual storage for pooled per-level strings
//-----------------------------------------------------------------------------
2023-10-03 14:23:56 +00:00
class CGameStringPool : public CStringPool , public CBaseGameSystem
2020-04-22 16:56:21 +00:00
{
virtual char const * Name ( ) { return " CGameStringPool " ; }
2023-10-03 14:23:56 +00:00
virtual void LevelShutdownPostEntity ( )
2020-04-22 16:56:21 +00:00
{
2023-10-03 14:23:56 +00:00
FreeAll ( ) ;
CGameString : : IncrementSerialNumber ( ) ;
2020-04-22 16:56:21 +00:00
}
public :
void Dump ( void )
{
2023-10-03 14:23:56 +00:00
for ( int i = m_Strings . FirstInorder ( ) ; i ! = m_Strings . InvalidIndex ( ) ; i = m_Strings . NextInorder ( i ) )
2020-04-22 16:56:21 +00:00
{
2023-10-03 14:23:56 +00:00
DevMsg ( " %d (0x%p) : %s \n " , i , m_Strings [ i ] , m_Strings [ i ] ) ;
2020-04-22 16:56:21 +00:00
}
DevMsg ( " \n " ) ;
2023-10-03 14:23:56 +00:00
DevMsg ( " Size: %d items \n " , m_Strings . Count ( ) ) ;
2020-04-22 16:56:21 +00:00
}
} ;
static CGameStringPool g_GameStringPool ;
2023-10-03 14:23:56 +00:00
2020-04-22 16:56:21 +00:00
//-----------------------------------------------------------------------------
// String system accessor
//-----------------------------------------------------------------------------
IGameSystem * GameStringSystem ( )
{
return & g_GameStringPool ;
}
//-----------------------------------------------------------------------------
// Purpose: The public accessor for the level-global pooled strings
//-----------------------------------------------------------------------------
string_t AllocPooledString ( const char * pszValue )
{
if ( pszValue & & * pszValue )
return MAKE_STRING ( g_GameStringPool . Allocate ( pszValue ) ) ;
return NULL_STRING ;
}
string_t FindPooledString ( const char * pszValue )
{
return MAKE_STRING ( g_GameStringPool . Find ( pszValue ) ) ;
}
2023-10-03 14:23:56 +00:00
int CGameString : : gm_iSerialNumber = 1 ;
# ifndef CLIENT_DLL
2020-04-22 16:56:21 +00:00
//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
void CC_DumpGameStringTable ( void )
{
g_GameStringPool . Dump ( ) ;
}
static ConCommand dumpgamestringtable ( " dumpgamestringtable " , CC_DumpGameStringTable , " Dump the contents of the game string table to the console. " , FCVAR_CHEAT ) ;
# endif