FS2_Open
Open source remastering of the Freespace 2 engine
console.h
Go to the documentation of this file.
1 #ifndef _CONSOLE_H
2 #define _CONSOLE_H
3 /*
4  * z64555's debug console, created for the FreeSpace Source Code project
5  *
6  * Portions of this source code are based on works by Volition, Inc. circa 1999. You may not sell or otherwise
7  * commercially exploit the source or things you created based on the source.
8  */
9 
22 #include "globalincs/pstypes.h"
23 #include "globalincs/vmallocator.h"
24 
25 #define DC_MAX_COMMANDS 300
26 
27 class debug_command;
28 
60 #define DCF(function_name, help_text) \
61  void dcf_##function_name(); \
62  debug_command dcmd_##function_name(#function_name, help_text, dcf_##function_name); \
63  void dcf_##function_name()
64 
71 #define DCF_BOOL(function_name, bool_variable) \
72  void dcf_##function_name(); \
73  debug_command dcmd_##function_name(#function_name, "Sets or toggles the boolean: "#bool_variable, dcf_##function_name ); \
74  void dcf_##function_name() { \
75  bool bool_tmp = bool_variable != 0; \
76  if (dc_optional_string_either("help", "--help")) { \
77  dc_printf( "Usage: %s [bool]\nSets %s to true or false. If nothing passed, then toggles it.\n", #function_name, #bool_variable ); \
78  return; \
79  } \
80  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
81  dc_printf("%s = %s\n", #bool_variable, (bool_variable ? "TRUE" : "FALSE")); \
82  return; \
83  } \
84  if (!dc_maybe_stuff_boolean(&bool_tmp)) { \
85  if (bool_variable != 0) \
86  bool_variable = 0; \
87  else \
88  bool_variable = 1; \
89  } else { \
90  if (bool_tmp) \
91  bool_variable = 1; \
92  else \
93  bool_variable = 0; \
94  } \
95  dc_printf("%s set to %s\n", #bool_variable, (bool_variable != 0 ? "TRUE" : "FALSE")); \
96  }
97 
98 
105 #define DCF_BOOL2(function_name, bool_variable, short_help, long_help) \
106  void dcf_##function_name(); \
107  debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
108  void dcf_##function_name() { \
109  if (dc_optional_string_either("help", "--help")) { \
110  dc_printf( #long_help ); \
111  return; \
112  } \
113  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
114  dc_printf("%s = %s\n", #function_name, (bool_variable ? "TRUE" : "FALSE")); \
115  return; \
116  } \
117  if (!dc_maybe_stuff_boolean(&bool_variable)) { \
118  bool_variable = !bool_variable; \
119  } \
120  }
121 
129  #define DCF_FLOAT(function_name, float_variable, short_help) \
130  void dcf_##function_name(); \
131  debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
132  void dcf_##function_name() { \
133  float value; \
134  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
135  dc_printf("%s = %f\n", #float_variable, float_variable); \
136  return; \
137  } \
138  dc_stuff_float(&value); \
139  float_variable = value; \
140  dc_printf("%s set to %f\n", #float_variable, float_variable); \
141  }
142 
152  #define DCF_FLOAT2(function_name, float_variable, lower_bounds, upper_bounds, short_help) \
153  void dcf_##function_name(); \
154  debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
155  void dcf_##function_name() { \
156  float value; \
157  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
158  dc_printf("%s = %f\n", #float_variable, float_variable); \
159  return; \
160  } \
161  dc_stuff_float(&value); \
162  CLAMP(float_variable, lower_bounds, upper_bounds); \
163  float_variable = value; \
164  dc_printf("%s set to %f\n", #float_variable, float_variable); \
165  }
166 
174  #define DCF_INT(function_name, int_variable, short_help) \
175  void dcf_##function_name(); \
176  debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
177  void dcf_##function_name() { \
178  int value; \
179  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
180  dc_printf("%s = %i\n", #int_variable, int_variable); \
181  return; \
182  } \
183  dc_stuff_int(&value); \
184  int_variable = value; \
185  dc_printf("%s set to %i\n", #int_variable, int_variable); \
186  }
187 
197  #define DCF_INT2(function_name, int_variable, lower_bounds, upper_bounds, short_help) \
198  void dcf_##function_name(); \
199  debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
200  void dcf_##function_name() { \
201  int value; \
202  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
203  dc_printf("%s = %i\n", #int_variable, int_variable); \
204  return; \
205  } \
206  dc_stuff_int(&value); \
207  CLAMP(int_variable, lower_bounds, upper_bounds); \
208  int_variable = value; \
209  dc_printf("%s set to %i\n", #int_variable, int_variable); \
210  }
211 
222 public:
223  const char *name;
224  const char *help;
225  void (*func)();
226 
227  debug_command();
228 
235  debug_command(const char *name, const char *help, void (*func)());
236 };
237 
242 class is_dcmd {
243 public:
244  const char *name;
245 
246  is_dcmd(const char *_name) : name(_name) {}
247 
249  {
250  return (strcmp(name, dcmd->name) == 0);
251  }
252 };
253 
254 extern bool Dc_debug_on;
255 extern int dc_commands_size;
256 extern uint lastline;
257 extern SCP_string dc_command_str; // The rest of the command line, from the end of the last processed arg on.
258 
265 bool dc_pause_output(void);
266 
271 void dc_printf(const char *format, ...);
272 
277 void debug_console(void (*func)(void) = NULL);
278 
279 #endif // _CONSOLE_H
GLenum GLsizei GLenum format
Definition: Gl.h:1509
bool Dc_debug_on
Flag used to print console and command debugging strings.
Definition: console.cpp:24
GLenum func
Definition: Glext.h:5605
SCP_string dc_command_str
Is progressively culled from the left as commands, arguments are parsed in DCF's. ...
Definition: console.cpp:27
const char * help
The short help string, as shown by 'help '.
Definition: console.h:224
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
unsigned int uint
Definition: pstypes.h:64
void dc_printf(const char *format,...)
Prints the given char string to the debug console.
Definition: console.cpp:358
int dc_commands_size
Definition: consolecmds.cpp:28
Class to aggregate a debug command with its name (as shown in the console) and short help...
Definition: console.h:221
uint lastline
Definition: console.cpp:32
const char * name
Definition: console.h:244
Predicate class used to search for a dcmd by name.
Definition: console.h:242
typedef void(APIENTRY *PFNGLARRAYELEMENTEXTPROC)(GLint i)
void debug_console(void(*func)(void)=NULL)
Opens and processes the debug console. (Blocking call)
Definition: console.cpp:495
is_dcmd(const char *_name)
Definition: console.h:246
bool operator()(debug_command *dcmd)
Definition: console.h:248
Parsing functions for the command line. Previously known as the command line scanner.
bool dc_pause_output(void)
Pauses the output of a command and allows user to scroll through the output history.
Definition: console.cpp:306
const char * name
The name of the command, as shown in the debug console.
Definition: console.h:223