r1420 - in trunk: . code/client code/qcommon code/renderer code/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Jul 7 18:31:41 EDT 2008


Author: tma
Date: 2008-07-07 18:31:39 -0400 (Mon, 07 Jul 2008)
New Revision: 1420

Modified:
   trunk/code/client/cl_cgame.c
   trunk/code/client/cl_input.c
   trunk/code/client/cl_main.c
   trunk/code/client/cl_parse.c
   trunk/code/client/cl_scrn.c
   trunk/code/client/client.h
   trunk/code/client/snd_dma.c
   trunk/code/client/snd_local.h
   trunk/code/client/snd_main.c
   trunk/code/client/snd_openal.c
   trunk/code/client/snd_public.h
   trunk/code/qcommon/common.c
   trunk/code/qcommon/cvar.c
   trunk/code/qcommon/q_shared.c
   trunk/code/qcommon/q_shared.h
   trunk/code/qcommon/qcommon.h
   trunk/code/renderer/tr_init.c
   trunk/code/renderer/tr_public.h
   trunk/code/server/server.h
   trunk/code/server/sv_client.c
   trunk/code/server/sv_init.c
   trunk/code/server/sv_main.c
   trunk/code/server/sv_snapshot.c
   trunk/voip-readme.txt
Log:
* 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


Modified: trunk/code/client/cl_cgame.c
===================================================================
--- trunk/code/client/cl_cgame.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/client/cl_cgame.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -917,7 +917,7 @@
 	}
 #endif
 
-#if USE_VOIP
+#ifdef USE_VOIP
 	if (!clc.speexInitialized) {
 		int i;
 		speex_bits_init(&clc.speexEncoderBits);

Modified: trunk/code/client/cl_input.c
===================================================================
--- trunk/code/client/cl_input.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/client/cl_input.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -52,7 +52,7 @@
 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_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 @@
 		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 @@
 		clc.voipOutgoingDataSize = 0;
 		clc.voipOutgoingDataFrames = 0;
 	} else
-	#endif
+#endif
 
 	if ( count >= 1 ) {
 		if ( cl_showSend->integer ) {
@@ -1000,7 +1000,7 @@
 	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

Modified: trunk/code/client/cl_main.c
===================================================================
--- trunk/code/client/cl_main.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/client/cl_main.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -33,7 +33,7 @@
 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_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 @@
 #endif
 
 
-#if USE_VOIP
+#ifdef USE_VOIP
 static
 void CL_UpdateVoipIgnore(const char *idstr, qboolean ignore)
 {
@@ -304,7 +304,7 @@
 			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 @@
 	}
 #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 @@
 	// 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 @@
 	// update audio
 	S_Update();
 
-#if USE_VOIP
+#ifdef USE_VOIP
 	CL_CaptureVoip();
 #endif
 
@@ -2812,6 +2812,7 @@
 	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 @@
 void CL_Init( void ) {
 	Com_Printf( "----- Client Initialization -----\n" );
 
-	Con_Init ();	
+	Con_Init ();
 
 	CL_ClearState ();
 
@@ -3035,7 +3036,7 @@
 
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 
 	Cvar_Set( "cl_running", "1" );
 
-	CL_GenerateQKey();	
+	CL_GenerateQKey();
 	Cvar_Get( "cl_guid", "", CVAR_USERINFO | CVAR_ROM );
 	CL_UpdateGUID( NULL, 0 );
 

Modified: trunk/code/client/cl_parse.c
===================================================================
--- trunk/code/client/cl_parse.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/client/cl_parse.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -330,7 +330,7 @@
 int cl_connectedToPureServer;
 int cl_connectedToCheatServer;
 
-#if USE_VOIP
+#ifdef USE_VOIP
 int cl_connectedToVoipServer;
 #endif
 
@@ -362,7 +362,7 @@
 		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 @@
 	}
 }
 
-#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 @@
 			CL_ParseDownload( msg );
 			break;
 		case svc_voip:
-#if USE_VOIP
+#ifdef USE_VOIP
 			CL_ParseVoip( msg );
 #endif
 			break;

Modified: trunk/code/client/cl_scrn.c
===================================================================
--- trunk/code/client/cl_scrn.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/client/cl_scrn.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -365,7 +365,7 @@
 		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 @@
 			// 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;
 		}
 	}

