1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 20:16:10 +08:00
This commit is contained in:
Nick Hastings
2023-12-17 12:13:38 -05:00
13 changed files with 37 additions and 471 deletions

View File

@ -22,8 +22,7 @@
class IFileSystem; // include FileSystem.h class IFileSystem; // include FileSystem.h
class IUniformRandomStream; // include vstdlib/random.h class IUniformRandomStream; // include vstdlib/random.h
class IEngineSound; // include engine/IEngineSound.h class IEngineSound; // include engine/IEngineSound.h
class IVEngineServer; class IVEngineServer;
class IVoiceServer;
class IStaticPropMgrServer; class IStaticPropMgrServer;
class ISpatialPartition; class ISpatialPartition;
class IVModelInfo; class IVModelInfo;
@ -40,7 +39,6 @@ class CSteamAPIContext;
class CSteamGameServerAPIContext; class CSteamGameServerAPIContext;
extern IVEngineServer *engine; extern IVEngineServer *engine;
extern IVoiceServer *g_pVoiceServer;
extern IFileSystem *filesystem; extern IFileSystem *filesystem;
extern IStaticPropMgrServer *staticpropmgr; extern IStaticPropMgrServer *staticpropmgr;
extern ISpatialPartition *partition; extern ISpatialPartition *partition;

View File

