1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 20:16:10 +08:00

Synced select headers with game.

--HG--
extra : amend_source : 1737bd6ba37e997efa1e53962978b38bfc1ece80
This commit is contained in:
Nicholas Hastings
2014-04-20 11:22:23 -04:00
parent d687ebe09f
commit c344e853c1
18 changed files with 484 additions and 124 deletions

View File

@ -352,10 +352,17 @@ public:
// Name of most recently load .sav file
virtual char const *GetMostRecentlyLoadedFileName() = 0;
virtual char const *GetSaveFileName() = 0;
// TERROR: savegame support
virtual void WriteSavegameScreenshot( const char *filename ) = 0;
virtual int GetLightForPointListenServerOnly(const Vector &, bool, Vector *) = 0;
virtual int TraceLightingListenServerOnly(const Vector &, const Vector &, Vector *, Vector *) = 0;
// TERROR: Only valid on win32 listenservers!!!
virtual bool GetLightForPointListenServerOnly( const Vector &pos, bool bClamp, Vector *ambientColor ) = 0;
// TERROR: Only valid on win32 listenservers!!!
// Traces the line and reports the lighting information for the impact point
virtual bool TraceLightingListenServerOnly( const Vector &start, const Vector &end,
Vector *diffuseLightColor, Vector *baseColor ) = 0;
// Cleans up the cluster list
virtual void CleanUpEntityClusterList( PVSInfo_t *pPVSInfo ) = 0;
@ -424,15 +431,16 @@ public:
virtual CGamestatsData *GetGamestatsData() = 0;
// Returns the SteamID of the specified player. It'll be NULL if the player hasn't authenticated yet.
virtual const CSteamID *GetClientSteamID( edict_t *pPlayerEdict ) = 0;
virtual const CSteamID *GetClientSteamID( edict_t *pPlayerEdict ) = 0;
// Validate session
virtual void HostValidateSession() = 0;
// Update the 360 pacifier/spinner
virtual void RefreshScreenIfNecessary() = 0;
virtual void *AllocLevelStaticDataName( unsigned int, const char * ) = 0;
// Allocate hunk memory
virtual void *AllocLevelStaticDataName( size_t bytes, const char *pszName ) = 0;
// Send a client command keyvalues
// keyvalues are deleted inside the function
@ -440,6 +448,8 @@ public:
// Returns the XUID of the specified player. It'll be NULL if the player hasn't connected yet.
virtual uint64 GetClientXUID( edict_t *pPlayerEdict ) = 0;
virtual void RecalculateTags() = 0;
};
#define INTERFACEVERSION_SERVERGAMEDLL "ServerGameDLL005"
@ -529,10 +539,6 @@ public:
// Called once per frame even when no level is loaded...
virtual void Think( bool finalTick ) = 0;
#ifdef _XBOX
virtual void GetTitleName( const char *pMapName, char* pTitleBuff, int titleBuffSize ) = 0;
#endif
virtual void PreSaveGameLoaded( char const *pSaveName, bool bCurrentlyInGame ) = 0;
// Returns true if the game DLL wants the server not to be made public.
@ -550,17 +556,26 @@ public:
// Called after tools are initialized (i.e. when Foundry is initialized so we can get IServerFoundry).
virtual void PostToolsInit() = 0;
// Called to apply lobby settings to a dedicated server
virtual void ApplyGameSettings( KeyValues *pKV ) = 0;
//
virtual void GetMatchmakingTags( char *buf, size_t bufSize ) = 0;
virtual void ServerHibernationUpdate( bool bHibernating ) = 0;
virtual void GenerateLumpFileName( const char *, char *, int, int ) = 0;
virtual void GenerateLumpFileName( const char *bspfilename, char *lumpfilename, int iBufferSize, int iIndex ) = 0;
virtual void GetMatchmakingGameData( char *buf, size_t bufSize ) = 0;
virtual void GetMatchmakingGameData( char *buf, size_t bufSize ) = 0;
// Called after the steam API has been activated post-level startup
virtual void GameServerSteamAPIActivated( void ) = 0;
// Called after the steam API has been shutdown post-level startup
virtual void GameServerSteamAPIShutdown( void ) = 0;
virtual const char *GetGameModeName( void ) = 0;
};
//-----------------------------------------------------------------------------
@ -730,7 +745,7 @@ public:
#define SERVER_DLL_SHARED_APPSYSTEMS "VServerDllSharedAppSystems001"
#define INTERFACEVERSION_SERVERGAMETAGS "ServerGameTags001"
#define INTERFACEVERSION_SERVERGAMETAGS "ServerGameTags002"
//-----------------------------------------------------------------------------
// Purpose: querying the game dll for Server cvar tags
@ -740,6 +755,8 @@ abstract_class IServerGameTags
public:
// Get the list of cvars that require tags to show differently in the server browser
virtual void GetTaggedConVarList( KeyValues *pCvarTagList ) = 0;
virtual int GetAvgServerLevel() = 0;
};
#endif // EIFACE_H

View File

@ -11,7 +11,6 @@
#pragma once
#endif
enum SolidType_t;
class IHandleEntity;
struct Ray_t;
@ -21,7 +20,7 @@ class QAngle;
class CGameTrace;
typedef CGameTrace trace_t;
class IClientUnknown;
class IPhysicsObject;
abstract_class ICollideable
{
@ -76,6 +75,7 @@ public:
// returns NULL unless this collideable has specified FSOLID_ROOT_PARENT_ALIGNED
virtual const matrix3x4_t *GetRootParentToWorldTransform() const = 0;
virtual IPhysicsObject *GetVPhysicsObject() const = 0;
};

View File

@ -97,7 +97,8 @@ public:
// emit an "ambient" sound that isn't spatialized
// only available on the client, assert on server
virtual void EmitAmbientSound( const char *pSample, float flVolume, int iPitch = PITCH_NORM, int flags = 0, float soundtime = 0.0f ) = 0;
// returns GUID
virtual int EmitAmbientSound( const char *pSample, float flVolume, int iPitch = PITCH_NORM, int flags = 0, float soundtime = 0.0f ) = 0;
// virtual EntChannel_t CreateEntChannel() = 0;
@ -107,7 +108,7 @@ public:
// Client .dll only functions
virtual int GetGuidForLastSoundEmitted() = 0;
virtual bool IsSoundStillPlaying( int guid ) = 0;
virtual void StopSoundByGuid( int guid ) = 0;
virtual void StopSoundByGuid( int guid, bool bForceSync = false ) = 0;
// Set's master volume (0.0->1.0)
virtual void SetVolumeByGuid( int guid, float fvol ) = 0;
@ -121,7 +122,6 @@ public:
virtual bool GetSoundChannelVolume( const char* sound, float &flVolumeLeft, float &flVolumeRight ) = 0;
virtual float GetElapsedTimeByGuid( int guid ) = 0;
};

View File

