Skip to content

Commit

Permalink
setup times changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenzzer committed Oct 9, 2023
1 parent 9fc0a3c commit 0cde80d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
5 changes: 3 additions & 2 deletions public/icvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class CConVarBaseData
inline bool HasMinValue( ) const { return m_minValue != nullptr; }
inline bool HasMaxValue( ) const { return m_maxValue != nullptr; }

inline int GetTimesChanges( void ) const { return m_iTimesChanged; }
inline int GetTimesChanged( void ) const { return m_iTimesChanged; }
inline void SetTimesChanged( int val ) { m_iTimesChanged = val; }

inline bool IsFlagSet( int64_t flag ) const { return ( flag & m_nFlags ) ? true : false; }
inline void AddFlags( int64_t flags ) { m_nFlags |= flags; }
Expand Down Expand Up @@ -463,7 +464,7 @@ abstract_class ICvar : public IAppSystem
// Install a global change callback (to be called when any convar changes)
virtual void InstallGlobalChangeCallback( FnChangeCallbackGlobal_t callback ) = 0;
virtual void RemoveGlobalChangeCallback( FnChangeCallbackGlobal_t callback ) = 0;
virtual void CallGlobalChangeCallbacks( BaseConVar* ref, CSplitScreenSlot nSlot, const char* newValue, char* oldValue ) = 0;
virtual void CallGlobalChangeCallbacks( BaseConVar* ref, CSplitScreenSlot nSlot, const char* newValue, const char* oldValue ) = 0;
// Reverts cvars which contain a specific flag
virtual void RevertFlaggedConVars( int nFlag ) = 0;

Expand Down
19 changes: 11 additions & 8 deletions public/tier1/convar.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,7 @@ class ConVar : public BaseConVar

// Deep copy
T oldValue = this->GetValue( );
GetConVarData()->SetValue( newValue, index );

g_pCVar->CallChangeCallback( this->m_Handle, index, (const CVValue_t*)&newValue, (const CVValue_t*)&oldValue );
g_pCVar->CallGlobalChangeCallbacks( this, index, szNewValue, szOldValue );
this->UpdateValue( newValue, index, (const CVValue_t*)&newValue, (const CVValue_t*)&oldValue, szNewValue, szOldValue );
}

inline void GetStringValue( char* dst, size_t len, const CSplitScreenSlot& index = 0 ) const { GetConVarData()->GetStringValue( dst, len, index ); }
Expand Down Expand Up @@ -581,6 +578,15 @@ class ConVar : public BaseConVar

SetupConVar(cvar);
}

inline void UpdateValue( const T& value, const CSplitScreenSlot& index, const CVValue_t* newValue, const CVValue_t* oldValue, const char* szNewValue, const char* szOldValue )
{
GetConVarData()->SetValue( value, index );

GetConVarData()->SetTimesChanged( GetConVarData()->GetTimesChanged( ) + 1 );
g_pCVar->CallChangeCallback( this->m_Handle, index, newValue, oldValue );
g_pCVar->CallGlobalChangeCallbacks( this, index, szNewValue, szOldValue );
}
};
static_assert(sizeof(ConVar<int>) == 0x10, "ConVar is of the wrong size!");
static_assert(sizeof(ConVar<int>) == sizeof(ConVar<Vector>), "Templated ConVar size varies!");
Expand All @@ -594,10 +600,7 @@ template<> inline void ConVar<const char*>::SetValue( const char*const& val, con
CConVarData<const char*>::ValueToString( newValue, szNewValue, sizeof(szNewValue) );
GetConVarData()->GetStringValue( szOldValue, sizeof(szOldValue), index );

GetConVarData()->SetValue( newValue, index );

g_pCVar->CallChangeCallback( this->m_Handle, index, (const CVValue_t*)&newValue, (const CVValue_t*)&szOldValue );
g_pCVar->CallGlobalChangeCallbacks( this, index, szNewValue, szOldValue );
this->UpdateValue( newValue, index, (const CVValue_t*)&newValue, (const CVValue_t*)&szOldValue, szNewValue, szOldValue );
}

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 0cde80d

Please sign in to comment.