FS2_Open
Open source remastering of the Freespace 2 engine
console.h File Reference

An overhauled/updated debug console to allow monitoring, testing, and general debugging of new features. More...

Go to the source code of this file.

Classes

class  debug_command
 Class to aggregate a debug command with its name (as shown in the console) and short help. More...
 
class  is_dcmd
 Predicate class used to search for a dcmd by name. More...
 

Macros

#define DC_MAX_COMMANDS   300
 
#define DCF(function_name, help_text)
 The potent DCF macro, used to define new debug commands for the console. More...
 
#define DCF_BOOL(function_name, bool_variable)
 
#define DCF_BOOL2(function_name, bool_variable, short_help, long_help)
 
#define DCF_FLOAT(function_name, float_variable, short_help)
 
#define DCF_FLOAT2(function_name, float_variable, lower_bounds, upper_bounds, short_help)
 
#define DCF_INT(function_name, int_variable, short_help)
 
#define DCF_INT2(function_name, int_variable, lower_bounds, upper_bounds, short_help)
 

Functions

bool dc_pause_output (void)
 Pauses the output of a command and allows user to scroll through the output history. More...
 
void dc_printf (const char *format,...)
 Prints the given char string to the debug console. More...
 
void debug_console (void(*func)(void)=NULL)
 Opens and processes the debug console. (Blocking call) More...
 

Variables

bool Dc_debug_on
 Flag used to print console and command debugging strings. More...
 
int dc_commands_size
 
uint lastline
 
SCP_string dc_command_str
 Is progressively culled from the left as commands, arguments are parsed in DCF's. More...
 

Detailed Description

An overhauled/updated debug console to allow monitoring, testing, and general debugging of new features.

Of key interest is Volition's DCF macro, which adds the function argument to the available command list in the debug console. These functions may be defined in the .cpp file that they are related to, but it is recommended that they be in their own .cpp if they have multiple sub-arguments (ex: Git has its sub-arguments delimited by a pair of -'s, or –)

Definition in file console.h.

Macro Definition Documentation

#define DC_MAX_COMMANDS   300

Definition at line 25 of file console.h.

#define DCF (   function_name,
  help_text 
)
Value:
void dcf_##function_name(); \
debug_command dcmd_##function_name(#function_name, help_text, dcf_##function_name); \
void dcf_##function_name()
typedef void(APIENTRY *PFNGLARRAYELEMENTEXTPROC)(GLint i)

The potent DCF macro, used to define new debug commands for the console.

Parameters
function_name[in]The name of the function, as shown in the debug console
help_txt[in]The short-help text, as shown as listed from the 'help' command

Each DCF is responsible for getting data from the debug console's command line. The parsing functions for the command line have been set up to have similar syntax and usage as the parselo commands. (see consoleparse.h) Most, if not all, argument and subcommand strings should be parsed by the dc_optional_string functions. Usage example: DCF(toggle_it, "description") { if (dc_optional_string_either("help", "--help")) { dc_printf("Usage: sample. Toggles This_var on/off\n");

} else if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { dc_printf("This_var is %s\n", (This_var ? "ON" : "OFF"));

} else { This_var = !This_var;

} }

In the console, the command would be listed as 'toggle_it', and dcf_help would display it as: toggle_it - Usage: sample. Toggles This_var on/off. Note: The only allowed function type is a void fn( void )

Definition at line 60 of file console.h.

#define DCF_BOOL (   function_name,
  bool_variable 
)
Value:
void dcf_##function_name(); \
debug_command dcmd_##function_name(#function_name, "Sets or toggles the boolean: "#bool_variable, dcf_##function_name ); \
void dcf_##function_name() { \
bool bool_tmp = bool_variable != 0; \
if (dc_optional_string_either("help", "--help")) { \
dc_printf( "Usage: %s [bool]\nSets %s to true or false. If nothing passed, then toggles it.\n", #function_name, #bool_variable ); \
return; \
} \
if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
dc_printf("%s = %s\n", #bool_variable, (bool_variable ? "TRUE" : "FALSE")); \
return; \
} \
if (!dc_maybe_stuff_boolean(&bool_tmp)) { \
if (bool_variable != 0) \
bool_variable = 0; \
else \
bool_variable = 1; \
} else { \
if (bool_tmp) \
bool_variable = 1; \
else \
bool_variable = 0; \
} \
dc_printf("%s set to %s\n", #bool_variable, (bool_variable != 0 ? "TRUE" : "FALSE")); \
}
void dc_printf(const char *format,...)
Prints the given char string to the debug console.
Definition: console.cpp:358
bool dc_maybe_stuff_boolean(bool *b)
Tries to stuff a bool from the Command_string.
bool dc_optional_string_either(const char *str1, const char *str2)
Searches for an optional string and it's alias.
typedef void(APIENTRY *PFNGLARRAYELEMENTEXTPROC)(GLint i)
if(aifft_max_checks<=0)
Definition: aiturret.cpp:1581

Definition at line 71 of file console.h.

#define DCF_BOOL2 (   function_name,
  bool_variable,
  short_help,
  long_help 
)
Value:
void dcf_##function_name(); \
debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
void dcf_##function_name() { \
if (dc_optional_string_either("help", "--help")) { \
dc_printf( #long_help ); \
return; \
} \
if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
dc_printf("%s = %s\n", #function_name, (bool_variable ? "TRUE" : "FALSE")); \
return; \
} \
if (!dc_maybe_stuff_boolean(&bool_variable)) { \
bool_variable = !bool_variable; \
} \
}
void dc_printf(const char *format,...)
Prints the given char string to the debug console.
Definition: console.cpp:358
bool dc_maybe_stuff_boolean(bool *b)
Tries to stuff a bool from the Command_string.
bool dc_optional_string_either(const char *str1, const char *str2)
Searches for an optional string and it's alias.
typedef void(APIENTRY *PFNGLARRAYELEMENTEXTPROC)(GLint i)
if(aifft_max_checks<=0)
Definition: aiturret.cpp:1581

