- Removed GetConVarMin/Max() and replaced them with GetConVarBounds()
authorScott Ehlert <ds@alliedmods.net>
Tue May 01 05:29:37 2007 +0000 (2007-05-01)
changeset 71493b19876407e
parent 713 7a8ac1106ace
child 715 1a3c0122be7c
- Removed GetConVarMin/Max() and replaced them with GetConVarBounds()
- Added SetConVarBounds() to set convar constraints after convar has already been created
core/convar_sm.h
core/smn_console.cpp
plugins/include/console.inc
     1.1 --- a/core/convar_sm.h	Mon Apr 30 22:53:27 2007 +0000
     1.2 +++ b/core/convar_sm.h	Tue May 01 05:29:37 2007 +0000
     1.3 @@ -200,8 +200,14 @@
     1.4  	static IConCommandBaseAccessor	*s_pAccessor;
     1.5  	
     1.6  public: // Hackalicous
     1.7 -	int GetFlags()				{ return m_nFlags; }
     1.8 -	void SetFlags(int flags)	{ m_nFlags = flags; }
     1.9 +	inline int GetFlags()
    1.10 +	{
    1.11 +		return m_nFlags;
    1.12 +	}
    1.13 +	inline void SetFlags(int flags)	
    1.14 +	{ 
    1.15 +		m_nFlags = flags; 
    1.16 +	}
    1.17  };
    1.18  
    1.19  //-----------------------------------------------------------------------------
    1.20 @@ -246,7 +252,10 @@
    1.21  	FnCommandCompletionCallback	m_fnCompletionCallback;
    1.22  	bool						m_bHasCompletionCallback;
    1.23  public: // Hackalicous
    1.24 -	FnCommandCallback			GetCallback() { return m_fnCommandCallback; }
    1.25 +	inline FnCommandCallback GetCallback()
    1.26 +	{ 
    1.27 +		return m_fnCommandCallback; 
    1.28 +	}
    1.29  };
    1.30  
    1.31  //-----------------------------------------------------------------------------
    1.32 @@ -360,7 +369,20 @@
    1.33  	// Call this function when ConVar changes
    1.34  	FnChangeCallback			m_fnChangeCallback;
    1.35  public: // Hackalicous
    1.36 -	FnChangeCallback			GetCallback() { return m_fnChangeCallback; }
    1.37 +	inline FnChangeCallback	GetCallback()
    1.38 +	{
    1.39 +		return m_fnChangeCallback;
    1.40 +	}
    1.41 +	inline void SetMin(bool set, float min)
    1.42 +	{ 
    1.43 +		m_bHasMin = set; 
    1.44 +		m_fMinVal = min; 
    1.45 +	}
    1.46 +	inline void SetMax(bool set, float max)
    1.47 +	{
    1.48 +		m_bHasMax = set;
    1.49 +		m_fMaxVal = max; 
    1.50 +	}
    1.51  };
    1.52  
    1.53  
     2.1 --- a/core/smn_console.cpp	Mon Apr 30 22:53:27 2007 +0000
     2.2 +++ b/core/smn_console.cpp	Tue May 01 05:29:37 2007 +0000
     2.3 @@ -22,6 +22,12 @@
     2.4  #include "sm_stringutil.h"
     2.5  #include "PlayerManager.h"
     2.6  
     2.7 +enum ConVarBounds
     2.8 +{
     2.9 +	ConVarBound_Upper = 0,
    2.10 +	ConVarBound_Lower
    2.11 +};
    2.12 +
    2.13  static cell_t sm_CreateConVar(IPluginContext *pContext, const cell_t *params)
    2.14  {
    2.15  	char *name, *defaultVal, *helpText;
    2.16 @@ -261,7 +267,7 @@
    2.17  	return 1;
    2.18  }
    2.19  
    2.20 -static cell_t sm_GetConVarMin(IPluginContext *pContext, const cell_t *params)
    2.21 +static cell_t sm_GetConVarBounds(IPluginContext *pContext, const cell_t *params)
    2.22  {
    2.23  	Handle_t hndl = static_cast<Handle_t>(params[1]);
    2.24  	HandleError err;
    2.25 @@ -274,18 +280,28 @@
    2.26  	}
    2.27  
    2.28  	cell_t *addr;
    2.29 -	bool hasMin;
    2.30 -	float min;
    2.31 -
    2.32 -	pContext->LocalToPhysAddr(params[2], &addr);
    2.33 +	bool hasBound;
    2.34 +	float bound;
    2.35  
    2.36 -	hasMin = pConVar->GetMin(min);
    2.37 -	*addr = sp_ftoc(min);
    2.38 +	switch (params[2])
    2.39 +	{
    2.40 +	case ConVarBound_Upper:
    2.41 +		hasBound = pConVar->GetMax(bound);
    2.42 +		break;
    2.43 +	case ConVarBound_Lower:
    2.44 +		hasBound = pConVar->GetMin(bound);
    2.45 +		break;
    2.46 +	default:
    2.47 +		return pContext->ThrowNativeError("Invalid ConVarBounds value %d");
    2.48 +	}
    2.49 +	
    2.50 +	pContext->LocalToPhysAddr(params[3], &addr);
    2.51 +	*addr = sp_ftoc(bound);
    2.52  
    2.53 -	return hasMin;
    2.54 +	return hasBound;
    2.55  }
    2.56  
    2.57 -static cell_t sm_GetConVarMax(IPluginContext *pContext, const cell_t *params)
    2.58 +static cell_t sm_SetConVarBounds(IPluginContext *pContext, const cell_t *params)
    2.59  {
    2.60  	Handle_t hndl = static_cast<Handle_t>(params[1]);
    2.61  	HandleError err;
    2.62 @@ -297,16 +313,19 @@
    2.63  		return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
    2.64  	}
    2.65  
    2.66 -	cell_t *addr;
    2.67 -	bool hasMax;
    2.68 -	float max;
    2.69 +	switch (params[2])
    2.70 +	{
    2.71 +	case ConVarBound_Upper:
    2.72 +		pConVar->SetMax(params[3] ? true : false, sp_ctof(params[4]));
    2.73 +		break;
    2.74 +	case ConVarBound_Lower:
    2.75 +		pConVar->SetMin(params[3] ? true : false, sp_ctof(params[4]));
    2.76 +		break;
    2.77 +	default:
    2.78 +		return pContext->ThrowNativeError("Invalid ConVarBounds value %d");
    2.79 +	}
    2.80  
    2.81 -	pContext->LocalToPhysAddr(params[2], &addr);
    2.82 -
    2.83 -	hasMax = pConVar->GetMax(max);
    2.84 -	*addr = sp_ftoc(max);
    2.85 -
    2.86 -	return hasMax;
    2.87 +	return 1;
    2.88  }
    2.89  
    2.90  static cell_t sm_GetConVarName(IPluginContext *pContext, const cell_t *params)
    2.91 @@ -630,8 +649,8 @@
    2.92  	{"GetConVarFlags",		sm_GetConVarFlags},
    2.93  	{"SetConVarFlags",		sm_SetConVarFlags},
    2.94  	{"GetConVarName",		sm_GetConVarName},
    2.95 -	{"GetConVarMin",		sm_GetConVarMin},
    2.96 -	{"GetConVarMax",		sm_GetConVarMax},
    2.97 +	{"GetConVarBounds",		sm_GetConVarBounds},
    2.98 +	{"SetConVarBounds",		sm_SetConVarBounds},
    2.99  	{"ResetConVar",			sm_ResetConVar},
   2.100  	{"QueryClientConVar",	sm_QueryClientConVar},
   2.101  	{"RegServerCmd",		sm_RegServerCmd},
     3.1 --- a/plugins/include/console.inc	Mon Apr 30 22:53:27 2007 +0000
     3.2 +++ b/plugins/include/console.inc	Tue May 01 05:29:37 2007 +0000
     3.3 @@ -19,6 +19,15 @@
     3.4  #define _console_included
     3.5  
     3.6  /**
     3.7 + * Console variable bound values used with Get/SetConVarBounds()
     3.8 + */
     3.9 +enum ConVarBounds
    3.10 +{
    3.11 +	ConVarBound_Upper = 0,
    3.12 +	ConVarBound_Lower
    3.13 +};
    3.14 +
    3.15 +/**
    3.16   * Console variable query helper values.
    3.17   */
    3.18  enum QueryCookie
    3.19 @@ -379,6 +388,29 @@
    3.20  native SetConVarFlags(Handle:convar, flags);
    3.21  
    3.22  /**
    3.23 + * Retrieves the specified bound of a console variable.
    3.24 + *
    3.25 + * @param convar		Handle to the convar.
    3.26 + * @param type			Type of bound to retrieve, ConVarBound_Lower or ConVarBound_Upper.
    3.27 + * @param value			By-reference cell to store the specified floating point bound value.
    3.28 + * @return				True if the convar has the specified bound set, false otherwise.
    3.29 + * @error				Invalid or corrupt Handle.
    3.30 + */
    3.31 +native bool:GetConVarBounds(Handle:convar, ConVarBounds:type, &Float:value);
    3.32 +
    3.33 +/**
    3.34 + * Sets the specified bound of a console variable.
    3.35 + *
    3.36 + * @param convar		Handle to the convar.
    3.37 + * @param type			Type of bound to set, ConVarBound_Lower or ConVarBound_Upper
    3.38 + * @param set			If set to true, convar will use specified bound. If false, bound will be removed.
    3.39 + * @param value			Floating point value to use as the specified bound.
    3.40 + * @noreturn
    3.41 + * @error				Invalid or corrupt Handle.
    3.42 + */
    3.43 +native SetConVarBounds(Handle:convar, ConVarBounds:type, bool:set, Float:value=0.0);
    3.44 +
    3.45 +/**
    3.46   * Retrieves the name of a console variable.
    3.47   *
    3.48   * @param convar		Handle to the convar.
    3.49 @@ -390,26 +422,6 @@
    3.50  native GetConVarName(Handle:convar, const String:name[], maxlength);
    3.51  
    3.52  /**
    3.53 - * Retrieves the minimum floating point value that a console variable can contain.
    3.54 - *
    3.55 - * @param convar		Handle to the convar.
    3.56 - * @param min			By-reference cell to store the minimum floating point value.
    3.57 - * @return				True if the convar has a minimum value set, false otherwise.
    3.58 - * @error				Invalid or corrupt Handle.
    3.59 - */
    3.60 -native bool:GetConVarMin(Handle:convar, &Float:min);
    3.61 -
    3.62 -/**
    3.63 - * Retrieves the maximum floating point value that a console variable can contain.
    3.64 - *
    3.65 - * @param convar		Handle to the convar.
    3.66 - * @param min			By-reference cell to store the maximum floating point value.
    3.67 - * @return				True if the convar has a maximum value set, false otherwise.
    3.68 - * @error				Invalid or corrupt Handle.
    3.69 - */
    3.70 -native bool:GetConVarMax(Handle:convar, &Float:max);
    3.71 -
    3.72 -/**
    3.73   * Resets the console variable to its default value.
    3.74   *
    3.75   * @param convar		Handle to the convar.