@ -23,7 +23,6 @@
#include "ai_saverestore.h" #include "ai_saverestore.h"
#include "ai_networkmanager.h" #include "ai_networkmanager.h"
#include "ndebugoverlay.h" #include "ndebugoverlay.h"
#include "ivoiceserver.h"
#include <stdarg.h> #include <stdarg.h>
#include "movehelper_server.h" #include "movehelper_server.h"
#include "networkstringtable_gamedll.h" #include "networkstringtable_gamedll.h"
@ -154,7 +153,6 @@ CUtlLinkedList<CMapEntityRef, unsigned short> g_MapEntityRefs;
// Engine interfaces. // Engine interfaces.
IVEngineServer *engine = NULL; IVEngineServer *engine = NULL;
IVoiceServer *g_pVoiceServer = NULL;
#if !defined(_STATIC_LINKED) #if !defined(_STATIC_LINKED)
IFileSystem *filesystem = NULL; IFileSystem *filesystem = NULL;
#else #else
@ -655,8 +653,6 @@ bool CServerGameDLL::DLLInit( CreateInterfaceFn appSystemFactory,
// init each (seperated for ease of debugging) // init each (seperated for ease of debugging)
if ( (engine = (IVEngineServer*)appSystemFactory(INTERFACEVERSION_VENGINESERVER, NULL)) == NULL ) if ( (engine = (IVEngineServer*)appSystemFactory(INTERFACEVERSION_VENGINESERVER, NULL)) == NULL )
return false; return false;
if ( (g_pVoiceServer = (IVoiceServer*)appSystemFactory(INTERFACEVERSION_VOICESERVER, NULL)) == NULL )
return false;
if ( (networkstringtable = (INetworkStringTableContainer *)appSystemFactory(INTERFACENAME_NETWORKSTRINGTABLESERVER,NULL)) == NULL ) if ( (networkstringtable = (INetworkStringTableContainer *)appSystemFactory(INTERFACENAME_NETWORKSTRINGTABLESERVER,NULL)) == NULL )
return false; return false;
if ( (staticpropmgr = (IStaticPropMgrServer *)appSystemFactory(INTERFACEVERSION_STATICPROPMGR_SERVER,NULL)) == NULL ) if ( (staticpropmgr = (IStaticPropMgrServer *)appSystemFactory(INTERFACEVERSION_STATICPROPMGR_SERVER,NULL)) == NULL )

View File

@ -50,7 +50,6 @@ LIB_OBJS= \
$(LIB_OBJ_DIR)/undiff.o \ $(LIB_OBJ_DIR)/undiff.o \
$(LIB_OBJ_DIR)/uniqueid.o \ $(LIB_OBJ_DIR)/uniqueid.o \
$(LIB_OBJ_DIR)/utlbufferutil.o \ $(LIB_OBJ_DIR)/utlbufferutil.o \
$(LIB_OBJ_DIR)/utlsymbol.o \
all: dirs $(NAME).$(SHLIBEXT) all: dirs $(NAME).$(SHLIBEXT)

View File

@ -355,10 +355,10 @@ enum RenderFx_t : unsigned char
enum Collision_Group_t enum Collision_Group_t
{ {
COLLISION_GROUP_NONE = 0, COLLISION_GROUP_ALWAYS = 0,
COLLISION_GROUP_UNKNOWN1, COLLISION_GROUP_NEVER,
COLLISION_GROUP_UNKNOWN2, COLLISION_GROUP_TRIGGER,
COLLISION_GROUP_UNKNOWN3, COLLISION_GROUP_CONDITIONALLY_SOLID,
COLLISION_GROUP_DEFAULT, COLLISION_GROUP_DEFAULT,
COLLISION_GROUP_DEBRIS, // Collides with nothing but world, static stuff and triggers COLLISION_GROUP_DEBRIS, // Collides with nothing but world, static stuff and triggers
COLLISION_GROUP_INTERACTIVE_DEBRIS, // Collides with everything except other interactive debris or debris COLLISION_GROUP_INTERACTIVE_DEBRIS, // Collides with everything except other interactive debris or debris

View File

@ -313,9 +313,12 @@ public:
virtual void unk101() = 0; virtual void unk101() = 0;
virtual void unk102() = 0; virtual void unk102() = 0;
virtual void unk103() = 0;
virtual void unk104() = 0; // Use these to setup who can hear whose voice.
virtual void unk105() = 0; // Pass in client indices (which are their ent indices - 1).
virtual bool GetClientListening(CPlayerSlot iReceiver, CPlayerSlot iSender) = 0;
virtual bool SetClientListening(CPlayerSlot iReceiver, CPlayerSlot iSender, bool bListen) = 0;
virtual bool SetClientProximity(CPlayerSlot iReceiver, CPlayerSlot iSender, bool bUseProximity) = 0;
virtual void unk106() = 0; virtual void unk106() = 0;
virtual void unk107() = 0; virtual void unk107() = 0;
@ -571,7 +574,7 @@ public:
virtual void ClientSetupVisibility( CPlayerSlot slot, vis_info_t *visinfo ) = 0; virtual void ClientSetupVisibility( CPlayerSlot slot, vis_info_t *visinfo ) = 0;
// A block of CUserCmds has arrived from the user, decode them and buffer for execution during player simulation // A block of CUserCmds has arrived from the user, decode them and buffer for execution during player simulation
virtual float ProcessUsercmds( CPlayerSlot slot, bf_read *buf, int numcmds, bool ignore, bool paused ) = 0; virtual int ProcessUsercmds( CPlayerSlot slot, bf_read *buf, int numcmds, bool ignore, bool paused ) = 0;
virtual bool IsPlayerSlotOccupied( CPlayerSlot slot ) = 0; virtual bool IsPlayerSlotOccupied( CPlayerSlot slot ) = 0;

View File

@ -37,7 +37,11 @@ class ILowLevelFileIO;
class CSteamID; class CSteamID;
typedef void * FileHandle_t; typedef void * FileHandle_t;
typedef int FileFindHandle_t; struct FileFindHandle_t
{
IFileSystem *m_pFileSystem;
intp m_nFindDataIndex;
};
typedef void (*FileSystemLoggingFunc_t)( const char *fileName, const char *accessType ); typedef void (*FileSystemLoggingFunc_t)( const char *fileName, const char *accessType );
typedef int WaitForResourcesHandle_t; typedef int WaitForResourcesHandle_t;
@ -575,9 +579,9 @@ public:
// FindFirst/FindNext. Also see FindFirstEx. // FindFirst/FindNext. Also see FindFirstEx.
virtual const char *FindFirst( const char *pWildCard, FileFindHandle_t *pHandle ) = 0; virtual const char *FindFirst( const char *pWildCard, FileFindHandle_t *pHandle ) = 0;
virtual const char *FindNext( FileFindHandle_t handle ) = 0; virtual const char *FindNext( FileFindHandle_t &handle ) = 0;
virtual bool FindIsDirectory( FileFindHandle_t handle ) = 0; virtual bool FindIsDirectory( FileFindHandle_t &handle ) = 0;
virtual void FindClose( FileFindHandle_t handle ) = 0; virtual void FindClose( FileFindHandle_t &handle ) = 0;
// Same as FindFirst, but you can filter by path ID, which can make it faster. // Same as FindFirst, but you can filter by path ID, which can make it faster.
virtual const char *FindFirstEx( const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle ) = 0; virtual const char *FindFirstEx( const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle ) = 0;

View File

@ -119,14 +119,14 @@ public:
virtual void SetFloat( const GameEventKeySymbol_t &keySymbol, float value ) = 0; virtual void SetFloat( const GameEventKeySymbol_t &keySymbol, float value ) = 0;
virtual void SetString( const GameEventKeySymbol_t &keySymbol, const char *value ) = 0; virtual void SetString( const GameEventKeySymbol_t &keySymbol, const char *value ) = 0;
virtual void SetPtr( const GameEventKeySymbol_t &keySymbol, void *value ) = 0; virtual void SetPtr( const GameEventKeySymbol_t &keySymbol, void *value ) = 0;
virtual void SetEntity(const GameEventKeySymbol_t &keySymbol, CEntityInstance *value) = 0;
virtual void SetEntity( const GameEventKeySymbol_t &keySymbol, CEntityIndex value ) = 0; virtual void SetEntity( const GameEventKeySymbol_t &keySymbol, CEntityIndex value ) = 0;
virtual void SetEntity( const GameEventKeySymbol_t &keySymbol, CEntityInstance *value ) = 0;
// Also sets the _pawn key
virtual void SetPlayer( const GameEventKeySymbol_t &keySymbol, CPlayerSlot value ) = 0;
// Also sets the _pawn key (Expects pawn entity to be passed) // Also sets the _pawn key (Expects pawn entity to be passed)
virtual void SetPlayer( const GameEventKeySymbol_t &keySymbol, CEntityInstance *pawn ) = 0; virtual void SetPlayer( const GameEventKeySymbol_t &keySymbol, CEntityInstance *pawn ) = 0;
// Also sets the _pawn key
virtual void SetPlayer( const GameEventKeySymbol_t &keySymbol, CPlayerSlot value ) = 0;
// Expects pawn entity to be passed, will set the controller entity as a controllerKeyName // Expects pawn entity to be passed, will set the controller entity as a controllerKeyName
// and pawn entity as a pawnKeyName. // and pawn entity as a pawnKeyName.

View File

@ -1,34 +0,0 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: This module defines the IVoiceServer interface, which is used by
// game code to control which clients are listening to which other
// clients' voice streams.
//
// $NoKeywords: $
//=============================================================================//
#ifndef IVOICESERVER_H
#define IVOICESERVER_H
#include "interface.h"
#define INTERFACEVERSION_VOICESERVER "VoiceServer002"
abstract_class IVoiceServer
{
public:
virtual ~IVoiceServer() {}
// Use these to setup who can hear whose voice.
// Pass in client indices (which are their ent indices - 1).
virtual bool GetClientListening(int iReceiver, int iSender) = 0;
virtual bool SetClientListening(int iReceiver, int iSender, bool bListen) = 0;
virtual bool SetClientProximity(int iReceiver, int iSender, bool bUseProximity) = 0;
};
#endif

View File

@ -1,4 +1,4 @@
//===== Copyright <EFBFBD> 1996-2005, Valve Corporation, All rights reserved. ======// //===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
// //
// Purpose: // Purpose:
// //
@ -55,9 +55,9 @@ public:
return m_SymbolTable.Find( pString ); return m_SymbolTable.Find( pString );
} }
UtlSymId_t AddString( const char *pString ) UtlSymId_t AddString( const char *pString, bool* created = NULL )
{ {
CUtlSymbol symbol = m_SymbolTable.AddString( pString ); CUtlSymbol symbol = m_SymbolTable.AddString( pString, created );
int index = ( int )( UtlSymId_t )symbol; int index = ( int )( UtlSymId_t )symbol;
if( m_Vector.Count() <= index ) if( m_Vector.Count() <= index )
{ {

View File

@ -1,4 +1,4 @@
//===== Copyright <EFBFBD> 1996-2005, Valve Corporation, All rights reserved. ======// //===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
// //
// Purpose: Defines a symbol table // Purpose: Defines a symbol table
// //
@ -102,7 +102,7 @@ public:
~CUtlSymbolTable(); ~CUtlSymbolTable();
// Finds and/or creates a symbol based on the string // Finds and/or creates a symbol based on the string
CUtlSymbol AddString( const char* pString ); CUtlSymbol AddString( const char* pString, bool* created = NULL );
// Finds the symbol for pString // Finds the symbol for pString
CUtlSymbol Find( const char* pString ) const; CUtlSymbol Find( const char* pString ) const;
@ -174,7 +174,7 @@ protected:
// stores the string data // stores the string data
CUtlVector<StringPool_t*> m_StringPools; CUtlVector<StringPool_t*> m_StringPools;
uint8 unknown[56];
private: private:
int FindPoolWithSpace( int len ) const; int FindPoolWithSpace( int len ) const;
const char* StringFromIndex( const CStringPoolIndex &index ) const; const char* StringFromIndex( const CStringPoolIndex &index ) const;
@ -193,10 +193,10 @@ public:
{ {
} }
CUtlSymbol AddString( const char* pString ) CUtlSymbol AddString( const char* pString, bool* created = NULL )
{ {
m_lock.LockForWrite(); m_lock.LockForWrite();
CUtlSymbol result = CUtlSymbolTable::AddString( pString ); CUtlSymbol result = CUtlSymbolTable::AddString( pString, created );
m_lock.UnlockWrite(); m_lock.UnlockWrite();
return result; return result;
} }

View File

@ -142,8 +142,8 @@ public:
~CUtlSymbolTableLargeBase() { } ~CUtlSymbolTableLargeBase() { }
// Finds and/or creates a symbol based on the string // Finds and/or creates a symbol based on the string
CUtlSymbolLarge AddString( const char* pString ); CUtlSymbolLarge AddString( const char* pString, bool* created = NULL );
CUtlSymbolLarge AddString( const char* pString, int nLength ); CUtlSymbolLarge AddString( const char* pString, int nLength, bool* created = NULL );
// Finds the symbol for pString // Finds the symbol for pString
CUtlSymbolLarge Find( const char* pString ) const; CUtlSymbolLarge Find( const char* pString ) const;
@ -326,7 +326,7 @@ inline CUtlSymbolLarge CUtlSymbolTableLargeBase< CASEINSENSITIVE, PAGE_SIZE, MUT
} }
template < bool CASEINSENSITIVE, size_t PAGE_SIZE, class MUTEX_TYPE > template < bool CASEINSENSITIVE, size_t PAGE_SIZE, class MUTEX_TYPE >
inline CUtlSymbolLarge CUtlSymbolTableLargeBase< CASEINSENSITIVE, PAGE_SIZE, MUTEX_TYPE >::AddString( const char* pString, int nLength ) inline CUtlSymbolLarge CUtlSymbolTableLargeBase< CASEINSENSITIVE, PAGE_SIZE, MUTEX_TYPE >::AddString( const char* pString, int nLength, bool* created )
{ {
CUtlSymbolLarge sym; CUtlSymbolLarge sym;
@ -348,9 +348,9 @@ inline CUtlSymbolLarge CUtlSymbolTableLargeBase< CASEINSENSITIVE, PAGE_SIZE, MUT
} }
template < bool CASEINSENSITIVE, size_t PAGE_SIZE, class MUTEX_TYPE > template < bool CASEINSENSITIVE, size_t PAGE_SIZE, class MUTEX_TYPE >
inline CUtlSymbolLarge CUtlSymbolTableLargeBase< CASEINSENSITIVE, PAGE_SIZE, MUTEX_TYPE >::AddString( const char* pString ) inline CUtlSymbolLarge CUtlSymbolTableLargeBase< CASEINSENSITIVE, PAGE_SIZE, MUTEX_TYPE >::AddString( const char* pString, bool* created )
{ {
return AddString( pString, pString ? strlen( pString ) : 0 ); return AddString( pString, pString ? strlen( pString ) : 0, created );
} }
template < bool CASEINSENSITIVE, size_t PAGE_SIZE, class MUTEX_TYPE > template < bool CASEINSENSITIVE, size_t PAGE_SIZE, class MUTEX_TYPE >

View File

@ -68,9 +68,6 @@
<ClCompile Include="utlbufferutil.cpp"> <ClCompile Include="utlbufferutil.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="utlsymbol.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\public\tier1\bitbuf.h"> <ClInclude Include="..\public\tier1\bitbuf.h">

View File

@ -1,397 +0,0 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: Defines a symbol table
//
// $Header: $
// $NoKeywords: $
//=============================================================================//
#ifdef _MSC_VER
#pragma warning (disable:4514)
#endif
#include "utlsymbol.h"
#include "KeyValues.h"
#include "tier0/threadtools.h"
#include "tier0/memdbgon.h"
#include "stringpool.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define INVALID_STRING_INDEX CStringPoolIndex( 0xFFFF, 0xFFFF )
#define MIN_STRING_POOL_SIZE 2048
//-----------------------------------------------------------------------------
// globals
//-----------------------------------------------------------------------------
CUtlSymbolTableMT* CUtlSymbol::s_pSymbolTable = 0;
bool CUtlSymbol::s_bAllowStaticSymbolTable = true;
//-----------------------------------------------------------------------------
// symbol methods
//-----------------------------------------------------------------------------
void CUtlSymbol::Initialize()
{
// If this assert fails, then the module that this call is in has chosen to disallow
// use of the static symbol table. Usually, it's to prevent confusion because it's easy
// to accidentally use the global symbol table when you really want to use a specific one.
Assert( s_bAllowStaticSymbolTable );
// necessary to allow us to create global symbols
static bool symbolsInitialized = false;
if (!symbolsInitialized)
{
s_pSymbolTable = new CUtlSymbolTableMT;
symbolsInitialized = true;
}
}
//-----------------------------------------------------------------------------
// Purpose: Singleton to delete table on exit from module
//-----------------------------------------------------------------------------
class CCleanupUtlSymbolTable
{
public:
~CCleanupUtlSymbolTable()
{
delete CUtlSymbol::s_pSymbolTable;
CUtlSymbol::s_pSymbolTable = NULL;
}
};
static CCleanupUtlSymbolTable g_CleanupSymbolTable;
CUtlSymbolTableMT* CUtlSymbol::CurrTable()
{
Initialize();
return s_pSymbolTable;
}
//-----------------------------------------------------------------------------
// string->symbol->string
//-----------------------------------------------------------------------------
CUtlSymbol::CUtlSymbol( const char* pStr )
{
m_Id = CurrTable()->AddString( pStr );
}
const char* CUtlSymbol::String( ) const
{
return CurrTable()->String(m_Id);
}
void CUtlSymbol::DisableStaticSymbolTable()
{
s_bAllowStaticSymbolTable = false;
}
//-----------------------------------------------------------------------------
// checks if the symbol matches a string
//-----------------------------------------------------------------------------
bool CUtlSymbol::operator==( const char* pStr ) const
{
if (m_Id == UTL_INVAL_SYMBOL)
return false;
return strcmp( String(), pStr ) == 0;
}
//-----------------------------------------------------------------------------
// symbol table stuff
//-----------------------------------------------------------------------------
inline const char* CUtlSymbolTable::StringFromIndex( const CStringPoolIndex &index ) const
{
Assert( index.m_iPool < m_StringPools.Count() );
Assert( index.m_iOffset < m_StringPools[index.m_iPool]->m_TotalLen );
return &m_StringPools[index.m_iPool]->m_Data[index.m_iOffset];
}
bool CUtlSymbolTable::CLess::operator()( const CStringPoolIndex &i1, const CStringPoolIndex &i2 ) const
{
// Need to do pointer math because CUtlSymbolTable is used in CUtlVectors, and hence
// can be arbitrarily moved in memory on a realloc. Yes, this is portable. In reality,
// right now at least, because m_LessFunc is the first member of CUtlRBTree, and m_Lookup
// is the first member of CUtlSymbolTabke, this == pTable
CUtlSymbolTable *pTable = (CUtlSymbolTable *)( (byte *)this - offsetof(CUtlSymbolTable::CTree, m_LessFunc) ) - offsetof(CUtlSymbolTable, m_Lookup );
const char* str1 = (i1 == INVALID_STRING_INDEX) ? pTable->m_pUserSearchString :
pTable->StringFromIndex( i1 );
const char* str2 = (i2 == INVALID_STRING_INDEX) ? pTable->m_pUserSearchString :
pTable->StringFromIndex( i2 );
if ( !pTable->m_bInsensitive )
return strcmp( str1, str2 ) < 0;
else
return strcmpi( str1, str2 ) < 0;
}
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
CUtlSymbolTable::CUtlSymbolTable( int growSize, int initSize, bool caseInsensitive ) :
m_Lookup( growSize, initSize ), m_bInsensitive( caseInsensitive ), m_StringPools( 8 )
{
}
CUtlSymbolTable::~CUtlSymbolTable()
{
// Release the stringpool string data
RemoveAll();
}
CUtlSymbol CUtlSymbolTable::Find( const char* pString ) const
{
if (!pString)
return CUtlSymbol();
// Store a special context used to help with insertion
m_pUserSearchString = pString;
// Passing this special invalid symbol makes the comparison function
// use the string passed in the context
UtlSymId_t idx = m_Lookup.Find( INVALID_STRING_INDEX );
#ifdef _DEBUG
m_pUserSearchString = NULL;
#endif
return CUtlSymbol( idx );
}
int CUtlSymbolTable::FindPoolWithSpace( int len ) const
{
for ( int i=0; i < m_StringPools.Count(); i++ )
{
StringPool_t *pPool = m_StringPools[i];
if ( (pPool->m_TotalLen - pPool->m_SpaceUsed) >= len )
{
return i;
}
}
return -1;
}
//-----------------------------------------------------------------------------
// Finds and/or creates a symbol based on the string
//-----------------------------------------------------------------------------
CUtlSymbol CUtlSymbolTable::AddString( const char* pString )
{
if (!pString)
return CUtlSymbol( UTL_INVAL_SYMBOL );
CUtlSymbol id = Find( pString );
if (id.IsValid())
return id;
int len = strlen(pString) + 1;
// Find a pool with space for this string, or allocate a new one.
int iPool = FindPoolWithSpace( len );
if ( iPool == -1 )
{
// Add a new pool.
int newPoolSize = MAX( len, MIN_STRING_POOL_SIZE );
StringPool_t *pPool = (StringPool_t*)malloc( sizeof( StringPool_t ) + newPoolSize - 1 );
pPool->m_TotalLen = newPoolSize;
pPool->m_SpaceUsed = 0;
iPool = m_StringPools.AddToTail( pPool );
}
// Copy the string in.
StringPool_t *pPool = m_StringPools[iPool];
Assert( pPool->m_SpaceUsed < 0xFFFF ); // This should never happen, because if we had a string > 64k, it
// would have been given its entire own pool.
unsigned short iStringOffset = pPool->m_SpaceUsed;
memcpy( &pPool->m_Data[pPool->m_SpaceUsed], pString, len );
pPool->m_SpaceUsed += len;
// didn't find, insert the string into the vector.
CStringPoolIndex index;
index.m_iPool = iPool;
index.m_iOffset = iStringOffset;
UtlSymId_t idx = m_Lookup.Insert( index );
return CUtlSymbol( idx );
}
//-----------------------------------------------------------------------------
// Look up the string associated with a particular symbol
//-----------------------------------------------------------------------------
const char* CUtlSymbolTable::String( CUtlSymbol id ) const
{
if (!id.IsValid())
return "";
Assert( m_Lookup.IsValidIndex((UtlSymId_t)id) );
return StringFromIndex( m_Lookup[id] );
}
//-----------------------------------------------------------------------------
// Remove all symbols in the table.
//-----------------------------------------------------------------------------
void CUtlSymbolTable::RemoveAll()
{
m_Lookup.Purge();
for ( int i=0; i < m_StringPools.Count(); i++ )
free( m_StringPools[i] );
m_StringPools.RemoveAll();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pFileName -
// Output : FileNameHandle_t
//-----------------------------------------------------------------------------
FileNameHandle_t CUtlFilenameSymbolTable::FindOrAddFileName( const char *pFileName )
{
if ( !pFileName )
{
return NULL;
}
// find first
FileNameHandle_t hFileName = FindFileName( pFileName );
if ( hFileName )
{
return hFileName;
}
// Fix slashes+dotslashes and make lower case first..
char fn[ MAX_PATH ];
Q_strncpy( fn, pFileName, sizeof( fn ) );
Q_RemoveDotSlashes( fn );
#ifdef _WIN32
strlwr( fn );
#endif
// Split the filename into constituent parts
char basepath[ MAX_PATH ];
Q_ExtractFilePath( fn, basepath, sizeof( basepath ) );
char filename[ MAX_PATH ];
Q_strncpy( filename, fn + Q_strlen( basepath ), sizeof( filename ) );
// not found, lock and look again
FileNameHandleInternal_t handle;
m_lock.LockForWrite();
handle.path = m_StringPool.FindStringHandle( basepath );
handle.file = m_StringPool.FindStringHandle( filename );
if ( handle.path && handle.file )
{
// found
m_lock.UnlockWrite();
return *( FileNameHandle_t * )( &handle );
}
// safely add it
handle.path = m_StringPool.ReferenceStringHandle( basepath );
handle.file = m_StringPool.ReferenceStringHandle( filename );
m_lock.UnlockWrite();
return *( FileNameHandle_t * )( &handle );
}
FileNameHandle_t CUtlFilenameSymbolTable::FindFileName( const char *pFileName )
{
if ( !pFileName )
{
return NULL;
}
// Fix slashes+dotslashes and make lower case first..
char fn[ MAX_PATH ];
Q_strncpy( fn, pFileName, sizeof( fn ) );
Q_RemoveDotSlashes( fn );
#ifdef _WIN32
strlwr( fn );
#endif
// Split the filename into constituent parts
char basepath[ MAX_PATH ];
Q_ExtractFilePath( fn, basepath, sizeof( basepath ) );
char filename[ MAX_PATH ];
Q_strncpy( filename, fn + Q_strlen( basepath ), sizeof( filename ) );
FileNameHandleInternal_t handle;
m_lock.LockForRead();
handle.path = m_StringPool.FindStringHandle(basepath);
handle.file = m_StringPool.FindStringHandle(filename);
m_lock.UnlockRead();
if ( handle.path == 0 || handle.file == 0 )
return NULL;
return *( FileNameHandle_t * )( &handle );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : handle -
// Output : const char
//-----------------------------------------------------------------------------
bool CUtlFilenameSymbolTable::String( const FileNameHandle_t& handle, char *buf, int buflen )
{
buf[ 0 ] = 0;
FileNameHandleInternal_t *internal = ( FileNameHandleInternal_t * )&handle;
if ( !internal )
{
return false;
}
m_lock.LockForRead();
const char *path = m_StringPool.HandleToString(internal->path);
const char *fn = m_StringPool.HandleToString(internal->file);
m_lock.UnlockRead();
if ( !path || !fn )
{
return false;
}
Q_strncpy( buf, path, buflen );
Q_strncat( buf, fn, buflen, COPY_ALL_CHARACTERS );
return true;
}
void CUtlFilenameSymbolTable::RemoveAll()
{
m_StringPool.FreeAll();
}
void CUtlFilenameSymbolTable::SpewStrings()
{
m_lock.LockForRead();
m_StringPool.SpewStrings();
m_lock.UnlockRead();
}