mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-01-08 10:13:28 +08:00
ConVar rework initial
This commit is contained in:
parent
8626bfe25f
commit
2460e77afe
170
public/icvar.h
170
public/icvar.h
@ -55,162 +55,66 @@ public:
|
||||
virtual bool AreConVarsLinkable( const ConVar *child, const ConVar *parent ) = 0;
|
||||
};
|
||||
|
||||
union CVValue_t;
|
||||
struct ConVarDesc_t;
|
||||
|
||||
struct characterset_t;
|
||||
struct CSplitScreenSlot;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: DLL interface to ConVars/ConCommands
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class ICvar : public IAppSystem
|
||||
{
|
||||
public:
|
||||
// Allocate a unique DLL identifier
|
||||
virtual CVarDLLIdentifier_t AllocateDLLIdentifier() = 0;
|
||||
// allow_developer - Allows finding convars with FCVAR_DEVELOPMENTONLY flag
|
||||
virtual ConVarID FindConVar(const char *name, bool allow_developer = false) = 0;
|
||||
virtual ConVarID FindFirstConVar() = 0;
|
||||
virtual ConVarID FindNextConVar(ConVarID previous) = 0;
|
||||
|
||||
// Register, unregister commands
|
||||
virtual void RegisterConCommand( ConCommandBase *pCommandBase ) = 0;
|
||||
virtual void UnregisterConCommand( ConCommandBase *pCommandBase ) = 0;
|
||||
virtual void UnregisterConCommands( CVarDLLIdentifier_t id ) = 0;
|
||||
|
||||
// If there is a +<varname> <value> on the command line, this returns the value.
|
||||
// Otherwise, it returns NULL.
|
||||
virtual const char* GetCommandLineValue( const char *pVariableName ) = 0;
|
||||
|
||||
// Try to find the cvar pointer by name
|
||||
virtual ConCommandBase *FindCommandBase( const char *name ) = 0;
|
||||
virtual const ConCommandBase *FindCommandBase( const char *name ) const = 0;
|
||||
virtual ConVar *FindVar ( const char *var_name ) = 0;
|
||||
virtual const ConVar *FindVar ( const char *var_name ) const = 0;
|
||||
virtual ConCommand *FindCommand( const char *name ) = 0;
|
||||
virtual const ConCommand *FindCommand( const char *name ) const = 0;
|
||||
virtual void SetConVarValue(ConVarID cvarid, CSplitScreenSlot nSlot, CVValue_t *value, void*) = 0;
|
||||
|
||||
virtual ConCommandID FindCommand(const char *name) = 0;
|
||||
virtual ConCommandID FindFirstCommand() = 0;
|
||||
virtual ConCommandID FindNextCommand(ConCommandID previous) = 0;
|
||||
|
||||
virtual void unk02() = 0;
|
||||
|
||||
// Install a global change callback (to be called when any convar changes)
|
||||
virtual void InstallGlobalChangeCallback( FnChangeCallback_t callback ) = 0;
|
||||
virtual void RemoveGlobalChangeCallback( FnChangeCallback_t callback ) = 0;
|
||||
virtual void CallGlobalChangeCallbacks( ConVar *var, const char *pOldString, float flOldValue ) = 0;
|
||||
|
||||
// Install a console printer
|
||||
virtual void InstallConsoleDisplayFunc( IConsoleDisplayFunc* pDisplayFunc ) = 0;
|
||||
virtual void RemoveConsoleDisplayFunc( IConsoleDisplayFunc* pDisplayFunc ) = 0;
|
||||
virtual void ConsoleColorPrintf( const Color& clr, const char *pFormat, ... ) const = 0;
|
||||
virtual void ConsolePrintf( const char *pFormat, ... ) const = 0;
|
||||
virtual void ConsoleDPrintf( const char *pFormat, ... ) const = 0;
|
||||
virtual void InstallGlobalChangeCallback(FnChangeCallback_t callback) = 0;
|
||||
virtual void RemoveGlobalChangeCallback(FnChangeCallback_t callback) = 0;
|
||||
virtual void CallGlobalChangeCallbacks(ConVar *var, const char *pOldString, float flOldValue) = 0;
|
||||
|
||||
// Reverts cvars which contain a specific flag
|
||||
virtual void RevertFlaggedConVars( int nFlag ) = 0;
|
||||
virtual void RevertFlaggedConVars(int nFlag) = 0;
|
||||
|
||||
// Method allowing the engine ICvarQuery interface to take over
|
||||
// A little hacky, owing to the fact the engine is loaded
|
||||
// well after ICVar, so we can't use the standard connect pattern
|
||||
virtual void InstallCVarQuery( ICvarQuery *pQuery ) = 0;
|
||||
|
||||
#if defined( _X360 )
|
||||
virtual void PublishToVXConsole( ) = 0;
|
||||
#endif
|
||||
|
||||
virtual void SetMaxSplitScreenSlots( int nSlots ) = 0;
|
||||
virtual void SetMaxSplitScreenSlots(int nSlots) = 0;
|
||||
virtual int GetMaxSplitScreenSlots() const = 0;
|
||||
|
||||
virtual void AddSplitScreenConVars() = 0;
|
||||
virtual void RemoveSplitScreenConVars( CVarDLLIdentifier_t id ) = 0;
|
||||
virtual void RegisterCreationListener() = 0;
|
||||
virtual void RemoveCreationListener() = 0;
|
||||
|
||||
virtual int GetConsoleDisplayFuncCount() const = 0;
|
||||
virtual void GetConsoleText( int nDisplayFuncIndex, char *pchText, size_t bufSize ) const = 0;
|
||||
virtual void unk2() = 0;
|
||||
virtual void unk3() = 0;
|
||||
virtual void unk4() = 0;
|
||||
virtual void unk5() = 0;
|
||||
virtual void unk6() = 0;
|
||||
|
||||
// Utilities for convars accessed by the material system thread
|
||||
virtual bool IsMaterialThreadSetAllowed( ) const = 0;
|
||||
virtual void QueueMaterialThreadSetValue( ConVar *pConVar, const char *pValue ) = 0;
|
||||
virtual void QueueMaterialThreadSetValue( ConVar *pConVar, int nValue ) = 0;
|
||||
virtual void QueueMaterialThreadSetValue( ConVar *pConVar, float flValue ) = 0;
|
||||
virtual bool HasQueuedMaterialThreadConVarSets() const = 0;
|
||||
virtual int ProcessQueuedMaterialThreadConVarSets() = 0;
|
||||
virtual characterset_t GetCharacterSet() = 0;
|
||||
|
||||
protected: class ICVarIteratorInternal;
|
||||
public:
|
||||
/// Iteration over all cvars.
|
||||
/// (THIS IS A SLOW OPERATION AND YOU SHOULD AVOID IT.)
|
||||
/// usage:
|
||||
/// { ICVar::Iterator iter(g_pCVar);
|
||||
/// for ( iter.SetFirst() ; iter.IsValid() ; iter.Next() )
|
||||
/// {
|
||||
/// ConCommandBase *cmd = iter.Get();
|
||||
/// }
|
||||
/// }
|
||||
/// The Iterator class actually wraps the internal factory methods
|
||||
/// so you don't need to worry about new/delete -- scope takes care
|
||||
// of it.
|
||||
/// We need an iterator like this because we can't simply return a
|
||||
/// pointer to the internal data type that contains the cvars --
|
||||
/// it's a custom, protected class with unusual semantics and is
|
||||
/// prone to change.
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
inline Iterator(ICvar *icvar);
|
||||
inline ~Iterator(void);
|
||||
inline void SetFirst( void );
|
||||
inline void Next( void );
|
||||
inline bool IsValid( void );
|
||||
inline ConCommandBase *Get( void );
|
||||
private:
|
||||
ICVarIteratorInternal *m_pIter;
|
||||
};
|
||||
virtual void unk8() = 0;
|
||||
|
||||
protected:
|
||||
// internals for ICVarIterator
|
||||
class ICVarIteratorInternal
|
||||
{
|
||||
public:
|
||||
virtual ~ICVarIteratorInternal() {}
|
||||
virtual void SetFirst( void ) = 0;
|
||||
virtual void Next( void ) = 0;
|
||||
virtual bool IsValid( void ) = 0;
|
||||
virtual ConCommandBase *Get( void ) = 0;
|
||||
};
|
||||
virtual void RegisterConVar(ConVarDesc_t, void*, ConVarID&, ConVar&) = 0;
|
||||
virtual void UnregisterConVar(ConVarID cvar) = 0;
|
||||
virtual ConVar* GetConVar(ConVarID cvar) = 0;
|
||||
|
||||
virtual ICVarIteratorInternal *FactoryInternalIterator( void ) = 0;
|
||||
friend class Iterator;
|
||||
|
||||
virtual void InstallConVarListener( IConVarListener *pListener ) = 0;
|
||||
virtual void RemoveConVarListener( IConVarListener *pListener ) = 0;
|
||||
virtual void GetConVarDetails( CUtlVector<CConVarDetail> &out ) = 0;
|
||||
|
||||
virtual void ResetConVarsToDefaultValues( const char *pszPrefix ) = 0;
|
||||
virtual ConVarSnapshot_t *TakeConVarSnapshot( void ) = 0;
|
||||
virtual void ResetConVarsToSnapshot( ConVarSnapshot_t *pSnapshot ) = 0;
|
||||
virtual void DestroyConVarSnapshot( ConVarSnapshot_t *pSnaoshot ) = 0;
|
||||
virtual void RegisterConCommand(void*, void*, ConCommandID&, ConCommand&) = 0;
|
||||
virtual void UnregisterConCommand(ConCommandID command) = 0;
|
||||
virtual ConCommand* GetConCommand(ConCommandID command) = 0;
|
||||
|
||||
virtual void QueueThreadSetValue(ConVarRefAbstract *ref, CSplitScreenSlot nSlot, CVValue_t *value) = 0;
|
||||
};
|
||||
|
||||
inline ICvar::Iterator::Iterator(ICvar *icvar)
|
||||
{
|
||||
m_pIter = icvar->FactoryInternalIterator();
|
||||
}
|
||||
|
||||
inline ICvar::Iterator::~Iterator( void )
|
||||
{
|
||||
MemAlloc_Free(m_pIter);
|
||||
}
|
||||
|
||||
inline void ICvar::Iterator::SetFirst( void )
|
||||
{
|
||||
m_pIter->SetFirst();
|
||||
}
|
||||
|
||||
inline void ICvar::Iterator::Next( void )
|
||||
{
|
||||
m_pIter->Next();
|
||||
}
|
||||
|
||||
inline bool ICvar::Iterator::IsValid( void )
|
||||
{
|
||||
return m_pIter->IsValid();
|
||||
}
|
||||
|
||||
inline ConCommandBase * ICvar::Iterator::Get( void )
|
||||
{
|
||||
return m_pIter->Get();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// These global names are defined by tier1.h, duplicated here so you
|
||||
// don't have to include tier1.h
|
||||
|
@ -116,9 +116,109 @@ public:
|
||||
virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0;
|
||||
};
|
||||
|
||||
enum EConVarType : short
|
||||
{
|
||||
EConVarType_Bool,
|
||||
EConVarType_Int16,
|
||||
EConVarType_UInt16,
|
||||
EConVarType_Int32,
|
||||
EConVarType_UInt32,
|
||||
EConVarType_Int64,
|
||||
EConVarType_UInt64,
|
||||
EConVarType_Float32,
|
||||
EConVarType_Float64,
|
||||
EConVarType_String,
|
||||
EConVarType_Color,
|
||||
EConVarType_Vector2,
|
||||
EConVarType_Vector3,
|
||||
EConVarType_Vector4,
|
||||
EConVarType_Qangle
|
||||
};
|
||||
|
||||
union CVValue_t
|
||||
{
|
||||
bool m_bValue;
|
||||
uint64 m_u64Value;
|
||||
int64 m_i64Value;
|
||||
uint m_u32Value;
|
||||
int m_iValue;
|
||||
float m_flValue;
|
||||
double m_dbValue;
|
||||
const char* m_szValue;
|
||||
};
|
||||
|
||||
struct ConVarDataType_t
|
||||
{
|
||||
const char* name;
|
||||
int data_size;
|
||||
int primitive; // 1 for primitive types, 0 for others
|
||||
void* GetStringValue;
|
||||
void* CopyValue;
|
||||
void* unk1;
|
||||
void* FromString;
|
||||
void* ToString;
|
||||
void* IsEqual;
|
||||
void* Clamp;
|
||||
const char* default_string_value;
|
||||
const char* undefined_string_value;
|
||||
};
|
||||
|
||||
struct ConVarDesc_t
|
||||
{
|
||||
const char *name;
|
||||
const char *description;
|
||||
int64 flags;
|
||||
char unk[64];
|
||||
ConVarDataType_t type;
|
||||
void *handle;
|
||||
void *convar;
|
||||
};
|
||||
|
||||
struct ConCommandDesc_t
|
||||
{
|
||||
const char* name;
|
||||
const char* description;
|
||||
int64 flags;
|
||||
void* callback;
|
||||
void* unk1;
|
||||
void* unk2;
|
||||
void* unk3;
|
||||
void* output_id_holder;
|
||||
};
|
||||
|
||||
class ConVar
|
||||
{
|
||||
public:
|
||||
const char *name;
|
||||
CVValue_t *defaultValue;
|
||||
CVValue_t *minValue;
|
||||
CVValue_t *maxValue;
|
||||
const char *description;
|
||||
EConVarType type;
|
||||
char padding[2];
|
||||
unsigned int timesChanged;
|
||||
int64 flags;
|
||||
unsigned int callbackId;
|
||||
int unk;
|
||||
CVValue_t value[];
|
||||
};
|
||||
|
||||
class ConCommand
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class ConVarRefAbstract
|
||||
{
|
||||
public:
|
||||
ConVarID *cvarid;
|
||||
ConVar *cvar;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: The base console invoked command/cvar interface
|
||||
//-----------------------------------------------------------------------------
|
||||
#if 0
|
||||
class ConCommandBase
|
||||
{
|
||||
friend class CCvar;
|
||||
@ -202,7 +302,7 @@ protected:
|
||||
// ConVars in this executable use this 'global' to access values.
|
||||
static IConCommandBaseAccessor *s_pAccessor;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Command tokenizer
|
||||
@ -283,7 +383,7 @@ inline const char *CCommand::operator[]( int nIndex ) const
|
||||
return Arg( nIndex );
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: The console invoked command
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -631,6 +731,7 @@ FORCEINLINE_CVAR int CSplitScreenAddedConVar::GetSplitScreenPlayerSlot() const
|
||||
return m_nSplitScreenSlot;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to read/write convars that already exist (replaces the FindVar method)
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -956,6 +1057,8 @@ private:
|
||||
FnMemberCommandCompletionCallback_t m_CompletionFunc;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning ( default : 4355 )
|
||||
#endif
|
||||
|
@ -28,6 +28,8 @@
|
||||
class IConVar;
|
||||
class CCommand;
|
||||
|
||||
typedef int ConVarID;
|
||||
typedef int ConCommandID;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ConVar flags
|
||||
@ -37,7 +39,7 @@ class CCommand;
|
||||
|
||||
// Command to ConVars and ConCommands
|
||||
// ConVar Systems
|
||||
#define FCVAR_UNREGISTERED (1<<0) // If this is set, don't add to linked list, etc.
|
||||
#define FCVAR_LINKED_CONCOMMAND (1<<0)
|
||||
#define FCVAR_DEVELOPMENTONLY (1<<1) // Hidden in released products. Flag is removed automatically if ALLOW_DEVELOPMENT_CVARS is defined.
|
||||
#define FCVAR_GAMEDLL (1<<2) // defined by the game DLL
|
||||
#define FCVAR_CLIENTDLL (1<<3) // defined by the client DLL
|
||||
@ -50,9 +52,9 @@ class CCommand;
|
||||
#define FCVAR_NOTIFY (1<<8) // notifies players when changed
|
||||
#define FCVAR_USERINFO (1<<9) // changes the client's info string
|
||||
|
||||
#define FCVAR_PRINTABLEONLY (1<<10) // This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ).
|
||||
#define FCVAR_MISSING0 (1<<10) // Something that hides the cvar from the cvar lookups
|
||||
#define FCVAR_UNLOGGED (1<<11) // If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log
|
||||
#define FCVAR_NEVER_AS_STRING (1<<12) // never try to print that cvar
|
||||
#define FCVAR_MISSING1 (1<<12) // Something that hides the cvar from the cvar lookups
|
||||
|
||||
// It's a ConVar that's shared between the client and the server.
|
||||
// At signon, the values of all such ConVars are sent from the server to the client (skipped for local
|
||||
@ -61,66 +63,29 @@ class CCommand;
|
||||
// If a value is changed while a server is active, it's replicated to all connected clients
|
||||
#define FCVAR_REPLICATED (1<<13) // server setting enforced on clients, TODO rename to FCAR_SERVER at some time
|
||||
#define FCVAR_CHEAT (1<<14) // Only useable in singleplayer / debug / multiplayer & sv_cheats
|
||||
#define FCVAR_SS (1<<15) // causes varnameN where N == 2 through max splitscreen slots for mod to be autogenerated
|
||||
#define FCVAR_PER_USER (1<<15) // causes varnameN where N == 2 through max splitscreen slots for mod to be autogenerated
|
||||
#define FCVAR_DEMO (1<<16) // record this cvar when starting a demo file
|
||||
#define FCVAR_DONTRECORD (1<<17) // don't record these command in demofiles
|
||||
#define FCVAR_SS_ADDED (1<<18) // This is one of the "added" FCVAR_SS variables for the splitscreen players
|
||||
#define FCVAR_MISSING2 (1<<18)
|
||||
#define FCVAR_RELEASE (1<<19) // Cvars tagged with this are the only cvars avaliable to customers
|
||||
#define FCVAR_RELOAD_MATERIALS (1<<20) // If this cvar changes, it forces a material reload
|
||||
#define FCVAR_RELOAD_TEXTURES (1<<21) // If this cvar changes, if forces a texture reload
|
||||
#define FCVAR_MENUBAR_ITEM (1<<20)
|
||||
#define FCVAR_MISSING3 (1<<21)
|
||||
|
||||
#define FCVAR_NOT_CONNECTED (1<<22) // cvar cannot be changed by a client that is connected to a server
|
||||
#define FCVAR_MATERIAL_SYSTEM_THREAD (1<<23) // Indicates this cvar is read from the material system thread
|
||||
#define FCVAR_ARCHIVE_XBOX (1<<24) // cvar written to config.cfg on the Xbox
|
||||
#define FCVAR_VCONSOLE_FUZZY_MATCHING (1<<23)
|
||||
|
||||
#define FCVAR_ACCESSIBLE_FROM_THREADS (1<<25) // used as a debugging tool necessary to check material system thread convars
|
||||
#define FCVAR_LINKED_CONCOMMAND (1<<26)
|
||||
#define FCVAR_VCONSOLE_FUZZY_MATCHING (1<<27)
|
||||
|
||||
#define FCVAR_SERVER_CAN_EXECUTE (1<<28) // the server is allowed to execute this command on clients via ClientCommand/NET_StringCmd/CBaseClientState::ProcessStringCmd.
|
||||
#define FCVAR_SERVER_CANNOT_QUERY (1<<29) // If this is set, then the server is not allowed to query this cvar's value (via IServerPluginHelpers::StartQueryCvarValue).
|
||||
#define FCVAR_VCONSOLE_SET_FOCUS (1<<30)
|
||||
#define FCVAR_CLIENTCMD_CAN_EXECUTE (1<<31) // IVEngineClient::ClientCmd is allowed to execute this command.
|
||||
#define FCVAR_SERVER_CAN_EXECUTE (1<<24) // the server is allowed to execute this command on clients via ClientCommand/NET_StringCmd/CBaseClientState::ProcessStringCmd.
|
||||
#define FCVAR_MISSING4 (1<<25)
|
||||
#define FCVAR_SERVER_CANNOT_QUERY (1<<26) // If this is set, then the server is not allowed to query this cvar's value (via IServerPluginHelpers::StartQueryCvarValue).
|
||||
#define FCVAR_VCONSOLE_SET_FOCUS (1<<27)
|
||||
#define FCVAR_CLIENTCMD_CAN_EXECUTE (1<<28) // IVEngineClient::ClientCmd is allowed to execute this command.
|
||||
// Note: IVEngineClient::ClientCmd_Unrestricted can run any client command.
|
||||
|
||||
#define FCVAR_EXECUTE_PER_TICK (1<<32)
|
||||
|
||||
|
||||
#define FCVAR_MATERIAL_THREAD_MASK ( FCVAR_RELOAD_MATERIALS | FCVAR_RELOAD_TEXTURES | FCVAR_MATERIAL_SYSTEM_THREAD )
|
||||
#define FCVAR_EXECUTE_PER_TICK (1<<29)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when a ConVar changes value
|
||||
// NOTE: For FCVAR_NEVER_AS_STRING ConVars, pOldValue == NULL
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef void ( *FnChangeCallback_t )( IConVar *var, const char *pOldValue, float flOldValue );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Abstract interface for ConVars
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IConVar
|
||||
{
|
||||
public:
|
||||
// Value set
|
||||
virtual void SetValue( const char *pValue ) = 0;
|
||||
virtual void SetValue( float flValue ) = 0;
|
||||
virtual void SetValue( int nValue ) = 0;
|
||||
virtual void SetValue( Color value ) = 0;
|
||||
|
||||
// Return name of command
|
||||
virtual const char *GetName( void ) const = 0;
|
||||
|
||||
// Return name of command (usually == GetName(), except in case of FCVAR_SS_ADDED vars
|
||||
virtual const char *GetBaseName( void ) const = 0;
|
||||
|
||||
// Accessors.. not as efficient as using GetState()/GetInfo()
|
||||
// if you call these methods multiple times on the same IConVar
|
||||
virtual bool IsFlagSet( int64 nFlag ) const = 0;
|
||||
|
||||
virtual int GetSplitScreenPlayerSlot() const = 0;
|
||||
|
||||
virtual void AddFlags( int64 flags ) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // ICONVAR_H
|
||||
|
@ -168,19 +168,10 @@ protected:
|
||||
I m_NumAlloced; // The number of allocated elements
|
||||
typename M::Iterator_t m_LastAlloc; // the last index allocated
|
||||
|
||||
// For debugging purposes;
|
||||
// it's in release builds so this can be used in libraries correctly
|
||||
ListElem_t *m_pElements;
|
||||
|
||||
FORCEINLINE M const &Memory( void ) const
|
||||
{
|
||||
return m_Memory;
|
||||
}
|
||||
|
||||
void ResetDbgInfo()
|
||||
{
|
||||
m_pElements = m_Memory.Base();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user