1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 12:06:07 +08:00

Update ICVar, IConVar, ConVar.

Related to issue in alliedmodders/metamod-source#45. Will be fixed after
updated tier1 libs are pushed and MM:S rebuilt.
This commit is contained in:
Nick Hastings
2018-05-05 09:34:46 -04:00
parent 1513625aa2
commit 068ad767c6
4 changed files with 64 additions and 10 deletions

View File

@ -106,6 +106,7 @@ public:
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 void QueueMaterialThreadSetValue(ConVar *pConVar, const Vector &vecValue) = 0;
virtual bool HasQueuedMaterialThreadConVarSets() const = 0;
virtual int ProcessQueuedMaterialThreadConVarSets() = 0;

View File

@ -353,8 +353,9 @@ public:
void InstallChangeCallback( FnChangeCallback_t callback );
// Retrieve value
FORCEINLINE_CVAR float GetFloat( void ) const;
FORCEINLINE_CVAR int GetInt( void ) const;
virtual float GetFloat( void ) const;
virtual int GetInt( void ) const;
virtual Vector GetVector( void ) const;
FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); }
FORCEINLINE_CVAR char const *GetString( void ) const;
@ -365,6 +366,7 @@ public:
virtual void SetValue( const char *value );
virtual void SetValue( float value );
virtual void SetValue( int value );
virtual void SetValue( const Vector &value );
// Reset to default value
void Revert( void );
@ -379,8 +381,9 @@ private:
// Called by CCvar when the value of a var is changing.
virtual void InternalSetValue(const char *value);
// For CVARs marked FCVAR_NEVER_AS_STRING
virtual void InternalSetFloatValue( float fNewValue );
virtual void InternalSetFloatValue( float fNewValue, bool bForce = false );
virtual void InternalSetIntValue( int nValue );
virtual void InternalSetVectorValue( const Vector &vecValue );
virtual bool ClampValue( float& value );
virtual void ChangeStringValue( const char *tempVal, float flOldValue );
@ -410,6 +413,7 @@ private:
// Values
float m_fValue;
int m_nValue;
Vector m_vecValue;
// Min/Max values
bool m_bHasMin;
@ -417,6 +421,13 @@ private:
bool m_bHasMax;
float m_fMaxVal;
bool m_bHasCompMin;
float m_fCompMinVal;
bool m_bHasCompMax;
float m_fCompMaxVal;
bool m_bCompetitiveRestrictions;
// Call this function when ConVar changes
FnChangeCallback_t m_fnChangeCallback;
};
@ -440,6 +451,15 @@ FORCEINLINE_CVAR int ConVar::GetInt( void ) const
return m_pParent->m_nValue;
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as an int
// Output : int
//-----------------------------------------------------------------------------
FORCEINLINE_CVAR Vector ConVar::GetVector(void) const
{
return m_pParent->m_vecValue;
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.

View File

@ -16,6 +16,7 @@
#pragma once
#endif
#include "mathlib/vector.h"
#include "tier0/dbg.h"
#include "tier0/platform.h"
#include "tier1/strtools.h"
@ -105,6 +106,7 @@ public:
virtual void SetValue( const char *pValue ) = 0;
virtual void SetValue( float flValue ) = 0;
virtual void SetValue( int nValue ) = 0;
virtual void SetValue( const Vector &value ) = 0;
// Return name of command
virtual const char *GetName( void ) const = 0;

View File

@ -821,13 +821,17 @@ void ConVar::ChangeStringValue( const char *tempVal, float flOldValue )
*m_pszString = 0;
}
// Invoke any necessary callback function
if ( m_fnChangeCallback )
// If nothing has changed, don't do the callbacks.
if (V_strcmp(pszOldValue, m_pszString) != 0)
{
m_fnChangeCallback( this, pszOldValue, flOldValue );
}
// Invoke any necessary callback function
if ( m_fnChangeCallback )
{
m_fnChangeCallback( this, pszOldValue, flOldValue );
}
g_pCVar->CallGlobalChangeCallbacks( this, pszOldValue, flOldValue );
g_pCVar->CallGlobalChangeCallbacks( this, pszOldValue, flOldValue );
}
stackfree( pszOldValue );
}
@ -858,9 +862,9 @@ bool ConVar::ClampValue( float& value )
// Purpose:
// Input : *value -
//-----------------------------------------------------------------------------
void ConVar::InternalSetFloatValue( float fNewValue )
void ConVar::InternalSetFloatValue( float fNewValue, bool bForce /*= false */ )
{
if ( fNewValue == m_fValue )
if ( fNewValue == m_fValue && !bForce )
return;
if ( IsFlagSet( FCVAR_MATERIAL_THREAD_MASK ) )
@ -937,6 +941,14 @@ void ConVar::InternalSetIntValue( int nValue )
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *value -
//-----------------------------------------------------------------------------
void ConVar::InternalSetVectorValue( const Vector &vecNewValue )
{
}
//-----------------------------------------------------------------------------
// Purpose: Private creation
//-----------------------------------------------------------------------------
@ -958,6 +970,15 @@ void ConVar::Create( const char *pName, const char *pDefaultValue, int flags /*=
m_bHasMax = bMax;
m_fMaxVal = fMax;
// AM stubbed out just enough for ABI compat
m_vecValue = vec3_origin;
m_bHasCompMin = false;
m_fCompMinVal = 0.0;
m_bHasCompMax = false;
m_fCompMaxVal = 0.0;
m_bCompetitiveRestrictions = false;
//
m_fnChangeCallback = callback;
m_fValue = ( float )atof( m_pszString );
@ -1007,6 +1028,16 @@ void ConVar::SetValue( int value )
var->InternalSetIntValue( value );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : value -
//-----------------------------------------------------------------------------
void ConVar::SetValue( const Vector &value )
{
ConVar *var = (ConVar *)m_pParent;
var->InternalSetVectorValue( value );
}
//-----------------------------------------------------------------------------
// Purpose: Reset to default value
//-----------------------------------------------------------------------------