diff options
Diffstat (limited to 'src/qcommon/cvar.c')
-rw-r--r-- | src/qcommon/cvar.c | 69 |
1 files changed, 51 insertions, 18 deletions
diff --git a/src/qcommon/cvar.c b/src/qcommon/cvar.c index c26ba543..0af10587 100644 --- a/src/qcommon/cvar.c +++ b/src/qcommon/cvar.c @@ -306,9 +306,9 @@ cvar_t *Cvar_Get( const char *var_name, const char *var_value, int flags ) { cvar_t *var; long hash; - if ( !var_name || ! var_value ) { + if ( !var_name || ! var_value ) { Com_Error( ERR_FATAL, "Cvar_Get: NULL parameter" ); - } + } if ( !Cvar_ValidateString( var_name ) ) { Com_Printf("invalid cvar name string: %s\n", var_name ); @@ -616,15 +616,15 @@ void Cvar_SetCheatState( void ) { // set all default vars to the safe value for ( var = cvar_vars ; var ; var = var->next ) { if ( var->flags & CVAR_CHEAT ) { - // the CVAR_LATCHED|CVAR_CHEAT vars might escape the reset here - // because of a different var->latchedString - if (var->latchedString) - { - Z_Free(var->latchedString); - var->latchedString = NULL; - } + // the CVAR_LATCHED|CVAR_CHEAT vars might escape the reset here + // because of a different var->latchedString + if (var->latchedString) + { + Z_Free(var->latchedString); + var->latchedString = NULL; + } if (strcmp(var->resetString,var->string)) { - Cvar_Set( var->name, var->resetString ); + Cvar_Set( var->name, var->resetString ); } } } @@ -653,7 +653,7 @@ qboolean Cvar_Command( void ) { } // set the value if forcing isn't required - Cvar_Set2 (v->name, Cmd_Argv(1), qfalse); + Cvar_Set2 (v->name, Cmd_Args(), qfalse); return qtrue; } @@ -691,21 +691,44 @@ void Cvar_Print_f(void) ============ Cvar_Toggle_f -Toggles a cvar for easy single key binding +Toggles a cvar for easy single key binding, optionally through a list of +given values ============ */ void Cvar_Toggle_f( void ) { - int v; + int i, c = Cmd_Argc(); + char *curval; - if ( Cmd_Argc() != 2 ) { - Com_Printf ("usage: toggle <variable>\n"); + if(c < 2) { + Com_Printf("usage: toggle <variable> [value1, value2, ...]\n"); + return; + } + + if(c == 2) { + Cvar_Set2(Cmd_Argv(1), va("%d", + !Cvar_VariableValue(Cmd_Argv(1))), + qfalse); + return; + } + + if(c == 3) { + Com_Printf("toggle: nothing to toggle to\n"); return; } - v = Cvar_VariableValue( Cmd_Argv( 1 ) ); - v = !v; + curval = Cvar_VariableString(Cmd_Argv(1)); - Cvar_Set2 (Cmd_Argv(1), va("%i", v), qfalse); + // don't bother checking the last arg for a match since the desired + // behaviour is the same as no match (set to the first argument) + for(i = 2; i + 1 < c; i++) { + if(strcmp(curval, Cmd_Argv(i)) == 0) { + Cvar_Set2(Cmd_Argv(1), Cmd_Argv(i + 1), qfalse); + return; + } + } + + // fallback + Cvar_Set2(Cmd_Argv(1), Cmd_Argv(2), qfalse); } /* @@ -840,6 +863,11 @@ void Cvar_List_f( void ) { } else { Com_Printf(" "); } + if (var->flags & CVAR_SYSTEMINFO) { + Com_Printf("s"); + } else { + Com_Printf(" "); + } if (var->flags & CVAR_USERINFO) { Com_Printf("U"); } else { @@ -870,6 +898,11 @@ void Cvar_List_f( void ) { } else { Com_Printf(" "); } + if (var->flags & CVAR_USER_CREATED) { + Com_Printf("?"); + } else { + Com_Printf(" "); + } Com_Printf (" %s \"%s\"\n", var->name, var->string); } |