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

Update IKeyValuesSystem & obsolete public/vstdlib

This commit is contained in:
GAMMACASE
2025-01-15 17:19:41 +03:00
parent a26ca82e87
commit 64f3cac5e9
16 changed files with 1807 additions and 2038 deletions

View File

@ -198,7 +198,7 @@ typedef void (*pfnDemoCustomDataCallback)( uint8 *pData, size_t iSize );
//-----------------------------------------------------------------------------
// Just an interface version name for the random number interface
// See vstdlib/random.h for the interface definition
// See tier1/random.h for the interface definition
// NOTE: If you change this, also change VENGINE_SERVER_RANDOM_INTERFACE_VERSION in eiface.h
//-----------------------------------------------------------------------------
#define VENGINE_CLIENT_RANDOM_INTERFACE_VERSION "VEngineRandom001"

View File

@ -483,7 +483,7 @@ public:
//-----------------------------------------------------------------------------
// Just an interface version name for the random number interface
// See vstdlib/random.h for the interface definition
// See tier1/random.h for the interface definition
// NOTE: If you change this, also change VENGINE_CLIENT_RANDOM_INTERFACE_VERSION in cdll_int.h
//-----------------------------------------------------------------------------
#define VENGINE_SERVER_RANDOM_INTERFACE_VERSION "VEngineRandom001"

View File

@ -24,7 +24,7 @@ class IMatRenderContext;
#include "dmxloader/dmxelement.h"
#include "tier1/utlintrusivelist.h"
#include "vstdlib/random.h"
#include "tier1/random.h"
#include "tier1/utlobjectreference.h"
#include "tier1/utlstringmap.h"
#include "tier1/utlmap.h"

View File

@ -1,67 +1,80 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef VSTDLIB_IKEYVALUESSYSTEM_H
#define VSTDLIB_IKEYVALUESSYSTEM_H
#ifdef _WIN32
#pragma once
#endif
#include "vstdlib/vstdlib.h"
class KeyValues;
class HKeySymbol
{
public:
HKeySymbol() : nIndex(~0) { }
HKeySymbol(uint32 idx) : nIndex(idx) { }
inline uint32 Get() { return nIndex; }
private:
uint32 nIndex;
};
//-----------------------------------------------------------------------------
// Purpose: Interface to shared data repository for KeyValues (included in vgui_controls.lib)
// allows for central data storage point of KeyValues symbol table
//-----------------------------------------------------------------------------
class IKeyValuesSystem
{
public:
// allocates/frees a KeyValues object from the shared mempool
virtual void *AllocKeyValuesMemory() = 0;
virtual void FreeKeyValuesMemory(KeyValues *pKV) = 0;
// symbol table access (used for key names)
virtual HKeySymbol GetSymbolForString( const char *name, bool bCreate = true ) = 0;
virtual const char *GetStringForSymbol(HKeySymbol symbol) = 0;
// for debugging, adds KeyValues record into global list so we can track memory leaks
virtual void AddKeyValuesToMemoryLeakList(void *pMem, HKeySymbol name) = 0;
virtual void RemoveKeyValuesFromMemoryLeakList(void *pMem) = 0;
// set/get a value for keyvalues resolution symbol
// e.g.: SetKeyValuesExpressionSymbol( "LOWVIOLENCE", true ) - enables [$LOWVIOLENCE]
virtual void SetKeyValuesExpressionSymbol( const char *name, bool bValue ) = 0;
virtual bool GetKeyValuesExpressionSymbol( const char *name ) = 0;
// symbol table access from code with case-preserving requirements (used for key names)
virtual HKeySymbol GetSymbolForStringCaseSensitive( HKeySymbol &hCaseInsensitiveSymbol, const char *name, bool bCreate = true ) = 0;
virtual HKeySymbol GetCaseInsensitiveSymbolFromCaseSensitiveSymbol( HKeySymbol symbol ) = 0;
virtual const char *CopyString( const char * ) = 0;
virtual void ReleaseStringCopy( const char * ) = 0;
virtual const wchar_t *CopyWString( const wchar_t * ) = 0;
virtual void ReleaseWStringCopy( const wchar_t * ) = 0;
};
VSTDLIB_INTERFACE IKeyValuesSystem *KeyValuesSystem();
// #define KEYVALUESSYSTEM_INTERFACE_VERSION "KeyValuesSystem002"
#endif // VSTDLIB_IKEYVALUESSYSTEM_H
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef VSTDLIB_IKEYVALUESSYSTEM_H
#define VSTDLIB_IKEYVALUESSYSTEM_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/platform.h"
class CUtlCharConversion;
class CUtlScratchMemoryPool;
class CTemporaryKeyValues;
class KeyValues;
class HKeySymbol
{
public:
HKeySymbol() : nIndex(~0) { }
HKeySymbol(uint32 idx) : nIndex(idx) { }
inline uint32 Get() { return nIndex; }
private:
uint32 nIndex;
};
//-----------------------------------------------------------------------------
// Purpose: Interface to shared data repository for KeyValues (included in vgui_controls.lib)
// allows for central data storage point of KeyValues symbol table
//-----------------------------------------------------------------------------
class IKeyValuesSystem
{
public:
virtual ~IKeyValuesSystem() = 0;
// allocates/frees a KeyValues object from the shared mempool
virtual KeyValues *AllocKeyValuesMemory() = 0;
virtual void FreeKeyValuesMemory(KeyValues *pKV) = 0;
// symbol table access (used for key names)
virtual HKeySymbol GetSymbolForString( const char *name, bool bCreate = true ) = 0;
virtual const char *GetStringForSymbol(HKeySymbol symbol) = 0;
// for debugging, adds KeyValues record into global list so we can track memory leaks
virtual void AddKeyValuesToMemoryLeakList(void *pMem, HKeySymbol name) = 0;
virtual void RemoveKeyValuesFromMemoryLeakList(void *pMem) = 0;
virtual void unk001() = 0;
// set/get a value for keyvalues resolution symbol
// e.g.: SetKeyValuesExpressionSymbol( "LOWVIOLENCE", true ) - enables [$LOWVIOLENCE]
virtual void SetKeyValuesExpressionSymbol( const char *name, bool bValue ) = 0;
virtual bool GetKeyValuesExpressionSymbol( const char *name ) = 0;
// symbol table access from code with case-preserving requirements (used for key names)
virtual HKeySymbol GetSymbolForStringCaseSensitive( HKeySymbol &hCaseInsensitiveSymbol, const char *name, bool bCreate = true ) = 0;
virtual HKeySymbol GetCaseInsensitiveSymbolFromCaseSensitiveSymbol( HKeySymbol symbol ) = 0;
virtual const char *CopyString( const char * ) = 0;
virtual void ReleaseStringCopy( const char * ) = 0;
virtual const wchar_t *CopyWString( const wchar_t * ) = 0;
virtual void ReleaseWStringCopy( const wchar_t * ) = 0;
virtual CUtlCharConversion *GetCharacterConversion( bool is_cstring ) = 0;
virtual CTemporaryKeyValues *AllocateTemporaryKeyValues() = 0;
virtual void ReleaseTemporaryKeyValues( CTemporaryKeyValues *temp_kv ) = 0;
// Returns previously used memory pool if any
virtual CUtlScratchMemoryPool *SetNewScratchMemoryPool( CUtlScratchMemoryPool *pool ) = 0;
};
PLATFORM_INTERFACE IKeyValuesSystem *KeyValuesSystem();
#endif // VSTDLIB_IKEYVALUESSYSTEM_H

