]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - cvar.h
Small fixes to tab completion
[xonotic/darkplaces.git] / cvar.h
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 // cvar flags
57 #define CVAR_SAVE 1
58 #define CVAR_NOTIFY 2
59
60 // type of a cvar for menu purposes
61 #define CVARMENUTYPE_FLOAT 1
62 #define CVARMENUTYPE_INTEGER 2
63 #define CVARMENUTYPE_SLIDER 3
64 #define CVARMENUTYPE_BOOL 4
65 #define CVARMENUTYPE_STRING 5
66 #define CVARMENUTYPE_OPTION 6
67
68 // which menu to put a cvar in
69 #define CVARMENU_GRAPHICS 1
70 #define CVARMENU_SOUND 2
71 #define CVARMENU_INPUT 3
72 #define CVARMENU_NETWORK 4
73 #define CVARMENU_SERVER 5
74
75 #define MAX_CVAROPTIONS 16
76
77 typedef struct
78 {
79         int value;
80         char *name;
81 }
82 cvaroption_t;
83
84 typedef struct
85 {
86         int                             type;
87         float                   valuemin, valuemax, valuestep;
88         int                             numoptions;
89         cvaroption_t    optionlist[MAX_CVAROPTIONS];
90 }
91 menucvar_t;
92
93 typedef struct cvar_s
94 {
95         int                             flags;
96         char                    *name;
97         char                    *string;
98 //      qboolean                archive;                // set to true to cause it to be saved to vars.rc
99 //      qboolean                server;         // notifies players when changed
100         int                             intvalue;
101         float                   value;
102         float                   vector[3];
103         menucvar_t              menuinfo;
104         struct cvar_s   *next;
105 } cvar_t;
106
107 void    Cvar_MenuSlider(cvar_t *variable, int menu, float slider_min, float slider_max, float slider_step);
108 void    Cvar_MenuBool(cvar_t *variable, int menu, char *name_false, char *name_true);
109 void    Cvar_MenuFloat(cvar_t *variable, int menu, float range_min, float range_max);
110 void    Cvar_MenuInteger(cvar_t *variable, int menu, int range_min, int range_max);
111 void    Cvar_MenuString(cvar_t *variable, int menu);
112 void    Cvar_MenuOption(cvar_t *variable, int menu, int value[16], char *name[16]);
113
114 void    Cvar_RegisterVariable (cvar_t *variable);
115 // registers a cvar that already has the name, string, and optionally the
116 // archive elements set.
117
118 void    Cvar_Set (char *var_name, char *value);
119 // equivelant to "<name> <variable>" typed at the console
120
121 void    Cvar_SetValue (char *var_name, float value);
122 // expands value to a string and calls Cvar_Set
123
124 float   Cvar_VariableValue (char *var_name);
125 // returns 0 if not defined or non numeric
126
127 char    *Cvar_VariableString (char *var_name);
128 // returns an empty string if not defined
129
130 char    *Cvar_CompleteVariable (char *partial);
131 // attempts to match a partial variable name for command line completion
132 // returns NULL if nothing fits
133
134 qboolean Cvar_Command (void);
135 // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
136 // command.  Returns true if the command was a variable reference that
137 // was handled. (print or change)
138
139 void    Cvar_WriteVariables (QFile *f);
140 // Writes lines containing "set variable value" for all variables
141 // with the archive flag set to true.
142
143 cvar_t *Cvar_FindVar (char *var_name);
144
145 extern cvar_t   *cvar_vars;
146
147 int             Cvar_CompleteCountPossible (char *partial);
148 char    **Cvar_CompleteBuildList (char *partial);
149 // Added by EvilTypeGuy - functions for tab completion system
150 // Thanks to Fett erich@heintz.com
151 // Thanks to taniwha
152
153 void    Cvar_List_f (void);
154 // Prints a list of Cvars including a count of them to the user console
155 // Referenced in cmd.c in Cmd_Init hence it's inclusion here
156 // Added by EvilTypeGuy eviltypeguy@qeradiant.com
157 // Thanks to Matthias "Maddes" Buecher, http://www.inside3d.com/qip/
158