@ -45,7 +45,8 @@ typedef int QueryCvarCookie_t;
#define INTERFACEVERSION_ISERVERPLUGINCALLBACKS_VERSION_1 "ISERVERPLUGINCALLBACKS001"
#define INTERFACEVERSION_ISERVERPLUGINCALLBACKS "ISERVERPLUGINCALLBACKS002"
#define INTERFACEVERSION_ISERVERPLUGINCALLBACKS_VERSION_2 "ISERVERPLUGINCALLBACKS002"
#define INTERFACEVERSION_ISERVERPLUGINCALLBACKS "ISERVERPLUGINCALLBACKS003"
//-----------------------------------------------------------------------------
// Purpose: callbacks the engine exposes to the 3rd party plugins (ala MetaMod)
@ -110,7 +111,10 @@ public:
// iCookie is the value returned by IServerPluginHelpers::StartQueryCvarValue.
// Added with version 2 of the interface.
virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue ) = 0;
// added with version 3 of the interface.
virtual void OnEdictAllocated( edict_t *edict ) = 0;
virtual void OnEdictFreed( const edict_t *edict ) = 0;
};
#define INTERFACEVERSION_ISERVERPLUGINHELPERS "ISERVERPLUGINHELPERS001"

View File

@ -432,7 +432,7 @@ public:
// override is cleared and the current .bsp is searched for an embedded PAK file
// and this file becomes the highest priority search path ( i.e., it's looked at first
// even before the mod's file system path ).
virtual void AddSearchPath( const char *pPath, const char *pathID, SearchPathAdd_t addType = PATH_ADD_TO_TAIL ) = 0;
virtual void AddSearchPath( const char *pPath, const char *pathID, SearchPathAdd_t addType = PATH_ADD_TO_TAIL, bool isLocalized = false ) = 0;
virtual bool RemoveSearchPath( const char *pPath, const char *pathID = 0 ) = 0;
// Remove all search paths (including write path?)
@ -456,7 +456,9 @@ public:
// interface for custom pack files > 4Gb
virtual bool AddPackFile( const char *fullpath, const char *pathID ) = 0;
virtual bool IsLocalizedPath ( const char * ) = 0;
// returns true if the path ends with the current localized language
virtual bool IsLocalizedPath( const char *pPath, const char *pathID ) = 0;
//--------------------------------------------------------
// File manipulation operations
//--------------------------------------------------------
@ -513,7 +515,9 @@ public:
FileFindHandle_t *pHandle
) = 0;
virtual void FindFileAbsoluteList( CUtlVector<CUtlString> &, const char *, const char * ) = 0;
// Searches for a file in all paths and results absolute path names for the file, works in pack files (zip and vpk) too
// Lets you search for something like sound/sound.cache and get a list of every sound cache
virtual void FindFileAbsoluteList( CUtlVector< CUtlString > &outAbsolutePathNames, const char *pWildCard, const char *pPathID ) = 0;
//--------------------------------------------------------
// File name and directory operations
@ -750,6 +754,7 @@ public:
virtual void AddVPKFile( char const *pszName, SearchPathAdd_t addType = PATH_ADD_TO_TAIL ) = 0;
virtual void RemoveVPKFile( char const *pszName ) = 0;
virtual void MoveOrAddVPKFile( char const *pszName, SearchPathAdd_t addType ) = 0;
virtual void GetVPKFileNames( CUtlVector<CUtlString> &destVector ) = 0;
virtual void RemoveAllMapSearchPaths() = 0;
virtual void SyncDvdDevCache() = 0;
@ -768,9 +773,8 @@ public:
// will be issued whenever the indicated # of seconds go by without an i/o request. Passing
// 0.0 will turn off the functionality.
virtual void SetIODelayAlarm( float flThreshhold ) = 0;
virtual void AddXLSPUpdateSearchPath(const void *, int) = 0;
virtual bool AddXLSPUpdateSearchPath( const void *pData, int nSize ) = 0;
};
//-----------------------------------------------------------------------------

View File