View File

@ -20,10 +20,11 @@
#endif
#endif
#include "platform.h"
#include "utlvector.h"
#include "Color.h"
#include "exprevaluator.h"
#include <vstdlib/IKeyValuesSystem.h>
#include "IKeyValuesSystem.h"
class IFileSystem;
class CUtlBuffer;
@ -49,15 +50,15 @@ typedef void *FileHandle_t;
DECLARE_POINTER_HANDLE( HTemporaryKeyValueAllocationScope );
PLATFORM_INTERFACE KeyValues *KeyValuesFromJSON( CUtlBuffer *buf, bool allow_unterminated = false, bool *parsed_successfully = nullptr );
PLATFORM_INTERFACE bool KeyValuesToJSON( KeyValues *kv, CUtlBuffer *buf );
class CTemporaryKeyValues
{
CTemporaryKeyValues() : m_pKeyValues(nullptr), m_hScope() {}
CTemporaryKeyValues() : m_pKeyValues( nullptr ), m_hScope() {}
~CTemporaryKeyValues()
{
// GAMMACASE: TODO: Complete with actual KeyValuesSystem call once it's reversed too.
#if 0
KeyValuesSystem()->ReleaseTemporaryAllocationScope( m_hScope );
#endif
KeyValuesSystem()->ReleaseTemporaryKeyValues( this );
}
private:

View File

@ -1,4 +1,4 @@
//========== Copyright <20> 2006, Valve Corporation, All rights reserved. ========
//========== Copyright <20> 2006, Valve Corporation, All rights reserved. ========
//
// Purpose:
//
@ -9,7 +9,7 @@
#include "tier0/tslist.h"
#include "functors.h"
#include "vstdlib/jobthread.h"
#include "jobthread.h"
#if defined( _WIN32 )
#pragma once

View File

@ -34,32 +34,29 @@ struct ExprNode
typedef ExprNode *ExprTree;
// callback to evaluate a $<symbol> during evaluation, return true or false
typedef bool (*GetSymbolProc_t)( const char *pKey, void *pUnknown );
typedef void (*SyntaxErrorProc_t)( const char *pReason );
typedef bool (*GetSymbolProc_t)( const char *pKey, void *pData );
typedef void (*SyntaxErrorProc_t)( const char *pReason, void *pData );
class CExpressionEvaluator
{
public:
CExpressionEvaluator();
~CExpressionEvaluator();
bool Evaluate( bool &result, const char *pInfixExpression, GetSymbolProc_t pGetSymbolProc = 0, SyntaxErrorProc_t pSyntaxErrorProc = 0 );
DLL_CLASS_IMPORT CExpressionEvaluator();
DLL_CLASS_IMPORT ~CExpressionEvaluator();
DLL_CLASS_IMPORT bool Evaluate(
bool &result, const char *pInfixExpression,
GetSymbolProc_t pGetSymbolProc = nullptr, SyntaxErrorProc_t pSyntaxErrorProc = nullptr,
void *pSymbolProcAdditionalData = nullptr, void *pErrorProcAdditionalData = nullptr
);
DLL_CLASS_IMPORT bool EvaluateAsUnmarkedSymbols(
bool &result, const char *pInfixExpression,
GetSymbolProc_t pGetSymbolProc = nullptr, SyntaxErrorProc_t pSyntaxErrorProc = nullptr,
void *pSymbolProcAdditionalData = nullptr, void *pErrorProcAdditionalData = nullptr
);
private:
CExpressionEvaluator( CExpressionEvaluator& ); // prevent copy constructor being used
char GetNextToken( void );
void FreeNode( ExprNode *pNode );
ExprNode *AllocateNode( void );
void FreeTree( ExprTree &node );
bool IsConditional( bool &bCondition, const char token );
bool IsNotOp( const char token );
bool IsIdentifierOrConstant( const char token );
bool MakeExprNode( ExprTree &tree, char token, Kind kind, ExprTree left, ExprTree right );
bool MakeFactor( ExprTree &tree );
bool MakeTerm( ExprTree &tree );
bool MakeExpression( ExprTree &tree );
bool BuildExpression( void );
bool SimplifyNode( ExprTree &node );
CExpressionEvaluator( CExpressionEvaluator & ) = delete;
ExprTree m_ExprTree; // Tree representation of the expression
char m_CurToken; // Current token read from the input expression
@ -68,6 +65,8 @@ private:
char m_Identifier[MAX_IDENTIFIER_LEN]; // Stores the identifier string
GetSymbolProc_t m_pGetSymbolProc;
SyntaxErrorProc_t m_pSyntaxErrorProc;
void *m_pSymbolProcData;
void *m_pErrorProcData;
bool m_bSetup;
};

View File

@ -1,130 +1,130 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef IPROCESSUTILS_H
#define IPROCESSUTILS_H
#ifdef _WIN32
#pragma once
#endif
#include "appframework/IAppSystem.h"
#include "tier1/utlstring.h"
#include "tier1/utlbuffer.h"
//-----------------------------------------------------------------------------
// Handle to a process. This is only for b/w compatibility.
//-----------------------------------------------------------------------------
class IProcess;
//-----------------------------------------------------------------------------
// Interface version
//-----------------------------------------------------------------------------
#define PIPEREAD_INFINITE INT32_MAX
abstract_class IPipeRead
{
public:
// NONBLOCKING FUNCTIONS
// Returns how much you can Read() without blocking.
virtual int GetNumBytesAvailable() = 0;
// Read whatever is available without blocking.
// This is the same as Read( sStr, GetNumBytesAvailable() ).
virtual void ReadAvailable( CUtlString &sStr, int32 nMaxBytes=PIPEREAD_INFINITE ) = 0;
virtual void ReadAvailable( CUtlBuffer* pOutBuffer, int32 nMaxBytes=PIPEREAD_INFINITE ) = 0;
// (POTENTIALLY) BLOCKING FUNCTIONS
// Read one line of output (also returns when the process quits).
// sStr will not include the \n (or \r\n) at the end of the line.
virtual void ReadLine( CUtlString &sStr ) = 0;
// This will block the calling thread until it gets the number of bytes specified
// or until the process exits. If sStr.Length() != nBytes, then you know the process exited.
//
// The returned string will always be null-terminated.
// If you call with nBytes=PIPEREAD_INFINITE, it'll read until the process exits.
virtual void Read( CUtlString &sStr, int32 nBytes=PIPEREAD_INFINITE ) = 0;
};
abstract_class IProcess
{
public:
// Note: If the process is still running, this will auto kill it unless you started the process with
// STARTPROCESS_NOAUTOKILL.
virtual void Release() = 0;
// Kill the running process. You still must call IProcess::Release to free the resources.
virtual void Abort() = 0;
// Returns true if a process is complete
virtual bool IsComplete() = 0;
// Waits until a process is complete.
// Returns the return value from the process.
virtual int WaitUntilComplete() = 0;
// Write to the process' stdin.
// This blocks until the process has read it.
virtual int WriteStdin( char *pBuf, int nBufLen ) = 0;
// Get stuff to read the outputs.
virtual IPipeRead* GetStdout() = 0;
virtual IPipeRead* GetStderr() = 0; // NOTE: Only valid if you used STARTPROCESS_SEPARATE_STDERR.
// Returns the exit code for the process. Doesn't work unless the process is complete.
// Returns -1 on error or if the process isn't complete.
virtual int GetExitCode() = 0;
};
// Flags to IProcessUtils::StartProcess.
#define STARTPROCESS_CONNECTSTDPIPES 0x01 // Necessary to use the stdin/stdout/stderr io functions.
#define STARTPROCESS_SHARE_CONSOLE 0x02 // The process writes directly to your console. The pipe objects returned by
// IProcess::GetStdout and GetStderr won't do anything.
#define STARTPROCESS_SEPARATE_STDERR 0x04 // Rather than having to read stdout and stderr to get the output, the default is to put the stderr output into stdout.
// This flag can change that behavior so you can get that output separately.
// Warning: There may be deadlock problems with this, specifically in CProcessPipeRead::GetActualProcessOutput if
// it's blocked reading stdout's pipe but the process is blocked waiting for us to flush stderr's pipe first.
// To fully support that case, we'd need threads, overlapped IO, or a more careful (and slower) GetActualProcessOutput call
// that bounces between the two pipes and never stalls.
//
// You can also get around this on the client side by reading the pipes from threads.
#define STARTPROCESS_NOAUTOKILL 0x08 // Prevents the process from being auto-terminated in IProcess::Release()
// or when IProcessUtils' Shutdown function is called.
#define STARTPROCESS_FATPIPES 0x10 // Use I/O pipes larger than the default size for processes that do lots of stdio
// (Only works with STARTPROCESS_CONNECTSTDPIPES)
//-----------------------------------------------------------------------------
// Interface for makefiles to build differently depending on where they are run from
//-----------------------------------------------------------------------------
abstract_class IProcessUtils : public IAppSystem
{
public:
// Starts, stops a process.
// If pWorkingDir is left at NULL, it'll use this process' working directory.
virtual IProcess* StartProcess( const char *pCommandLine, int fFlags, const char *pWorkingDir=NULL )= 0;
virtual IProcess* StartProcess( int argc, const char **argv, int fFlags, const char *pWorkingDir=NULL ) = 0;
// Run a process and get its output.
// If pStdout is set, then stdout AND stderr are put into pStdout.
// If not, then the text output is ignored.
//
// Returns -1 if it was unable to run the process. Otherwise, returns the exit code from the process.
virtual int SimpleRunProcess( const char *pCommandLine, const char *pWorkingDir=NULL, CUtlString *pStdout=NULL ) = 0;
};
DECLARE_TIER1_INTERFACE( IProcessUtils, g_pProcessUtils );
#endif // IPROCESSUTILS_H
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef IPROCESSUTILS_H
#define IPROCESSUTILS_H
#ifdef _WIN32
#pragma once
#endif
#include "appframework/IAppSystem.h"
#include "tier1/utlstring.h"
#include "tier1/utlbuffer.h"
//-----------------------------------------------------------------------------
// Handle to a process. This is only for b/w compatibility.
//-----------------------------------------------------------------------------
class IProcess;
//-----------------------------------------------------------------------------
// Interface version
//-----------------------------------------------------------------------------
#define PIPEREAD_INFINITE INT32_MAX
abstract_class IPipeRead
{
public:
// NONBLOCKING FUNCTIONS
// Returns how much you can Read() without blocking.
virtual int GetNumBytesAvailable() = 0;
// Read whatever is available without blocking.
// This is the same as Read( sStr, GetNumBytesAvailable() ).
virtual void ReadAvailable( CUtlString &sStr, int32 nMaxBytes=PIPEREAD_INFINITE ) = 0;
virtual void ReadAvailable( CUtlBuffer* pOutBuffer, int32 nMaxBytes=PIPEREAD_INFINITE ) = 0;
// (POTENTIALLY) BLOCKING FUNCTIONS
// Read one line of output (also returns when the process quits).
// sStr will not include the \n (or \r\n) at the end of the line.
virtual void ReadLine( CUtlString &sStr ) = 0;
// This will block the calling thread until it gets the number of bytes specified
// or until the process exits. If sStr.Length() != nBytes, then you know the process exited.
//
// The returned string will always be null-terminated.
// If you call with nBytes=PIPEREAD_INFINITE, it'll read until the process exits.
virtual void Read( CUtlString &sStr, int32 nBytes=PIPEREAD_INFINITE ) = 0;
};
abstract_class IProcess
{
public:
// Note: If the process is still running, this will auto kill it unless you started the process with
// STARTPROCESS_NOAUTOKILL.
virtual void Release() = 0;
// Kill the running process. You still must call IProcess::Release to free the resources.
virtual void Abort() = 0;
// Returns true if a process is complete
virtual bool IsComplete() = 0;
// Waits until a process is complete.
// Returns the return value from the process.
virtual int WaitUntilComplete() = 0;
// Write to the process' stdin.
// This blocks until the process has read it.
virtual int WriteStdin( char *pBuf, int nBufLen ) = 0;
// Get stuff to read the outputs.
virtual IPipeRead* GetStdout() = 0;
virtual IPipeRead* GetStderr() = 0; // NOTE: Only valid if you used STARTPROCESS_SEPARATE_STDERR.
// Returns the exit code for the process. Doesn't work unless the process is complete.
// Returns -1 on error or if the process isn't complete.
virtual int GetExitCode() = 0;
};
// Flags to IProcessUtils::StartProcess.
#define STARTPROCESS_CONNECTSTDPIPES 0x01 // Necessary to use the stdin/stdout/stderr io functions.
#define STARTPROCESS_SHARE_CONSOLE 0x02 // The process writes directly to your console. The pipe objects returned by
// IProcess::GetStdout and GetStderr won't do anything.
#define STARTPROCESS_SEPARATE_STDERR 0x04 // Rather than having to read stdout and stderr to get the output, the default is to put the stderr output into stdout.
// This flag can change that behavior so you can get that output separately.
// Warning: There may be deadlock problems with this, specifically in CProcessPipeRead::GetActualProcessOutput if
// it's blocked reading stdout's pipe but the process is blocked waiting for us to flush stderr's pipe first.
// To fully support that case, we'd need threads, overlapped IO, or a more careful (and slower) GetActualProcessOutput call
// that bounces between the two pipes and never stalls.
//
// You can also get around this on the client side by reading the pipes from threads.
#define STARTPROCESS_NOAUTOKILL 0x08 // Prevents the process from being auto-terminated in IProcess::Release()
// or when IProcessUtils' Shutdown function is called.
#define STARTPROCESS_FATPIPES 0x10 // Use I/O pipes larger than the default size for processes that do lots of stdio
// (Only works with STARTPROCESS_CONNECTSTDPIPES)
//-----------------------------------------------------------------------------
// Interface for makefiles to build differently depending on where they are run from
//-----------------------------------------------------------------------------
abstract_class IProcessUtils : public IAppSystem
{
public:
// Starts, stops a process.
// If pWorkingDir is left at NULL, it'll use this process' working directory.
virtual IProcess* StartProcess( const char *pCommandLine, int fFlags, const char *pWorkingDir=NULL )= 0;
virtual IProcess* StartProcess( int argc, const char **argv, int fFlags, const char *pWorkingDir=NULL ) = 0;
// Run a process and get its output.
// If pStdout is set, then stdout AND stderr are put into pStdout.
// If not, then the text output is ignored.
//
// Returns -1 if it was unable to run the process. Otherwise, returns the exit code from the process.
virtual int SimpleRunProcess( const char *pCommandLine, const char *pWorkingDir=NULL, CUtlString *pStdout=NULL ) = 0;
};
DECLARE_TIER1_INTERFACE( IProcessUtils, g_pProcessUtils );
#endif // IPROCESSUTILS_H

File diff suppressed because it is too large Load Diff

View File

@ -1,113 +1,113 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Random number generator
//
// $Workfile: $
// $NoKeywords: $
//===========================================================================//
#ifndef VSTDLIB_RANDOM_H
#define VSTDLIB_RANDOM_H
#include "vstdlib/vstdlib.h"
#include "tier0/basetypes.h"
#include "tier0/threadtools.h"
#define NTAB 32
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning( disable:4251 )
#endif
//-----------------------------------------------------------------------------
// A generator of uniformly distributed random numbers
//-----------------------------------------------------------------------------
class IUniformRandomStream
{
public:
// Sets the seed of the random number generator
virtual void SetSeed( int iSeed ) = 0;
// Generates random numbers
virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f ) = 0;
virtual int RandomInt( int iMinVal, int iMaxVal ) = 0;
virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f ) = 0;
};
//-----------------------------------------------------------------------------
// The standard generator of uniformly distributed random numbers
//-----------------------------------------------------------------------------
class VSTDLIB_CLASS CUniformRandomStream : public IUniformRandomStream
{
public:
CUniformRandomStream();
// Sets the seed of the random number generator
virtual void SetSeed( int iSeed );
// Generates random numbers
virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f );
virtual int RandomInt( int iMinVal, int iMaxVal );
virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f );
private:
int GenerateRandomNumber();
int m_idum;
int m_iy;
int m_iv[NTAB];
CThreadFastMutex m_mutex;
};
//-----------------------------------------------------------------------------
// A generator of gaussian distributed random numbers
//-----------------------------------------------------------------------------
class VSTDLIB_CLASS CGaussianRandomStream
{
public:
// Passing in NULL will cause the gaussian stream to use the
// installed global random number generator
CGaussianRandomStream( IUniformRandomStream *pUniformStream = NULL );
// Attaches to a random uniform stream
void AttachToStream( IUniformRandomStream *pUniformStream = NULL );
// Generates random numbers
float RandomFloat( float flMean = 0.0f, float flStdDev = 1.0f );
private:
IUniformRandomStream *m_pUniformStream;
bool m_bHaveValue;
float m_flRandomValue;
CThreadFastMutex m_mutex;
};
//-----------------------------------------------------------------------------
// A couple of convenience functions to access the library's global uniform stream
//-----------------------------------------------------------------------------
VSTDLIB_INTERFACE void RandomSeed( int iSeed );
VSTDLIB_INTERFACE float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f );
VSTDLIB_INTERFACE float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f );
VSTDLIB_INTERFACE int RandomInt( int iMinVal, int iMaxVal );
VSTDLIB_INTERFACE float RandomGaussianFloat( float flMean = 0.0f, float flStdDev = 1.0f );
//-----------------------------------------------------------------------------
// Installs a global random number generator, which will affect the Random functions above
//-----------------------------------------------------------------------------
VSTDLIB_INTERFACE void InstallUniformRandomStream( IUniformRandomStream *pStream );
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // VSTDLIB_RANDOM_H
//===== Copyright <EFBFBD> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Random number generator
//
// $Workfile: $
// $NoKeywords: $
//===========================================================================//
#ifndef VSTDLIB_RANDOM_H
#define VSTDLIB_RANDOM_H
#include "platform.h"
#include "tier0/basetypes.h"
#include "tier0/threadtools.h"
#define NTAB 32
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning( disable:4251 )
#endif
//-----------------------------------------------------------------------------
// A generator of uniformly distributed random numbers
//-----------------------------------------------------------------------------
class IUniformRandomStream
{
public:
// Sets the seed of the random number generator
virtual void SetSeed( int iSeed ) = 0;
// Generates random numbers
virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f ) = 0;
virtual int RandomInt( int iMinVal, int iMaxVal ) = 0;
virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f ) = 0;
};
//-----------------------------------------------------------------------------
// The standard generator of uniformly distributed random numbers
//-----------------------------------------------------------------------------
class DLL_CLASS_IMPORT CUniformRandomStream : public IUniformRandomStream
{
public:
CUniformRandomStream();
// Sets the seed of the random number generator
virtual void SetSeed( int iSeed );
// Generates random numbers
virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f );
virtual int RandomInt( int iMinVal, int iMaxVal );
virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f );
private:
int GenerateRandomNumber();
int m_idum;
int m_iy;
int m_iv[NTAB];
CThreadFastMutex m_mutex;
};
//-----------------------------------------------------------------------------
// A generator of gaussian distributed random numbers
//-----------------------------------------------------------------------------
class DLL_CLASS_IMPORT CGaussianRandomStream
{
public:
// Passing in NULL will cause the gaussian stream to use the
// installed global random number generator
CGaussianRandomStream( IUniformRandomStream *pUniformStream = NULL );
// Attaches to a random uniform stream
void AttachToStream( IUniformRandomStream *pUniformStream = NULL );
// Generates random numbers
float RandomFloat( float flMean = 0.0f, float flStdDev = 1.0f );
private:
IUniformRandomStream *m_pUniformStream;
bool m_bHaveValue;
float m_flRandomValue;
CThreadFastMutex m_mutex;
};
//-----------------------------------------------------------------------------
// A couple of convenience functions to access the library's global uniform stream
//-----------------------------------------------------------------------------
DLL_IMPORT void RandomSeed( int iSeed );
DLL_IMPORT float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f );
DLL_IMPORT float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f );
DLL_IMPORT int RandomInt( int iMinVal, int iMaxVal );
DLL_IMPORT float RandomGaussianFloat( float flMean = 0.0f, float flStdDev = 1.0f );
//-----------------------------------------------------------------------------
// Installs a global random number generator, which will affect the Random functions above
//-----------------------------------------------------------------------------
DLL_IMPORT void InstallUniformRandomStream( IUniformRandomStream *pStream );
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // VSTDLIB_RANDOM_H