Definition at line 105 of file console.h.

#define DCF_FLOAT (   function_name,
  float_variable,
  short_help 
)
Value:
void dcf_##function_name(); \
debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
void dcf_##function_name() { \
if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
dc_printf("%s = %f\n", #float_variable, float_variable); \
return; \
} \
dc_stuff_float(&value); \
float_variable = value; \
dc_printf("%s set to %f\n", #float_variable, float_variable); \
}
GLsizei const GLfloat * value
Definition: Glext.h:5646
void dc_printf(const char *format,...)
Prints the given char string to the debug console.
Definition: console.cpp:358
bool dc_optional_string_either(const char *str1, const char *str2)
Searches for an optional string and it's alias.
void dc_stuff_float(float *f)
Stuffs a float to the given variable.
typedef void(APIENTRY *PFNGLARRAYELEMENTEXTPROC)(GLint i)
if(aifft_max_checks<=0)
Definition: aiturret.cpp:1581
typedef float(SCP_EXT_CALLCONV *SCPTRACKIR_PFFLOATVOID)()

Definition at line 129 of file console.h.

#define DCF_FLOAT2 (   function_name,
  float_variable,
  lower_bounds,
  upper_bounds,
  short_help 
)
Value:
void dcf_##function_name(); \
debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
void dcf_##function_name() { \
if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
dc_printf("%s = %f\n", #float_variable, float_variable); \
return; \
} \
CLAMP(float_variable, lower_bounds, upper_bounds); \
float_variable = value; \
dc_printf("%s set to %f\n", #float_variable, float_variable); \
}
GLsizei const GLfloat * value
Definition: Glext.h:5646
#define CLAMP(x, min, max)
Definition: pstypes.h:488
void dc_printf(const char *format,...)
Prints the given char string to the debug console.
Definition: console.cpp:358
bool dc_optional_string_either(const char *str1, const char *str2)
Searches for an optional string and it's alias.
void dc_stuff_float(float *f)
Stuffs a float to the given variable.
typedef void(APIENTRY *PFNGLARRAYELEMENTEXTPROC)(GLint i)
if(aifft_max_checks<=0)
Definition: aiturret.cpp:1581
typedef float(SCP_EXT_CALLCONV *SCPTRACKIR_PFFLOATVOID)()

Definition at line 152 of file console.h.

#define DCF_INT (   function_name,
  int_variable,
  short_help 
)
Value:
void dcf_##function_name(); \
debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
void dcf_##function_name() { \
if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
dc_printf("%s = %i\n", #int_variable, int_variable); \
return; \
} \
dc_stuff_int(&value); \
int_variable = value; \
dc_printf("%s set to %i\n", #int_variable, int_variable); \
}
GLsizei const GLfloat * value
Definition: Glext.h:5646
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
void dc_printf(const char *format,...)
Prints the given char string to the debug console.
Definition: console.cpp:358
bool dc_optional_string_either(const char *str1, const char *str2)
Searches for an optional string and it's alias.
typedef void(APIENTRY *PFNGLARRAYELEMENTEXTPROC)(GLint i)
void dc_stuff_int(int *i)
Stuffs an int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats...
if(aifft_max_checks<=0)
Definition: aiturret.cpp:1581

Definition at line 174 of file console.h.

#define DCF_INT2 (   function_name,
  int_variable,
  lower_bounds,
  upper_bounds,
  short_help 
)
Value:
void dcf_##function_name(); \
debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
void dcf_##function_name() { \
if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) { \
dc_printf("%s = %i\n", #int_variable, int_variable); \
return; \
} \
dc_stuff_int(&value); \
CLAMP(int_variable, lower_bounds, upper_bounds); \
int_variable = value; \
dc_printf("%s set to %i\n", #int_variable, int_variable); \
}
GLsizei const GLfloat * value
Definition: Glext.h:5646
#define CLAMP(x, min, max)
Definition: pstypes.h:488
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
void dc_printf(const char *format,...)
Prints the given char string to the debug console.
Definition: console.cpp:358
bool dc_optional_string_either(const char *str1, const char *str2)
Searches for an optional string and it's alias.
typedef void(APIENTRY *PFNGLARRAYELEMENTEXTPROC)(GLint i)
void dc_stuff_int(int *i)
Stuffs an int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats...
if(aifft_max_checks<=0)
Definition: aiturret.cpp:1581

Definition at line 197 of file console.h.

Function Documentation

bool dc_pause_output ( void  )

Pauses the output of a command and allows user to scroll through the output history.

Returns true if user has pressed Esc, returns false otherwise. Use this in your function to (safely?) break out of the loop it's presumably in.

Definition at line 306 of file console.cpp.

void dc_printf ( const char *  format,
  ... 
)

Prints the given char string to the debug console.

See the doc for std::printf() for formating and more details

Definition at line 358 of file console.cpp.

void debug_console ( void(*)(void func = NULL)

Opens and processes the debug console. (Blocking call)

TODO: Make this a non-blocking call so that the game can still run while the debug console is open.

Definition at line 495 of file console.cpp.

Variable Documentation

SCP_string dc_command_str

Is progressively culled from the left as commands, arguments are parsed in DCF's.

The entered command line, arguments and all.

Definition at line 27 of file console.cpp.

int dc_commands_size

Definition at line 28 of file consolecmds.cpp.

bool Dc_debug_on

Flag used to print console and command debugging strings.

Definition at line 24 of file console.cpp.

uint lastline

Definition at line 32 of file console.cpp.