@ -94,7 +94,7 @@ public:
virtual void Shutdown() { m_pFileSystemPassThru->Shutdown(); }
virtual void RemoveAllSearchPaths( void ) { m_pFileSystemPassThru->RemoveAllSearchPaths(); }
virtual void AddSearchPath( const char *pPath, const char *pathID, SearchPathAdd_t addType ) { m_pFileSystemPassThru->AddSearchPath( pPath, pathID, addType ); }
virtual void AddSearchPath( const char *pPath, const char *pathID, SearchPathAdd_t addType, bool isLocalized ) { m_pFileSystemPassThru->AddSearchPath( pPath, pathID, addType, isLocalized ); }
virtual bool RemoveSearchPath( const char *pPath, const char *pathID ) { return m_pFileSystemPassThru->RemoveSearchPath( pPath, pathID ); }
virtual void RemoveFile( char const* pRelativePath, const char *pathID ) { m_pFileSystemPassThru->RemoveFile( pRelativePath, pathID ); }
virtual bool RenameFile( char const *pOldPath, char const *pNewPath, const char *pathID ) { return m_pFileSystemPassThru->RenameFile( pOldPath, pNewPath, pathID ); }
@ -120,6 +120,7 @@ public:
virtual const char *FindNext( FileFindHandle_t handle ) { return m_pFileSystemPassThru->FindNext( handle ); }
virtual bool FindIsDirectory( FileFindHandle_t handle ) { return m_pFileSystemPassThru->FindIsDirectory( handle ); }
virtual void FindClose( FileFindHandle_t handle ) { m_pFileSystemPassThru->FindClose( handle ); }
virtual void FindFileAbsoluteList( CUtlVector< CUtlString > &outAbsolutePathNames, const char *pWildCard, const char *pPathID ) { m_pFileSystemPassThru->FindFileAbsoluteList( outAbsolutePathNames, pWildCard, pPathID ); }
virtual const char *GetLocalPath( const char *pFileName, char *pLocalPath, int localPathBufferSize ) { return m_pFileSystemPassThru->GetLocalPath( pFileName, pLocalPath, localPathBufferSize ); }
virtual bool FullPathToRelativePath( const char *pFullpath, char *pRelative, int maxlen ) { return m_pFileSystemPassThru->FullPathToRelativePath( pFullpath, pRelative, maxlen ); }
virtual bool GetCurrentDirectory( char* pDirectory, int maxlen ) { return m_pFileSystemPassThru->GetCurrentDirectory( pDirectory, maxlen ); }
@ -161,10 +162,8 @@ public:
const char *pPathID,
FileFindHandle_t *pHandle
) { return m_pFileSystemPassThru->FindFirstEx( pWildCard, pPathID, pHandle ); }
virtual void FindFileAbsoluteList( CUtlVector<CUtlString> &a, const char *b, const char *c ) { m_pFileSystemPassThru->FindFileAbsoluteList(a, b, c); }
virtual void MarkPathIDByRequestOnly( const char *pPathID, bool bRequestOnly ) { m_pFileSystemPassThru->MarkPathIDByRequestOnly( pPathID, bRequestOnly ); }
virtual bool AddPackFile( const char *fullpath, const char *pathID ) { return m_pFileSystemPassThru->AddPackFile( fullpath, pathID ); }
virtual bool IsLocalizedPath ( const char *path ) { return m_pFileSystemPassThru->IsLocalizedPath(path); }
virtual FSAsyncStatus_t AsyncAppend(const char *pFileName, const void *pSrc, int nSrcBytes, bool bFreeMemory, FSAsyncControl_t *pControl ) { return m_pFileSystemPassThru->AsyncAppend( pFileName, pSrc, nSrcBytes, bFreeMemory, pControl); }
virtual FSAsyncStatus_t AsyncWrite(const char *pFileName, const void *pSrc, int nSrcBytes, bool bFreeMemory, bool bAppend, FSAsyncControl_t *pControl ) { return m_pFileSystemPassThru->AsyncWrite( pFileName, pSrc, nSrcBytes, bFreeMemory, bAppend, pControl); }
virtual FSAsyncStatus_t AsyncWriteFile(const char *pFileName, const CUtlBuffer *pSrc, int nSrcBytes, bool bFreeMemory, bool bAppend, FSAsyncControl_t *pControl ) { return m_pFileSystemPassThru->AsyncWriteFile( pFileName, pSrc, nSrcBytes, bFreeMemory, bAppend, pControl); }
@ -176,6 +175,7 @@ public:
virtual bool AsyncResume() { return m_pFileSystemPassThru->AsyncResume(); }
virtual const char *RelativePathToFullPath( const char *pFileName, const char *pPathID, char *pLocalPath, int localPathBufferSize, PathTypeFilter_t pathFilter = FILTER_NONE, PathTypeQuery_t *pPathType = NULL ) { return m_pFileSystemPassThru->RelativePathToFullPath( pFileName, pPathID, pLocalPath, localPathBufferSize, pathFilter, pPathType ); }
virtual int GetSearchPath( const char *pathID, bool bGetPackFiles, char *pPath, int nMaxLen ) { return m_pFileSystemPassThru->GetSearchPath( pathID, bGetPackFiles, pPath, nMaxLen ); }
virtual bool IsLocalizedPath( const char *pPath, const char *pathID ) { return m_pFileSystemPassThru->IsLocalizedPath( pPath, pathID ); }
virtual FileHandle_t OpenEx( const char *pFileName, const char *pOptions, unsigned flags = 0, const char *pathID = 0, char **ppszResolvedFilename = NULL ) { return m_pFileSystemPassThru->OpenEx( pFileName, pOptions, flags, pathID, ppszResolvedFilename );}
virtual int ReadEx( void* pOutput, int destSize, int size, FileHandle_t file ) { return m_pFileSystemPassThru->ReadEx( pOutput, destSize, size, file ); }
@ -240,6 +240,7 @@ public:
virtual void AddVPKFile( char const *pPkName, SearchPathAdd_t addType = PATH_ADD_TO_TAIL ) { m_pFileSystemPassThru->AddVPKFile( pPkName, addType ); }
virtual void RemoveVPKFile( char const *pPkName ) { m_pFileSystemPassThru->RemoveVPKFile( pPkName ); }
virtual void MoveOrAddVPKFile( char const *pszName, SearchPathAdd_t addType ) { m_pFileSystemPassThru->MoveOrAddVPKFile( pszName, addType ); }
virtual void GetVPKFileNames( CUtlVector<CUtlString> &destVector ) { m_pFileSystemPassThru->GetVPKFileNames( destVector ); }
virtual void RemoveAllMapSearchPaths( void ) { m_pFileSystemPassThru->RemoveAllMapSearchPaths(); }
@ -256,7 +257,7 @@ public:
virtual bool AddDLCSearchPaths() { return m_pFileSystemPassThru->AddDLCSearchPaths(); }
virtual bool IsSpecificDLCPresent( unsigned int nDLCPackage ) { return m_pFileSystemPassThru->IsSpecificDLCPresent( nDLCPackage ); }
virtual void SetIODelayAlarm( float flThreshhold ) { m_pFileSystemPassThru->SetIODelayAlarm( flThreshhold ); }
virtual void AddXLSPUpdateSearchPath( const void *a, int b ) { m_pFileSystemPassThru->AddXLSPUpdateSearchPath(a, b); }
virtual bool AddXLSPUpdateSearchPath( const void *pData, int nSize ) { return m_pFileSystemPassThru->AddXLSPUpdateSearchPath( pData, nSize ); }
protected:
IFileSystem *m_pFileSystemPassThru;

View File

@ -25,7 +25,7 @@ public:
virtual ~IClient() {}
// connect client
virtual void Connect( const char * szName, int nUserID, INetChannel *pNetChannel, bool bFakePlayer, CUtlVector< NetMessageCvar_t > *pVecCvars = NULL ) = 0;
virtual void Connect(const char * szName, int nUserID, INetChannel *pNetChannel, bool bFakePlayer, int clientChallenge ) = 0;
// set the client in a pending state waiting for a new game
virtual void Inactivate( void ) = 0;
@ -88,14 +88,7 @@ public:
virtual bool CheckConnect( void ) = 0;
virtual bool IsLowViolenceClient( void ) const = 0;
virtual IClient *GetSplitScreenOwner() = 0;
// get the number of players on this client's machine
virtual int GetNumPlayers() = 0;
virtual bool IsHumanPlayer() const = 0;
};
#endif // ICLIENT_H

View File

@ -156,6 +156,7 @@ protected:
class ICVarIteratorInternal
{
public:
virtual ~ICVarIteratorInternal() {}
virtual void SetFirst( void ) = 0;
virtual void Next( void ) = 0;
virtual bool IsValid( void ) = 0;
@ -175,7 +176,7 @@ inline ICvar::Iterator::Iterator(ICvar *icvar)
inline ICvar::Iterator::~Iterator( void )
{
g_pMemAlloc->Free(m_pIter);
delete m_pIter;
}
inline void ICvar::Iterator::SetFirst( void )

View File

@ -84,6 +84,8 @@ public:
virtual void SetUint64( const char *keyName, uint64 value ) = 0;
virtual void SetFloat( const char *keyName, float value ) = 0;
virtual void SetString( const char *keyName, const char *value ) = 0;
virtual KeyValues *GetDataKeys() = 0;
};
#define EVENT_DEBUG_ID_INIT 42

View File

@ -60,7 +60,7 @@ public:
virtual void ProcessPacket( struct netpacket_s* packet, bool bHasHeader ) = 0;
virtual bool SendNetMsg(INetMessage &msg, bool bForceReliable = false, bool bVoice = false ) = 0;
#ifdef _LINUX
#ifdef POSIX
FORCEINLINE bool SendNetMsg(INetMessage const &msg, bool bForceReliable = false, bool bVoice = false ) { return SendNetMsg( *( (INetMessage *) &msg ), bForceReliable, bVoice ); }
#endif
virtual bool SendData(bf_write &msg, bool bReliable = true) = 0;
@ -88,6 +88,7 @@ public:
virtual void SetFileTransmissionMode(bool bBackgroundMode) = 0;
virtual void SetCompressionMode( bool bUseCompression ) = 0;
virtual unsigned int RequestFile(const char *filename) = 0;
virtual float GetTimeSinceLastReceived( void ) const = 0; // get time since last received packet in seconds
virtual void SetMaxBufferSize(bool bReliable, int nBytes, bool bVoice = false ) = 0;

View File

@ -32,6 +32,7 @@ public:
ENTITIES, // all other entity bytes
SOUNDS, // game sounds
EVENTS, // event messages
TEMPENTS, // temp entities
USERMESSAGES, // user messages
ENTMESSAGES, // entity messages
VOICE, // voice data

View File