View File

@ -16,6 +16,7 @@
#include "unitlib/unitlib.h" // just here for tests - remove before checking in!!!
#include "platform.h"
#include "tier1/utlmemory.h"
#include "tier1/cbyteswap.h"
#include "tier1/bufferstring.h"
@ -36,7 +37,7 @@ struct characterset_t;
// { '\t', "t" }
// END_CHAR_CONVERSION( CStringConversion, '\\' )
//-----------------------------------------------------------------------------
class CUtlCharConversion
class DLL_CLASS_IMPORT CUtlCharConversion
{
public:
struct ConversionArray_t
@ -45,7 +46,14 @@ public:
const char *m_pReplacementString;
};
CUtlCharConversion( char nEscapeChar, const char *pDelimiter, int nCount, ConversionArray_t *pArray );
CUtlCharConversion( char nEscapeChar, const char *pDelimiter, int nCount, const ConversionArray_t *pArray );
CUtlCharConversion( CUtlCharConversion &&rhs );
CUtlCharConversion( const CUtlCharConversion &rhs );
CUtlCharConversion &operator=( CUtlCharConversion &&rhs );
CUtlCharConversion &operator=( const CUtlCharConversion &rhs );
char GetEscapeChar() const;
const char *GetDelimiter() const;
int GetDelimiterLength() const;
@ -90,12 +98,12 @@ protected:
//-----------------------------------------------------------------------------
// Character conversions for C strings
//-----------------------------------------------------------------------------
CUtlCharConversion *GetCStringCharConversion();
PLATFORM_INTERFACE CUtlCharConversion *GetCStringCharConversion();
//-----------------------------------------------------------------------------
// Character conversions for quoted strings, with no escape sequences
// Character conversions for JSON strings
//-----------------------------------------------------------------------------
CUtlCharConversion *GetNoEscCharConversion();
PLATFORM_INTERFACE CUtlCharConversion *GetJSONCharConversion();
//-----------------------------------------------------------------------------
@ -106,13 +114,11 @@ CUtlCharConversion *GetNoEscCharConversion();
typedef unsigned short ushort;
template < class A >
static const char *GetFmtStr( int nRadix = 10, bool bPrint = true ) { Assert( 0 ); return ""; }
template <> inline const char *GetFmtStr< short > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%hd"; }
template <> inline const char *GetFmtStr< ushort > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%hu"; }
template <> inline const char *GetFmtStr< uint16 > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%hu"; }
template <> inline const char *GetFmtStr< int > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%d"; }
template <> inline const char *GetFmtStr< uint > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 || nRadix == 16 ); return nRadix == 16 ? "%x" : "%u"; }
template <> inline const char *GetFmtStr< int64 > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%lld"; }