Modified: trunk/code/client/client.h
===================================================================
--- trunk/code/client/client.h	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/client/client.h	2008-07-07 22:31:39 UTC (rev 1420)
@@ -34,7 +34,7 @@
 #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 @@
 	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_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_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_strafe;
 extern 	kbutton_t 	in_speed;
 
-#if USE_VOIP
+#ifdef USE_VOIP
 extern 	kbutton_t 	in_voiprecord;
 #endif
 
@@ -500,7 +500,7 @@
 extern int cl_connectedToPureServer;
 extern int cl_connectedToCheatServer;
 
-#if USE_VOIP
+#ifdef USE_VOIP
 extern int cl_connectedToVoipServer;
 void CL_Voip_f( void );
 #endif

Modified: trunk/code/client/snd_dma.c
===================================================================
--- trunk/code/client/snd_dma.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/client/snd_dma.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -121,7 +121,7 @@
 }
 
 
-#if USE_VOIP
+#ifdef USE_VOIP
 static
 void S_Base_StartCapture( void )
 {
@@ -1530,7 +1530,7 @@
 	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;

Modified: trunk/code/client/snd_local.h
===================================================================
--- trunk/code/client/snd_local.h	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/client/snd_local.h	2008-07-07 22:31:39 UTC (rev 1420)
@@ -140,7 +140,7 @@
 	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 );

Modified: trunk/code/client/snd_main.c
===================================================================
--- trunk/code/client/snd_main.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/client/snd_main.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -62,7 +62,7 @@
 	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 @@
 }
 
 
-#if USE_VOIP
+#ifdef USE_VOIP
 /*
 =================
 S_StartCapture

Modified: trunk/code/client/snd_openal.c
===================================================================
--- trunk/code/client/snd_openal.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/client/snd_openal.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -1696,7 +1696,7 @@
 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 @@
 {
 }
 
-#if USE_VOIP
+#ifdef USE_VOIP
 static
 void S_AL_StartCapture( void )
 {
@@ -1925,7 +1925,7 @@
 	qalcDestroyContext(alContext);
 	qalcCloseDevice(alDevice);
 
-#if USE_VOIP
+#ifdef USE_VOIP
 	if (alCaptureDevice != NULL) {
 		qalcCaptureStop(alCaptureDevice);
 		qalcCaptureCloseDevice(alCaptureDevice);
@@ -2067,7 +2067,7 @@
 	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 @@
 	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;

Modified: trunk/code/client/snd_public.h
===================================================================
--- trunk/code/client/snd_public.h	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/client/snd_public.h	2008-07-07 22:31:39 UTC (rev 1420)
@@ -72,7 +72,7 @@
 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 );

Modified: trunk/code/qcommon/common.c
===================================================================
--- trunk/code/qcommon/common.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/qcommon/common.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -473,10 +473,12 @@
 			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 @@
   // 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();

Modified: trunk/code/qcommon/cvar.c
===================================================================
--- trunk/code/qcommon/cvar.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/qcommon/cvar.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -189,7 +189,110 @@
 	}
 }
 
+/*
+============
+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;
+}
+
+
 /*
 ============
 Cvar_Get
@@ -220,6 +323,8 @@
 
 	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 @@
 	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 @@
 		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 @@
 
 /*
 =====================
+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 @@
 
 /*
 =====================
-Cvar_Register
+Cvar_Update
 
 updates an interpreted modules' version of a cvar
 =====================

Modified: trunk/code/qcommon/q_shared.c
===================================================================
--- trunk/code/qcommon/q_shared.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/qcommon/q_shared.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -726,6 +726,28 @@
 	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

Modified: trunk/code/qcommon/q_shared.h
===================================================================
--- trunk/code/qcommon/q_shared.h	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/qcommon/q_shared.h	2008-07-07 22:31:39 UTC (rev 1420)
@@ -678,6 +678,8 @@
 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 @@
 
 // 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;

Modified: trunk/code/qcommon/qcommon.h
===================================================================
--- trunk/code/qcommon/qcommon.h	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/qcommon/qcommon.h	2008-07-07 22:31:39 UTC (rev 1420)
@@ -528,6 +528,7 @@
 // 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 );
 

Modified: trunk/code/renderer/tr_init.c
===================================================================
--- trunk/code/renderer/tr_init.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/renderer/tr_init.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -159,30 +159,6 @@
 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 @@
 	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 @@
 	// 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 @@
 	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 );

Modified: trunk/code/renderer/tr_public.h
===================================================================
--- trunk/code/renderer/tr_public.h	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/renderer/tr_public.h	2008-07-07 22:31:39 UTC (rev 1420)
@@ -131,6 +131,7 @@
 
 	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 );

Modified: trunk/code/server/server.h
===================================================================
--- trunk/code/server/server.h	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/server/server.h	2008-07-07 22:31:39 UTC (rev 1420)
@@ -33,7 +33,7 @@
 
 #define	MAX_ENT_CLUSTERS	16
 
-#if USE_VOIP
+#ifdef USE_VOIP
 typedef struct voipServerPacket_s
 {
 	int generation;
@@ -179,7 +179,7 @@
 	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	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_WriteDownloadToClient( client_t *cl , msg_t *msg );
 
-#if USE_VOIP
+#ifdef USE_VOIP
 void SV_WriteVoipToClient( client_t *cl, msg_t *msg );
 #endif
 

Modified: trunk/code/server/sv_client.c
===================================================================
--- trunk/code/server/sv_client.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/server/sv_client.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -1083,7 +1083,7 @@
 	}
 }
 
-#if USE_VOIP
+#ifdef USE_VOIP
 /*
 ==================
 SV_WriteVoipToClient
@@ -1378,10 +1378,10 @@
 		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 @@
 }
 
 
-#if USE_VOIP
+#ifdef USE_VOIP
 static
 void SV_UpdateVoipIgnore(client_t *cl, const char *idstr, qboolean ignore)
 {
@@ -1468,7 +1468,7 @@
 	{"stopdl", SV_StopDownload_f},
 	{"donedl", SV_DoneDownload_f},
 
-#if USE_VOIP
+#ifdef USE_VOIP
 	{"voip", SV_Voip_f},
 #endif
 
@@ -1692,7 +1692,7 @@
 }
 
 
-#if USE_VOIP
+#ifdef USE_VOIP
 static
 qboolean SV_ShouldIgnoreVoipSender(const client_t *cl)
 {
@@ -1922,7 +1922,7 @@
 	} 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 ) {

Modified: trunk/code/server/sv_init.c
===================================================================
--- trunk/code/server/sv_init.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/server/sv_init.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -654,12 +654,9 @@
 	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 );

Modified: trunk/code/server/sv_main.c
===================================================================
--- trunk/code/server/sv_main.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/server/sv_main.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -22,7 +22,7 @@
 
 #include "server.h"
 
-#if USE_VOIP
+#ifdef USE_VOIP
 cvar_t *sv_voip;
 #endif
 
@@ -411,9 +411,9 @@
 	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
 

Modified: trunk/code/server/sv_snapshot.c
===================================================================
--- trunk/code/server/sv_snapshot.c	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/code/server/sv_snapshot.c	2008-07-07 22:31:39 UTC (rev 1420)
@@ -653,7 +653,7 @@
 	// Add any download data if the client is downloading
 	SV_WriteDownloadToClient( client, &msg );
 
-#if USE_VOIP
+#ifdef USE_VOIP
 	SV_WriteVoipToClient( client, &msg );
 #endif
 

Modified: trunk/voip-readme.txt
===================================================================
--- trunk/voip-readme.txt	2008-07-06 20:07:43 UTC (rev 1419)
+++ trunk/voip-readme.txt	2008-07-07 22:31:39 UTC (rev 1420)
@@ -37,7 +37,7 @@
          "0" to disable. Without this, all VoIP packets are refused by the
          server, which means no one gets to use in-game VoIP.
 
-voip: set to "1" (the default) to enable client-side VoIP support. Set to "0"
+cl_voip: set to "1" (the default) to enable client-side VoIP support. Set to "0"
       to disable. Without this, you will neither be able to transmit voice nor
       hear other people.
 




More information about the quake3-commits mailing list