aboutsummaryrefslogtreecommitdiffstats
path: root/code
diff options
context:
space:
mode:
authortma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2008-07-07 22:31:39 +0000
committertma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2008-07-07 22:31:39 +0000
commit80e25417be92abff3053a4d8f209349a16e6d334 (patch)
tree1058d52d8de3d7115cf5b018e00408b0db8c5341 /code
parentafbf4dd0c3999e58f59b3d4e3dd4b93d6abe8fd0 (diff)
downloadioquake3-aero-80e25417be92abff3053a4d8f209349a16e6d334.tar.gz
ioquake3-aero-80e25417be92abff3053a4d8f209349a16e6d334.zip
* Rename voip cvar to cl_voip
* s/#if USE_VOIP/#ifdef USE_VOIP/ * Add generalised runtime cvar range checking, currently on [sv|cl]_voip, dedicated and a bunch of r_ variables git-svn-id: svn://svn.icculus.org/quake3/trunk@1420 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code')
-rw-r--r--code/client/cl_cgame.c2
-rw-r--r--code/client/cl_input.c10
-rw-r--r--code/client/cl_main.c36
-rw-r--r--code/client/cl_parse.c10
-rw-r--r--code/client/cl_scrn.c6
-rw-r--r--code/client/client.h12
-rw-r--r--code/client/snd_dma.c4
-rw-r--r--code/client/snd_local.h2
-rw-r--r--code/client/snd_main.c4
-rw-r--r--code/client/snd_openal.c10
-rw-r--r--code/client/snd_public.h2
-rw-r--r--code/qcommon/common.c10
-rw-r--r--code/qcommon/cvar.c126
-rw-r--r--code/qcommon/q_shared.c22
-rw-r--r--code/qcommon/q_shared.h22
-rw-r--r--code/qcommon/qcommon.h1
-rw-r--r--code/renderer/tr_init.c30
-rw-r--r--code/renderer/tr_public.h1
-rw-r--r--code/server/server.h8
-rw-r--r--code/server/sv_client.c14
-rw-r--r--code/server/sv_init.c7
-rw-r--r--code/server/sv_main.c6
-rw-r--r--code/server/sv_snapshot.c2
23 files changed, 238 insertions, 109 deletions
diff --git a/code/client/cl_cgame.c b/code/client/cl_cgame.c
index 12c1171..615884f 100644
--- a/code/client/cl_cgame.c
+++ b/code/client/cl_cgame.c
@@ -917,7 +917,7 @@ void CL_FirstSnapshot( void ) {
}
#endif
-#if USE_VOIP
+#ifdef USE_VOIP
if (!clc.speexInitialized) {
int i;
speex_bits_init(&clc.speexEncoderBits);
diff --git a/code/client/cl_input.c b/code/client/cl_input.c
index a17a662..077d689 100644
--- a/code/client/cl_input.c
+++ b/code/client/cl_input.c
@@ -52,7 +52,7 @@ kbutton_t in_lookup, in_lookdown, in_moveleft, in_moveright;
kbutton_t in_strafe, in_speed;
kbutton_t in_up, in_down;
-#if USE_VOIP
+#ifdef USE_VOIP
kbutton_t in_voiprecord;
#endif
@@ -220,7 +220,7 @@ void IN_SpeedUp(void) {IN_KeyUp(&in_speed);}
void IN_StrafeDown(void) {IN_KeyDown(&in_strafe);}
void IN_StrafeUp(void) {IN_KeyUp(&in_strafe);}
-#if USE_VOIP
+#ifdef USE_VOIP
void IN_VoipRecordDown(void)
{
IN_KeyDown(&in_voiprecord);
@@ -759,7 +759,7 @@ void CL_WritePacket( void ) {
Com_Printf("MAX_PACKET_USERCMDS\n");
}
- #if USE_VOIP
+#ifdef USE_VOIP
if (clc.voipOutgoingDataSize > 0) { // only send if data.
// Move cl_voipSendTarget from a string to the bitmasks if needed.
if (cl_voipSendTarget->modified) {
@@ -841,7 +841,7 @@ void CL_WritePacket( void ) {
clc.voipOutgoingDataSize = 0;
clc.voipOutgoingDataFrames = 0;
} else
- #endif
+#endif
if ( count >= 1 ) {
if ( cl_showSend->integer ) {
@@ -1000,7 +1000,7 @@ void CL_InitInput( void ) {
Cmd_AddCommand ("+mlook", IN_MLookDown);
Cmd_AddCommand ("-mlook", IN_MLookUp);
-#if USE_VOIP
+#ifdef USE_VOIP
Cmd_AddCommand ("+voiprecord", IN_VoipRecordDown);
Cmd_AddCommand ("-voiprecord", IN_VoipRecordUp);
#endif
diff --git a/code/client/cl_main.c b/code/client/cl_main.c
index 2d3a2d4..b54efc1 100644
--- a/code/client/cl_main.c
+++ b/code/client/cl_main.c
@@ -33,7 +33,7 @@ cvar_t *cl_useMumble;
cvar_t *cl_mumbleScale;
#endif
-#if USE_VOIP
+#ifdef USE_VOIP
cvar_t *cl_voipUseVAD;
cvar_t *cl_voipVADThreshold;
cvar_t *cl_voipSend;
@@ -41,7 +41,7 @@ cvar_t *cl_voipSendTarget;
cvar_t *cl_voipGainDuringCapture;
cvar_t *cl_voipCaptureMult;
cvar_t *cl_voipShowMeter;
-cvar_t *voip;
+cvar_t *cl_voip;
#endif
cvar_t *cl_nodelta;
@@ -179,7 +179,7 @@ void CL_UpdateMumble(void)
#endif
-#if USE_VOIP
+#ifdef USE_VOIP
static
void CL_UpdateVoipIgnore(const char *idstr, qboolean ignore)
{
@@ -304,7 +304,7 @@ void CL_CaptureVoip(void)
dontCapture = qtrue; // single player game.
else if (clc.demoplaying)
dontCapture = qtrue; // playing back a demo.
- else if ( voip->integer == 0 )
+ else if ( cl_voip->integer == 0 )
dontCapture = qtrue; // client has VoIP support disabled.
else if ( audioMult == 0.0f )
dontCapture = qtrue; // basically silenced incoming audio.
@@ -1162,7 +1162,7 @@ void CL_Disconnect( qboolean showMainMenu ) {
}
#endif
-#if USE_VOIP
+#ifdef USE_VOIP
if (cl_voipSend->integer) {
int tmp = cl_voipUseVAD->integer;
cl_voipUseVAD->integer = 0; // disable this for a moment.
@@ -1219,7 +1219,7 @@ void CL_Disconnect( qboolean showMainMenu ) {
// not connected to a pure server anymore
cl_connectedToPureServer = qfalse;
-#if USE_VOIP
+#ifdef USE_VOIP
// not connected to voip server anymore.
cl_connectedToVoipServer = qfalse;
#endif
@@ -2640,7 +2640,7 @@ void CL_Frame ( int msec ) {
// update audio
S_Update();
-#if USE_VOIP
+#ifdef USE_VOIP
CL_CaptureVoip();
#endif
@@ -2812,6 +2812,7 @@ void CL_InitRef( void ) {
ri.FS_FileExists = FS_FileExists;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Set = Cvar_Set;
+ ri.Cvar_CheckRange = Cvar_CheckRange;
// cinematic stuff
@@ -2978,7 +2979,7 @@ CL_Init
void CL_Init( void ) {
Com_Printf( "----- Client Initialization -----\n" );
- Con_Init ();
+ Con_Init ();
CL_ClearState ();
@@ -3035,7 +3036,7 @@ void CL_Init( void ) {
cl_conXOffset = Cvar_Get ("cl_conXOffset", "0", 0);
#ifdef MACOS_X
- // In game video is REALLY slow in Mac OS X right now due to driver slowness
+ // In game video is REALLY slow in Mac OS X right now due to driver slowness
cl_inGameVideo = Cvar_Get ("r_inGameVideo", "0", CVAR_ARCHIVE);
#else
cl_inGameVideo = Cvar_Get ("r_inGameVideo", "1", CVAR_ARCHIVE);
@@ -3052,7 +3053,7 @@ void CL_Init( void ) {
m_forward = Cvar_Get ("m_forward", "0.25", CVAR_ARCHIVE);
m_side = Cvar_Get ("m_side", "0.25", CVAR_ARCHIVE);
#ifdef MACOS_X
- // Input is jittery on OS X w/o this
+ // Input is jittery on OS X w/o this
m_filter = Cvar_Get ("m_filter", "1", CVAR_ARCHIVE);
#else
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE);
@@ -3091,7 +3092,7 @@ void CL_Init( void ) {
cl_mumbleScale = Cvar_Get ("cl_mumbleScale", "0.0254", CVAR_ARCHIVE);
#endif
-#if USE_VOIP
+#ifdef USE_VOIP
cl_voipSend = Cvar_Get ("cl_voipSend", "0", 0);
cl_voipSendTarget = Cvar_Get ("cl_voipSendTarget", "all", 0);
cl_voipGainDuringCapture = Cvar_Get ("cl_voipGainDuringCapture", "0.2", CVAR_ARCHIVE);
@@ -3099,24 +3100,21 @@ void CL_Init( void ) {
cl_voipUseVAD = Cvar_Get ("cl_voipUseVAD", "0", CVAR_ARCHIVE);
cl_voipVADThreshold = Cvar_Get ("cl_voipVADThreshold", "0.25", CVAR_ARCHIVE);
cl_voipShowMeter = Cvar_Get ("cl_voipShowMeter", "1", CVAR_ARCHIVE);
- voip = Cvar_Get ("voip", "1", CVAR_USERINFO | CVAR_ARCHIVE | CVAR_LATCH);
// This is a protocol version number.
- if ( (voip->integer < 0) || (voip->integer > 1) ) {
- Com_Printf("WARNING: voip cvar must be 0 or 1. Setting to 1.");
- Cvar_Set ("voip", "1");
- }
+ cl_voip = Cvar_Get ("cl_voip", "1", CVAR_USERINFO | CVAR_ARCHIVE | CVAR_LATCH);
+ Cvar_CheckRange( cl_voip, 0, 1, qtrue );
// If your data rate is too low, you'll get Connection Interrupted warnings
// when VoIP packets arrive, even if you have a broadband connection.
// This might work on rates lower than 25000, but for safety's sake, we'll
// just demand it. Who doesn't have at least a DSL line now, anyhow? If
// you don't, you don't need VoIP. :)
- if ((voip->integer) && (Cvar_VariableIntegerValue("rate") < 25000)) {
+ if ((cl_voip->integer) && (Cvar_VariableIntegerValue("rate") < 25000)) {
Com_Printf("Your network rate is too slow for VoIP.\n");
Com_Printf("Set 'Data Rate' to 'LAN/Cable/xDSL' in 'Setup/System/Network' and restart.\n");
Com_Printf("Until then, VoIP is disabled.\n");
- Cvar_Set("voip", "0");
+ Cvar_Set("cl_voip", "0");
}
#endif
@@ -3161,7 +3159,7 @@ void CL_Init( void ) {
Cvar_Set( "cl_running", "1" );
- CL_GenerateQKey();
+ CL_GenerateQKey();
Cvar_Get( "cl_guid", "", CVAR_USERINFO | CVAR_ROM );
CL_UpdateGUID( NULL, 0 );
diff --git a/code/client/cl_parse.c b/code/client/cl_parse.c
index 2219529..3c4b4fb 100644
--- a/code/client/cl_parse.c
+++ b/code/client/cl_parse.c
@@ -330,7 +330,7 @@ void CL_ParseSnapshot( msg_t *msg ) {
int cl_connectedToPureServer;
int cl_connectedToCheatServer;
-#if USE_VOIP
+#ifdef USE_VOIP
int cl_connectedToVoipServer;
#endif
@@ -362,7 +362,7 @@ void CL_SystemInfoChanged( void ) {
return;
}
-#if USE_VOIP
+#ifdef USE_VOIP
// in the future, (val) will be a protocol version string, so only
// accept explicitly 1, not generally non-zero.
s = Info_ValueForKey( systemInfo, "sv_voip" );
@@ -635,11 +635,11 @@ void CL_ParseDownload ( msg_t *msg ) {
}
}
-#if USE_VOIP
+#ifdef USE_VOIP
static
qboolean CL_ShouldIgnoreVoipSender(int sender)
{
- if (!voip->integer)
+ if (!cl_voip->integer)
return qtrue; // VoIP is disabled.
else if ((sender == clc.clientNum) && (!clc.demoplaying))
return qtrue; // ignore own voice (unless playing back a demo).
@@ -900,7 +900,7 @@ void CL_ParseServerMessage( msg_t *msg ) {
CL_ParseDownload( msg );
break;
case svc_voip:
-#if USE_VOIP
+#ifdef USE_VOIP
CL_ParseVoip( msg );
#endif
break;
diff --git a/code/client/cl_scrn.c b/code/client/cl_scrn.c
index 31b3df4..ecf47a5 100644
--- a/code/client/cl_scrn.c
+++ b/code/client/cl_scrn.c
@@ -365,7 +365,7 @@ void SCR_DrawVoipMeter( void ) {
return; // single player game.
else if (clc.demoplaying)
return; // playing back a demo.
- else if (!voip->integer)
+ else if (!cl_voip->integer)
return; // client has VoIP support disabled.
limit = (int) (clc.voipPower * 10.0f);
@@ -528,9 +528,9 @@ void SCR_DrawScreenField( stereoFrame_t stereoFrame ) {
// always supply STEREO_CENTER as vieworg offset is now done by the engine.
CL_CGameRendering(stereoFrame);
SCR_DrawDemoRecording();
- #if USE_VOIP
+#ifdef USE_VOIP
SCR_DrawVoipMeter();
- #endif
+#endif
break;
}
}
diff --git a/code/client/client.h b/code/client/client.h
index 42d4b0a..b380999 100644
--- a/code/client/client.h
+++ b/code/client/client.h
@@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "cl_curl.h"
#endif /* USE_CURL */
-#if USE_VOIP
+#ifdef USE_VOIP
#include "speex/speex.h"
#include "speex/speex_preprocess.h"
#endif
@@ -230,7 +230,7 @@ typedef struct {
int timeDemoMaxDuration; // maximum frame duration
unsigned char timeDemoDurations[ MAX_TIMEDEMO_DURATIONS ]; // log of frame durations
-#if USE_VOIP
+#ifdef USE_VOIP
qboolean speexInitialized;
int speexFrameSize;
int speexSampleRate;
@@ -407,7 +407,7 @@ extern cvar_t *cl_useMumble;
extern cvar_t *cl_mumbleScale;
#endif
-#if USE_VOIP
+#ifdef USE_VOIP
// cl_voipSendTarget is a string: "all" to broadcast to everyone, "none" to
// send to no one, or a comma-separated list of client numbers:
// "0,7,2,23" ... an empty string is treated like "all".
@@ -418,7 +418,7 @@ extern cvar_t *cl_voipSendTarget;
extern cvar_t *cl_voipGainDuringCapture;
extern cvar_t *cl_voipCaptureMult;
extern cvar_t *cl_voipShowMeter;
-extern cvar_t *voip;
+extern cvar_t *cl_voip;
#endif
//=================================================
@@ -475,7 +475,7 @@ extern kbutton_t in_mlook, in_klook;
extern kbutton_t in_strafe;
extern kbutton_t in_speed;
-#if USE_VOIP
+#ifdef USE_VOIP
extern kbutton_t in_voiprecord;
#endif
@@ -500,7 +500,7 @@ void Key_SetCatcher( int catcher );
extern int cl_connectedToPureServer;
extern int cl_connectedToCheatServer;
-#if USE_VOIP
+#ifdef USE_VOIP
extern int cl_connectedToVoipServer;
void CL_Voip_f( void );
#endif
diff --git a/code/client/snd_dma.c b/code/client/snd_dma.c
index 0848fe4..3058281 100644
--- a/code/client/snd_dma.c
+++ b/code/client/snd_dma.c
@@ -121,7 +121,7 @@ void S_Base_SoundInfo(void) {
}
-#if USE_VOIP
+#ifdef USE_VOIP
static
void S_Base_StartCapture( void )
{
@@ -1530,7 +1530,7 @@ qboolean S_Base_Init( soundInterface_t *si ) {
si->SoundInfo = S_Base_SoundInfo;
si->SoundList = S_Base_SoundList;
-#if USE_VOIP
+#ifdef USE_VOIP
si->StartCapture = S_Base_StartCapture;
si->AvailableCaptureSamples = S_Base_AvailableCaptureSamples;
si->Capture = S_Base_Capture;
diff --git a/code/client/snd_local.h b/code/client/snd_local.h
index 1a8b5dc..86c7d4a 100644
--- a/code/client/snd_local.h
+++ b/code/client/snd_local.h
@@ -140,7 +140,7 @@ typedef struct
void (*ClearSoundBuffer)( void );
void (*SoundInfo)( void );
void (*SoundList)( void );
-#if USE_VOIP
+#ifdef USE_VOIP
void (*StartCapture)( void );
int (*AvailableCaptureSamples)( void );
void (*Capture)( int samples, byte *data );
diff --git a/code/client/snd_main.c b/code/client/snd_main.c
index 3da9fd0..2f48117 100644
--- a/code/client/snd_main.c
+++ b/code/client/snd_main.c
@@ -62,7 +62,7 @@ static qboolean S_ValidSoundInterface( soundInterface_t *si )
if( !si->SoundInfo ) return qfalse;
if( !si->SoundList ) return qfalse;
-#if USE_VOIP
+#ifdef USE_VOIP
if( !si->StartCapture ) return qfalse;
if( !si->AvailableCaptureSamples ) return qfalse;
if( !si->Capture ) return qfalse;
@@ -313,7 +313,7 @@ void S_SoundList( void )
}
-#if USE_VOIP
+#ifdef USE_VOIP
/*
=================
S_StartCapture
diff --git a/code/client/snd_openal.c b/code/client/snd_openal.c
index 1cb48b8..6147131 100644
--- a/code/client/snd_openal.c
+++ b/code/client/snd_openal.c
@@ -1696,7 +1696,7 @@ void S_AL_MusicUpdate( void )
static ALCdevice *alDevice;
static ALCcontext *alContext;
-#if USE_VOIP
+#ifdef USE_VOIP
static ALCdevice *alCaptureDevice;
static cvar_t *s_alCapture;
#endif
@@ -1844,7 +1844,7 @@ void S_AL_SoundList( void )
{
}
-#if USE_VOIP
+#ifdef USE_VOIP
static
void S_AL_StartCapture( void )
{
@@ -1925,7 +1925,7 @@ void S_AL_Shutdown( void )
qalcDestroyContext(alContext);
qalcCloseDevice(alDevice);
-#if USE_VOIP
+#ifdef USE_VOIP
if (alCaptureDevice != NULL) {
qalcCaptureStop(alCaptureDevice);
qalcCaptureCloseDevice(alCaptureDevice);
@@ -2067,7 +2067,7 @@ qboolean S_AL_Init( soundInterface_t *si )
qalDopplerFactor( s_alDopplerFactor->value );
qalDopplerVelocity( s_alDopplerSpeed->value );
-#if USE_VOIP
+#ifdef USE_VOIP
// !!! FIXME: some of these alcCaptureOpenDevice() values should be cvars.
// !!! FIXME: add support for capture device enumeration.
// !!! FIXME: add some better error reporting.
@@ -2122,7 +2122,7 @@ qboolean S_AL_Init( soundInterface_t *si )
si->SoundInfo = S_AL_SoundInfo;
si->SoundList = S_AL_SoundList;
-#if USE_VOIP
+#ifdef USE_VOIP
si->StartCapture = S_AL_StartCapture;
si->AvailableCaptureSamples = S_AL_AvailableCaptureSamples;
si->Capture = S_AL_Capture;
diff --git a/code/client/snd_public.h b/code/client/snd_public.h
index e1c2309..1587f33 100644
--- a/code/client/snd_public.h
+++ b/code/client/snd_public.h
@@ -72,7 +72,7 @@ void SNDDMA_Activate( void );
void S_UpdateBackgroundTrack( void );
-#if USE_VOIP
+#ifdef USE_VOIP
void S_StartCapture( void );
int S_AvailableCaptureSamples( void );
void S_Capture( int samples, byte *data );
diff --git a/code/qcommon/common.c b/code/qcommon/common.c
index f100b82..5888592 100644
--- a/code/qcommon/common.c
+++ b/code/qcommon/common.c
@@ -473,10 +473,12 @@ qboolean Com_AddStartupCommands( void ) {
continue;
}
- // set commands won't override menu startup
- if ( Q_stricmpn( com_consoleLines[i], "set", 3 ) ) {
- added = qtrue;
+ // set commands already added with Com_StartupVariable
+ if ( !Q_stricmpn( com_consoleLines[i], "set", 3 ) ) {
+ continue;
}
+
+ added = qtrue;
Cbuf_AddText( com_consoleLines[i] );
Cbuf_AddText( "\n" );
}
@@ -2562,8 +2564,10 @@ void Com_Init( char *commandLine ) {
// get dedicated here for proper hunk megs initialization
#ifdef DEDICATED
com_dedicated = Cvar_Get ("dedicated", "1", CVAR_INIT);
+ Cvar_CheckRange( com_dedicated, 1, 2, qtrue );
#else
com_dedicated = Cvar_Get ("dedicated", "0", CVAR_LATCH);
+ Cvar_CheckRange( com_dedicated, 0, 2, qtrue );
#endif
// allocate the stack based hunk allocator
Com_InitHunkMemory();
diff --git a/code/qcommon/cvar.c b/code/qcommon/cvar.c
index 2526e38..fc2a9fa 100644
--- a/code/qcommon/cvar.c
+++ b/code/qcommon/cvar.c
@@ -189,6 +189,109 @@ void Cvar_CommandCompletion( void(*callback)(const char *s) ) {
}
}
+/*
+============
+Cvar_Validate
+============
+*/
+static const char *Cvar_Validate( cvar_t *var,
+ const char *value, qboolean warn )
+{
+ static char s[ MAX_CVAR_VALUE_STRING ];
+ float valuef;
+ qboolean changed = qfalse;
+
+ if( !var->validate )
+ return value;
+
+ if( !value )
+ return value;
+
+ if( Q_isanumber( value ) )
+ {
+ valuef = atof( value );
+
+ if( var->integral )
+ {
+ if( !Q_isintegral( valuef ) )
+ {
+ if( warn )
+ Com_Printf( "WARNING: cvar '%s' must be integral", var->name );
+
+ valuef = (int)valuef;
+ changed = qtrue;
+ }
+ }
+ }
+ else
+ {
+ if( warn )
+ Com_Printf( "WARNING: cvar '%s' must be numeric", var->name );
+
+ valuef = atof( var->resetString );
+ changed = qtrue;
+ }
+
+ if( valuef < var->min )
+ {
+ if( warn )
+ {
+ if( changed )
+ Com_Printf( " and is" );
+ else
+ Com_Printf( "WARNING: cvar '%s'", var->name );
+
+ if( Q_isintegral( var->min ) )
+ Com_Printf( " out of range (min %d)", (int)var->min );
+ else
+ Com_Printf( " out of range (min %f)", var->min );
+ }
+
+ valuef = var->min;
+ changed = qtrue;
+ }
+ else if( valuef > var->max )
+ {
+ if( warn )
+ {
+ if( changed )
+ Com_Printf( " and is" );
+ else
+ Com_Printf( "WARNING: cvar '%s'", var->name );
+
+ if( Q_isintegral( var->max ) )
+ Com_Printf( " out of range (max %d)", (int)var->max );
+ else
+ Com_Printf( " out of range (max %f)", var->max );
+ }
+
+ valuef = var->max;
+ changed = qtrue;
+ }
+
+ if( changed )
+ {
+ if( Q_isintegral( valuef ) )
+ {
+ Com_sprintf( s, sizeof( s ), "%d", (int)valuef );
+
+ if( warn )
+ Com_Printf( ", setting to %d\n", (int)valuef );
+ }
+ else
+ {
+ Com_sprintf( s, sizeof( s ), "%f", valuef );
+
+ if( warn )
+ Com_Printf( ", setting to %f\n", valuef );
+ }
+
+ return s;
+ }
+ else
+ return value;
+}
+
/*
============
@@ -220,6 +323,8 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
var = Cvar_FindVar (var_name);
if ( var ) {
+ var_value = Cvar_Validate( var, var_value, qfalse );
+
// if the C code is now specifying a variable that the user already
// set a value for, take the new value as the reset value
if ( ( var->flags & CVAR_USER_CREATED ) && !( flags & CVAR_USER_CREATED )
@@ -282,6 +387,7 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) {
var->value = atof (var->string);
var->integer = atoi(var->string);
var->resetString = CopyString( var_value );
+ var->validate = qfalse;
// link the variable in
var->next = cvar_vars;
@@ -364,6 +470,8 @@ cvar_t *Cvar_Set2( const char *var_name, const char *value, qboolean force ) {
value = var->resetString;
}
+ value = Cvar_Validate( var, value, qtrue );
+
if((var->flags & CVAR_LATCH) && var->latchedString) {
if(!strcmp(value,var->latchedString))
return var;
@@ -879,6 +987,22 @@ void Cvar_InfoStringBuffer( int bit, char* buff, int buffsize ) {
/*
=====================
+Cvar_CheckRange
+=====================
+*/
+void Cvar_CheckRange( cvar_t *var, float min, float max, qboolean integral )
+{
+ var->validate = qtrue;
+ var->min = min;
+ var->max = max;
+ var->integral = integral;
+
+ // Force an initial range check
+ Cvar_Set( var->name, var->string );
+}
+
+/*
+=====================
Cvar_Register
basically a slightly modified Cvar_Get for the interpreted modules
@@ -899,7 +1023,7 @@ void Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultVa
/*
=====================
-Cvar_Register
+Cvar_Update
updates an interpreted modules' version of a cvar
=====================
diff --git a/code/qcommon/q_shared.c b/code/qcommon/q_shared.c
index 1bc8076..e9f59af 100644
--- a/code/qcommon/q_shared.c
+++ b/code/qcommon/q_shared.c
@@ -726,6 +726,28 @@ char* Q_strrchr( const char* string, int c )
return sp;
}
+qboolean Q_isanumber( const char *s )
+{
+#ifdef Q3_VM
+ //FIXME: implement
+ return qfalse;
+#else
+ char *p;
+
+ if( *s == '\0' )
+ return qfalse;
+
+ strtof( s, &p );
+
+ return *p == '\0';
+#endif
+}
+
+qboolean Q_isintegral( float f )
+{
+ return (int)f == f;
+}
+
/*
=============
Q_strncpyz
diff --git a/code/qcommon/q_shared.h b/code/qcommon/q_shared.h
index 9aa19d9..248fcf1 100644
--- a/code/qcommon/q_shared.h
+++ b/code/qcommon/q_shared.h
@@ -678,6 +678,8 @@ int Q_isprint( int c );
int Q_islower( int c );
int Q_isupper( int c );
int Q_isalpha( int c );
+qboolean Q_isanumber( const char *s );
+qboolean Q_isintegral( float f );
// portable case insensitive compare
int Q_stricmp (const char *s1, const char *s2);
@@ -786,15 +788,19 @@ default values.
// nothing outside the Cvar_*() functions should modify these fields!
typedef struct cvar_s {
- char *name;
- char *string;
- char *resetString; // cvar_restart will reset to this value
- char *latchedString; // for CVAR_LATCH vars
- int flags;
+ char *name;
+ char *string;
+ char *resetString; // cvar_restart will reset to this value
+ char *latchedString; // for CVAR_LATCH vars
+ int flags;
qboolean modified; // set each time the cvar is changed
- int modificationCount; // incremented each time the cvar is changed
- float value; // atof( string )
- int integer; // atoi( string )
+ int modificationCount; // incremented each time the cvar is changed
+ float value; // atof( string )
+ int integer; // atoi( string )
+ qboolean validate;
+ qboolean integral;
+ float min;
+ float max;
struct cvar_s *next;
struct cvar_s *hashNext;
} cvar_t;
diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h
index 58b0a29..c5efef8 100644
--- a/code/qcommon/qcommon.h
+++ b/code/qcommon/qcommon.h
@@ -528,6 +528,7 @@ char *Cvar_InfoString_Big( int bit );
// returns an info string containing all the cvars that have the given bit set
// in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc )
void Cvar_InfoStringBuffer( int bit, char *buff, int buffsize );
+void Cvar_CheckRange( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral );
void Cvar_Restart_f( void );
diff --git a/code/renderer/tr_init.c b/code/renderer/tr_init.c
index d838c61..492b924 100644
--- a/code/renderer/tr_init.c
+++ b/code/renderer/tr_init.c
@@ -159,30 +159,6 @@ int max_polys;
cvar_t *r_maxpolyverts;
int max_polyverts;
-static void AssertCvarRange( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral )
-{
- if ( shouldBeIntegral )
- {
- if ( ( int ) cv->value != cv->integer )
- {
- ri.Printf( PRINT_WARNING, "WARNING: cvar '%s' must be integral (%f)\n", cv->name, cv->value );
- ri.Cvar_Set( cv->name, va( "%d", cv->integer ) );
- }
- }
-
- if ( cv->value < minVal )
- {
- ri.Printf( PRINT_WARNING, "WARNING: cvar '%s' out of range (%f < %f)\n", cv->name, cv->value, minVal );
- ri.Cvar_Set( cv->name, va( "%f", minVal ) );
- }
- else if ( cv->value > maxVal )
- {
- ri.Printf( PRINT_WARNING, "WARNING: cvar '%s' out of range (%f > %f)\n", cv->name, cv->value, maxVal );
- ri.Cvar_Set( cv->name, va( "%f", maxVal ) );
- }
-}
-
-
/*
** InitOpenGL
**
@@ -918,7 +894,7 @@ void R_Register( void )
r_picmip = ri.Cvar_Get ("r_picmip", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_roundImagesDown = ri.Cvar_Get ("r_roundImagesDown", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_colorMipLevels = ri.Cvar_Get ("r_colorMipLevels", "0", CVAR_LATCH );
- AssertCvarRange( r_picmip, 0, 16, qtrue );
+ ri.Cvar_CheckRange( r_picmip, 0, 16, qtrue );
r_detailTextures = ri.Cvar_Get( "r_detailtextures", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_texturebits = ri.Cvar_Get( "r_texturebits", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_colorbits = ri.Cvar_Get( "r_colorbits", "0", CVAR_ARCHIVE | CVAR_LATCH );
@@ -944,7 +920,7 @@ void R_Register( void )
// temporary latched variables that can only change over a restart
//
r_displayRefresh = ri.Cvar_Get( "r_displayRefresh", "0", CVAR_LATCH );
- AssertCvarRange( r_displayRefresh, 0, 200, qtrue );
+ ri.Cvar_CheckRange( r_displayRefresh, 0, 200, qtrue );
r_fullbright = ri.Cvar_Get ("r_fullbright", "0", CVAR_LATCH|CVAR_CHEAT );
r_mapOverBrightBits = ri.Cvar_Get ("r_mapOverBrightBits", "2", CVAR_LATCH );
r_intensity = ri.Cvar_Get ("r_intensity", "1", CVAR_LATCH );
@@ -957,7 +933,7 @@ void R_Register( void )
r_lodbias = ri.Cvar_Get( "r_lodbias", "0", CVAR_ARCHIVE );
r_flares = ri.Cvar_Get ("r_flares", "0", CVAR_ARCHIVE );
r_znear = ri.Cvar_Get( "r_znear", "4", CVAR_CHEAT );
- AssertCvarRange( r_znear, 0.001f, 200, qtrue );
+ ri.Cvar_CheckRange( r_znear, 0.001f, 200, qtrue );
r_zproj = ri.Cvar_Get( "r_zproj", "64", CVAR_ARCHIVE );
r_stereoSeparation = ri.Cvar_Get( "r_stereoSeparation", "64", CVAR_ARCHIVE );
r_ignoreGLErrors = ri.Cvar_Get( "r_ignoreGLErrors", "1", CVAR_ARCHIVE );
diff --git a/code/renderer/tr_public.h b/code/renderer/tr_public.h
index 6cefe16..c6846a9 100644
--- a/code/renderer/tr_public.h
+++ b/code/renderer/tr_public.h
@@ -131,6 +131,7 @@ typedef struct {
cvar_t *(*Cvar_Get)( const char *name, const char *value, int flags );
void (*Cvar_Set)( const char *name, const char *value );
+ void (*Cvar_CheckRange)( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral );
void (*Cmd_AddCommand)( const char *name, void(*cmd)(void) );
void (*Cmd_RemoveCommand)( const char *name );
diff --git a/code/server/server.h b/code/server/server.h
index 61fd882..64c4d1e 100644
--- a/code/server/server.h
+++ b/code/server/server.h
@@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define MAX_ENT_CLUSTERS 16
-#if USE_VOIP
+#ifdef USE_VOIP
typedef struct voipServerPacket_s
{
int generation;
@@ -179,7 +179,7 @@ typedef struct client_s {
netchan_buffer_t *netchan_start_queue;
netchan_buffer_t **netchan_end_queue;
-#if USE_VOIP
+#ifdef USE_VOIP
qboolean hasVoip;
qboolean muteAllVoip;
qboolean ignoreVoipFromClient[MAX_CLIENTS];
@@ -284,7 +284,7 @@ extern cvar_t *sv_strictAuth;
extern serverBan_t serverBans[SERVER_MAXBANS];
extern int serverBansCount;
-#if USE_VOIP
+#ifdef USE_VOIP
extern cvar_t *sv_voip;
#endif
@@ -345,7 +345,7 @@ void SV_ClientThink (client_t *cl, usercmd_t *cmd);
void SV_WriteDownloadToClient( client_t *cl , msg_t *msg );
-#if USE_VOIP
+#ifdef USE_VOIP
void SV_WriteVoipToClient( client_t *cl, msg_t *msg );
#endif
diff --git a/code/server/sv_client.c b/code/server/sv_client.c
index 180bbf3..5554ebf 100644
--- a/code/server/sv_client.c
+++ b/code/server/sv_client.c
@@ -1083,7 +1083,7 @@ void SV_WriteDownloadToClient( client_t *cl , msg_t *msg )
}
}
-#if USE_VOIP
+#ifdef USE_VOIP
/*
==================
SV_WriteVoipToClient
@@ -1378,10 +1378,10 @@ void SV_UserinfoChanged( client_t *cl ) {
cl->snapshotMsec = 50;
}
-#if USE_VOIP
+#ifdef USE_VOIP
// in the future, (val) will be a protocol version string, so only
// accept explicitly 1, not generally non-zero.
- val = Info_ValueForKey (cl->userinfo, "voip");
+ val = Info_ValueForKey (cl->userinfo, "cl_voip");
cl->hasVoip = (atoi(val) == 1) ? qtrue : qfalse;
#endif
@@ -1421,7 +1421,7 @@ static void SV_UpdateUserinfo_f( client_t *cl ) {
}
-#if USE_VOIP
+#ifdef USE_VOIP
static
void SV_UpdateVoipIgnore(client_t *cl, const char *idstr, qboolean ignore)
{
@@ -1468,7 +1468,7 @@ static ucmd_t ucmds[] = {
{"stopdl", SV_StopDownload_f},
{"donedl", SV_DoneDownload_f},
-#if USE_VOIP
+#ifdef USE_VOIP
{"voip", SV_Voip_f},
#endif
@@ -1692,7 +1692,7 @@ static void SV_UserMove( client_t *cl, msg_t *msg, qboolean delta ) {
}
-#if USE_VOIP
+#ifdef USE_VOIP
static
qboolean SV_ShouldIgnoreVoipSender(const client_t *cl)
{
@@ -1922,7 +1922,7 @@ void SV_ExecuteClientMessage( client_t *cl, msg_t *msg ) {
} else if ( c == clc_moveNoDelta ) {
SV_UserMove( cl, msg, qfalse );
} else if ( c == clc_voip ) {
-#if USE_VOIP
+#ifdef USE_VOIP
SV_UserVoip( cl, msg );
#endif
} else if ( c != clc_EOF ) {
diff --git a/code/server/sv_init.c b/code/server/sv_init.c
index 97154f0..52102ce 100644
--- a/code/server/sv_init.c
+++ b/code/server/sv_init.c
@@ -654,12 +654,9 @@ void SV_Init (void) {
Cvar_Get ("sv_cheats", "1", CVAR_SYSTEMINFO | CVAR_ROM );
sv_serverid = Cvar_Get ("sv_serverid", "0", CVAR_SYSTEMINFO | CVAR_ROM );
sv_pure = Cvar_Get ("sv_pure", "1", CVAR_SYSTEMINFO );
-#if USE_VOIP
+#ifdef USE_VOIP
sv_voip = Cvar_Get ("sv_voip", "1", CVAR_SYSTEMINFO | CVAR_LATCH);
- if ( (sv_voip->integer < 0) || (sv_voip->integer > 1) ) {
- Com_Printf("WARNING: sv_voip must be 0 or 1. Setting to 1.");
- Cvar_Set ("sv_voip", "1");
- }
+ Cvar_CheckRange( sv_voip, 0, 1, qtrue );
#endif
Cvar_Get ("sv_paks", "", CVAR_SYSTEMINFO | CVAR_ROM );
Cvar_Get ("sv_pakNames", "", CVAR_SYSTEMINFO | CVAR_ROM );
diff --git a/code/server/sv_main.c b/code/server/sv_main.c
index 667db41..6a941e2 100644
--- a/code/server/sv_main.c
+++ b/code/server/sv_main.c
@@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "server.h"
-#if USE_VOIP
+#ifdef USE_VOIP
cvar_t *sv_voip;
#endif
@@ -411,9 +411,9 @@ void SVC_Info( netadr_t from ) {
Info_SetValueForKey( infostring, "gametype", va("%i", sv_gametype->integer ) );
Info_SetValueForKey( infostring, "pure", va("%i", sv_pure->integer ) );
-#if USE_VOIP
+#ifdef USE_VOIP
if (sv_voip->integer) {
- Info_SetValueForKey( infostring, "voip", va("%i", sv_voip->integer ) );
+ Info_SetValueForKey( infostring, "cl_voip", va("%i", sv_voip->integer ) );
}
#endif
diff --git a/code/server/sv_snapshot.c b/code/server/sv_snapshot.c
index 71fdc8b..2e0ad92 100644
--- a/code/server/sv_snapshot.c
+++ b/code/server/sv_snapshot.c
@@ -653,7 +653,7 @@ void SV_SendClientSnapshot( client_t *client ) {
// Add any download data if the client is downloading
SV_WriteDownloadToClient( client, &msg );
-#if USE_VOIP
+#ifdef USE_VOIP
SV_WriteVoipToClient( client, &msg );
#endif