~ubuntu-branches/ubuntu/wily/nexuiz/wily

« back to all changes in this revision

Viewing changes to cvar.h

  • Committer: Bazaar Package Importer
  • Author(s): Bruno "Fuddl" Kleinert
  • Date: 2009-10-16 12:52:25 UTC
  • mto: (1.1.7 upstream) (2.2.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20091016125225-4mccppxccoa1w39o
ImportĀ upstreamĀ versionĀ 2.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#ifndef CVAR_H
 
57
#define CVAR_H
 
58
 
 
59
// cvar flags
 
60
 
 
61
#define CVAR_SAVE 1
 
62
#define CVAR_NOTIFY 2
 
63
#define CVAR_READONLY 4
 
64
#define CVAR_SERVERINFO 8
 
65
#define CVAR_USERINFO 16
 
66
// CVAR_PRIVATE means do not $ expand or sendcvar this cvar under any circumstances (rcon_password uses this)
 
67
#define CVAR_PRIVATE 32
 
68
// this means that this cvar should update a userinfo key but the name does not correspond directly to the userinfo key to update, and may require additional conversion ("_cl_color" for example should update "topcolor" and "bottomcolor")
 
69
#define CVAR_NQUSERINFOHACK 64
 
70
// used to determine if flags is valid
 
71
#define CVAR_NORESETTODEFAULTS 128
 
72
// for engine-owned cvars that must not be reset on gametype switch (e.g. scr_screenshot_name, which otherwise isn't set to the mod name properly)
 
73
#define CVAR_MAXFLAGSVAL 255
 
74
// for internal use only!
 
75
#define CVAR_DEFAULTSET (1<<30)
 
76
#define CVAR_ALLOCATED (1<<31)
 
77
 
 
78
/*
 
79
// type of a cvar for menu purposes
 
80
#define CVARMENUTYPE_FLOAT 1
 
81
#define CVARMENUTYPE_INTEGER 2
 
82
#define CVARMENUTYPE_SLIDER 3
 
83
#define CVARMENUTYPE_BOOL 4
 
84
#define CVARMENUTYPE_STRING 5
 
85
#define CVARMENUTYPE_OPTION 6
 
86
 
 
87
// which menu to put a cvar in
 
88
#define CVARMENU_GRAPHICS 1
 
89
#define CVARMENU_SOUND 2
 
90
#define CVARMENU_INPUT 3
 
91
#define CVARMENU_NETWORK 4
 
92
#define CVARMENU_SERVER 5
 
93
 
 
94
#define MAX_CVAROPTIONS 16
 
95
 
 
96
typedef struct cvaroption_s
 
97
{
 
98
        int value;
 
99
        const char *name;
 
100
}
 
101
cvaroption_t;
 
102
 
 
103
typedef struct menucvar_s
 
104
{
 
105
        int type;
 
106
        float valuemin, valuemax, valuestep;
 
107
        int numoptions;
 
108
        cvaroption_t optionlist[MAX_CVAROPTIONS];
 
109
}
 
110
menucvar_t;
 
111
*/
 
112
 
 
113
typedef struct cvar_s
 
114
{
 
115
        int flags;
 
116
 
 
117
        char *name;
 
118
 
 
119
        char *string;
 
120
        char *description;
 
121
        int integer;
 
122
        float value;
 
123
        float vector[3];
 
124
 
 
125
        char *defstring;
 
126
 
 
127
        //menucvar_t menuinfo;
 
128
        struct cvar_s *next;
 
129
        struct cvar_s *nextonhashchain;
 
130
} cvar_t;
 
131
 
 
132
/*
 
133
void Cvar_MenuSlider(cvar_t *variable, int menu, float slider_min, float slider_max, float slider_step);
 
134
void Cvar_MenuBool(cvar_t *variable, int menu, const char *name_false, const char *name_true);
 
135
void Cvar_MenuFloat(cvar_t *variable, int menu, float range_min, float range_max);
 
136
void Cvar_MenuInteger(cvar_t *variable, int menu, int range_min, int range_max);
 
137
void Cvar_MenuString(cvar_t *variable, int menu);
 
138
void Cvar_MenuOption(cvar_t *variable, int menu, int value[16], const char *name[16]);
 
139
*/
 
140
 
 
141
/// registers a cvar that already has the name, string, and optionally the
 
142
/// archive elements set.
 
143
void Cvar_RegisterVariable (cvar_t *variable);
 
144
 
 
145
/// equivelant to "<name> <variable>" typed at the console
 
146
void Cvar_Set (const char *var_name, const char *value);
 
147
 
 
148
/// expands value to a string and calls Cvar_Set
 
149
void Cvar_SetValue (const char *var_name, float value);
 
150
 
 
151
void Cvar_SetQuick (cvar_t *var, const char *value);
 
152
void Cvar_SetValueQuick (cvar_t *var, float value);
 
153
 
 
154
float Cvar_VariableValue (const char *var_name);
 
155
// returns 0 if not defined or non numeric
 
156
 
 
157
const char *Cvar_VariableString (const char *var_name);
 
158
// returns an empty string if not defined
 
159
 
 
160
const char *Cvar_VariableDefString (const char *var_name);
 
161
// returns an empty string if not defined
 
162
 
 
163
const char *Cvar_VariableDescription (const char *var_name);
 
164
// returns an empty string if not defined
 
165
 
 
166
const char *Cvar_CompleteVariable (const char *partial);
 
167
// attempts to match a partial variable name for command line completion
 
168
// returns NULL if nothing fits
 
169
 
 
170
void Cvar_CompleteCvarPrint (const char *partial);
 
171
 
 
172
qboolean Cvar_Command (void);
 
173
// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
 
174
// command.  Returns true if the command was a variable reference that
 
175
// was handled. (print or change)
 
176
 
 
177
void Cvar_UnlockDefaults (void);
 
178
void Cvar_LockDefaults_f (void);
 
179
void Cvar_ResetToDefaults_All_f (void);
 
180
void Cvar_ResetToDefaults_NoSaveOnly_f (void);
 
181
void Cvar_ResetToDefaults_SaveOnly_f (void);
 
182
 
 
183
void Cvar_WriteVariables (qfile_t *f);
 
184
// Writes lines containing "set variable value" for all variables
 
185
// with the archive flag set to true.
 
186
 
 
187
cvar_t *Cvar_FindVar (const char *var_name);
 
188
cvar_t *Cvar_FindVarAfter (const char *prev_var_name, int neededflags);
 
189
 
 
190
int Cvar_CompleteCountPossible (const char *partial);
 
191
const char **Cvar_CompleteBuildList (const char *partial);
 
192
// Added by EvilTypeGuy - functions for tab completion system
 
193
// Thanks to Fett erich@heintz.com
 
194
// Thanks to taniwha
 
195
 
 
196
/// Prints a list of Cvars including a count of them to the user console
 
197
/// Referenced in cmd.c in Cmd_Init hence it's inclusion here.
 
198
/// Added by EvilTypeGuy eviltypeguy@qeradiant.com
 
199
/// Thanks to Matthias "Maddes" Buecher, http://www.inside3d.com/qip/
 
200
void Cvar_List_f (void);
 
201
 
 
202
void Cvar_Set_f (void);
 
203
void Cvar_SetA_f (void);
 
204
// commands to create new cvars (or set existing ones)
 
205
// seta creates an archived cvar (saved to config)
 
206
 
 
207
/// allocates a cvar by name and returns its address,
 
208
/// or merely sets its value if it already exists.
 
209
cvar_t *Cvar_Get (const char *name, const char *value, int flags, const char *newdescription);
 
210
 
 
211
extern char *cvar_dummy_description; // ALWAYS the same pointer
 
212
extern cvar_t *cvar_vars; // used to list all cvars
 
213
 
 
214
#ifdef FILLALLCVARSWITHRUBBISH
 
215
void Cvar_FillAll_f();
 
216
#endif /* FILLALLCVARSWITHRUBBISH */
 
217
 
 
218
#endif
 
219