View File

@ -1,25 +0,0 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#if !defined( CVAR_H )
#define CVAR_H
#ifdef _WIN32
#pragma once
#endif
#include "vstdlib/vstdlib.h"
#include "icvar.h"
//-----------------------------------------------------------------------------
// Returns a CVar dictionary for tool usage
//-----------------------------------------------------------------------------
VSTDLIB_INTERFACE CreateInterfaceFn VStdLib_GetICVarFactory();
#endif // CVAR_H

View File

@ -1,16 +0,0 @@
#include <appframework/IAppSystem.h>
#include <tier1/functors.h>
class IEventQueue;
abstract_class IEventSystem : public IAppSystem
{
public:
virtual IEventQueue *CreateEventQueue() = 0;
virtual void DestroyEventQueue( IEventQueue *pQueue ) = 0;
virtual void RunEvents( IEventQueue *pQueue ) = 0;
virtual int RegisterEvent( const char *pszName ) = 0;
virtual void FireEvent( int eventId, IEventQueue *pQueue, const void *pListener, CFunctorData *pData ) = 0;
virtual void RegisterListener( int eventId, IEventQueue *pQueue, CFunctorCallback *pCallback ) = 0;
virtual void UnregisterListener( int eventId, IEventQueue *pQueue, CFunctorCallback *pCallback ) = 0;
};

