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
This commit is contained in:
Bill Currie 2004-02-14 02:56:29 +00:00
parent 0e147a7b61
commit 103299e7e4
5 changed files with 143 additions and 56 deletions

View file

@ -39,22 +39,96 @@ static __attribute__ ((unused)) const char rcsid[] =
#endif #endif
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/mathlib.h"
#include "QF/progs.h" #include "QF/progs.h"
#include "QF/zone.h" #include "QF/va.h"
#include "rua_internal.h" #include "rua_internal.h"
/*
bi_Cvar_GetCvarString
QC-Function for get a string from a cvar
*/
static void static void
bi_Cvar_GetCvarString (progs_t *pr) bi_Cvar_SetString (progs_t *pr)
{ {
const char *varname = P_GSTRING (pr, 0); 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 static void
@ -71,8 +145,15 @@ bi_Cvar_Toggle (progs_t *pr)
} }
static builtin_t builtins[] = { static builtin_t builtins[] = {
{"Cvar_GetCvarString", bi_Cvar_GetCvarString, -1}, {"Cvar_SetFloat", bi_Cvar_SetFloat, -1},
{"Cvar_Toggle", bi_Cvar_Toggle, -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} {0}
}; };

View file

@ -49,7 +49,7 @@ CvarToggleView time_view;
CvarRangeView gamma_view; CvarRangeView gamma_view;
CvarRangeView viewsize_view; CvarRangeView viewsize_view;
Group control_options; Group control_options; // not done
CvarToggleView grab_mouse_view; CvarToggleView grab_mouse_view;
CvarToggleView freelook_view; CvarToggleView freelook_view;
CvarToggleView lookspring_view; CvarToggleView lookspring_view;
@ -65,19 +65,14 @@ CvarRangeView volume_view;
CvarRangeView bgmvolume_view; CvarRangeView bgmvolume_view;
Group player_options; Group player_options;
// input for playername and teamname
InputLine player_config_plname_il; InputLine player_config_plname_il;
InputLine player_config_tname_il; InputLine player_config_tname_il;
InputLine player_config_iactive;
CvarColorView topcolor_view; CvarColorView topcolor_view;
CvarColorView bottomcolor_view; CvarColorView bottomcolor_view;
// this holds active inputline pointer
InputLine player_config_iactive;
Group network_options; Group network_options;
// input for playername
InputLine network_config_rate_il; InputLine network_config_rate_il;
// this holds active inputline pointer
InputLine network_config_iactive; InputLine network_config_iactive;
/* /*
@ -355,12 +350,12 @@ CB_control_options =
[grab_mouse_view toggle]; [grab_mouse_view toggle];
break; break;
case "autorun": case "autorun":
if(cvar("cl_forwardspeed") < 400) { if(Cvar_GetFloat ("cl_forwardspeed") < 400) {
Cbuf_AddText ("set cl_forwardspeed 400\n"); Cvar_SetFloat ("cl_forwardspeed", 400);
Cbuf_AddText ("set cl_backspeed 400\n"); Cvar_SetFloat ("cl_backspeed", 400);
} else { } else {
Cbuf_AddText ("set cl_forwardspeed 200\n"); Cvar_SetFloat ("cl_forwardspeed", 200);
Cbuf_AddText ("set cl_backspeed 200\n"); Cvar_SetFloat ("cl_backspeed", 200);
} }
break; break;
case "freelook": case "freelook":
@ -373,10 +368,10 @@ CB_control_options =
[lookstrafe_view toggle]; [lookstrafe_view toggle];
break; break;
case "m_pitch": case "m_pitch":
if(cvar("m_pitch") < 0) { if(Cvar_GetFloat ("m_pitch") < 0) {
Cbuf_AddText ("set m_pitch 0.022\n"); Cvar_SetFloat ("m_pitch", 0.022);
} else { } else {
Cbuf_AddText ("set m_pitch -0.022\n"); Cvar_SetFloat ("m_pitch", -0.022);
} }
break; break;
case "mouseamp": case "mouseamp":
@ -409,9 +404,9 @@ DRAW_control_options =
[grab_mouse_view draw]; [grab_mouse_view draw];
draw_val_item (x + 70, y + 80, spacing, "Auto run", 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", 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; bar_pad = y + 90;
[mouse_amp_view setBasePos:x y:y]; [mouse_amp_view setBasePos:x y:y];
@ -627,9 +622,11 @@ KEYEV_player_options =
case QFK_RETURN: case QFK_RETURN:
if (player_config_iactive) { if (player_config_iactive) {
if (player_config_iactive == player_config_plname_il) { 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) { } 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; player_config_iactive = NIL;
} else { } else {
@ -683,12 +680,6 @@ DRAW_player_options =
[player_options setBasePos:x y:y]; [player_options setBasePos:x y:y];
[player_options draw]; [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]); opt_cursor (x + 62, y + player_config_cursor_tbl[player_config_cursor]);
return 1; return 1;
}; };
@ -710,8 +701,8 @@ CB_ME_player_options =
teamname_cvar = "team"; // FIXME: is this something else in netquake? teamname_cvar = "team"; // FIXME: is this something else in netquake?
[player_config_plname_il setText:Cvar_GetCvarString (playername_cvar)]; [player_config_plname_il setText:Cvar_GetString (playername_cvar)];
[player_config_tname_il setText:Cvar_GetCvarString (teamname_cvar)]; [player_config_tname_il setText:Cvar_GetString (teamname_cvar)];
}; };
/* /*
@ -832,7 +823,8 @@ KEYEV_network_options =
case QFK_RETURN: case QFK_RETURN:
if (network_config_iactive) { if (network_config_iactive) {
if(network_config_iactive == network_config_rate_il) { 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; network_config_iactive = NIL;
} else { } else {
@ -882,7 +874,7 @@ DRAW_network_options =
integer () integer ()
CB_ME_network_options = CB_ME_network_options =
{ {
[network_config_rate_il setText:Cvar_GetCvarString("rate")]; [network_config_rate_il setText:Cvar_GetString ("rate")];
}; };
/* /*

View file

@ -64,7 +64,7 @@
-(BOOL)value -(BOOL)value
{ {
return cvar (name); return Cvar_GetInteger (name);
} }
@end @end
@ -110,21 +110,21 @@
@implementation CvarColor @implementation CvarColor
-(void)next -(void)next
{ {
local float val = cvar (name); local float val = Cvar_GetFloat (name);
val = min_max_cnt (0, 13, 1, val, 1); val = min_max_cnt (0, 13, 1, val, 1);
cvar_set (name, ftos (val)); Cvar_SetFloat (name, val);
} }
-(void)prev -(void)prev
{ {
local float val = cvar (name); local float val = Cvar_GetFloat (name);
val = min_max_cnt (0, 13, 1, val, 0); val = min_max_cnt (0, 13, 1, val, 0);
cvar_set (name, ftos (val)); Cvar_SetFloat (name, val);
} }
-(integer)value -(integer)value
{ {
return (integer) cvar (name); return Cvar_GetInteger (name);
} }
@end @end
@ -174,26 +174,26 @@
-(void)inc -(void)inc
{ {
local float val = cvar (name); local float val = Cvar_GetFloat (name);
val = min_max_cnt (min, max, step, val, 1); val = min_max_cnt (min, max, step, val, 1);
cvar_set (name, ftos (val)); Cvar_SetFloat (name, val);
} }
-(void)dec -(void)dec
{ {
local float val = cvar (name); local float val = Cvar_GetFloat (name);
val = min_max_cnt (min, max, step, val, 0); val = min_max_cnt (min, max, step, val, 0);
cvar_set (name, ftos (val)); Cvar_SetFloat (name, val);
} }
-(float)value -(float)value
{ {
return cvar (name); return Cvar_GetFloat (name);
} }
-(integer)percentage -(integer)percentage
{ {
return to_percentage(min, max, cvar (name)); return to_percentage(min, max, Cvar_GetFloat (name));
} }
@end @end
@ -253,13 +253,13 @@
@implementation CrosshairCvar @implementation CrosshairCvar
-(void) next -(void) next
{ {
local integer val = cvar (name); local integer val = Cvar_GetInteger (name);
cvar_set (name, itos ((val + 1) % 4)); Cvar_SetInteger (name, (val + 1) % 4);
} }
-(integer) crosshair -(integer) crosshair
{ {
return cvar (name); return Cvar_GetInteger (name);
} }
@end @end

View file

@ -1,7 +1,14 @@
#ifndef __ruamoko_cvar_h #ifndef __ruamoko_cvar_h
#define __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; @extern void (string varname) Cvar_Toggle;
#endif//__ruamoko_cvar_h #endif//__ruamoko_cvar_h

View file

@ -1,4 +1,11 @@
#include "cvar.h" #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; void (string varname) Cvar_Toggle = #0;