1 // Emacs style mode select   -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // $Id: command.h 1529 2020-05-14 09:44:10Z wesleyjohnson $
5 //
6 // Copyright (C) 1998-2000 by DooM Legacy Team.
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 //
19 // $Log: command.h,v $
20 // Revision 1.8  2003/05/30 22:44:08  hurdler
21 // add checkcvar function to FS
22 //
23 // Revision 1.7  2001/01/25 22:15:41  bpereira
24 // added heretic support
25 //
26 // Revision 1.6  2000/11/11 13:59:45  bpereira
27 // Revision 1.5  2000/10/08 13:29:59  bpereira
28 // Revision 1.4  2000/08/31 14:30:55  bpereira
29 // Revision 1.3  2000/04/16 18:38:06  bpereira
30 // Revision 1.2  2000/02/27 00:42:10  hurdler
31 // Revision 1.1.1.1  2000/02/22 20:32:32  hurdler
32 // Initial import into CVS (v1.29 pr3)
33 //
34 //
35 // DESCRIPTION:
36 //   Command line processing for console.
37 //   CV variable support, saving, loading of config.
38 //
39 //-----------------------------------------------------------------------------
40 
41 
42 #ifndef COMMAND_H
43 #define COMMAND_H
44 
45 #include "doomtype.h"
46 
47 //===================================
48 // Command buffer & command execution
49 //===================================
50 
51 typedef void (*com_func_t) (void);
52 
53 typedef enum {
54   // need 0 as noop
55   CC_info = 1,
56   CC_cheat,   // cheats
57   CC_command, // general commands
58   CC_savegame, // savegames
59   CC_config,  // config files
60   CC_control, // keys, bind
61   CC_fs, // fragglescript
62   CC_chat, // chat
63   CC_net, // network
64   CC_console // console
65 } command_type_e;
66 void  COM_AddCommand (const char * name, com_func_t func, byte command_type );
67 
68 typedef struct {
69   byte   num;     // number of actual args
70   char * arg[4];  // first 4
71 } COM_args_t;
72 
73 // get some args
74 void  COM_Args( COM_args_t * comargs );
75 
76 // Any args
77 int     COM_Argc (void);
78 char *  COM_Argv (int arg);   // if argv>argc, returns empty string
79 int     COM_CheckParm (const char * check); // like M_CheckParm :)
80 
81 // match existing command or NULL
82 const char *  COM_CompleteCommand (const char * partial, int skips);
83 
84 // insert at queu (at end of other command)
85 void    COM_BufAddText (const char * text);
86 
87 // insert in head (before other command)
88 void    COM_BufInsertText (const char * text);
89 
90 // Execute commands in buffer, flush them
91 void    COM_BufExecute( byte cs_config );
92 
93 // setup command buffer, at game tartup
94 void    COM_Init (void);
95 
96 
97 // ======================
98 // Variable sized buffers
99 // ======================
100 
101 typedef struct vsbuf_s
102 {
103     boolean allowoverflow;  // if false, do a I_Error
104     boolean overflowed;     // set to true if the buffer size failed
105     byte    *data;
106     int     maxsize;
107     int     cursize;
108 } vsbuf_t;
109 
110 void VS_Alloc (vsbuf_t *buf, int initsize);
111 void VS_Free  (vsbuf_t *buf);
112 void VS_Clear (vsbuf_t *buf);
113 void *VS_GetSpace (vsbuf_t *buf, int length);
114 boolean VS_Write (vsbuf_t *buf, void *data, int length);
115 // strcats onto the buf
116 boolean VS_Print (vsbuf_t *buf, const char * data);
117 
118 // ======================
119 
120 
121 //==================
122 // Console variables
123 //==================
124 // console vars are variables that can be changed through code or console,
125 // at RUN TIME. They can also act as simplified commands, because a
126 // function can be attached to a console var, which is called whenever the
127 // variable is modified (using flag CV_CALL).
128 
129 // flags for console vars
130 
131 typedef enum
132 {
133     CV_SAVE   = 0x01, // save to config when quit game
134     CV_CALL   = 0x02, // call function on change
135     CV_NETVAR = 0x04, // send it when change (see logboris.txt at 12-4-2000)
136     CV_NOINIT = 0x08, // dont call function when var is registered (1st set)
137     CV_FLOAT  = 0x10, // the value is fixed 16:16, where unit is FRACUNIT
138                       // (allow user to enter 0.45 for ex)
139                       // WARNING: currently only supports set with CV_Set()
140     CV_VALUE  = 0x20, // Value is too large for EV, but not a string.
141     CV_STRING = 0x40, // String value.
142     CV_NET_LOCK = 0x100, // some variable can't be changed in network but is not netvar (ex: splitscreen)
143     CV_HIDEN   = 0x200,   // variable is not part of the cvar list so cannot be accessed by the console
144                           // can only be set when we have the pointer to hit
145                           // used on the menu
146     CV_CFG1   = 0x2000,  // Restricted to main config file.
147     CV_SHOWMODIF = 0x4000,  // say something when modified
148     CV_SHOWMODIF_ONCE = 0x8000,  // same, but resets this flag to 0 after showing, set in toggle
149 } cv_flags_e;
150 
151 typedef enum
152 {
153     CS_CONFIG   = 0x07, // the config file source, 3 bits
154     CS_PUSHED   = 0x08, // a value from another config has been pushed
155     CS_EV_PROT  = 0x10, // protect the EV value
156     CS_EV_PARAM = 0x40, // A command line param is in EV.
157     CS_MODIFIED = 0x80, // this bit is set when cvar is modified
158 } cv_state_e;
159 
160 typedef enum
161 {
162 // Configfile Value sources.
163     CFG_none,     // not loaded
164     CFG_main,     // the main config file
165     CFG_drawmode, // the drawmode config file
166     CFG_other,    // some other config value
167     CFG_netvar,   // pushed by network setting
168 // Searches
169 //    CFG_all = 0x40,  // match all
170     CFG_null = 0x4f, // match none
171 } cv_config_e;
172 
173 typedef struct {
174     int   value;
175     const char * strvalue;
176 } CV_PossibleValue_t;
177 
178 // [WDJ] CV_PossibleValue supports the following structures.
179 // MIN .. MAX : First element has label MIN.  Last element is maximum value.
180 // MIN INC .. MAX : Label INC is the increment.
181 // List of values : Next or previous value on the list.
182 
183 // [WDJ] Ptrs together for better packing. Beware many consts of this type.
184 typedef struct consvar_s
185 {
186 // Declare in consvar_t instance.  If this order is altered, about 60 instances have to be fixed.
187     const char * name;
188     const char * defaultvalue;
189     uint32_t flags;            // flags see cv_flags_e above
190     CV_PossibleValue_t * PossibleValue;  // table of possible values
191     void    (*func) (void);    // called on change, if CV_CALL set, optional
192 // Undeclared
193     int32_t  value;            // for int and fixed_t
194     uint16_t netid;            // hashed netid for net send and receive
195                                // used only with CV_NETVAR
196     byte     state;  // cv_state_e
197     byte     EV;  // [WDJ] byte value, set from value changes, set from demos.
198        // This saves user settings from being changed by demos.
199        // Do not make it anything except byte.  Byte is efficient for most
200        // enables, and enum. Two bytes of space are free due to alignment.
201        // For most user settings this is slightly easier to manage than
202        // creating more EN vars.  For the exceptions, create a setting function
203        // to pass consvar settings to EN vars.
204     char *  string;      // value in string
205        // Saved user config is in string.
206        // When pointing to a PossibleValue, it will need to be a const char *.
207        // Otherwise, it is allocated with Z_Alloc, Z_Free.
208     struct  consvar_s * next;
209 
210 } consvar_t;
211 
212 extern CV_PossibleValue_t CV_OnOff[];
213 extern CV_PossibleValue_t CV_YesNo[];
214 extern CV_PossibleValue_t CV_Unsigned[];
215 extern CV_PossibleValue_t CV_uint16[];
216 extern CV_PossibleValue_t CV_byte[];
217 // register a variable for use at the console
218 void  CV_RegisterVar (consvar_t *variable);
219 
220 // returns the name of the nearest console variable name found
221 //  partial : partial variable name
222 const char * CV_CompleteVar (const char * partial, int skips);
223 
224 // Sets a var to a string value.
225 void  CV_Set (consvar_t *var, const char * str_value);
226 
227 // expands value to a string and calls CV_Set
228 void  CV_SetValue (consvar_t *var, int value);
229 
230 // Set a command line parameter value.
231 void  CV_SetParam (consvar_t *var, int value);
232 extern byte command_EV_param;
233 
234 // Makes a copy of the string, and handles PossibleValue string values.
235 //   str : a reference to a string, it will by copied.
236 void  CV_Set_cvar_string( consvar_t * cvar, const char * str );
237 void  CV_Free_cvar_string( consvar_t * cvar );
238 
239 // If a OnChange func tries to change other values,
240 // this function should be used.
241 void CV_Set_by_OnChange (consvar_t *cvar, int value);
242 
243 // it a setvalue but with a modulo at the maximum
244 void  CV_ValueIncDec (consvar_t *var, int increment);
245 
246 // Called after demo to restore the user settings.
247 void  CV_Restore_User_Settings( void );
248 
249 // Iterator for saving variables
250 consvar_t *  CV_IteratorFirst( void );
251 consvar_t *  CV_Iterator( consvar_t * cv );
252 
253 consvar_t * CV_FindVar (const char * name);
254 
255 // Return the string value of the config var, current or pushed.
256 // Return NULL if not found.
257 const char *  CV_Get_Config_string( consvar_t * cvar, byte c_config );
258 
259 // Get the values of a pushed cvar, into the temp cvar.
260 boolean  CV_Get_Pushed_cvar( consvar_t * cvar, byte c_config, /*OUT*/ consvar_t * temp_cvar );
261 
262 // Put the values in the temp cvar, into the pushed or current cvar.
263 void  CV_Put_Config_cvar( consvar_t * cvar, byte c_config, /*IN*/ consvar_t * temp_cvar );
264 
265 // Put the string value to the pushed or current cvar.
266 // This will create or push, as needed.
267 //   str : str value, will be copied.  Will set numeric value too.
268 void  CV_Put_Config_string( consvar_t * cvar, byte cfg, const char * str );
269 
270 // Remove the cvar value for the config.
271 void  CV_Delete_Config_cvar( consvar_t * cvar, byte c_config );
272 
273 // Clear all values from the config file.
274 void  CV_Clear_Config( byte cs_config );
275 
276 // Return true if any value of the config is current, or pushed.
277 boolean CV_Config_check( byte cfg );
278 
279 
280 #endif // COMMAND_H
281