]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cvar.c
fixed a crash with r_lerpsprites 0 mode
[xonotic/darkplaces.git] / cvar.c
diff --git a/cvar.c b/cvar.c
index 790bdd051220133bc264c2465cec29edbd6140b2..db209739fd3c4995e4051fdc8ea7eedc7f797cf2 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 See the GNU General Public License for more details.
 
@@ -223,6 +223,11 @@ void Cvar_Set (const char *var_name, const char *value)
                Con_Printf ("Cvar_Set: variable %s not found\n", var_name);
                return;
        }
+       if (var->flags & CVAR_READONLY)
+       {
+               Con_Printf ("Cvar_Set: %s is read-only\n", var_name);
+               return;
+       }
 
        Cvar_SetQuick(var, value);
 }
@@ -232,22 +237,26 @@ void Cvar_Set (const char *var_name, const char *value)
 Cvar_SetValue
 ============
 */
-void Cvar_SetValueQuick (cvar_t *var, float value)
+void Cvar_SetValueQuick(cvar_t *var, float value)
 {
-       char    val[32];
+       char val[256];
 
-       // LordHavoc: changed from %f to %g to use shortest representation
-       sprintf (val, "%g",value);
-       Cvar_SetQuick (var, val);
+       if ((float)((int)value) == value)
+               sprintf(val, "%i", (int)value);
+       else
+               sprintf(val, "%f", value);
+       Cvar_SetQuick(var, val);
 }
 
-void Cvar_SetValue (const char *var_name, float value)
+void Cvar_SetValue(const char *var_name, float value)
 {
-       char    val[32];
+       char val[256];
 
-       // LordHavoc: changed from %f to %g to use shortest representation
-       sprintf (val, "%g",value);
-       Cvar_Set (var_name, val);
+       if ((float)((int)value) == value)
+               sprintf(val, "%i", (int)value);
+       else
+               sprintf(val, "%f", value);
+       Cvar_Set(var_name, val);
 }
 
 /*
@@ -306,7 +315,9 @@ qboolean    Cvar_Command (void)
 // perform a variable print or set
        if (Cmd_Argc() == 1)
        {
-               Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string);
+               // only print if host_initialized (otherwise it could print twice if this is in a script)
+               if (host_initialized)
+                       Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string);
                return true;
        }