@ -28,7 +28,7 @@ public:
virtual void SetNetChannel(INetChannel * netchan) = 0; // netchannel this message is from/for
virtual void SetReliable( bool state ) = 0; // set to true if it's a reliable message
virtual bool Process( void ) = 0; // calles the recently set handler to process this message
virtual bool Process( void ) = 0; // calls the recently set handler to process this message
virtual bool ReadFromBuffer( bf_read &buffer ) = 0; // returns true if parsing was OK
virtual bool WriteToBuffer( bf_write &buffer ) = 0; // returns true if writing was OK
@ -40,6 +40,7 @@ public:
virtual const char *GetName( void ) const = 0; // returns network message name, eg "svc_serverinfo"
virtual INetChannel *GetNetChannel( void ) const = 0;
virtual const char *ToString( void ) const = 0; // returns a human readable string about message content
virtual size_t GetSize() const = 0;
};

View File

@ -34,13 +34,13 @@ public:
virtual void PacketEnd( void ) = 0; // all messages has been parsed
virtual void FileRequested(const char *fileName, unsigned int transferID, bool isReplayDemoFile) = 0; // other side request a file for download
virtual void FileRequested(const char *fileName, unsigned int transferID ) = 0; // other side request a file for download
virtual void FileReceived(const char *fileName, unsigned int transferID, bool isReplayDemoFile) = 0; // we received a file
virtual void FileReceived(const char *fileName, unsigned int transferID ) = 0; // we received a file
virtual void FileDenied(const char *fileName, unsigned int transferID, bool isReplayDemoFile) = 0; // a file request was denied by other side
virtual void FileDenied(const char *fileName, unsigned int transferID ) = 0; // a file request was denied by other side
virtual void FileSent(const char *fileName, unsigned int transferID, bool isReplayDemoFile) = 0; // we sent a file
virtual void FileSent(const char *fileName, unsigned int transferID ) = 0; // we sent a file
};
#define PROCESS_NET_MESSAGE( name ) \

View File

@ -375,11 +375,6 @@ FORCEINLINE T Square( T const &a )
}
FORCEINLINE bool IsPowerOfTwo( uint x )
{
return ( x & ( x - 1 ) ) == 0;
}
// return the smallest power of two >= x.
// returns 0 if x == 0 or x > 0x80000000 (ie numbers that would be negative if x was signed)
// NOTE: the old code took an int, and if you pass in an int of 0x80000000 casted to a uint,

View File

@ -34,9 +34,10 @@
#define CLEARBITS(iBitVector, bits) ((iBitVector) &= ~(bits))
#define FBitSet(iBitVector, bit) ((iBitVector) & (bit))
inline bool IsPowerOfTwo( int value )
template <typename T>
inline bool IsPowerOfTwo( T value )
{
return (value & ( value - 1 )) == 0;
return (value & ( value - (T)1 )) == (T)0;
}
#define CONST_INTEGER_AS_STRING(x) #x //Wraps the integer in quotes, allowing us to form constant strings with it

View File

