mirror of
https://github.com/0TheSpy/Seaside.git
synced 2025-09-19 12:16:13 +08:00
Update ConVars.cpp
This commit is contained in:
@ -3,10 +3,6 @@
|
||||
|
||||
#include "Interfaces.hpp"
|
||||
|
||||
//extern auto iff.g_pCVar;
|
||||
//typedef void(__cdecl* CONMSGPROC)(const char*, ...);
|
||||
//extern auto iff.myConMsg;
|
||||
|
||||
|
||||
static void V_strncpy(char* pDest, char const* pSrc, int maxLen)
|
||||
{
|
||||
@ -31,7 +27,6 @@ static int V_snprintf(char* pDest, int maxLen, const char* pFormat, ...)
|
||||
#endif
|
||||
va_end(marker);
|
||||
|
||||
// Len < 0 represents an overflow
|
||||
if (len < 0)
|
||||
{
|
||||
len = maxLen;
|
||||
@ -41,9 +36,6 @@ static int V_snprintf(char* pDest, int maxLen, const char* pFormat, ...)
|
||||
return len;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base class, containing simple memory management
|
||||
//-----------------------------------------------------------------------------
|
||||
CUtlBinaryBlock::CUtlBinaryBlock(int growSize, int initSize)
|
||||
{
|
||||
MEM_ALLOC_CREDIT();
|
||||
@ -78,7 +70,6 @@ void CUtlBinaryBlock::SetLength(int nLength)
|
||||
int nOverFlow = nLength - m_Memory.NumAllocated();
|
||||
m_Memory.Grow(nOverFlow);
|
||||
|
||||
// If the reallocation failed, clamp length
|
||||
if (nLength > m_Memory.NumAllocated())
|
||||
{
|
||||
m_nActualLength = m_Memory.NumAllocated();
|
||||
@ -118,8 +109,6 @@ void CUtlBinaryBlock::Set(const void* pValue, int nLen)
|
||||
}
|
||||
}
|
||||
|
||||
// Simple string class.
|
||||
//-----------------------------------------------------------------------------
|
||||
CUtlString::CUtlString()
|
||||
{
|
||||
}
|
||||
@ -134,7 +123,6 @@ CUtlString::CUtlString(const CUtlString& string)
|
||||
Set(string.Get());
|
||||
}
|
||||
|
||||
// Attaches the string to external memory. Useful for avoiding a copy
|
||||
CUtlString::CUtlString(void* pMemory, int nSizeInBytes, int nInitialLength) : m_Storage(pMemory, nSizeInBytes, nInitialLength)
|
||||
{
|
||||
}
|
||||
@ -160,14 +148,10 @@ const char* CUtlString::Get() const
|
||||
return reinterpret_cast<const char*>(m_Storage.Get());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Statically constructed list of ConCommandBases,
|
||||
// used for registering them with the ICVar interface
|
||||
//-----------------------------------------------------------------------------
|
||||
ConCommandBase* ConCommandBase::s_pConCommandBases = NULL;
|
||||
IConCommandBaseAccessor* ConCommandBase::s_pAccessor = NULL;
|
||||
static int s_nCVarFlag = 0;
|
||||
static int s_nDLLIdentifier = -1; // A unique identifier indicating which DLL this convar came from
|
||||
static int s_nDLLIdentifier = -1;
|
||||
static bool s_bRegistered = false;
|
||||
|
||||
class CDefaultAccessor : public IConCommandBaseAccessor
|
||||
@ -175,7 +159,6 @@ class CDefaultAccessor : public IConCommandBaseAccessor
|
||||
public:
|
||||
virtual bool RegisterConCommandBase(ConCommandBase* pVar)
|
||||
{
|
||||
// Link to engine's list instead
|
||||
iff.g_pCVar->RegisterConCommand(pVar);
|
||||
return true;
|
||||
}
|
||||
@ -183,9 +166,6 @@ public:
|
||||
|
||||
static CDefaultAccessor s_DefaultAccessor;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called by the framework to register ConCommandBases with the ICVar
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar_Register(int nCVarFlag, IConCommandBaseAccessor* pAccessor)
|
||||
{
|
||||
if (!iff.g_pCVar || s_bRegistered)
|
||||
@ -208,7 +188,6 @@ void ConVar_Register(int nCVarFlag, IConCommandBaseAccessor* pAccessor)
|
||||
pCur = pNext;
|
||||
}
|
||||
|
||||
//3//g_pCVar->ProcessQueuedMaterialThreadConVarSets();
|
||||
ConCommandBase::s_pConCommandBases = NULL;
|
||||
}
|
||||
|
||||
@ -224,9 +203,6 @@ void ConVar_Unregister()
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Default constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ConCommandBase::ConCommandBase(void)
|
||||
{
|
||||
m_bRegistered = false;
|
||||
@ -237,58 +213,33 @@ ConCommandBase::ConCommandBase(void)
|
||||
m_pNext = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: The base console invoked command/cvar interface
|
||||
// Input : *pName - name of variable/command
|
||||
// *pHelpString - help text
|
||||
// flags - flags
|
||||
//-----------------------------------------------------------------------------
|
||||
ConCommandBase::ConCommandBase(const char* pName, const char* pHelpString /*=0*/, int flags /*= 0*/)
|
||||
ConCommandBase::ConCommandBase(const char* pName, const char* pHelpString , int flags )
|
||||
{
|
||||
Create(pName, pHelpString, flags);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
ConCommandBase::~ConCommandBase(void)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Output : Returns true on success, false on failure.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConCommandBase::IsCommand(void) const
|
||||
{
|
||||
// Assert( 0 ); This can't assert. . causes a recursive assert in Sys_Printf, etc.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the DLL identifier
|
||||
//-----------------------------------------------------------------------------
|
||||
CVarDLLIdentifier_t ConCommandBase::GetDLLIdentifier() const
|
||||
{
|
||||
return s_nDLLIdentifier;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *pName -
|
||||
// callback -
|
||||
// *pHelpString -
|
||||
// flags -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConCommandBase::Create(const char* pName, const char* pHelpString /*= 0*/, int flags /*= 0*/)
|
||||
void ConCommandBase::Create(const char* pName, const char* pHelpString , int flags )
|
||||
{
|
||||
static char* empty_string = (char*)"";
|
||||
|
||||
m_bRegistered = false;
|
||||
|
||||
// Name should be static data
|
||||
Assert(pName);
|
||||
m_pszName = pName;
|
||||
m_pszHelpString = pHelpString ? pHelpString : empty_string;
|
||||
@ -306,12 +257,9 @@ void ConCommandBase::Create(const char* pName, const char* pHelpString /*= 0*/,
|
||||
}
|
||||
else
|
||||
{
|
||||
// It's unregistered
|
||||
m_pNext = NULL;
|
||||
}
|
||||
|
||||
// If s_pAccessor is already set (this ConVar is not a global variable),
|
||||
// register it.
|
||||
if (s_pAccessor)
|
||||
{
|
||||
Init();
|
||||
@ -319,9 +267,6 @@ void ConCommandBase::Create(const char* pName, const char* pHelpString /*= 0*/,
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Used internally by OneTimeInit to initialize.
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConCommandBase::Init()
|
||||
{
|
||||
if (s_pAccessor)
|
||||
@ -339,30 +284,17 @@ void ConCommandBase::Shutdown()
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return name of the command/var
|
||||
// Output : const char
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* ConCommandBase::GetName(void) const
|
||||
{
|
||||
return m_pszName;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : flag -
|
||||
// Output : Returns true on success, false on failure.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConCommandBase::IsFlagSet(int flag) const
|
||||
{
|
||||
return (flag & m_nFlags) ? true : false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : flags -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConCommandBase::AddFlags(int flags)
|
||||
{
|
||||
m_nFlags |= flags;
|
||||
@ -384,10 +316,6 @@ int ConCommandBase::GetFlags(void) const
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Output : const ConCommandBase
|
||||
//-----------------------------------------------------------------------------
|
||||
const ConCommandBase* ConCommandBase::GetNext(void) const
|
||||
{
|
||||
return m_pNext;
|
||||
@ -399,11 +327,6 @@ ConCommandBase* ConCommandBase::GetNext(void)
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Copies string using local new/delete operators
|
||||
// Input : *from -
|
||||
// Output : char
|
||||
//-----------------------------------------------------------------------------
|
||||
char* ConCommandBase::CopyString(const char* from)
|
||||
{
|
||||
int len;
|
||||
@ -423,47 +346,26 @@ char* ConCommandBase::CopyString(const char* from)
|
||||
return to;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Output : const char
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* ConCommandBase::GetHelpText(void) const
|
||||
{
|
||||
return m_pszHelpString;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Has this cvar been registered
|
||||
// Output : Returns true on success, false on failure.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConCommandBase::IsRegistered(void) const
|
||||
{
|
||||
return m_bRegistered;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Con Commands start here
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct characterset_t
|
||||
{
|
||||
char set[256];
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global methods
|
||||
//-----------------------------------------------------------------------------
|
||||
static characterset_t s_BreakSet;
|
||||
static bool s_bBuiltBreakSet = false;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Tokenizer class
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
void CCommand::Reset()
|
||||
{
|
||||
@ -477,82 +379,56 @@ characterset_t* CCommand::DefaultBreakSet()
|
||||
return &s_BreakSet;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Default console command autocompletion function
|
||||
//-----------------------------------------------------------------------------
|
||||
int DefaultCompletionFunc(const char* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructs a console command
|
||||
//-----------------------------------------------------------------------------
|
||||
//ConCommand::ConCommand()
|
||||
//{
|
||||
// m_bIsNewConCommand = true;
|
||||
//}
|
||||
|
||||
ConCommand::ConCommand(const char* pName, FnCommandCallbackVoid_t callback, const char* pHelpString /*= 0*/, int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/)
|
||||
ConCommand::ConCommand(const char* pName, FnCommandCallbackVoid_t callback, const char* pHelpString , int flags , FnCommandCompletionCallback completionFunc )
|
||||
{
|
||||
// Set the callback
|
||||
m_fnCommandCallbackV1 = callback;
|
||||
m_bUsingNewCommandCallback = false;
|
||||
m_bUsingCommandCallbackInterface = false;
|
||||
m_fnCompletionCallback = completionFunc ? completionFunc : DefaultCompletionFunc;
|
||||
m_bHasCompletionCallback = completionFunc != 0 ? true : false;
|
||||
|
||||
// Setup the rest
|
||||
BaseClass::Create(pName, pHelpString, flags);
|
||||
}
|
||||
|
||||
ConCommand::ConCommand(const char* pName, FnCommandCallback_t callback, const char* pHelpString /*= 0*/, int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/)
|
||||
ConCommand::ConCommand(const char* pName, FnCommandCallback_t callback, const char* pHelpString , int flags , FnCommandCompletionCallback completionFunc )
|
||||
{
|
||||
// Set the callback
|
||||
m_fnCommandCallback = callback;
|
||||
m_bUsingNewCommandCallback = true;
|
||||
m_fnCompletionCallback = completionFunc ? completionFunc : DefaultCompletionFunc;
|
||||
m_bHasCompletionCallback = completionFunc != 0 ? true : false;
|
||||
m_bUsingCommandCallbackInterface = false;
|
||||
|
||||
// Setup the rest
|
||||
BaseClass::Create(pName, pHelpString, flags);
|
||||
}
|
||||
|
||||
ConCommand::ConCommand(const char* pName, ICommandCallback* pCallback, const char* pHelpString /*= 0*/, int flags /*= 0*/, ICommandCompletionCallback* pCompletionCallback /*= 0*/)
|
||||
ConCommand::ConCommand(const char* pName, ICommandCallback* pCallback, const char* pHelpString , int flags , ICommandCompletionCallback* pCompletionCallback )
|
||||
{
|
||||
// Set the callback
|
||||
m_pCommandCallback = pCallback;
|
||||
m_bUsingNewCommandCallback = false;
|
||||
m_pCommandCompletionCallback = pCompletionCallback;
|
||||
m_bHasCompletionCallback = (pCompletionCallback != 0);
|
||||
m_bUsingCommandCallbackInterface = true;
|
||||
|
||||
// Setup the rest
|
||||
BaseClass::Create(pName, pHelpString, flags);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ConCommand::~ConCommand(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns true if this is a command
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConCommand::IsCommand(void) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Invoke the function if there is one
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConCommand::Dispatch(const CCommand& command)
|
||||
{
|
||||
if (m_bUsingNewCommandCallback)
|
||||
@ -580,14 +456,10 @@ void ConCommand::Dispatch(const CCommand& command)
|
||||
}
|
||||
}
|
||||
|
||||
// Command without callback!!!
|
||||
AssertMsg(0, ("Encountered ConCommand '%s' without a callback!\n", GetName()));
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Calls the autocompletion method to get autocompletion suggestions
|
||||
//-----------------------------------------------------------------------------
|
||||
int ConCommand::AutoCompleteSuggest(const char* partial, CUtlVector< CUtlString >& commands)
|
||||
{
|
||||
if (m_bUsingCommandCallbackInterface)
|
||||
@ -612,9 +484,6 @@ int ConCommand::AutoCompleteSuggest(const char* partial, CUtlVector< CUtlString
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if the console command can autocomplete
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConCommand::CanAutoComplete(void)
|
||||
{
|
||||
return m_bHasCompletionCallback;
|
||||
@ -622,16 +491,7 @@ bool ConCommand::CanAutoComplete(void)
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Console Variables
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Various constructors
|
||||
//-----------------------------------------------------------------------------
|
||||
ConVar::ConVar(const char* pName, const char* pDefaultValue, int flags /* = 0 */)
|
||||
ConVar::ConVar(const char* pName, const char* pDefaultValue, int flags )
|
||||
{
|
||||
Create(pName, pDefaultValue, flags);
|
||||
}
|
||||
@ -657,13 +517,8 @@ ConVar::ConVar(const char* pName, const char* pDefaultValue, int flags, const ch
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ConVar::~ConVar(void)
|
||||
{
|
||||
//if(IsRegistered())
|
||||
// convar->UnregisterConCommand(this);
|
||||
if (m_Value.m_pszString) {
|
||||
delete[] m_Value.m_pszString;
|
||||
m_Value.m_pszString = NULL;
|
||||
@ -671,9 +526,6 @@ ConVar::~ConVar(void)
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Install a change callback (there shouldn't already be one....)
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar::InstallChangeCallback(FnChangeCallback_t callback, bool bInvoke)
|
||||
{
|
||||
if (callback) {
|
||||
@ -683,11 +535,9 @@ void ConVar::InstallChangeCallback(FnChangeCallback_t callback, bool bInvoke)
|
||||
callback(this, m_Value.m_pszString, m_Value.m_fValue);
|
||||
}
|
||||
else {
|
||||
//Warning("InstallChangeCallback ignoring duplicate change callback!!!\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
//Warning("InstallChangeCallback called with NULL callback, ignoring!!!\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -717,34 +567,19 @@ bool ConVar::IsRegistered(void) const
|
||||
|
||||
const char* ConVar::GetName(void) const
|
||||
{
|
||||
//printf("getname called\n");
|
||||
return m_pParent->m_pszName;
|
||||
}
|
||||
|
||||
//void ConVar::convarplaceholder(){}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Output : Returns true on success, false on failure.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConVar::IsCommand(void) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input :
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar::Init()
|
||||
{
|
||||
BaseClass::Init();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *value -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar::InternalSetValue(const char* value)
|
||||
{
|
||||
printf("Executed ConVar::InternalSetValue to %s\n", value);
|
||||
@ -765,7 +600,6 @@ void ConVar::InternalSetValue(const char* value)
|
||||
}
|
||||
|
||||
|
||||
// Redetermine value
|
||||
*(uint32_t*)&m_Value.m_fValue = *(uint32_t*)&fNewValue ^ (uint32_t)this;
|
||||
*(uint32_t*)&m_Value.m_nValue = (uint32_t)fNewValue ^ (uint32_t)this;
|
||||
|
||||
@ -774,54 +608,6 @@ void ConVar::InternalSetValue(const char* value)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void ConVar::InternalSetValue(const char* value)
|
||||
{
|
||||
if (IsFlagSet(FCVAR_MATERIAL_THREAD_MASK))
|
||||
{
|
||||
if (g_pCVar && !g_pCVar->IsMaterialThreadSetAllowed())
|
||||
{
|
||||
g_pCVar->QueueMaterialThreadSetValue(this, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
float fNewValue;
|
||||
char tempVal[32];
|
||||
char* val;
|
||||
|
||||
Assert(m_pParent == this); // Only valid for root convars.
|
||||
|
||||
float flOldValue = m_fValue;
|
||||
|
||||
val = (char*)value;
|
||||
if (!value)
|
||||
fNewValue = 0.0f;
|
||||
else
|
||||
fNewValue = (float)atof(value);
|
||||
|
||||
if (ClampValue(fNewValue))
|
||||
{
|
||||
Q_snprintf(tempVal, sizeof(tempVal), "%f", fNewValue);
|
||||
val = tempVal;
|
||||
}
|
||||
|
||||
// Redetermine value
|
||||
m_fValue = fNewValue;
|
||||
m_nValue = (int)(m_fValue);
|
||||
|
||||
if (!(m_nFlags & FCVAR_NEVER_AS_STRING))
|
||||
{
|
||||
ChangeStringValue(val, flOldValue);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *tempVal -
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ConVar::ChangeStringValue(const char* tempVal, float flOldValue)
|
||||
{
|
||||
printf("Executed ConVar::ChangeStringValue (tempVal %s; flOldValue %f)\n", tempVal, flOldValue);
|
||||
@ -842,7 +628,6 @@ void ConVar::ChangeStringValue(const char* tempVal, float flOldValue)
|
||||
|
||||
memcpy(m_Value.m_pszString, std::to_string(this->GetFloat()).c_str(), len);
|
||||
|
||||
// Invoke any necessary callback function
|
||||
for (int i = 0; i < m_fnChangeCallbacks.Count(); i++) {
|
||||
m_fnChangeCallbacks[i](this, pszOldValue, flOldValue);
|
||||
}
|
||||
@ -857,11 +642,6 @@ void ConVar::InternalSetColorValue(Color cValue)
|
||||
InternalSetIntValue(color);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Check whether to clamp and then perform clamp
|
||||
// Input : value -
|
||||
// Output : Returns true if value changed
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConVar::ClampValue(float& value)
|
||||
{
|
||||
if (m_bHasMin && (value < m_fMinVal))
|
||||
@ -879,92 +659,6 @@ bool ConVar::ClampValue(float& value)
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *value -
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
void ConVar::InternalSetFloatValue(float fNewValue)
|
||||
{
|
||||
if (fNewValue == m_fValue)
|
||||
return;
|
||||
|
||||
if (IsFlagSet(FCVAR_MATERIAL_THREAD_MASK))
|
||||
{
|
||||
if (g_pCVar && !g_pCVar->IsMaterialThreadSetAllowed())
|
||||
{
|
||||
g_pCVar->QueueMaterialThreadSetValue(this, fNewValue);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Assert(m_pParent == this); // Only valid for root convars.
|
||||
|
||||
// Check bounds
|
||||
ClampValue(fNewValue);
|
||||
|
||||
// Redetermine value
|
||||
float flOldValue = m_fValue;
|
||||
m_fValue = fNewValue;
|
||||
m_nValue = (int)m_fValue;
|
||||
|
||||
if (!(m_nFlags & FCVAR_NEVER_AS_STRING))
|
||||
{
|
||||
char tempVal[32];
|
||||
Q_snprintf(tempVal, sizeof(tempVal), "%f", m_fValue);
|
||||
ChangeStringValue(tempVal, flOldValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert(!m_fnChangeCallback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *value -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar::InternalSetIntValue(int nValue)
|
||||
{
|
||||
if (nValue == m_nValue)
|
||||
return;
|
||||
|
||||
if (IsFlagSet(FCVAR_MATERIAL_THREAD_MASK))
|
||||
{
|
||||
if (g_pCVar && !g_pCVar->IsMaterialThreadSetAllowed())
|
||||
{
|
||||
g_pCVar->QueueMaterialThreadSetValue(this, nValue);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Assert(m_pParent == this); // Only valid for root convars.
|
||||
|
||||
float fValue = (float)nValue;
|
||||
if (ClampValue(fValue))
|
||||
{
|
||||
nValue = (int)(fValue);
|
||||
}
|
||||
|
||||
// Redetermine value
|
||||
float flOldValue = m_fValue;
|
||||
m_fValue = fValue;
|
||||
m_nValue = nValue;
|
||||
|
||||
if (!(m_nFlags & FCVAR_NEVER_AS_STRING))
|
||||
{
|
||||
char tempVal[32];
|
||||
Q_snprintf(tempVal, sizeof(tempVal), "%d", m_nValue);
|
||||
ChangeStringValue(tempVal, flOldValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert(!m_fnChangeCallback);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void ConVar::InternalSetFloatValue(float fNewValue)
|
||||
@ -976,7 +670,6 @@ void ConVar::InternalSetFloatValue(float fNewValue)
|
||||
|
||||
ClampValue(fNewValue);
|
||||
|
||||
// Redetermine value
|
||||
float flOldValue = m_Value.m_fValue;
|
||||
*(uint32_t*)&m_Value.m_fValue = *(uint32_t*)&fNewValue ^ (uint32_t)this;
|
||||
*(uint32_t*)&m_Value.m_nValue = (uint32_t)fNewValue ^ (uint32_t)this;
|
||||
@ -987,7 +680,6 @@ void ConVar::InternalSetFloatValue(float fNewValue)
|
||||
ChangeStringValue(tempVal, flOldValue);
|
||||
}
|
||||
else {
|
||||
//assert(m_fnChangeCallbacks.Count() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1003,7 +695,6 @@ void ConVar::InternalSetIntValue(int nValue)
|
||||
nValue = (int)(fValue);
|
||||
}
|
||||
|
||||
// Redetermine value
|
||||
float flOldValue = m_Value.m_fValue;
|
||||
*(uint32_t*)&m_Value.m_fValue = *(uint32_t*)&fValue ^ (uint32_t)this;
|
||||
*(uint32_t*)&m_Value.m_nValue = *(uint32_t*)&nValue ^ (uint32_t)this;
|
||||
@ -1014,23 +705,17 @@ void ConVar::InternalSetIntValue(int nValue)
|
||||
ChangeStringValue(tempVal, flOldValue);
|
||||
}
|
||||
else {
|
||||
//assert(m_fnChangeCallbacks.Count() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Private creation
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ConVar::Create(const char* pName, const char* pDefaultValue, int flags /*= 0*/,
|
||||
const char* pHelpString /*= NULL*/, bool bMin /*= false*/, float fMin /*= 0.0*/,
|
||||
bool bMax /*= false*/, float fMax /*= false*/, FnChangeCallback_t callback /*= NULL*/)
|
||||
void ConVar::Create(const char* pName, const char* pDefaultValue, int flags ,
|
||||
const char* pHelpString , bool bMin , float fMin ,
|
||||
bool bMax , float fMax , FnChangeCallback_t callback )
|
||||
{
|
||||
static const char* empty_string = "";
|
||||
|
||||
m_pParent = this;
|
||||
|
||||
// Name should be static data
|
||||
m_pszDefaultValue = pDefaultValue ? pDefaultValue : empty_string;
|
||||
|
||||
m_Value.m_StringLength = strlen(m_pszDefaultValue) + 1;
|
||||
@ -1053,10 +738,6 @@ void ConVar::Create(const char* pName, const char* pDefaultValue, int flags /*=
|
||||
BaseClass::Create(pName, pHelpString, flags);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : *value -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar::SetValue(const char* value)
|
||||
{
|
||||
printf("Executed ConVar::SetValue to %s\n",value);
|
||||
@ -1064,10 +745,6 @@ void ConVar::SetValue(const char* value)
|
||||
var->InternalSetValue(value);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : value -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar::SetValue(float value)
|
||||
{
|
||||
printf("Executed ConVar::SetValue to %f\n", value);
|
||||
@ -1075,10 +752,6 @@ void ConVar::SetValue(float value)
|
||||
var->InternalSetFloatValue(value);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : value -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar::SetValue(int value)
|
||||
{
|
||||
printf("Executed ConVar::SetValue to %d\n", value);
|
||||
@ -1093,8 +766,6 @@ void ConVar::SetValue(Color value)
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
|
||||
int ConVar::GetFlags(void) const
|
||||
{
|
||||
return m_pParent->m_nFlags;
|
||||
@ -1110,64 +781,33 @@ const char* ConVar::GetBaseName(void) const
|
||||
return m_pParent->m_pszName;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Reset to default value
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar::Revert(void)
|
||||
{
|
||||
// Force default value again
|
||||
ConVar* var = (ConVar*)m_pParent;
|
||||
var->SetValue(var->m_pszDefaultValue);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : minVal -
|
||||
// Output : true if there is a min set
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConVar::GetMin(float& minVal) const
|
||||
{
|
||||
minVal = m_pParent->m_fMinVal;
|
||||
return m_pParent->m_bHasMin;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : maxVal -
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConVar::GetMax(float& maxVal) const
|
||||
{
|
||||
maxVal = m_pParent->m_fMaxVal;
|
||||
return m_pParent->m_bHasMax;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Output : const char
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* ConVar::GetDefault(void) const
|
||||
{
|
||||
return m_pParent->m_pszDefaultValue;
|
||||
}
|
||||
|
||||
/*
|
||||
void ConVar::SetDefault(const char* pszDefault)
|
||||
{
|
||||
static char* empty_string = (char*)"";
|
||||
m_pszDefaultValue = pszDefault ? pszDefault : empty_string;
|
||||
Assert(m_pszDefaultValue);
|
||||
}
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This version is simply used to make reading convars simpler.
|
||||
// Writing convars isn't allowed in this mode
|
||||
//-----------------------------------------------------------------------------
|
||||
class CEmptyConVar : public ConVar
|
||||
{
|
||||
public:
|
||||
CEmptyConVar() : ConVar("", "0") {}
|
||||
// Used for optimal read access
|
||||
virtual void SetValue(const char* pValue) {}
|
||||
virtual void SetValue(float flValue) {}
|
||||
virtual void SetValue(int nValue) {}
|
||||
@ -1221,9 +861,6 @@ bool ConVarRef::IsValid() const
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ConVar_PrintFlags(const ConCommandBase* var)
|
||||
{
|
||||
bool any = false;
|
||||
|
Reference in New Issue
Block a user