mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-01-03 16:13:22 +08:00
Update setting ConVar int values from string to more closely match game logic.
( https://github.com/alliedmodders/sourcemod/issues/648 ) They use a double as a go-between to gain precision, rather than casting the float value to an int,
This commit is contained in:
parent
884ba15d3c
commit
0b94b21a91
@ -127,6 +127,7 @@ int V_atoi (const char *str);
|
||||
int64 V_atoi64(const char *str);
|
||||
uint64 V_atoui64(const char *str);
|
||||
float V_atof (const char *str);
|
||||
double V_atod(const char *str);
|
||||
char* V_stristr( char* pStr, const char* pSearch );
|
||||
const char* V_stristr( const char* pStr, const char* pSearch );
|
||||
const char* V_strnistr( const char* pStr, const char* pSearch, int n );
|
||||
|
@ -784,6 +784,7 @@ int ConVar::GetSplitScreenPlayerSlot( void ) const
|
||||
void ConVar::InternalSetValue( const char *value )
|
||||
{
|
||||
float fNewValue;
|
||||
double dblNewValue;
|
||||
char tempVal[ 32 ];
|
||||
char *val;
|
||||
|
||||
@ -792,17 +793,19 @@ void ConVar::InternalSetValue( const char *value )
|
||||
float flOldValue = m_Value.m_fValue;
|
||||
|
||||
val = (char *)value;
|
||||
fNewValue = ( float )atof( value );
|
||||
dblNewValue = V_atod(value);
|
||||
fNewValue = ( float )dblNewValue;
|
||||
|
||||
if ( ClampValue( fNewValue ) )
|
||||
{
|
||||
dblNewValue = fNewValue;
|
||||
Q_snprintf( tempVal,sizeof(tempVal), "%f", fNewValue );
|
||||
val = tempVal;
|
||||
}
|
||||
|
||||
// Redetermine value
|
||||
m_Value.m_fValue = fNewValue;
|
||||
m_Value.m_nValue = ( int )( fNewValue );
|
||||
m_Value.m_nValue = ( int )( dblNewValue );
|
||||
|
||||
if ( !( m_nFlags & FCVAR_NEVER_AS_STRING ) )
|
||||
{
|
||||
@ -970,7 +973,8 @@ void ConVar::Create( const char *pName, const char *pDefaultValue, int flags /*=
|
||||
if (callback)
|
||||
m_fnChangeCallbacks.AddToTail(callback);
|
||||
|
||||
m_Value.m_fValue = ( float )atof( m_Value.m_pszString );
|
||||
double dblValue = V_atod( m_Value.m_pszString );
|
||||
m_Value.m_fValue = ( float )dblValue;
|
||||
|
||||
// Bounds Check, should never happen, if it does, no big deal
|
||||
if ( m_bHasMin && ( m_Value.m_fValue < m_fMinVal ) )
|
||||
@ -983,7 +987,7 @@ void ConVar::Create( const char *pName, const char *pDefaultValue, int flags /*=
|
||||
Assert( 0 );
|
||||
}
|
||||
|
||||
m_Value.m_nValue = ( int )m_Value.m_fValue;
|
||||
m_Value.m_nValue = ( int )dblValue;
|
||||
|
||||
BaseClass::Create( pName, pHelpString, flags );
|
||||
}
|
||||
|
@ -379,8 +379,13 @@ int V_atoi (const char *str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
float V_atof (const char *str)
|
||||
{
|
||||
return (float)V_atod(str);
|
||||
}
|
||||
|
||||
|
||||
double V_atod (const char *str)
|
||||
{
|
||||
_AssertValidStringPtr( str );
|
||||
double val;
|
||||
|
Loading…
x
Reference in New Issue
Block a user