From 103299e7e4dfe6894f42a2670efb9a190bf53d44 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 14 Feb 2004 02:56:29 +0000 Subject: [PATCH] rename Cvar_GetCvarString to Cvar_GetString and add Cvar_Set{String,Float,Integer,Vector} and Cvar_Get{String,Float,Integer,Vector}. use them in the menus --- libs/ruamoko/rua_cvar.c | 101 ++++++++++++++++++++++++++++---- ruamoko/cl_menu/options.qc | 50 +++++++--------- ruamoko/cl_menu/options_util.qc | 30 +++++----- ruamoko/include/cvar.h | 9 ++- ruamoko/lib/cvar.r | 9 ++- 5 files changed, 143 insertions(+), 56 deletions(-) diff --git a/libs/ruamoko/rua_cvar.c b/libs/ruamoko/rua_cvar.c index 63a7eec55..f5bc5c942 100644 --- a/libs/ruamoko/rua_cvar.c +++ b/libs/ruamoko/rua_cvar.c @@ -39,22 +39,96 @@ static __attribute__ ((unused)) const char rcsid[] = #endif #include "QF/cvar.h" +#include "QF/mathlib.h" #include "QF/progs.h" -#include "QF/zone.h" +#include "QF/va.h" #include "rua_internal.h" -/* - bi_Cvar_GetCvarString - - QC-Function for get a string from a cvar -*/ static void -bi_Cvar_GetCvarString (progs_t *pr) +bi_Cvar_SetString (progs_t *pr) { const char *varname = P_GSTRING (pr, 0); + const char *val = P_GSTRING (pr, 1); + cvar_t *var = Cvar_FindVar (varname); - RETURN_STRING (pr, Cvar_VariableString (varname)); + if (var) + Cvar_Set (var, val); +} + +static void +bi_Cvar_SetInteger (progs_t *pr) +{ + const char *varname = P_GSTRING (pr, 0); + int val = P_INT (pr, 1); + cvar_t *var = Cvar_FindVar (varname); + + if (var) + Cvar_Set (var, va ("%d", val)); +} + +static void +bi_Cvar_SetFloat (progs_t *pr) +{ + const char *varname = P_GSTRING (pr, 0); + float val = P_FLOAT (pr, 1); + cvar_t *var = Cvar_FindVar (varname); + + if (var) + Cvar_Set (var, va ("%g", val)); +} + +static void +bi_Cvar_SetVector (progs_t *pr) +{ + const char *varname = P_GSTRING (pr, 0); + float *val = P_VECTOR (pr, 1); + cvar_t *var = Cvar_FindVar (varname); + + if (var) + Cvar_Set (var, va ("%g %g %g", val[0], val[1], val[2])); +} + +static void +bi_Cvar_GetString (progs_t *pr) +{ + const char *varname = P_GSTRING (pr, 0); + cvar_t *var = Cvar_FindVar (varname); + + if (var) + RETURN_STRING (pr, var->string); + else + RETURN_STRING (pr, ""); +} + +static void +bi_Cvar_GetInteger (progs_t *pr) +{ + const char *varname = P_GSTRING (pr, 0); + cvar_t *var = Cvar_FindVar (varname); + + R_INT (pr) = var ? var->int_val : 0; +} + +static void +bi_Cvar_GetFloat (progs_t *pr) +{ + const char *varname = P_GSTRING (pr, 0); + cvar_t *var = Cvar_FindVar (varname); + + R_FLOAT (pr) = var ? var->value : 0; +} + +static void +bi_Cvar_GetVector (progs_t *pr) +{ + const char *varname = P_GSTRING (pr, 0); + cvar_t *var = Cvar_FindVar (varname); + + if (var) + RETURN_VECTOR (pr, var->vec); + else + VectorZero (R_VECTOR (pr)); } static void @@ -71,8 +145,15 @@ bi_Cvar_Toggle (progs_t *pr) } static builtin_t builtins[] = { - {"Cvar_GetCvarString", bi_Cvar_GetCvarString, -1}, - {"Cvar_Toggle", bi_Cvar_Toggle, -1}, + {"Cvar_SetFloat", bi_Cvar_SetFloat, -1}, + {"Cvar_SetInteger", bi_Cvar_SetInteger, -1}, + {"Cvar_SetVector", bi_Cvar_SetVector, -1}, + {"Cvar_SetString", bi_Cvar_SetString, -1}, + {"Cvar_GetFloat", bi_Cvar_GetFloat, -1}, + {"Cvar_GetInteger", bi_Cvar_GetInteger, -1}, + {"Cvar_GetVector", bi_Cvar_GetVector, -1}, + {"Cvar_GetString", bi_Cvar_GetString, -1}, + {"Cvar_Toggle", bi_Cvar_Toggle, -1}, {0} }; diff --git a/ruamoko/cl_menu/options.qc b/ruamoko/cl_menu/options.qc index f0571e59f..53585ea01 100644 --- a/ruamoko/cl_menu/options.qc +++ b/ruamoko/cl_menu/options.qc @@ -49,7 +49,7 @@ CvarToggleView time_view; CvarRangeView gamma_view; CvarRangeView viewsize_view; -Group control_options; +Group control_options; // not done CvarToggleView grab_mouse_view; CvarToggleView freelook_view; CvarToggleView lookspring_view; @@ -65,19 +65,14 @@ CvarRangeView volume_view; CvarRangeView bgmvolume_view; Group player_options; -// input for playername and teamname InputLine player_config_plname_il; InputLine player_config_tname_il; +InputLine player_config_iactive; CvarColorView topcolor_view; CvarColorView bottomcolor_view; -// this holds active inputline pointer -InputLine player_config_iactive; - Group network_options; -// input for playername InputLine network_config_rate_il; -// this holds active inputline pointer InputLine network_config_iactive; /* @@ -355,12 +350,12 @@ CB_control_options = [grab_mouse_view toggle]; break; case "autorun": - if(cvar("cl_forwardspeed") < 400) { - Cbuf_AddText ("set cl_forwardspeed 400\n"); - Cbuf_AddText ("set cl_backspeed 400\n"); + if(Cvar_GetFloat ("cl_forwardspeed") < 400) { + Cvar_SetFloat ("cl_forwardspeed", 400); + Cvar_SetFloat ("cl_backspeed", 400); } else { - Cbuf_AddText ("set cl_forwardspeed 200\n"); - Cbuf_AddText ("set cl_backspeed 200\n"); + Cvar_SetFloat ("cl_forwardspeed", 200); + Cvar_SetFloat ("cl_backspeed", 200); } break; case "freelook": @@ -373,10 +368,10 @@ CB_control_options = [lookstrafe_view toggle]; break; case "m_pitch": - if(cvar("m_pitch") < 0) { - Cbuf_AddText ("set m_pitch 0.022\n"); + if(Cvar_GetFloat ("m_pitch") < 0) { + Cvar_SetFloat ("m_pitch", 0.022); } else { - Cbuf_AddText ("set m_pitch -0.022\n"); + Cvar_SetFloat ("m_pitch", -0.022); } break; case "mouseamp": @@ -409,9 +404,9 @@ DRAW_control_options = [grab_mouse_view draw]; draw_val_item (x + 70, y + 80, spacing, "Auto run", - cvar ("cl_forwardspeed") < 400 ? "Off" : "On"); + Cvar_GetFloat ("cl_forwardspeed") < 400 ? "Off" : "On"); draw_val_item (x + 70, y + 90, spacing, "Mouse Invert", - cvar ("m_pitch") < 0 ? "On" : "Off"); + Cvar_GetFloat ("m_pitch") < 0 ? "On" : "Off"); bar_pad = y + 90; [mouse_amp_view setBasePos:x y:y]; @@ -627,9 +622,11 @@ KEYEV_player_options = case QFK_RETURN: if (player_config_iactive) { if (player_config_iactive == player_config_plname_il) { - cvar_set (playername_cvar, [player_config_plname_il text]); + Cvar_SetString (playername_cvar, + [player_config_plname_il text]); } else if (player_config_iactive == player_config_tname_il) { - cvar_set (teamname_cvar, [player_config_tname_il text]); + Cvar_SetString (teamname_cvar, + [player_config_tname_il text]); } player_config_iactive = NIL; } else { @@ -683,12 +680,6 @@ DRAW_player_options = [player_options setBasePos:x y:y]; [player_options draw]; -// draw_val_item (x + 70, y + PLAYER_CONF_Y_PAD + 45, spacing, "Top color", -// " " + ftos (cvar ("topcolor"))); -// draw_val_item (x + 70, y + PLAYER_CONF_Y_PAD + 60, spacing, -// "Bottom color", " " + ftos (cvar ("bottomcolor"))); - - opt_cursor (x + 62, y + player_config_cursor_tbl[player_config_cursor]); return 1; }; @@ -710,8 +701,8 @@ CB_ME_player_options = teamname_cvar = "team"; // FIXME: is this something else in netquake? - [player_config_plname_il setText:Cvar_GetCvarString (playername_cvar)]; - [player_config_tname_il setText:Cvar_GetCvarString (teamname_cvar)]; + [player_config_plname_il setText:Cvar_GetString (playername_cvar)]; + [player_config_tname_il setText:Cvar_GetString (teamname_cvar)]; }; /* @@ -832,7 +823,8 @@ KEYEV_network_options = case QFK_RETURN: if (network_config_iactive) { if(network_config_iactive == network_config_rate_il) { - cvar_set("rate", [network_config_rate_il text]); + Cvar_SetString ("rate", + [network_config_rate_il text]); } network_config_iactive = NIL; } else { @@ -882,7 +874,7 @@ DRAW_network_options = integer () CB_ME_network_options = { - [network_config_rate_il setText:Cvar_GetCvarString("rate")]; + [network_config_rate_il setText:Cvar_GetString ("rate")]; }; /* diff --git a/ruamoko/cl_menu/options_util.qc b/ruamoko/cl_menu/options_util.qc index 715e8b030..83f5f0b28 100644 --- a/ruamoko/cl_menu/options_util.qc +++ b/ruamoko/cl_menu/options_util.qc @@ -64,7 +64,7 @@ -(BOOL)value { - return cvar (name); + return Cvar_GetInteger (name); } @end @@ -110,21 +110,21 @@ @implementation CvarColor -(void)next { - local float val = cvar (name); + local float val = Cvar_GetFloat (name); val = min_max_cnt (0, 13, 1, val, 1); - cvar_set (name, ftos (val)); + Cvar_SetFloat (name, val); } -(void)prev { - local float val = cvar (name); + local float val = Cvar_GetFloat (name); val = min_max_cnt (0, 13, 1, val, 0); - cvar_set (name, ftos (val)); + Cvar_SetFloat (name, val); } -(integer)value { - return (integer) cvar (name); + return Cvar_GetInteger (name); } @end @@ -174,26 +174,26 @@ -(void)inc { - local float val = cvar (name); + local float val = Cvar_GetFloat (name); val = min_max_cnt (min, max, step, val, 1); - cvar_set (name, ftos (val)); + Cvar_SetFloat (name, val); } -(void)dec { - local float val = cvar (name); + local float val = Cvar_GetFloat (name); val = min_max_cnt (min, max, step, val, 0); - cvar_set (name, ftos (val)); + Cvar_SetFloat (name, val); } -(float)value { - return cvar (name); + return Cvar_GetFloat (name); } -(integer)percentage { - return to_percentage(min, max, cvar (name)); + return to_percentage(min, max, Cvar_GetFloat (name)); } @end @@ -253,13 +253,13 @@ @implementation CrosshairCvar -(void) next { - local integer val = cvar (name); - cvar_set (name, itos ((val + 1) % 4)); + local integer val = Cvar_GetInteger (name); + Cvar_SetInteger (name, (val + 1) % 4); } -(integer) crosshair { - return cvar (name); + return Cvar_GetInteger (name); } @end diff --git a/ruamoko/include/cvar.h b/ruamoko/include/cvar.h index e8bbd3fee..ff3d0c7fe 100644 --- a/ruamoko/include/cvar.h +++ b/ruamoko/include/cvar.h @@ -1,7 +1,14 @@ #ifndef __ruamoko_cvar_h #define __ruamoko_cvar_h -@extern string (string varname) Cvar_GetCvarString; +@extern void (string varname, string value) Cvar_SetString; +@extern void (string varname, float value) Cvar_SetFloat; +@extern void (string varname, integer value) Cvar_SetInteger; +@extern void (string varname, vector value) Cvar_SetVector; +@extern string (string varname) Cvar_GetString; +@extern float (string varname) Cvar_GetFloat; +@extern integer (string varname) Cvar_GetInteger; +@extern vector (string varname) Cvar_GetVector; @extern void (string varname) Cvar_Toggle; #endif//__ruamoko_cvar_h diff --git a/ruamoko/lib/cvar.r b/ruamoko/lib/cvar.r index 76b70acae..bfb6bd068 100644 --- a/ruamoko/lib/cvar.r +++ b/ruamoko/lib/cvar.r @@ -1,4 +1,11 @@ #include "cvar.h" -string (string varname) Cvar_GetCvarString = #0; +void (string varname, string value) Cvar_SetString = #0; +void (string varname, float value) Cvar_SetFloat = #0; +void (string varname, integer value) Cvar_SetInteger = #0; +void (string varname, vector value) Cvar_SetVector = #0; +string (string varname) Cvar_GetString = #0; +float (string varname) Cvar_GetFloat = #0; +integer (string varname) Cvar_GetInteger = #0; +vector (string varname) Cvar_GetVector = #0; void (string varname) Cvar_Toggle = #0;