View File

@ -1,51 +0,0 @@
//======== (C) Copyright 1999, 2000 Valve, L.L.C. All rights reserved. ========
//
// The copyright to the contents herein is the property of Valve, L.L.C.
// The contents may be used and/or copied only with the written permission of
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
// the agreement/contract under which the contents have been supplied.
//
// Purpose:
//
// $Workfile: $
// $NoKeywords: $
//=============================================================================
#pragma warning(disable: 4514)
// First include standard libraries
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <malloc.h>
#include <memory.h>
#include <ctype.h>
// Next, include public
#include "tier0/basetypes.h"
#include "tier0/dbg.h"
#include "tier0/valobject.h"
// Next, include vstdlib
#include "vstdlib/vstdlib.h"
#include "tier1/strtools.h"
#include "vstdlib/random.h"
#include "tier1/keyvalues.h"
#include "tier1/utlmemory.h"
#include "tier1/utlrbtree.h"
#include "tier1/utlvector.h"
#include "tier1/utllinkedlist.h"
#include "tier1/utlmultilist.h"
#include "tier1/utlsymbol.h"
#include "tier0/icommandline.h"
#include "tier1/netadr.h"
#include "tier1/mempool.h"
#include "tier1/utlbuffer.h"
#include "tier1/utlstring.h"
#include "tier1/utlmap.h"
#include "tier0/memdbgon.h"

