• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 // cvar.h
21 
22 /*
23 
24 cvar_t variables are used to hold scalar or string variables that can be changed or displayed at the console or prog code as well as accessed directly
25 in C code.
26 
27 it is sufficient to initialize a cvar_t with just the first two fields, or
28 you can add a ,true flag for variables that you want saved to the configuration
29 file when the game is quit:
30 
31 cvar_t	r_draworder = {"r_draworder","1"};
32 cvar_t	scr_screensize = {"screensize","1",true};
33 
34 Cvars must be registered before use, or they will have a 0 value instead of the float interpretation of the string.  Generally, all cvar_t declarations should be registered in the apropriate init function before any console commands are executed:
35 Cvar_RegisterVariable (&host_framerate);
36 
37 
38 C code usually just references a cvar in place:
39 if ( r_draworder.value )
40 
41 It could optionally ask for the value to be looked up for a string name:
42 if (Cvar_VariableValue ("r_draworder"))
43 
44 Interpreted prog code can access cvars with the cvar(name) or
45 cvar_set (name, value) internal functions:
46 teamplay = cvar("teamplay");
47 cvar_set ("registered", "1");
48 
49 The user can access cvars from the console in two ways:
50 r_draworder			prints the current value
51 r_draworder 0		sets the current value to 0
52 Cvars are restricted from having the same names as commands to keep this
53 interface from being ambiguous.
54 */
55 
56 typedef struct cvar_s
57 {
58 	char	*name;
59 	char	*string;
60 	qboolean archive;		// set to true to cause it to be saved to vars.rc
61 	qboolean server;		// notifies players when changed
62 	float	value;
63 	struct cvar_s *next;
64 } cvar_t;
65 
66 // Helper macro to avoid missing initializer warnings
67 #define CVAR2(NAME, STRING) {(char*) (NAME),(char*) (STRING), 0, 0, 0.0f, (struct cvar_s*) 0}
68 #define CVAR3(NAME, STRING, ARCHIVE) {(char*) (NAME), (char*) (STRING), (ARCHIVE), 0, 0.0f, (struct cvar_s*) 0}
69 #define CVAR4(NAME, STRING, ARCHIVE, INFO) {(char*) (NAME), (char*) (STRING), (ARCHIVE), (INFO), 0.0f, (struct cvar_s*) 0}
70 
71 void 	Cvar_RegisterVariable (cvar_t *variable);
72 // registers a cvar that allready has the name, string, and optionally the
73 // archive elements set.
74 
75 void 	Cvar_Set (const char *var_name, const char *value);
76 // equivelant to "<name> <variable>" typed at the console
77 
78 void	Cvar_SetValue (const char *var_name, float value);
79 // expands value to a string and calls Cvar_Set
80 
81 float	Cvar_VariableValue (const char *var_name);
82 // returns 0 if not defined or non numeric
83 
84 const char	*Cvar_VariableString (const char *var_name);
85 // returns an empty string if not defined
86 
87 const char 	*Cvar_CompleteVariable (const char *partial);
88 // attempts to match a partial variable name for command line completion
89 // returns NULL if nothing fits
90 
91 qboolean Cvar_Command (void);
92 // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
93 // command.  Returns true if the command was a variable reference that
94 // was handled. (print or change)
95 
96 void 	Cvar_WriteVariables (FILE *f);
97 // Writes lines containing "set variable value" for all variables
98 // with the archive flag set to true.
99 
100 cvar_t *Cvar_FindVar (const char *var_name);
101 
102 extern cvar_t	*cvar_vars;
103