@ -14,21 +14,37 @@
#pragma once
#endif
// These memory debugging switches aren't relevant under Linux builds since memoverride.cpp
// isn't built into Linux projects
#ifndef POSIX
// Define this in release to get memory tracking even in release builds
//#define USE_MEM_DEBUG 1
// Define this in release to get light memory debugging
//#define USE_LIGHT_MEM_DEBUG
// Define this to require -uselmd to turn light memory debugging on
//#define LIGHT_MEM_DEBUG_REQUIRES_CMD_LINE_SWITCH
#endif
#if defined( _MEMTEST )
#ifdef _WIN32
#define USE_MEM_DEBUG 1
#endif
#endif
// Undefine this if using a compiler lacking threadsafe RTTI (like vc6)
#define MEM_DEBUG_CLASSNAME 1
#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE)
#include <stddef.h>
#if defined( OSX )
#include <malloc/malloc.h>
#endif
#include "tier0/mem.h"
#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE)
struct _CrtMemState;
#define MEMALLOC_VERSION 1
@ -41,15 +57,18 @@ typedef size_t (*MemAllocFailHandler_t)( size_t );
//-----------------------------------------------------------------------------
abstract_class IMemAlloc
{
public:
private:
// Release versions
virtual void *Alloc( size_t nSize ) = 0;
public:
virtual void *Realloc( void *pMem, size_t nSize ) = 0;
virtual void Free( void *pMem ) = 0;
virtual void *Expand_NoLongerSupported( void *pMem, size_t nSize ) = 0;
// Debug versions
virtual void *Alloc( size_t nSize, const char *pFileName, int nLine ) = 0;
public:
virtual void *Realloc( void *pMem, size_t nSize, const char *pFileName, int nLine ) = 0;
virtual void Free( void *pMem, const char *pFileName, int nLine ) = 0;
virtual void *Expand_NoLongerSupported( void *pMem, size_t nSize, const char *pFileName, int nLine ) = 0;
@ -106,7 +125,8 @@ public:
virtual void SetStatsExtraInfo( const char *pMapName, const char *pComment ) = 0;
#endif
// Returns 0 if no failure, otherwise the size_t of the last requested chunk
// Returns 0 if no failure, otherwise the size_t of the last requested chunk.
// "I'm sure this is completely thread safe!" Brian Deen 7/19/2012.
virtual size_t MemoryAllocFailed() = 0;
virtual void CompactIncremental() = 0;
@ -128,16 +148,58 @@ MEM_INTERFACE IMemAlloc *g_pMemAlloc;
//-----------------------------------------------------------------------------
#ifdef MEMALLOC_REGIONS
#ifndef MEMALLOC_REGION
#define MEMALLOC_REGION 0
#endif
inline void *MemAlloc_Alloc( size_t nSize )
{
return g_pMemAlloc->RegionAlloc( MEMALLOC_REGION, nSize );
}
inline void *MemAlloc_Alloc( size_t nSize, const char *pFileName, int nLine )
{
return g_pMemAlloc->RegionAlloc( MEMALLOC_REGION, nSize, pFileName, nLine );
}
#else
#undef MEMALLOC_REGION
inline void *MemAlloc_Alloc( size_t nSize )
{
return g_pMemAlloc->IndirectAlloc( nSize );
}
inline void *MemAlloc_Alloc( size_t nSize, const char *pFileName, int nLine )
{
return g_pMemAlloc->IndirectAlloc( nSize, pFileName, nLine );
}
#endif
inline void MemAlloc_Free( void *ptr )
{
g_pMemAlloc->Free( ptr );
}
inline void MemAlloc_Free( void *ptr, const char *pFileName, int nLine )
{
g_pMemAlloc->Free( ptr, pFileName, nLine );
}
//-----------------------------------------------------------------------------
inline bool ValueIsPowerOfTwo( size_t value ) // don't clash with mathlib definition
{
return (value & ( value - 1 )) == 0;
}
inline void *MemAlloc_AllocAligned( size_t size, size_t align )
{
unsigned char *pAlloc, *pResult;
if (!IsPowerOfTwo(uint(align)))
if (!IsPowerOfTwo(align))
return NULL;
align = (align > sizeof(void *) ? align : sizeof(void *)) - 1;
if ( (pAlloc = (unsigned char*)g_pMemAlloc->Alloc( sizeof(void *) + align + size ) ) == (unsigned char*)NULL)
if ( (pAlloc = (unsigned char*)g_pMemAlloc->IndirectAlloc( sizeof(void *) + align + size ) ) == (unsigned char*)NULL)
return NULL;
pResult = (unsigned char*)( (size_t)(pAlloc + sizeof(void *) + align ) & ~align );
@ -150,12 +212,48 @@ inline void *MemAlloc_AllocAligned( size_t size, size_t align, const char *pszFi
{
unsigned char *pAlloc, *pResult;
if (!IsPowerOfTwo(uint(align)))
if (!IsPowerOfTwo(align))
return NULL;
align = (align > sizeof(void *) ? align : sizeof(void *)) - 1;
if ( (pAlloc = (unsigned char*)g_pMemAlloc->Alloc( sizeof(void *) + align + size, pszFile, nLine ) ) == (unsigned char*)NULL)
if ( (pAlloc = (unsigned char*)g_pMemAlloc->IndirectAlloc( sizeof(void *) + align + size, pszFile, nLine ) ) == (unsigned char*)NULL)
return NULL;
pResult = (unsigned char*)( (size_t)(pAlloc + sizeof(void *) + align ) & ~align );
((unsigned char**)(pResult))[-1] = pAlloc;
return (void *)pResult;
}
inline void *MemAlloc_AllocAlignedUnattributed( size_t size, size_t align )
{
unsigned char *pAlloc, *pResult;
if (!ValueIsPowerOfTwo(align))
return NULL;
align = (align > sizeof(void *) ? align : sizeof(void *)) - 1;
if ( (pAlloc = (unsigned char*)MemAlloc_Alloc( sizeof(void *) + align + size ) ) == (unsigned char*)NULL)
return NULL;
pResult = (unsigned char*)( (size_t)(pAlloc + sizeof(void *) + align ) & ~align );
((unsigned char**)(pResult))[-1] = pAlloc;
return (void *)pResult;
}
inline void *MemAlloc_AllocAlignedFileLine( size_t size, size_t align, const char *pszFile, int nLine )
{
unsigned char *pAlloc, *pResult;
if (!ValueIsPowerOfTwo(align))
return NULL;
align = (align > sizeof(void *) ? align : sizeof(void *)) - 1;
if ( (pAlloc = (unsigned char*)MemAlloc_Alloc( sizeof(void *) + align + size, pszFile, nLine ) ) == (unsigned char*)NULL)
return NULL;
pResult = (unsigned char*)( (size_t)(pAlloc + sizeof(void *) + align ) & ~align );
@ -166,7 +264,7 @@ inline void *MemAlloc_AllocAligned( size_t size, size_t align, const char *pszFi
inline void *MemAlloc_ReallocAligned( void *ptr, size_t size, size_t align )
{
if ( !IsPowerOfTwo( uint(align) ) )
if ( !ValueIsPowerOfTwo( align ) )
return NULL;
// Don't change alignment between allocation + reallocation.
@ -212,6 +310,23 @@ inline void MemAlloc_FreeAligned( void *pMemBlock )
g_pMemAlloc->Free( pAlloc );
}
inline void MemAlloc_FreeAligned( void *pMemBlock, const char *pszFile, int nLine )
{
void *pAlloc;
if ( pMemBlock == NULL )
return;
pAlloc = pMemBlock;
// pAlloc points to the pointer to starting of the memory block
pAlloc = (void *)(((size_t)pAlloc & ~( sizeof(void *) - 1 ) ) - sizeof(void *));
// pAlloc is the pointer to the start of memory block
pAlloc = *( (void **)pAlloc );
g_pMemAlloc->Free( pAlloc, pszFile, nLine );
}
inline size_t MemAlloc_GetSizeAligned( void *pMemBlock )
{
void *pAlloc;
@ -232,19 +347,37 @@ inline size_t MemAlloc_GetSizeAligned( void *pMemBlock )
//-----------------------------------------------------------------------------
#if (defined(_DEBUG) || defined(USE_MEM_DEBUG))
#define MEM_ALLOC_CREDIT_(tag) CMemAllocAttributeAlloction memAllocAttributeAlloction( tag, __LINE__ )
#define MemAlloc_PushAllocDbgInfo( pszFile, line ) g_pMemAlloc->PushAllocDbgInfo( pszFile, line )
#define MemAlloc_PopAllocDbgInfo() g_pMemAlloc->PopAllocDbgInfo()
#define MemAlloc_RegisterAllocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) g_pMemAlloc->RegisterAllocation( pFileName, nLine, nLogicalSize, nActualSize, nTime )
#define MemAlloc_RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) g_pMemAlloc->RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime )
#else
#define MEM_ALLOC_CREDIT_(tag) ((void)0)
#define MemAlloc_PushAllocDbgInfo( pszFile, line ) ((void)0)
#define MemAlloc_PopAllocDbgInfo() ((void)0)
#define MemAlloc_RegisterAllocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) ((void)0)
#define MemAlloc_RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) ((void)0)
#endif
#define MemAlloc_DumpStats() g_pMemAlloc->DumpStats()
#define MemAlloc_CompactHeap() g_pMemAlloc->CompactHeap()
#define MemAlloc_OutOfMemory() g_pMemAlloc->OutOfMemory()
#define MemAlloc_CompactIncremental() g_pMemAlloc->CompactIncremental()
#define MemAlloc_DumpStatsFileBase( _filename ) g_pMemAlloc->DumpStatsFileBase( _filename )
#define MemAlloc_CrtCheckMemory() g_pMemAlloc->CrtCheckMemory()
#define MemAlloc_GlobalMemoryStatus( _usedMemory, _freeMemory ) g_pMemAlloc->GlobalMemoryStatus( _usedMemory, _freeMemory )
#define MemAlloc_MemoryAllocFailed() g_pMemAlloc->MemoryAllocFailed()
#define MemAlloc_GetDebugInfoSize() g_pMemAlloc->GetDebugInfoSize()
#define MemAlloc_SaveDebugInfo( pvDebugInfo ) g_pMemAlloc->SaveDebugInfo( pvDebugInfo )
#define MemAlloc_RestoreDebugInfo( pvDebugInfo ) g_pMemAlloc->RestoreDebugInfo( pvDebugInfo )
#define MemAlloc_InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) g_pMemAlloc->InitDebugInfo( pvDebugInfo, pchRootFileName, nLine )
#define MemAlloc_GetSize( x ) g_pMemAlloc->GetSize( x );
//-----------------------------------------------------------------------------
class CMemAllocAttributeAlloction
@ -265,7 +398,7 @@ public:
//-----------------------------------------------------------------------------
#if defined(_WIN32) && ( defined(_DEBUG) || defined(USE_MEM_DEBUG) )
#if defined(MSVC) && ( defined(_DEBUG) || defined(USE_MEM_DEBUG) )
#pragma warning(disable:4290)
#pragma warning(push)
@ -275,7 +408,14 @@ public:
// Note: typeid().name() is not threadsafe, so if the project needs to access it in multiple threads
// simultaneously, it'll need a mutex.
#if defined(_CPPRTTI) && defined(MEM_DEBUG_CLASSNAME)
#define MEM_ALLOC_CREDIT_CLASS() MEM_ALLOC_CREDIT_( typeid(*this).name() )
template <typename T> const char *MemAllocClassName( T *p )
{
static const char *pszName = typeid(*p).name(); // @TODO: support having debug heap ignore certain allocations, and ignore memory allocated here [5/7/2009 tom]
return pszName;
}
#define MEM_ALLOC_CREDIT_CLASS() MEM_ALLOC_CREDIT_( MemAllocClassName( this ) )
#define MEM_ALLOC_CLASSNAME(type) (typeid((type*)(0)).name())
#else
#define MEM_ALLOC_CREDIT_CLASS() MEM_ALLOC_CREDIT_( __FILE__ )
@ -306,8 +446,13 @@ struct MemAllocFileLine_t
};
#define MEMALLOC_DEFINE_EXTERNAL_TRACKING( tag ) \
static CUtlMap<void *, MemAllocFileLine_t, int> g_##tag##Allocs( DefLessFunc( void *) ); \
static const char *g_psz##tag##Alloc = strcpy( (char *)g_pMemAlloc->Alloc( strlen( #tag "Alloc" ) + 1, "intentional leak", 0 ), #tag "Alloc" );
static CUtlMap<void *, MemAllocFileLine_t, int> s_##tag##Allocs( DefLessFunc( void *) ); \
CUtlMap<void *, MemAllocFileLine_t, int> * g_p##tag##Allocs = &s_##tag##Allocs; \
const char * g_psz##tag##Alloc = strcpy( (char *)MemAlloc_Alloc( strlen( #tag "Alloc" ) + 1, "intentional leak", 0 ), #tag "Alloc" );
#define MEMALLOC_DECLARE_EXTERNAL_TRACKING( tag ) \
extern CUtlMap<void *, MemAllocFileLine_t, int> * g_p##tag##Allocs; \
extern const char * g_psz##tag##Alloc;
#define MemAlloc_RegisterExternalAllocation( tag, p, size ) \
if ( !p ) \
@ -318,7 +463,7 @@ struct MemAllocFileLine_t
g_pMemAlloc->GetActualDbgInfo( fileLine.pszFile, fileLine.line ); \
if ( fileLine.pszFile != g_psz##tag##Alloc ) \
{ \
g_##tag##Allocs.Insert( p, fileLine ); \
g_p##tag##Allocs->Insert( p, fileLine ); \
} \
\
MemAlloc_RegisterAllocation( fileLine.pszFile, fileLine.line, size, size, 0); \
@ -330,11 +475,11 @@ struct MemAllocFileLine_t
else \
{ \
MemAllocFileLine_t fileLine = { g_psz##tag##Alloc, 0 }; \
CUtlMap<void *, MemAllocFileLine_t, int>::IndexType_t iRecordedFileLine = g_##tag##Allocs.Find( p ); \
if ( iRecordedFileLine != g_##tag##Allocs.InvalidIndex() ) \
CUtlMap<void *, MemAllocFileLine_t, int>::IndexType_t iRecordedFileLine = g_p##tag##Allocs->Find( p ); \
if ( iRecordedFileLine != g_p##tag##Allocs->InvalidIndex() ) \
{ \
fileLine = g_##tag##Allocs[iRecordedFileLine]; \
g_##tag##Allocs.RemoveAt( iRecordedFileLine ); \
fileLine = (*g_p##tag##Allocs)[iRecordedFileLine]; \
g_p##tag##Allocs->RemoveAt( iRecordedFileLine ); \
} \
\
MemAlloc_RegisterDeallocation( fileLine.pszFile, fileLine.line, size, size, 0); \
@ -343,6 +488,7 @@ struct MemAllocFileLine_t
#else
#define MEMALLOC_DEFINE_EXTERNAL_TRACKING( tag )
#define MEMALLOC_DECLARE_EXTERNAL_TRACKING( tag )
#define MemAlloc_RegisterExternalAllocation( tag, p, size ) ((void)0)
#define MemAlloc_RegisterExternalDeallocation( tag, p, size ) ((void)0)
@ -350,6 +496,51 @@ struct MemAllocFileLine_t
//-----------------------------------------------------------------------------
#elif defined( POSIX )
#if defined( OSX )
// Mac always aligns allocs, don't need to call posix_memalign
//inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; posix_memalign(&pTmp, alignment, size); return pTmp;}
inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; pTmp = malloc(size); return pTmp;}
#endif
inline void *_aligned_malloc( size_t nSize, size_t align ) { return memalign( align, nSize ); }
inline void _aligned_free( void *ptr ) { free( ptr ); }
inline void *MemAlloc_Alloc( size_t nSize, const char *pFileName = NULL, int nLine = 0 ) { return malloc( nSize ); }
inline void MemAlloc_Free( void *ptr, const char *pFileName = NULL, int nLine = 0 ) { free( ptr ); }
inline void *MemAlloc_AllocAligned( size_t size, size_t align, const char *pszFile = NULL, int nLine = 0 ) { return memalign( align, size ); }
inline void *MemAlloc_AllocAlignedFileLine( size_t size, size_t align, const char *pszFile = NULL, int nLine = 0 ) { return memalign( align, size ); }
inline void MemAlloc_FreeAligned( void *pMemBlock, const char *pszFile = NULL, int nLine = 0 ) { free( pMemBlock ); }
#if defined( OSX )
inline size_t _msize( void *ptr ) { return malloc_size( ptr ); }
#else
inline size_t _msize( void *ptr ) { return malloc_usable_size( ptr ); }
#endif
inline void *MemAlloc_ReallocAligned( void *ptr, size_t size, size_t align )
{
void *ptr_new_aligned = memalign( align, size );
if( ptr_new_aligned )
{
size_t old_size = _msize( ptr );
size_t copy_size = ( size < old_size ) ? size : old_size;
memcpy( ptr_new_aligned, ptr, copy_size );
free( ptr );
}
return ptr_new_aligned;
}
#else
#define MemAlloc_GetDebugInfoSize() g_pMemAlloc->GetDebugInfoSize()
#define MemAlloc_SaveDebugInfo( pvDebugInfo ) g_pMemAlloc->SaveDebugInfo( pvDebugInfo )
#define MemAlloc_RestoreDebugInfo( pvDebugInfo ) g_pMemAlloc->RestoreDebugInfo( pvDebugInfo )
#define MemAlloc_InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) g_pMemAlloc->InitDebugInfo( pvDebugInfo, pchRootFileName, nLine )
#endif // !STEAM && !NO_MALLOC_OVERRIDE
//-----------------------------------------------------------------------------
@ -358,11 +549,128 @@ struct MemAllocFileLine_t
#define MEM_ALLOC_CREDIT_(tag) ((void)0)
#define MEM_ALLOC_CREDIT() MEM_ALLOC_CREDIT_(__FILE__)
#define MEM_ALLOC_CREDIT_FUNCTION()
#define MEM_ALLOC_CREDIT_CLASS()
#define MEM_ALLOC_CLASSNAME(type) NULL
#define MemAlloc_PushAllocDbgInfo( pszFile, line )
#define MemAlloc_PopAllocDbgInfo()
#define MemAlloc_RegisterAllocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) ((void)0)
#define MemAlloc_RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) ((void)0)
#define MemAlloc_DumpStats() ((void)0)
#define MemAlloc_CompactHeap() ((void)0)
#define MemAlloc_OutOfMemory() ((void)0)
#define MemAlloc_CompactIncremental() ((void)0)
#define MemAlloc_DumpStatsFileBase( _filename ) ((void)0)
inline bool MemAlloc_CrtCheckMemory() { return true; }
inline void MemAlloc_GlobalMemoryStatus( size_t *pusedMemory, size_t *pfreeMemory )
{
*pusedMemory = 0;
*pfreeMemory = 0;
}
#define MemAlloc_MemoryAllocFailed() 0
#define MemAlloc_GetDebugInfoSize() 0
#define MemAlloc_SaveDebugInfo( pvDebugInfo ) ((void)0)
#define MemAlloc_RestoreDebugInfo( pvDebugInfo ) ((void)0)
#define MemAlloc_InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) ((void)0)
#define MEMALLOC_DEFINE_EXTERNAL_TRACKING( tag )
#define MemAlloc_RegisterExternalAllocation( tag, p, size ) ((void)0)
#define MemAlloc_RegisterExternalDeallocation( tag, p, size ) ((void)0)
#endif // !STEAM && NO_MALLOC_OVERRIDE
//-----------------------------------------------------------------------------
// linux memory tracking via hooks.
#if defined( POSIX ) && !defined( NO_HOOK_MALLOC )
PLATFORM_INTERFACE void MemoryLogMessage( char const *s ); // throw a message into the memory log
PLATFORM_INTERFACE void EnableMemoryLogging( bool bOnOff );
PLATFORM_INTERFACE void DumpMemoryLog( int nThresh );
PLATFORM_INTERFACE void DumpMemorySummary( void );
PLATFORM_INTERFACE void SetMemoryMark( void );
PLATFORM_INTERFACE void DumpChangedMemory( int nThresh );
#else
FORCEINLINE void MemoryLogMessage( char const *s )
{
}
FORCEINLINE void EnableMemoryLogging( bool bOnOff )
{
}
FORCEINLINE void DumpMemoryLog( int nThresh )
{
}
FORCEINLINE void DumpMemorySummary( void )
{
}
FORCEINLINE void SetMemoryMark( void )
{
}
FORCEINLINE void DumpChangedMemory( int nThresh )
{
}
#endif
#ifdef POSIX
// ApproximateProcessMemoryUsage returns the approximate memory footprint of this process.
PLATFORM_INTERFACE size_t ApproximateProcessMemoryUsage( void );
#else
FORCEINLINE size_t ApproximateProcessMemoryUsage( void )
{
return 0;
}
#endif
struct aligned_tmp_t
{
// empty base class
};
// template here to allow adding alignment at levels of hierarchy that aren't the base
template< int bytesAlignment = 16, class T = aligned_tmp_t >
class CAlignedNewDelete : public T
{
public:
/*
Note that this class does not overload operator new[] and delete[] which means that
classes that depend on this for alignment may end up misaligned if an array is
allocated. This problem is now mostly theoretical because this class is mostly
obsolete.
*/
void *operator new( size_t nSize )
{
return MemAlloc_AllocAligned( nSize, bytesAlignment );
}
void* operator new( size_t nSize, int nBlockUse, const char *pFileName, int nLine )
{
return MemAlloc_AllocAlignedFileLine( nSize, bytesAlignment, pFileName, nLine );
}
void operator delete(void *pData)
{
if ( pData )
{
MemAlloc_FreeAligned( pData );
}
}
void operator delete( void* pData, int nBlockUse, const char *pFileName, int nLine )
{
if ( pData )
{
MemAlloc_FreeAligned( pData, pFileName, nLine );
}
}
};
#endif /* TIER0_MEMALLOC_H */

View File

@ -19,47 +19,53 @@
#define USE_MEM_DEBUG 1
#endif
#if defined(NO_HOOK_MALLOC)
#undef USE_MEM_DEBUG
#endif
// If debug build or ndebug and not already included MS custom alloc files, or already included this file
#if (defined(_DEBUG) || !defined(_INC_CRTDBG)) || defined(MEMDBGON_H)
#include "basetypes.h"
#ifdef _WIN32
#include <tchar.h>
#else
#include <wchar.h>
#endif
#include <string.h>
#if defined __APPLE__
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#include "tier0/basetypes.h"
#include "tier0/valve_off.h"
#ifdef COMPILER_MSVC
#include <tchar.h>
#else
#include <wchar.h>
#endif
#include <string.h>
#include <malloc.h>
#include "tier0/valve_on.h"
#include "commonmacros.h"
#include "memalloc.h"
#ifdef _WIN32
#ifndef MEMALLOC_REGION
#define MEMALLOC_REGION 0
#endif
#else
#undef MEMALLOC_REGION
#endif
#if defined(USE_MEM_DEBUG)
#if defined(_LINUX) || defined(__APPLE__)
#if defined(POSIX)
#define _NORMAL_BLOCK 1
#include "tier0/valve_off.h"
#include <cstddef>
#include <glob.h>
#include <new>
#include <sys/types.h>
#if !defined( DID_THE_OPERATOR_NEW )
#define DID_THE_OPERATOR_NEW
inline void* operator new( size_t nSize, int blah, const char *pFileName, int nLine )
{
return g_pMemAlloc->Alloc( nSize, pFileName, nLine );
}
inline void* operator new[]( size_t nSize, int blah, const char *pFileName, int nLine )
{
return g_pMemAlloc->Alloc( nSize, pFileName, nLine );
}
#define DID_THE_OPERATOR_NEW
// posix doesn't have a new of this form, so we impl our own
void* operator new( size_t nSize, int blah, const char *pFileName, int nLine );
void* operator new[]( size_t nSize, int blah, const char *pFileName, int nLine );
#endif
#else // defined(_LINUX)
#else // defined(POSIX)
// Include crtdbg.h and make sure _DEBUG is set to 1.
#if !defined(_DEBUG)
@ -70,7 +76,7 @@
#include <crtdbg.h>
#endif // !defined(_DEBUG)
#endif // defined(_LINUX)
#endif // defined(POSIX)
#endif
#include "tier0/memdbgoff.h"
@ -97,22 +103,30 @@ inline void *MemAlloc_InlineCallocMemset( void *pMem, size_t nCount, size_t nEle
}
#endif
#define calloc(c, s) MemAlloc_InlineCallocMemset(malloc(c*s), c, s)
#ifndef USE_LIGHT_MEM_DEBUG
#define free(p) g_pMemAlloc->Free( p )
#define _aligned_free( p ) MemAlloc_FreeAligned( p )
#else
extern const char *g_pszModule;
#define free(p) g_pMemAlloc->Free( p, g_pszModule, 0 )
#define _aligned_free( p ) MemAlloc_FreeAligned( p, g_pszModule, 0 )
#endif
#define _msize(p) g_pMemAlloc->GetSize( p )
#define _expand(p, s) _expand_NoLongerSupported(p, s)
#define _aligned_free( p ) MemAlloc_FreeAligned( p )
// --------------------------------------------------------
// Debug path
#if defined(USE_MEM_DEBUG)
#define malloc(s) g_pMemAlloc->Alloc( s, __FILE__, __LINE__)
#define malloc(s) MemAlloc_Alloc( s, __FILE__, __LINE__)
#define realloc(p, s) g_pMemAlloc->Realloc( p, s, __FILE__, __LINE__ )
#define _aligned_malloc( s, a ) MemAlloc_AllocAligned( s, a, __FILE__, __LINE__ )
#define _aligned_malloc( s, a ) MemAlloc_AllocAlignedFileLine( s, a, __FILE__, __LINE__ )
#define _malloc_dbg(s, t, f, l) WHYCALLINGTHISDIRECTLY(s)
#if !defined( GNUC )
#if defined(__AFX_H__) && defined(DEBUG_NEW)
#define new DEBUG_NEW
#else
@ -120,6 +134,7 @@ inline void *MemAlloc_InlineCallocMemset( void *pMem, size_t nCount, size_t nEle
#define MEMALL_DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new MEMALL_DEBUG_NEW
#endif
#endif
#undef _strdup
#undef strdup
@ -142,7 +157,7 @@ inline char *MemAlloc_StrDup(const char *pString, const char *pFileName, unsigne
return NULL;
size_t len = strlen(pString) + 1;
if ((pMemory = (char *)g_pMemAlloc->Alloc(len, pFileName, nLine)) != NULL)
if ((pMemory = (char *)MemAlloc_Alloc(len, pFileName, nLine)) != NULL)
{
return strcpy( pMemory, pString );
}
@ -158,7 +173,7 @@ inline wchar_t *MemAlloc_WcStrDup(const wchar_t *pString, const char *pFileName,
return NULL;
size_t len = (wcslen(pString) + 1);
if ((pMemory = (wchar_t *)g_pMemAlloc->Alloc(len * sizeof(wchar_t), pFileName, nLine)) != NULL)
if ((pMemory = (wchar_t *)MemAlloc_Alloc(len * sizeof(wchar_t), pFileName, nLine)) != NULL)
{
return wcscpy( pMemory, pString );
}
@ -172,9 +187,15 @@ inline wchar_t *MemAlloc_WcStrDup(const wchar_t *pString, const char *pFileName,
// --------------------------------------------------------
// Release path
#define malloc(s) g_pMemAlloc->Alloc( s )
#ifndef USE_LIGHT_MEM_DEBUG
#define malloc(s) MemAlloc_Alloc( s )
#define realloc(p, s) g_pMemAlloc->Realloc( p, s )
#define _aligned_malloc( s, a ) MemAlloc_AllocAligned( s, a )
#else
#define malloc(s) MemAlloc_Alloc( s, g_pszModule, 0 )
#define realloc(p, s) g_pMemAlloc->Realloc( p, s, g_pszModule, 0 )
#define _aligned_malloc( s, a ) MemAlloc_AllocAlignedFileLine( s, a, g_pszModule, 0 )
#endif
#ifndef _malloc_dbg
#define _malloc_dbg(s, t, f, l) WHYCALLINGTHISDIRECTLY(s)
@ -203,7 +224,7 @@ inline char *MemAlloc_StrDup(const char *pString)
return NULL;
size_t len = strlen(pString) + 1;
if ((pMemory = (char *)g_pMemAlloc->Alloc(len)) != NULL)
if ((pMemory = (char *)malloc(len)) != NULL)
{
return strcpy( pMemory, pString );
}
@ -219,7 +240,7 @@ inline wchar_t *MemAlloc_WcStrDup(const wchar_t *pString)
return NULL;
size_t len = (wcslen(pString) + 1);
if ((pMemory = (wchar_t *)g_pMemAlloc->Alloc(len * sizeof(wchar_t))) != NULL)
if ((pMemory = (wchar_t *)malloc(len * sizeof(wchar_t))) != NULL)
{
return wcscpy( pMemory, pString );
}
@ -244,4 +265,9 @@ inline wchar_t *MemAlloc_WcStrDup(const wchar_t *pString)
#endif
#endif // _INC_CRTDBG
#else
// Needed for MEM_ALLOC_CREDIT(), MemAlloc_Alloc(), etc.
#include "memalloc.h"
#endif // !STEAM && !NO_MALLOC_OVERRIDE

View File

@ -27,6 +27,7 @@ class IToolSystem;
class IClientRenderable;
class Vector;
class QAngle;
class IEntityFactoryDictionary;
//-----------------------------------------------------------------------------
@ -159,6 +160,14 @@ public:
#define VCLIENTTOOLS_INTERFACE_VERSION "VCLIENTTOOLS001"
class CEntityRespawnInfo
{
public:
int m_nHammerID;
const char *m_pEntText;
};
//-----------------------------------------------------------------------------
// Purpose: Interface from engine to tools for manipulating entities
//-----------------------------------------------------------------------------
@ -186,6 +195,11 @@ public:
// entity spawning
virtual void *CreateEntityByName( const char *szClassName ) = 0;
virtual void DispatchSpawn( void *pEntity ) = 0;
virtual bool DestroyEntityByHammerId( int iHammerID ) = 0;
// This function respawns the entity into the same entindex slot AND tricks the EHANDLE system into thinking it's the same
// entity version so anyone holding an EHANDLE to the entity points at the newly-respawned entity.
virtual bool RespawnEntitiesWithEdits( CEntityRespawnInfo *pInfos, int nInfos ) = 0;
// This reloads a portion or all of a particle definition file.
// It's up to the server to decide if it cares about this file
@ -193,28 +207,19 @@ public:
virtual void ReloadParticleDefintions( const char *pFileName, const void *pBufData, int nLen ) = 0;
virtual void AddOriginToPVS( const Vector &org ) = 0;
virtual void MoveEngineViewTo( const Vector &vPos, const QAngle &vAngles ) = 0;
// Call UTIL_Remove on the entity.
virtual void RemoveEntity_OBSOLETE_USE_DESTROY( int nHammerID ) = 0;
virtual void RemoveEntity( CBaseEntity *pEntity ) = 0;
virtual void RemoveEntityImmediate( CBaseEntity *pEntity ) = 0;
virtual IEntityFactoryDictionary *GetEntityFactoryDictionary( void ) = 0;
};
#define VSERVERTOOLS_INTERFACE_VERSION "VSERVERTOOLS001"
typedef IServerTools IServerTools001;
//-----------------------------------------------------------------------------
// Purpose: Client side tool interace (right now just handles IClientRenderables).
// In theory could support hooking into client side entities directly
//-----------------------------------------------------------------------------
class IServerChoreoTools : public IBaseInterface
{
public:
// Iterates through ALL entities (separate list for client vs. server)
virtual EntitySearchResult NextChoreoEntity( EntitySearchResult currentEnt ) = 0;
EntitySearchResult FirstChoreoEntity() { return NextChoreoEntity( NULL ); }
virtual const char *GetSceneFile( EntitySearchResult sr ) = 0;
// For interactive editing
virtual int GetEntIndex( EntitySearchResult sr ) = 0;
virtual void ReloadSceneFromDisk( int entindex ) = 0;
};
#define VSERVERCHOREOTOOLS_INTERFACE_VERSION "VSERVERCHOREOTOOLS001"
#define VSERVERTOOLS_INTERFACE_VERSION_1 "VSERVERTOOLS001"
#define VSERVERTOOLS_INTERFACE_VERSION "VSERVERTOOLS002"
#define VSERVERTOOLS_INTERFACE_VERSION_INT 2
#endif // ITOOLENTITY_H