View File

@ -1,125 +0,0 @@
//========== Copyright <20> 2005, Valve Corporation, All rights reserved. ========
//
// Purpose: A simple tool for coverage tests
//
//=============================================================================
#ifndef VCOVER_H
#define VCOVER_H
#include "tier1/utlrbtree.h"
#include "vstdlib.h"
#if defined( _WIN32 )
#pragma once
#endif
class CVCoverage
{
public:
CVCoverage() :
m_bActive( false ),
m_depth( 0 ),
m_token( 1 )
{
}
bool IsActive() const
{
return m_bActive;
}
void SetActive( bool bActive )
{
Assert( bActive != m_bActive );
m_bActive = bActive;
if ( bActive )
++m_token;
}
void Begin()
{
++m_depth;
}
void End()
{
--m_depth;
}
void Reset()
{
m_locations.RemoveAll();
}
bool ShouldCover( unsigned token ) const
{
return ( m_bActive && m_depth > 0 && token != m_token );
}
unsigned Cover( const char *pszFile, int line )
{
Location_t location = { pszFile, line };
m_locations.Insert( location );
return m_token;
}
void Report()
{
for ( int i = m_locations.FirstInorder(); i != m_locations.InvalidIndex(); i = m_locations.NextInorder( i ) )
{
Msg( "%s(%d) :\n", m_locations[i].pszFile, m_locations[i].line );
}
}
private:
struct Location_t
{
const char *pszFile;
int line;
};
class CLocationLess
{
public:
CLocationLess( int ignored ) {}
bool operator!() { return false; }
bool operator()( const Location_t &lhs, const Location_t &rhs ) const
{
if ( lhs.line < rhs.line )
{
return true;
}
return CaselessStringLessThan( lhs.pszFile, rhs.pszFile );
}
};
bool m_bActive;
int m_depth;
unsigned m_token;
CUtlRBTree< Location_t, unsigned short, CLocationLess > m_locations;
};
VSTDLIB_INTERFACE CVCoverage g_VCoverage;
#ifdef VCOVER_ENABLED
#define VCOVER() \
do \
{ \
static token; \
if ( g_VCoverage.ShouldCover( token ) ) \
{ \
token = g_VCoverage.Cover( __FILE__, __LINE__ ); \
} \
} while( 0 )
#else
#define VCOVER() ((void)0)
#endif
#endif // VCOVER_H

View File

@ -1,33 +0,0 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#ifndef VSTDLIB_H
#define VSTDLIB_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/platform.h"
//-----------------------------------------------------------------------------
// dll export stuff
//-----------------------------------------------------------------------------
#ifdef VSTDLIB_DLL_EXPORT
#define VSTDLIB_INTERFACE DLL_EXPORT
#define VSTDLIB_OVERLOAD DLL_GLOBAL_EXPORT
#define VSTDLIB_CLASS DLL_CLASS_EXPORT
#define VSTDLIB_GLOBAL DLL_GLOBAL_EXPORT
#else
#define VSTDLIB_INTERFACE DLL_IMPORT
#define VSTDLIB_OVERLOAD DLL_GLOBAL_IMPORT
#define VSTDLIB_CLASS DLL_CLASS_IMPORT
#define VSTDLIB_GLOBAL DLL_GLOBAL_IMPORT
#endif
#endif // VSTDLIB_H