diff --git a/include/cvar.h b/include/cvar.h index bd52712..cef579b 100644 --- a/include/cvar.h +++ b/include/cvar.h @@ -81,9 +81,10 @@ cvar_t *Cvar_Get (char *name, char *value, int cvarflags, char *description); void Cvar_Alias_Get (char *name, cvar_t *cvar); -void Cvar_Set (char *var, char *value); +void Cvar_Set (cvar_t *var, char *value); // equivelant to " " typed at the console +void Cvar_SetValue (cvar_t *var, float value); float Cvar_VariableValue (char *var_name); // returns 0 if not defined or non numeric diff --git a/source/cd_audio.c b/source/cd_audio.c index aefb5a7..04a8a67 100644 --- a/source/cd_audio.c +++ b/source/cd_audio.c @@ -764,12 +764,12 @@ void CDAudio_Update(void) newVolume = (int)(bgmvolume->value * 255.0); if (newVolume < 0) { - Cvar_SetValue ("bgmvolume", 0.0); + Cvar_SetValue (bgmvolume, 0.0); newVolume = 0; } else if (newVolume > 255) { - Cvar_SetValue ("bgmvolume", 1.0); + Cvar_SetValue (bgmvolume, 1.0); newVolume = 255; } if (cdvolume != newVolume) diff --git a/source/cd_win.c b/source/cd_win.c index 0f9a548..c31f195 100644 --- a/source/cd_win.c +++ b/source/cd_win.c @@ -417,7 +417,7 @@ void CDAudio_Update(void) { if (cdvolume) { - Cvar_SetValue ("bgmvolume", 0.0); + Cvar_SetValue (bgmvolume, 0.0); /* cdvolume = bgmvolume.value; CVAR_FIXME */ cdvolume = bgmvolume->value; @@ -425,7 +425,7 @@ void CDAudio_Update(void) } else { - Cvar_SetValue ("bgmvolume", 1.0); + Cvar_SetValue (bgmvolume, 1.0); /* cdvolume = bgmvolume.value; CVAR_FIXME */ cdvolume = bgmvolume->value; diff --git a/source/cl_main.c b/source/cl_main.c index 3eed777..3d2cbc0 100644 --- a/source/cl_main.c +++ b/source/cl_main.c @@ -628,9 +628,9 @@ void CL_Color_f (void) bottom = 13; sprintf (num, "%i", top); - Cvar_Set ("topcolor", num); + Cvar_Set (topcolor, num); sprintf (num, "%i", bottom); - Cvar_Set ("bottomcolor", num); + Cvar_Set (bottomcolor, num); } /* @@ -965,7 +965,7 @@ void CL_ConnectionlessPacket (void) "You may need to reload your server browser and %s.\n", s, localid->string, PROGRAM); Con_Printf("===========================\n"); - Cvar_Set("localid", ""); + Cvar_Set(localid, ""); return; } diff --git a/source/cl_pred.c b/source/cl_pred.c index 0ae2ed7..2eb8542 100644 --- a/source/cl_pred.c +++ b/source/cl_pred.c @@ -136,7 +136,7 @@ void CL_PredictMove (void) /* if (cl_pushlatency.value > 0) CVAR_FIXME */ if (cl_pushlatency->value > 0) - Cvar_Set ("pushlatency", "0"); + Cvar_Set (cl_pushlatency, "0"); if (cl.paused) return; diff --git a/source/common.c b/source/common.c index 68431a1..1b343b8 100644 --- a/source/common.c +++ b/source/common.c @@ -1112,7 +1112,7 @@ void COM_CheckRegistered (void) } if (static_registered) { - Cvar_Set ("registered", "1"); + Cvar_Set (registered, "1"); Con_Printf ("Playing registered version.\n"); } } diff --git a/source/cvar.c b/source/cvar.c index f419afb..8c7a9c2 100644 --- a/source/cvar.c +++ b/source/cvar.c @@ -178,16 +178,10 @@ void Cvar_Info (cvar_t *var); Cvar_Set ============ */ -void Cvar_Set (char *var_name, char *value) +void Cvar_Set (cvar_t *var, char *value) { - cvar_t *var; - - var = Cvar_FindVar (var_name); if (!var) - { // there is an error in C code if this happens - Con_Printf ("Cvar_Set: variable %s not found\n", var_name); return; - } Z_Free (var->string); // free the old value string @@ -197,6 +191,20 @@ void Cvar_Set (char *var_name, char *value) Cvar_Info(var); } + +/* +============ +Cvar_SetValue +============ +*/ +void Cvar_SetValue (cvar_t *var_name, float value) +{ + char val[32]; + + sprintf (val, "%f",value); + Cvar_Set (var_name, val); +} + /* ============ Cvar_Command @@ -222,7 +230,7 @@ qboolean Cvar_Command (void) return true; } - Cvar_Set (v->name, Cmd_Argv(1)); + Cvar_Set (v, Cmd_Argv(1)); return true; } @@ -262,7 +270,7 @@ void Cvar_Set_f(void) var = Cvar_FindAlias (var_name); if (var) { - Cvar_Set (var->name, value); + Cvar_Set (var, value); } else { @@ -290,7 +298,7 @@ void Cvar_Toggle_f (void) return; } - Cvar_Set (var->name, var->value ? "0" : "1"); + Cvar_Set (var, var->value ? "0" : "1"); } void Cvar_Help_f (void) diff --git a/source/gl_draw.c b/source/gl_draw.c index 55ce2b3..d54b2f1 100644 --- a/source/gl_draw.c +++ b/source/gl_draw.c @@ -437,12 +437,11 @@ void Draw_Init (void) /* Cvar_RegisterVariable (&cl_verstring); CVAR_FIXME */ - cl_verstring = Cvar_Get("cl_verstring", PROGRAM " " VERSION, CVAR_NONE, "None"); // 3dfx can only handle 256 wide textures if (!Q_strncasecmp ((char *)gl_renderer, "3dfx",4) || !Q_strncasecmp ((char *)gl_renderer, "Mesa",4)) - Cvar_Set ("gl_max_size", "256"); + Cvar_Set (gl_max_size, "256"); Cmd_AddCommand ("gl_texturemode", &Draw_TextureMode_f); diff --git a/source/gl_screen.c b/source/gl_screen.c index cc173ed..3176be8 100644 --- a/source/gl_screen.c +++ b/source/gl_screen.c @@ -345,21 +345,21 @@ static void SCR_CalcRefdef (void) /* if (scr_viewsize.value < 30) CVAR_FIXME */ if (scr_viewsize->value < 30) - Cvar_Set ("viewsize","30"); + Cvar_Set (scr_viewsize,"30"); /* if (scr_viewsize.value > 120) CVAR_FIXME */ if (scr_viewsize->value > 120) - Cvar_Set ("viewsize","120"); + Cvar_Set (scr_viewsize,"120"); // bound field of view /* if (scr_fov.value < 10) CVAR_FIXME */ if (scr_fov->value < 10) - Cvar_Set ("fov","10"); + Cvar_Set (scr_fov,"10"); /* if (scr_fov.value > 170) CVAR_FIXME */ if (scr_fov->value > 170) - Cvar_Set ("fov","170"); + Cvar_Set (scr_fov,"170"); // intermission is always full screen if (cl.intermission) @@ -441,7 +441,7 @@ void SCR_SizeUp_f (void) { /* Cvar_SetValue ("viewsize",scr_viewsize.value+10); CVAR_FIXME */ - scr_viewsize->value = scr_viewsize->value+10; + Cvar_SetValue (scr_viewsize, scr_viewsize->value+10); vid.recalc_refdef = 1; } @@ -458,7 +458,7 @@ void SCR_SizeDown_f (void) { /* Cvar_SetValue ("viewsize",scr_viewsize.value-10); CVAR_FIXME */ - scr_viewsize->value = scr_viewsize->value-10; + Cvar_SetValue (scr_viewsize, scr_viewsize->value-10); vid.recalc_refdef = 1; } diff --git a/source/gl_vidnt.c b/source/gl_vidnt.c index 26a70af..01e829e 100644 --- a/source/gl_vidnt.c +++ b/source/gl_vidnt.c @@ -480,7 +480,7 @@ int VID_SetMode (int modenum, unsigned char *palette) SetForegroundWindow (mainwindow); VID_SetPalette (palette); vid_modenum = modenum; - Cvar_SetValue ("vid_mode", (float)vid_modenum); + Cvar_SetValue (vid_mode, (float)vid_modenum); while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { diff --git a/source/menu.c b/source/menu.c index 15e1133..11df4a8 100644 --- a/source/menu.c +++ b/source/menu.c @@ -410,8 +410,8 @@ void M_AdjustSliders (int dir) if (scr_viewsize->value > 120) /* scr_viewsize.value = 120; CVAR_FIXME */ - scr_viewsize->value = 120; -/* Cvar_SetValue ("viewsize", scr_viewsize.value); + Cvar_SetValue (scr_viewsize, 120); +/* Cvar_SetValue (viewsize, scr_viewsize.value); CVAR_FIXME */ break; case 4: // gamma @@ -429,7 +429,7 @@ void M_AdjustSliders (int dir) if (v_gamma->value > 1) /* v_gamma.value = 1; CVAR_FIXME */ - v_gamma->value = 1; + Cvar_SetValue (v_gamma, 1); /* Cvar_SetValue ("gamma", v_gamma.value); CVAR_FIXME */ break; @@ -448,7 +448,7 @@ void M_AdjustSliders (int dir) if (sensitivity->value > 11) /* sensitivity.value = 11; CVAR_FIXME */ - sensitivity->value = 11; + Cvar_SetValue (sensitivity, 11); /* Cvar_SetValue ("sensitivity", sensitivity.value); CVAR_FIXME */ break; @@ -456,43 +456,43 @@ void M_AdjustSliders (int dir) #ifdef _WIN32 /* bgmvolume.value += dir * 1.0; CVAR_FIXME */ - bgmvolume->value += dir * 1.0; + Cvar_SetValue (bgmvolume, bgmvolume->value + dir * 1.0); #else /* bgmvolume.value += dir * 0.1; CVAR_FIXME */ - bgmvolume->value += dir * 0.1; + Cvar_SetValue (bgmvolume, bgmvolume->value + dir * 0.1); #endif /* if (bgmvolume.value < 0) CVAR_FIXME */ if (bgmvolume->value < 0) /* bgmvolume.value = 0; CVAR_FIXME */ - bgmvolume->value = 0; + Cvar_SetValue (bgmvolume, 0); /* if (bgmvolume.value > 1) CVAR_FIXME */ if (bgmvolume->value > 1) /* bgmvolume.value = 1; CVAR_FIXME */ - bgmvolume->value = 1; + Cvar_SetValue (bgmvolume, 1); /* Cvar_SetValue ("bgmvolume", bgmvolume.value); CVAR_FIXME */ break; case 7: // sfx volume /* volume.value += dir * 0.1; CVAR_FIXME */ - volume->value += dir * 0.1; + Cvar_SetValue (volume, volume->value + dir * 0.1); /* if (volume.value < 0) CVAR_FIXME */ if (volume->value < 0) /* volume.value = 0; CVAR_FIXME */ - volume->value = 0; + Cvar_SetValue (volume, 0); /* if (volume.value > 1) CVAR_FIXME */ if (volume->value > 1) /* volume.value = 1; CVAR_FIXME */ - volume->value = 1; + Cvar_SetValue (volume, 1); /*CVAR_FIXME */ break; @@ -501,49 +501,50 @@ void M_AdjustSliders (int dir) CVAR_FIXME */ if (cl_forwardspeed->value > 200) { - cl_forwardspeed->value = 200; - cl_backspeed->value = 200; + Cvar_SetValue (cl_forwardspeed, 200); + Cvar_SetValue (cl_backspeed, 200); } else { - cl_forwardspeed->value = 400; - cl_backspeed->value = 400; + Cvar_SetValue (cl_forwardspeed, 400); + Cvar_SetValue (cl_backspeed, 400); } break; case 9: // invert mouse /* m_pitch- -m_pitch.value); CVAR_FIXME */ - m_pitch->value = -m_pitch->value; + Cvar_SetValue (m_pitch, -m_pitch->value); break; case 10: // lookspring /* Cvar_SetValue ("lookspring", !lookspring.value); CVAR_FIXME */ - lookspring->value = !lookspring->value; + Cvar_SetValue (lookspring, !lookspring->value); break; case 11: // lookstrafe /* Cvar_SetValue ("lookstrafe", !lookstrafe.value); CVAR_FIXME */ - lookstrafe->value = !lookstrafe->value; + Cvar_SetValue (lookstrafe, !lookstrafe->value); break; case 12: /* Cvar_SetValue ("cl_sbar", !cl_sbar.value); CVAR_FIXME */ - cl_sbar->value = !cl_sbar->value; + Cvar_SetValue (cl_sbar, !cl_sbar->value); break; case 13: /* Cvar_SetValue ("cl_hudswap", !cl_hudswap.value); CVAR_FIXME */ - cl_hudswap->value = !cl_hudswap->value; + Cvar_SetValue (cl_hudswap, !cl_hudswap->value); + break; case 15: // _windowed_mouse /* Cvar_SetValue ("_windowed_mouse", !_windowed_mouse.value); CVAR_FIXME */ - _windowed_mouse->value = !_windowed_mouse->value; + Cvar_SetValue (_windowed_mouse, !_windowed_mouse->value); break; } } diff --git a/source/pr_cmds.c b/source/pr_cmds.c index 4307136..6a61042 100644 --- a/source/pr_cmds.c +++ b/source/pr_cmds.c @@ -754,11 +754,13 @@ float cvar (string) */ void PF_cvar_set (void) { - char *var, *val; + char *var_name, *val; + cvar_t *var; - var = G_STRING(OFS_PARM0); + var_name = G_STRING(OFS_PARM0); val = G_STRING(OFS_PARM1); - + var = Cvar_FindVar(var_name); + Cvar_Set (var, val); } diff --git a/source/screen.c b/source/screen.c index 1ff158f..78ed96e 100644 --- a/source/screen.c +++ b/source/screen.c @@ -322,21 +322,21 @@ static void SCR_CalcRefdef (void) /* if (scr_viewsize.value < 30) CVAR_FIXME */ if (scr_viewsize->value < 30) - Cvar_Set ("viewsize","30"); + Cvar_Set (scr_viewsize,"30"); /* if (scr_viewsize.value > 120) CVAR_FIXME */ if (scr_viewsize->value > 120) - Cvar_Set ("viewsize","120"); + Cvar_Set (scr_viewsize,"120"); // bound field of view /* if (scr_fov.value < 10) CVAR_FIXME */ if (scr_fov->value < 10) - Cvar_Set ("fov","10"); + Cvar_Set (scr_fov,"10"); /* if (scr_fov.value > 170) CVAR_FIXME */ if (scr_fov->value > 170) - Cvar_Set ("fov","170"); + Cvar_Set (scr_fov,"170"); /* r_refdef.fov_x = scr_fov.value; CVAR_FIXME */ @@ -391,7 +391,7 @@ void SCR_SizeUp_f (void) if (scr_viewsize->value < 120) { /* Cvar_SetValue ("viewsize",scr_viewsize.value+10); CVAR_FIXME */ - scr_viewsize->value = scr_viewsize->value+10; + Cvar_SetValue (scr_viewsize,scr_viewsize->value+10); vid.recalc_refdef = 1; } } @@ -408,7 +408,7 @@ void SCR_SizeDown_f (void) { /* Cvar_SetValue ("viewsize",scr_viewsize.value-10); CVAR_FIXME */ - scr_viewsize->value = scr_viewsize->value-10; + Cvar_SetValue (scr_viewsize,scr_viewsize->value-10); vid.recalc_refdef = 1; } diff --git a/source/snd_dma.c b/source/snd_dma.c index ace4696..51bb81b 100644 --- a/source/snd_dma.c +++ b/source/snd_dma.c @@ -255,7 +255,7 @@ void S_Init (void) if (host_parms.memsize < 0x800000) { - Cvar_Set ("loadas8bit", "1"); + Cvar_Set (loadas8bit, "1"); Con_Printf ("loading all sounds as 8bit\n"); } diff --git a/source/sv_main.c b/source/sv_main.c index ffa8c11..c568d7c 100644 --- a/source/sv_main.c +++ b/source/sv_main.c @@ -715,17 +715,17 @@ void SVC_DirectConnect (void) /* if ( maxclients.value > MAX_CLIENTS ) CVAR_FIXME */ if ( maxclients->value > MAX_CLIENTS ) - maxclients->value = MAX_CLIENTS; + Cvar_SetValue (maxclients, MAX_CLIENTS); /* if (maxspectators.value > MAX_CLIENTS) CVAR_FIXME */ if (maxspectators->value > MAX_CLIENTS) - maxspectators->value = MAX_CLIENTS; + Cvar_SetValue (maxspectators, MAX_CLIENTS); /* if (maxspectators.value + maxclients.value > MAX_CLIENTS) CVAR_FIXME */ if (maxspectators->value + maxclients->value > MAX_CLIENTS) /* Cvar_SetValue ("maxspectators", MAX_CLIENTS - maxspectators.value + maxclients.value); CVAR_FIXME */ - maxspectators->value = MAX_CLIENTS - maxspectators->value + maxclients->value; + Cvar_SetValue (maxspectators, MAX_CLIENTS - maxspectators->value + maxclients->value); /* if ( (spectator && spectators >= (int)maxspectators.value) CVAR_FIXME */ if ( (spectator && spectators >= (int)maxspectators->value) diff --git a/source/sv_sys_win.c b/source/sv_sys_win.c index acee89d..5763a3c 100644 --- a/source/sv_sys_win.c +++ b/source/sv_sys_win.c @@ -245,7 +245,7 @@ int main (int argc, char **argv) if (COM_CheckParm ("-nopriority")) { - Cvar_Set ("sys_sleep", "0"); + Cvar_Set (sys_sleep, "0"); } else { @@ -257,7 +257,7 @@ int main (int argc, char **argv) // sys_sleep > 0 seems to cause packet loss on WinNT (why?) if (WinNT) - Cvar_Set ("sys_sleep", "0"); + Cvar_Set (sys_sleep, "0"); // run one frame immediately for first heartbeat SV_Frame (0.1); diff --git a/source/vid_win.c b/source/vid_win.c index 786e761..40b6fcf 100644 --- a/source/vid_win.c +++ b/source/vid_win.c @@ -207,8 +207,8 @@ void VID_RememberWindowPos (void) (rect.right > 0) && (rect.bottom > 0)) { - Cvar_SetValue ("vid_window_x", (float)rect.left); - Cvar_SetValue ("vid_window_y", (float)rect.top); + Cvar_SetValue (vid_window_x, (float)rect.left); + Cvar_SetValue (vid_window_y, (float)rect.top); } } } @@ -235,8 +235,8 @@ void VID_CheckWindowXY (void) CVAR_FIXME */ ((int)vid_window_y->value < 0)) { - Cvar_SetValue ("vid_window_x", 0.0); - Cvar_SetValue ("vid_window_y", 0.0 ); + Cvar_SetValue (vid_window_x, 0.0); + Cvar_SetValue (vid_window_y, 0.0 ); } } @@ -1327,8 +1327,8 @@ qboolean VID_SetWindowedMode (int modenum) { if (COM_CheckParm ("-resetwinpos")) { - Cvar_SetValue ("vid_window_x", 0.0); - Cvar_SetValue ("vid_window_y", 0.0); + Cvar_SetValue (vid_window_x, 0.0); + Cvar_SetValue (vid_window_y, 0.0); } windowed_mode_set; @@ -1690,11 +1690,11 @@ int VID_SetMode (int modenum, unsigned char *palette) modenum = vid_default; } - Cvar_SetValue ("vid_mode", (float)modenum); + Cvar_SetValue (vid_mode, (float)modenum); } else { - Cvar_SetValue ("vid_mode", (float)vid_modenum); + Cvar_SetValue (vid_mode, (float)vid_modenum); return 0; } } @@ -1783,7 +1783,7 @@ int VID_SetMode (int modenum, unsigned char *palette) ReleaseDC(NULL,hdc); vid_modenum = modenum; - Cvar_SetValue ("vid_mode", (float)vid_modenum); + Cvar_SetValue (vid_mode, (float)vid_modenum); if (!VID_AllocBuffers (vid.width, vid.height)) { @@ -2478,8 +2478,8 @@ void VID_Update (vrect_t *rects) { if (COM_CheckParm ("-resetwinpos")) { - Cvar_SetValue ("vid_window_x", 0.0); - Cvar_SetValue ("vid_window_y", 0.0); + Cvar_SetValue (vid_window_x, 0.0); + Cvar_SetValue (vid_window_y, 0.0); } VID_CheckWindowXY (); @@ -2504,8 +2504,8 @@ void VID_Update (vrect_t *rects) if (COM_CheckParm ("-resetwinpos")) { - Cvar_SetValue ("vid_window_x", 0.0); - Cvar_SetValue ("vid_window_y", 0.0); + Cvar_SetValue (vid_window_x, 0.0); + Cvar_SetValue (vid_window_y, 0.0); } /* if ((_vid_default_mode_win.value < 0) || @@ -2515,12 +2515,12 @@ void VID_Update (vrect_t *rects) CVAR_FIXME */ (_vid_default_mode_win->value >= nummodes)) { - Cvar_SetValue ("_vid_default_mode_win", windowed_default); + Cvar_SetValue (_vid_default_mode_win, windowed_default); } /* Cvar_SetValue ("vid_mode", _vid_default_mode_win.value); CVAR_FIXME */ - Cvar_SetValue ("vid_mode", _vid_default_mode_win->value); + Cvar_SetValue (vid_mode, _vid_default_mode_win->value); } } @@ -2544,7 +2544,7 @@ void VID_Update (vrect_t *rects) /* VID_SetMode ((int)vid_mode.value, vid_curpal); CVAR_FIXME */ VID_SetMode ((int)vid_mode->value, vid_curpal); - Cvar_SetValue ("vid_mode", (float)vid_modenum); + Cvar_SetValue (vid_mode, (float)vid_modenum); // so if mode set fails, we don't keep on // trying to set that mode vid_realmode = vid_modenum; @@ -3522,7 +3522,7 @@ void VID_MenuKey (int key) case 'd': S_LocalSound ("misc/menu1.wav"); firstupdate = 0; - Cvar_SetValue ("_vid_default_mode_win", vid_modenum); + Cvar_SetValue (_vid_default_mode_win, vid_modenum); break; default: