Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/code/Makefile.am b/code/Makefile.am
- index 2972f47..e22b1b4 100644
- --- a/code/Makefile.am
- +++ b/code/Makefile.am
- @@ -262,7 +262,9 @@ FS2_SOURCES = \
- ddsutils/ddsutils.h \
- debris/debris.cpp \
- debris/debris.h \
- + debugconsole/consolecmds.cpp \
- debugconsole/console.cpp \
- + debugconsole/consoleparse.cpp \
- debugconsole/dbugfile.h \
- debugconsole/timerbar.cpp \
- debugconsole/timerbar.h \
- diff --git a/code/ai/aicode.cpp b/code/ai/aicode.cpp
- index e94fce9..3d5de1b 100644
- --- a/code/ai/aicode.cpp
- +++ b/code/ai/aicode.cpp
- @@ -18,6 +18,7 @@
- #include "ai/ai.h"
- +#include "debugconsole/console.h"
- #include "globalincs/linklist.h"
- #include "object/object.h"
- #include "physics/physics.h"
- @@ -11367,16 +11368,14 @@ float get_wing_largest_radius(object *objp, int formation_object_flag)
- float Wing_y_scale = 2.0f;
- float Wing_scale = 1.0f;
- -DCF(wing_y_scale, "")
- +DCF(wing_y_scale, "Adjusts the wing formation scale along the Y axis (Default is 2.0)")
- {
- - dc_get_arg(ARG_FLOAT);
- - Wing_y_scale = Dc_arg_float;
- + dc_stuff_float(&Wing_y_scale);
- }
- -DCF(wing_scale, "")
- +DCF(wing_scale, "Adjusts the wing formation scale. (Default is 1.0f)")
- {
- - dc_get_arg(ARG_FLOAT);
- - Wing_scale = Dc_arg_float;
- + dc_stuff_float(&Wing_scale);
- }
- /**
- diff --git a/code/ai/aiturret.cpp b/code/ai/aiturret.cpp
- index ad8c4da..5ee314f 100644
- --- a/code/ai/aiturret.cpp
- +++ b/code/ai/aiturret.cpp
- @@ -22,6 +22,7 @@
- #include "iff_defs/iff_defs.h"
- #include "weapon/muzzleflash.h"
- #include "parse/scripting.h"
- +#include "debugconsole/console.h"
- #include <limits.h>
- @@ -38,8 +39,7 @@
- float Lethality_range_const = 2.0f;
- DCF(lethality_range, "N for modifying range: 1 / (1+N) at 100")
- {
- - dc_get_arg(ARG_FLOAT);
- - Lethality_range_const = Dc_arg_float;
- + dc_stuff_float(&Lethality_range_const);
- }
- float Player_lethality_bump[NUM_SKILL_LEVELS] = {
- @@ -1466,10 +1466,16 @@ ship_subsys *aifft_list[MAX_AIFFT_TURRETS];
- float aifft_rank[MAX_AIFFT_TURRETS];
- int aifft_list_size = 0;
- int aifft_max_checks = 5;
- -DCF(mf, "")
- +DCF(mf, "Adjusts the maximum number of tries an AI may do when trying to pick a subsystem to attack (Default is 5)")
- {
- - dc_get_arg(ARG_INT);
- - aifft_max_checks = Dc_arg_int;
- + dc_stuff_int(&aifft_max_checks);
- +
- + if (aifft_max_checks <= 0) {
- + dc_printf("Value must be a non-negative, non-zero integer\n");
- + dc_printf("aifft_max_checks set to default value of 5\n");
- +
- + aifft_max_checks = 5;
- + }
- }
- diff --git a/code/asteroid/asteroid.cpp b/code/asteroid/asteroid.cpp
- index 99b6bad..cf87c48 100644
- --- a/code/asteroid/asteroid.cpp
- +++ b/code/asteroid/asteroid.cpp
- @@ -39,6 +39,8 @@
- #include "network/multimsgs.h"
- #include "network/multi.h"
- #include "parse/scripting.h"
- +#include "debugconsole/console.h"
- +
- #include <algorithm>
- #include "globalincs/compatibility.h"
- @@ -1404,23 +1406,8 @@ void asteroid_level_close()
- Asteroid_field.num_initial_asteroids=0;
- }
- -DCF(asteroids,"Turns asteroids on/off")
- -{
- - if ( Dc_command ) {
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if ( Dc_arg_type & ARG_TRUE )
- - Asteroids_enabled = 1;
- - else if ( Dc_arg_type & ARG_FALSE )
- - Asteroids_enabled = 0;
- - else if ( Dc_arg_type & ARG_NONE )
- - Asteroids_enabled ^= 1;
- - }
- - if ( Dc_help )
- - dc_printf( "Usage: asteroids [bool]\nTurns asteroid system on/off. If nothing passed, then toggles it.\n" );
- -
- - if ( Dc_status )
- - dc_printf( "asteroids are %s\n", (Asteroids_enabled?"ON":"OFF") );
- -}
- +DCF_BOOL2(asteroids, Asteroids_enabled, "enables or disables asteroids", "Usage: asteroids [bool]\nTurns asteroid system on/off. If nothing passed, then toggles it.\n");
- +
- void hud_target_asteroid()
- {
- diff --git a/code/bmpman/bmpman.cpp b/code/bmpman/bmpman.cpp
- index 1340437..0e5af20 100644
- --- a/code/bmpman/bmpman.cpp
- +++ b/code/bmpman/bmpman.cpp
- @@ -37,6 +37,7 @@
- #include "jpgutils/jpgutils.h"
- #include "parse/parselo.h"
- #include "network/multiutil.h"
- +#include "debugconsole/console.h"
- #define BMPMAN_INTERNAL
- #include "bmpman/bm_internal.h"
- @@ -669,46 +670,53 @@ int bm_reload(int bitmap_handle, const char* filename)
- DCF(bm_frag,"Shows BmpMan fragmentation")
- {
- - if ( Dc_command ) {
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Displays a graphic showing the BmpMan fragmentation. Color key:\n");
- + dc_printf("\tGray : NONE\n");
- + dc_printf("\tRed : PCXn");
- + dc_printf("\tGreen : USER, TGA, PNG, DDS\n");
- + dc_printf("\tBlue : ANI, EFF\n\n");
- - gr_clear();
- -
- - int x=0, y=0;
- - int xs=2, ys=2;
- - int w=4, h=4;
- -
- - for (int i=0; i<MAX_BITMAPS; i++ ) {
- - switch( bm_bitmaps[i].type ) {
- - case BM_TYPE_NONE:
- - gr_set_color(128,128,128);
- - break;
- - case BM_TYPE_PCX:
- - gr_set_color(255,0,0);
- - break;
- - case BM_TYPE_USER:
- - case BM_TYPE_TGA:
- - case BM_TYPE_PNG:
- - case BM_TYPE_DDS:
- - gr_set_color(0,255,0);
- - break;
- - case BM_TYPE_ANI:
- - case BM_TYPE_EFF:
- - gr_set_color(0,0,255);
- - break;
- - }
- + dc_printf("Once done reviewing the graphic, press any key to return to the console\n");
- + return;
- + }
- +
- + gr_clear();
- - gr_rect( x+xs, y+ys, w, h );
- - x += w+xs+xs;
- - if ( x > 639 ) {
- - x = 0;
- - y += h + ys + ys;
- - }
- + int x=0, y=0;
- + int xs=2, ys=2;
- + int w=4, h=4;
- + for (int i=0; i<MAX_BITMAPS; i++ ) {
- + switch( bm_bitmaps[i].type ) {
- + case BM_TYPE_NONE:
- + gr_set_color(128,128,128);
- + break;
- + case BM_TYPE_PCX:
- + gr_set_color(255,0,0);
- + break;
- + case BM_TYPE_USER:
- + case BM_TYPE_TGA:
- + case BM_TYPE_PNG:
- + case BM_TYPE_DDS:
- + gr_set_color(0,255,0);
- + break;
- + case BM_TYPE_ANI:
- + case BM_TYPE_EFF:
- + gr_set_color(0,0,255);
- + break;
- }
- - gr_flip();
- - key_getch();
- + gr_rect( x+xs, y+ys, w, h );
- + x += w+xs+xs;
- + if ( x > 639 ) {
- + x = 0;
- + y += h + ys + ys;
- + }
- }
- +
- + gr_flip();
- + key_getch();
- }
- static int find_block_of(int n)
- @@ -2068,48 +2076,52 @@ void bm_unload_all()
- DCF(bmpman,"Shows/changes bitmap caching parameters and usage")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_STRING);
- - if ( !strcmp( Dc_arg, "flush" )) {
- - dc_printf( "Total RAM usage before flush: %d bytes\n", bm_texture_ram );
- - int i;
- - for (i = 0; i < MAX_BITMAPS; i++) {
- - if ( bm_bitmaps[i].type != BM_TYPE_NONE ) {
- - bm_free_data(i);
- - }
- - }
- - dc_printf( "Total RAM after flush: %d bytes\n", bm_texture_ram );
- - } else if ( !strcmp( Dc_arg, "ram" )) {
- - dc_get_arg(ARG_INT);
- - Bm_max_ram = Dc_arg_int*1024*1024;
- - } else {
- - // print usage, not stats
- - Dc_help = 1;
- - }
- - }
- -
- - if ( Dc_help ) {
- - dc_printf( "Usage: BmpMan keyword\nWhere keyword can be in the following forms:\n" );
- - dc_printf( "BmpMan flush Unloads all bitmaps.\n" );
- - dc_printf( "BmpMan ram x Sets max mem usage to x MB. (Set to 0 to have no limit.)\n" );
- - dc_printf( "\nUse '? BmpMan' to see status of Bitmap manager.\n" );
- - Dc_status = 0; // don't print status if help is printed. Too messy.
- + if ( dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: BmpMan [arg]\nWhere arg can be any of the following:\n" );
- + dc_printf( "\tflush Unloads all bitmaps.\n" );
- + dc_printf( "\tram [x] Sets max mem usage to x MB. (Set to 0 to have no limit.)\n" );
- + dc_printf( "\t? Displays status of Bitmap manager.\n" );
- + return;
- }
- - if ( Dc_status ) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- dc_printf( "Total RAM usage: %d bytes\n", bm_texture_ram );
- -
- - if ( Bm_max_ram > 1024*1024 )
- - dc_printf( "Max RAM allowed: %.1f MB\n", i2fl(Bm_max_ram)/(1024.0f*1024.0f) );
- - else if ( Bm_max_ram > 1024 )
- - dc_printf( "Max RAM allowed: %.1f KB\n", i2fl(Bm_max_ram)/(1024.0f) );
- - else if ( Bm_max_ram > 0 )
- - dc_printf( "Max RAM allowed: %d bytes\n", Bm_max_ram );
- - else
- - dc_printf( "No RAM limit\n" );
- + if (Bm_max_ram > 1024*1024) {
- + dc_printf( "\tMax RAM allowed: %.1f MB\n", i2fl(Bm_max_ram)/(1024.0f*1024.0f) );
- + } else if ( Bm_max_ram > 1024 ) {
- + dc_printf( "\tMax RAM allowed: %.1f KB\n", i2fl(Bm_max_ram)/(1024.0f) );
- + } else if ( Bm_max_ram > 0 ) {
- + dc_printf( "\tMax RAM allowed: %d bytes\n", Bm_max_ram );
- + } else {
- + dc_printf( "\tNo RAM limit\n" );
- + }
- + return;
- + }
- + if (dc_optional_string("flush")) {
- + dc_printf( "Total RAM usage before flush: %d bytes\n", bm_texture_ram );
- + int i;
- + for (i = 0; i < MAX_BITMAPS; i++) {
- + if ( bm_bitmaps[i].type != BM_TYPE_NONE ) {
- + bm_free_data(i);
- + }
- + }
- + dc_printf( "Total RAM after flush: %d bytes\n", bm_texture_ram );
- + } else if (dc_optional_string("ram")) {
- + dc_stuff_int(&Bm_max_ram);
- +
- + if (Bm_max_ram > 0) {
- + dc_printf("BmpMan limited to %i, MB's\n", Bm_max_ram);
- + Bm_max_ram *= 1024 * 1024;
- + } else if (Bm_max_ram == 0) {
- + dc_printf("!!BmpMan memory is unlimited!!\n");
- + } else {
- + dc_printf("Illegal value. Must be non-negative.");
- + }
- + } else {
- + dc_printf("<BmpMan> No argument given\n");
- }
- }
- diff --git a/code/controlconfig/controlsconfig.cpp b/code/controlconfig/controlsconfig.cpp
- index 6db4073..442f885 100644
- --- a/code/controlconfig/controlsconfig.cpp
- +++ b/code/controlconfig/controlsconfig.cpp
- @@ -29,6 +29,7 @@
- #include "network/multi_pmsg.h"
- #include "network/multiutil.h"
- #include "parse/scripting.h"
- +#include "debugconsole/console.h"
- #ifndef NDEBUG
- @@ -348,7 +349,7 @@ int Config_allowed[] = {
- #ifndef NDEBUG
- int Show_controls_info = 0;
- -DCF_BOOL(show_controls_info, Show_controls_info)
- +DCF_BOOL(show_controls_info, Show_controls_info);
- #endif
- static int Axes_origin[JOY_NUM_AXES];
- diff --git a/code/debugconsole/console.cpp b/code/debugconsole/console.cpp
- index fcf34f5..72eaf40 100644
- --- a/code/debugconsole/console.cpp
- +++ b/code/debugconsole/console.cpp
- @@ -8,601 +8,489 @@
- */
- -
- -#include <stdlib.h>
- -#include <stdio.h>
- -#include <stdarg.h>
- -#include <setjmp.h>
- -#include <string.h>
- -
- +#include "debugconsole/console.h"
- +#include "debugconsole/consoleparse.h"
- +#include "globalincs/alphacolors.h"
- #include "globalincs/pstypes.h"
- +#include "globalincs/version.h"
- +#include "globalincs/vmallocator.h"
- #include "graphics/font.h"
- #include "io/timer.h"
- #include "io/key.h"
- -#include "globalincs/alphacolors.h"
- #include "osapi/osapi.h"
- -
- -#define MAX_COMMANDS 300
- -
- -static int Num_debug_commands = 0;
- -static debug_command *Debug_command[MAX_COMMANDS];
- -
- -
- -debug_command::debug_command(char *_name, char *_help, void (*_func)() )
- +#include <algorithm>
- +#include <cmath>
- +
- +// ========================= GLOBALS =========================
- +bool Dc_debug_on; //!< Flag used to print console and command debugging strings
- +
- +// Commands and History
- +SCP_string dc_command_str; //!< The entered command line, arguments and all.
- + //!< Is progressively culled from the left as commands, arguments are parsed in DCF's
- +
- +// Misc
- +bool debug_inited = FALSE;
- +uint lastline = 0; // Number of lines written to the console since the last command was processed
- +
- +
- +// ========================= LOCALS ==========================
- +// Text Buffer
- +uint DBROWS = 80; // # of buffer rows
- +uint DBCOLS = 80; // # of buffer columns
- +uint lastwhite = 0; // Last whitespace character encountered, used by putc for 'true' word wrapping
- +ubyte DTABS = 4; //!< Tab size in spaces
- +
- +
- +SCP_deque<SCP_string> dc_buffer;
- +
- +// Display Window
- +uint DROWS = 25;
- +uint DCOLS = 80;
- +const uint DROWS_MIN = 25;
- +const uint DCOLS_MIN = 80;
- +uint dc_scroll_x; // X scroll position (Leftmost character)
- +uint dc_scroll_y; // Y scroll position (Topmost character)
- +int row_height; // Row/Line height, in pixels
- +int col_width; // Col/Character width, in pixels
- +int dc_font = FONT1;
- +
- +SCP_string dc_title;
- +
- +#define SCROLL_X_MAX (DBCOLS - DCOLS)
- +#define SCROLL_Y_MAX (DBROWS - DROWS)
- +
- +// Commands and History
- +uint DCMDS = 40; // Max number of commands to remember
- +const uint DCMDS_MIN = 3;
- +
- +SCP_deque<SCP_string> dc_history;
- +SCP_deque<SCP_string>::iterator last_oldcommand; // Iterator to the last old command. Is reset to the start every new command push.
- +
- +const char dc_prompt[]= "> "; // The prompt c_str
- +SCP_string dc_command_buf; // The command line as shown in the console. Essentially an input buffer for dc_command_str
- +
- +// Local functions
- +/**
- + * @brief Initializes the debug console.
- + */
- +void dc_init(void);
- +
- +/**
- + * @brief Process the entered command string
- + */
- +void dc_do_command(SCP_string *cmd_str);
- +
- +/**
- + * @brief Draws the in-game console.
- + */
- +void dc_draw(bool show_prompt);
- +
- +/**
- + * Draws the cursor
- + * @param [in] cmd_string The formatted command string displayed by dc_draw_window
- + * @param [in] x, y The x and y screen position of the command string
- + */
- +void dc_draw_cursor( SCP_string &cmd_string, int x, int y );
- +
- +/**
- + * Draws the window text
- + */
- +void dc_draw_window(bool show_prompt);
- +
- +/**
- + * @brief Stuffs the given character into the output buffer.
- + * @details Also handles tab alignment, newlines, and maintains the target.
- + */
- +void dc_putc(char c);
- +
- +/**
- + * @brief Predicate function used to sort debug_commands
- + */
- +bool dcmd_less(debug_command *first, debug_command *second);
- +
- +// ============================== IMPLEMENTATIONS =============================
- +void dc_do_command(SCP_string *cmd_str)
- {
- - int i;
- -
- - if ( Num_debug_commands >= MAX_COMMANDS ) {
- - Int3(); // Too many debug console commands!! Increase MAX_COMMANDS!!
- + /**
- + * Grab the first word from the cmd_str
- + * If it is not a literal, ignore it "Invalid keyword: %s"
- + * Search for the command...
- + * Compare the word against valid commands
- + * If command not found, ignore it "Invalid or unknown command: %s"\
- + * Process the command...
- + * Call the function to process the command (the rest of the command line is in the parser)
- + * Function takes care of long_help and status depending on the mode.
- + */
- + SCP_string command;
- + extern SCP_vector<debug_command*> dc_commands; // z64: I don't like this extern here, at all. Nope nope nope.
- +
- + if (cmd_str->empty()) {
- return;
- }
- - for (i=0; i<Num_debug_commands; i++ ) {
- - int ret = stricmp( Debug_command[i]->name, _name );
- -
- - if ( ret == 0) {
- - Int3(); // This debug console command already exists!!!!
- - return;
- - } else if ( ret > 0 ) {
- - break; // Insert it here
- -
- - } else if ( ret < 0 ) {
- - // do nothing
- - }
- - }
- -
- - if ( i < Num_debug_commands ) {
- - // Insert it at element i
- - int j;
- - for (j=Num_debug_commands; j>i; j-- ) {
- - Debug_command[j] = Debug_command[j-1];
- - }
- - Debug_command[i] = this;
- - Num_debug_commands++;
- - } else {
- - Debug_command[Num_debug_commands] = this;
- - Num_debug_commands++;
- - }
- -
- - name = _name;
- - help = _help;
- - func = _func;
- -}
- -
- -// some global variables
- -int Dc_command; // If this is set, then process the command
- -int Dc_help; // If this is set, then print out the help text in the form, "usage: ... \nLong description\n" );
- -int Dc_status; // If this is set, then print out the current status of the command.
- -char *Dc_arg; // The (lowercased) string value of the argument retrieved from dc_arg
- -char *Dc_arg_org; // Dc_arg before it got converted to lowercase
- -uint Dc_arg_type; // The type of dc_arg.
- -char *Dc_command_line; // The rest of the command line, from the end of the last processed arg on.
- -int Dc_arg_int; // If Dc_arg_type & ARG_INT is set, then this is the value
- -ubyte Dc_arg_ubyte; // If Dc_arg_type & ARG_UBYTE is set, then this is the value
- -float Dc_arg_float; // If Dc_arg_type & ARG_FLOAT is set, then this is the value
- -
- -int scroll_times = 0; // incremented each time display scrolls
- -
- -int debug_inited = 0;
- -
- -#define DROWS 25
- -#define DCOLS 80
- -
- -int debug_x=0, debug_y=0;
- -char debug_text[DROWS][DCOLS];
- -
- -
- -static char command_line[1024];
- -static int command_line_pos = 0;
- -#define DEBUG_HISTORY 16
- -static char oldcommand_line[DEBUG_HISTORY][1024];
- -int last_oldcommand=-1;
- -int command_scroll = 0;
- + dc_parse_init(*cmd_str);
- -///=========================== SCANNER =======================
- -typedef enum {
- - LETTER, QUOTE, SPECIAL, EOF_CODE, DIGIT
- -} CHAR_CODE;
- + dc_stuff_string_white(command); // Grab the first token, presumably this is a command
- -typedef enum {
- - NO_TOKEN, IDENTIFIER, NUMBER, STRING
- -} TOKEN_CODE;
- + SCP_vector<debug_command*>::iterator it = find_if(dc_commands.begin(), dc_commands.end(), is_dcmd(command.c_str()));
- -
- -#define MAX_TOKEN_STRING_LENGTH 128
- -
- -char scanner_ch;
- -TOKEN_CODE scanner_token;
- -
- -char scanner_token_string[MAX_TOKEN_STRING_LENGTH];
- -char scanner_word_string[MAX_TOKEN_STRING_LENGTH];
- -char * scanner_bufferp = "";
- -char * scanner_tokenp = scanner_token_string;
- -
- -CHAR_CODE scanner_char_table[256];
- -
- -#define scanner_char_code(x) scanner_char_table[x]
- -
- -void scanner_get_char()
- -{
- - if ( *scanner_bufferp == '\0' ) {
- - scanner_ch = 0;
- + if (it == dc_commands.end()) {
- + dc_printf("Command not found: '%s'\n", command.c_str());
- return;
- - }
- - scanner_ch = *scanner_bufferp++;
- -}
- -
- -void scanner_init()
- -{
- - int ch;
- - for (ch=0; ch<256; ++ch) scanner_char_table[ch] = SPECIAL;
- - for (ch='0'; ch<='9'; ++ch) scanner_char_table[ch] = DIGIT;
- - for (ch='A'; ch<='Z'; ++ch) scanner_char_table[ch] = LETTER;
- - for (ch='a'; ch<='z'; ++ch) scanner_char_table[ch] = LETTER;
- -
- - scanner_char_table['.'] = DIGIT;
- - scanner_char_table['-'] = DIGIT;
- - scanner_char_table['+'] = DIGIT;
- -
- - scanner_char_table['_'] = LETTER;
- - scanner_char_table[34] = QUOTE;
- - scanner_char_table[0] = EOF_CODE;
- -
- - scanner_char_table[':'] = LETTER;
- - scanner_char_table['\\'] = LETTER;
- + } // Else, we found our command
- - scanner_ch = 0;
- -}
- -
- -void scanner_skip_blanks()
- -{
- - while( (scanner_ch ==' ') || (scanner_ch =='\t') )
- - scanner_get_char();
- -}
- -
- -void scanner_downshift_word()
- -{
- - int offset = 'a' - 'A';
- - char * tp;
- + try {
- + (*it)->func(); // Run the command!
- +
- + } catch (errParseString err) {
- + dc_printf("Require string(s) not found: \n");
- + for (int i = 0; i < err.expected_tokens.size(); ++i) {
- + dc_printf("%i: %s\n", err.expected_tokens[i].c_str());
- + }
- - strcpy_s( scanner_word_string, scanner_token_string );
- + dc_printf("Found '%s' instead\n", err.found_token.c_str());
- - tp = scanner_word_string;
- - do {
- - *tp = (char)((*tp>='A') && (*tp <='Z') ? *tp + offset : *tp) ;
- - tp++;
- - } while (*tp != '\0' );
- -}
- + } catch (errParse err) {
- + dc_printf("Invalid argument. Expected %s, found '%s'\n", token_str[err.expected_type], err.found_token.c_str());
- -void scanner_get_word()
- -{
- - while( (scanner_char_code(scanner_ch)==LETTER) || (scanner_char_code(scanner_ch)==DIGIT) ) {
- - *scanner_tokenp++ = scanner_ch;
- - scanner_get_char();
- }
- - *scanner_tokenp = '\0';
- -
- - scanner_token = IDENTIFIER;
- -}
- -
- -void scanner_get_string()
- -{
- - *scanner_tokenp++ = 34;
- - scanner_get_char();
- - while(scanner_ch != 34 ) {
- - *scanner_tokenp++ = scanner_ch;
- - scanner_get_char();
- + // dc_maybe_stuff_string is vulnerable to overflow. Once the errParseOverflow throw class (or w/e) gets
- + // implemented, this last command should be put into its own try{} catch{} block.
- + if (dc_maybe_stuff_string(command)) {
- + dc_printf( "Ignoring the unused command line tail '%s'\n", command.c_str() );
- }
- - scanner_get_char();
- - *scanner_tokenp++ = 34;
- - *scanner_tokenp = '\0';
- - scanner_token = STRING;
- }
- -void scanner_get_token()
- +void dc_draw(bool show_prompt = FALSE)
- {
- - scanner_skip_blanks();
- - scanner_tokenp = scanner_token_string;
- - *scanner_tokenp = 0;
- -
- - switch( scanner_char_code(scanner_ch) ) {
- - case QUOTE: scanner_get_string(); break;
- - case EOF_CODE: scanner_token = NO_TOKEN; break;
- - case DIGIT:
- - case LETTER: scanner_get_word(); break;
- - default:
- - *scanner_tokenp++ = scanner_ch;
- - *scanner_tokenp = '\0';
- - scanner_get_char();
- - scanner_token = IDENTIFIER;
- - break;
- - }
- + gr_clear();
- + gr_set_font(dc_font);
- + gr_set_color_fast( &Color_bright );
- + gr_string( 0x8000, 3, dc_title.c_str(), false );
- - scanner_downshift_word();
- -}
- + gr_set_color_fast( &Color_normal );
- -void scanner_start_command( char * s )
- -{
- - scanner_bufferp = s;
- - scanner_get_char();
- -}
- + dc_draw_window(show_prompt);
- -int Dc_debug_on = 0;
- -jmp_buf dc_bad_arg;
- + gr_flip();
- +}
- -void dc_get_arg(uint type)
- +void dc_draw_cursor( SCP_string &cmd_string, int x, int y )
- {
- - scanner_get_token();
- + int t;
- + int w, h; // gr_string width and height
- - Dc_command_line = scanner_bufferp;
- - Dc_arg_org = scanner_token_string;
- - Dc_arg = scanner_word_string;
- + t = timer_get_fixed_seconds() / (F1_0/3);
- + if ( t & 1 ) {
- + gr_get_string_size( &w, &h, cmd_string.c_str() );
- - if (Dc_debug_on) {
- - dc_printf( "next arg is '%s', was originally '%s'\n", Dc_arg, Dc_arg_org );
- - dc_printf( "Rest of the command line is '%s'\n", Dc_command_line );
- + w %= (DCOLS * Current_font->w);
- + //gr_string( w, debug_y*16, "_" );
- + gr_rect((x + (w + 1)), (y + (h + 1)), 2, Current_font->h, false);
- }
- +}
- - if ( scanner_token == NO_TOKEN ) {
- - Dc_arg_type = ARG_NONE;
- - } else if ( scanner_token == IDENTIFIER ) {
- - Dc_arg_type = ARG_STRING;
- - } else if ( scanner_token == STRING ) {
- - Dc_arg_type = ARG_QUOTE;
- +void dc_draw_window(bool show_prompt)
- +{
- + uint cmd_lines; // Number of lines for the command string
- + uint buffer_lines; // Number of lines from the buffer to draw
- + uint i; // The current row we're drawing
- + uint j; // The current row of the command string we're drawing
- + SCP_string out_str; // The command string + prompt character
- + SCP_string::iterator str_it; // Iterator to out_str
- +
- + out_str = dc_prompt + dc_command_buf;
- + cmd_lines = (out_str.size() / DCOLS) + 1;
- + if (show_prompt) {
- + buffer_lines = DROWS - cmd_lines;
- } else {
- - Dc_arg_type = ARG_STRING;
- + buffer_lines = DROWS;
- }
- - if ( Dc_arg_type & ARG_STRING ) {
- - int i, num_digits, len;
- -
- - len = strlen(Dc_arg);
- - num_digits = 0;
- -
- - for (i=0; i<len; i++) {
- - if ( scanner_char_table[Dc_arg[i]] == DIGIT ) {
- - num_digits++;
- - }
- -
- - if ( num_digits==len ) {
- - Dc_arg_type |= ARG_FLOAT;
- - Dc_arg_float = (float)atof(Dc_arg);
- - if ( !strchr( Dc_arg, '.' )) {
- - Dc_arg_type |= ARG_INT;
- - Dc_arg_int = atoi(Dc_arg);
- - Dc_arg_type |= ARG_UBYTE;
- - Dc_arg_ubyte = (ubyte)atoi(Dc_arg);
- - }
- - } else {
- - if ( (Dc_arg[0] == '0') && (Dc_arg[1] == 'x') ) {
- - char *p;
- - int n;
- - n = strtol(Dc_arg,&p,0);
- - if ( *p == 0 ) {
- - Dc_arg_type |= ARG_INT|ARG_HEX;
- - Dc_arg_int = n;
- - }
- - }
- - }
- - }
- -
- - if (Dc_debug_on) {
- - if ( Dc_arg_type & ARG_FLOAT ) {
- - dc_printf( "Found float number! %f\n", Dc_arg_float );
- - }
- -
- - if ( Dc_arg_type & ARG_INT ) {
- - dc_printf( "Found int number! %d\n", Dc_arg_int );
- - }
- -
- - if ( Dc_arg_type & ARG_UBYTE ) {
- - dc_printf( "Found ubyte number! %d\n", Dc_arg_ubyte );
- - }
- -
- - if ( Dc_arg_type & ARG_HEX ) {
- - dc_printf( "Found hex number! 0x%x\n", Dc_arg_int );
- - }
- - }
- -
- - if ( !stricmp( Dc_arg, "on" ) ) {
- - Dc_arg_type |= ARG_TRUE;
- - }
- - if ( !stricmp( Dc_arg, "true" ) ) {
- - Dc_arg_type |= ARG_TRUE;
- - }
- - if ( !stricmp( Dc_arg, "off" ) ) {
- - Dc_arg_type |= ARG_FALSE;
- - }
- - if ( !stricmp( Dc_arg, "false" ) ) {
- - Dc_arg_type |= ARG_FALSE;
- - }
- + // Ensure the window is not bigger than the buffer
- + CLAMP(DROWS, DROWS_MIN, DBROWS);
- + CLAMP(DCOLS, DCOLS_MIN, DBCOLS);
- - if ( !stricmp( Dc_arg, "+" ) ) {
- - Dc_arg_type |= ARG_PLUS;
- - }
- -
- - if ( !stricmp( Dc_arg, "-" ) ) {
- - Dc_arg_type |= ARG_MINUS;
- - }
- -
- - if ( !stricmp( Dc_arg, "," ) ) {
- - Dc_arg_type |= ARG_COMMA;
- - }
- + // Ensure we don't scroll too far
- + CLAMP(dc_scroll_x, 0, (DBCOLS - DCOLS));
- + if (dc_buffer.size() >= buffer_lines) {
- + CLAMP(dc_scroll_y, 0, (dc_buffer.size() - buffer_lines));
- + } else {
- + dc_scroll_y = 0; // Disallow vscroll until the buffer is larger than the window
- }
- - if ( Dc_arg_type & ARG_INT) {
- - if ( Dc_arg_int ) {
- - Dc_arg_type |= ARG_TRUE;
- - } else {
- - Dc_arg_type |= ARG_FALSE;
- + // Draw the buffer strings
- + for (i = 0; i < buffer_lines; ++i) {
- + if ((i + dc_scroll_y) < dc_buffer.size()) {
- + gr_string(0, ((i * row_height) + row_height), dc_buffer[i + dc_scroll_y].substr(dc_scroll_x).c_str(), false);
- }
- }
- - if ( Dc_arg_type & ARG_UBYTE) {
- - if ( Dc_arg_ubyte ) {
- - Dc_arg_type |= ARG_TRUE;
- - } else {
- - Dc_arg_type |= ARG_FALSE;
- + // Draw the command string w/ padding only if the prompt is active.
- + if (show_prompt) {
- + i += 1; // 1 line between the output and the input text
- + j = 0;
- + gr_set_color_fast(&Color_bright);
- + for (str_it = out_str.begin(); str_it < out_str.end(); ++str_it) {
- + if (j == (DCOLS - 1)) {
- + // Insert a newline char at every place the string needs to return the 'carriage'
- + str_it = out_str.insert(str_it, '\n');
- + j = 0;
- + } else {
- + ++j;
- + }
- }
- - }
- + gr_string(0, ((i * row_height) + row_height), out_str.c_str(), false);
- - if ( !(Dc_arg_type&type) ) {
- - if ( (Dc_arg_type & ARG_NONE) && !(type & ARG_NONE) ) {
- - dc_printf( "Error: Not enough parameters.\n" );
- - } else {
- - dc_printf( "Error: '%s' invalid type\n", Dc_arg );
- - longjmp(dc_bad_arg,1);
- - }
- + dc_draw_cursor(out_str, 0, ((i * row_height)));
- + gr_set_color_fast(&Color_normal);
- }
- }
- -void debug_help();
- -
- -void debug_do_command(char * command)
- +void dc_init(void)
- {
- + extern SCP_vector<debug_command*> dc_commands;
- - int i;
- - int mode = 0;
- -
- - if ( strlen(command) < 1 ) {
- + if (debug_inited) {
- return;
- }
- - Dc_debug_on = 0;
- - Dc_command_line = command;
- - scanner_start_command(command);
- + debug_inited = TRUE;
- - if (setjmp(dc_bad_arg) ) {
- - return;
- - }
- + // Sort debug_commands
- + std::sort(dc_commands.begin(), dc_commands.end(), dcmd_less);
- - dc_get_arg( ARG_ANY );
- + // Init window settings
- + dc_font = FONT1;
- + row_height = (Current_font->h) * 1.5; // Row/Line height, in pixels
- + col_width = Current_font->w; // Col/Character width, in pixels
- + dc_scroll_x = 0;
- + dc_scroll_y = 0;
- + DCOLS = (gr_screen.max_w / col_width) - 1; // Subtract as needed. Windowed mode has some quirks with the resolution
- + DROWS = (gr_screen.max_h / row_height) - 2;
- + DBCOLS = DCOLS;
- + DBROWS = 2 * DROWS;
- - if ( !strcmp( Dc_arg, "debug" ) ) {
- - Dc_debug_on = 1;
- - dc_printf( "Command line: '%s'\n", Dc_command_line );
- - dc_get_arg( ARG_ANY );
- - }
- + // Init History
- + dc_history.clear();
- + dc_history.push_back("");
- + last_oldcommand = dc_history.begin();
- - if ( !stricmp( Dc_arg, "xyzzy" ) ) {
- - dc_printf("Nothing happens.\n");
- - return;
- - }
- -
- - if ( !strcmp( Dc_arg, "?" ) ) {
- - mode = 1;
- - dc_get_arg( ARG_ANY );
- + // Init buffers
- + dc_buffer.clear();
- + dc_buffer.push_back("");
- +
- + dc_command_buf.reserve(MAX_CLI_LEN);
- + dc_command_buf.clear();
- - if ( Dc_arg_type&ARG_NONE ) {
- - debug_help();
- - return;
- - }
- - }
- + sprintf(dc_title, "FreeSpace Open v%i.%i.%i", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_VERSION_BUILD);
- + dc_printf("Debug console started.\n" );
- +}
- - if ( !strcmp( Dc_arg, "help" ) || !strcmp( Dc_arg, "man" ) ) {
- - mode = 2;
- - dc_get_arg( ARG_ANY );
- - if ( Dc_arg_type&ARG_NONE ) {
- - debug_help();
- - return;
- - }
- - }
- +bool dc_pause_output(void)
- +{
- + dc_printf("More to follow. Press any key to continue. ESC halts output...");
- - if ( strstr( Dc_command_line, "?" ) ) {
- - mode = 2;
- - }
- + int key;
- + bool loop;
- + do {
- + loop = true;
- - if ( !(Dc_arg_type&ARG_STRING) ) {
- - dc_printf( "Invalid keyword '%s'\n", Dc_arg );
- - return;
- - }
- + os_poll();
- + dc_draw(FALSE);
- - if (Dc_debug_on) {
- - dc_printf( "Searching for command '%s'\n", Dc_arg );
- - }
- + key = key_inkey();
- + switch (key) {
- + case KEY_ESC:
- + return true;
- + break;
- - for (i=0; i<Num_debug_commands; i++ ) {
- - if ( !stricmp( Debug_command[i]->name, Dc_arg ) ) {
- -
- - if (mode==0) {
- - if (Dc_debug_on) {
- - dc_printf( "Calling function '%s'\n", Dc_arg );
- - }
- - Dc_command = 1;
- - Dc_help = 0;
- - Dc_status = 1;
- - } else if (mode==1) {
- - if (Dc_debug_on) {
- - dc_printf( "Checking status for '%s'\n", Dc_arg );
- - }
- - Dc_command = 0;
- - Dc_help = 0;
- - Dc_status = 1;
- - } else {
- - if (Dc_debug_on) {
- - dc_printf( "Doing help for '%s'\n", Dc_arg );
- - }
- - Dc_command = 0;
- - Dc_help = 1;
- - Dc_status = 0;
- + case KEY_PAGEUP:
- + if (dc_scroll_y > 1) {
- + dc_scroll_y--;
- }
- + break;
- - (*Debug_command[i]->func)();
- -
- - if (mode==0) {
- - dc_get_arg(ARG_ANY);
- - if (!(Dc_arg_type&ARG_NONE)) {
- - dc_printf( "Ignoring the unused command line tail '%s %s'\n", Dc_arg_org, Dc_command_line );
- - }
- + case KEY_PAGEDOWN:
- + if (dc_scroll_y < DBROWS) {
- + dc_scroll_y++;
- + } else {
- + dc_scroll_y = DBROWS;
- }
- + break;
- - return;
- + case KEY_LEFT:
- + // TODO: Scroll Left
- + break;
- + case KEY_RIGHT:
- + // TODO: Scroll Right
- + break;
- + case 0:
- + // No key pressed
- + break;
- + default:
- + // Non-control key pressed, break.
- + loop = false;
- }
- - }
- + } while (loop);
- - dc_printf( "Unknown command '%s'\n", Dc_arg );
- -}
- + dc_printf("\n");
- + return false;
- +};
- -void debug_draw()
- +void dc_printf(const char *format, ...)
- {
- - int i;
- -
- - gr_clear();
- - gr_set_font(FONT1);
- - gr_set_color_fast( &Color_bright );
- - gr_string( 0x8000, 3, "Debug Console" );
- -
- - gr_set_color_fast( &Color_normal );
- -
- - for (i=0; i<DROWS; i++ ) {
- - gr_string( 0, i*16+16, debug_text[i] );
- - }
- -
- - int t = timer_get_fixed_seconds() / (F1_0/3);
- - if ( t & 1 ) {
- - int w,h;
- - char c;
- -
- - c = debug_text[debug_y][command_line_pos+1];
- - debug_text[debug_y][command_line_pos+1] = 0;
- -
- - gr_get_string_size( &w, &h, debug_text[debug_y] );
- + SCP_string tmp;
- + va_list args;
- + SCP_string::iterator tmp_it;
- - //gr_string( w, debug_y*16, "_" );
- - gr_rect(w+1,debug_y*16+1+16,2,14);
- + va_start(args, format);
- + vsprintf(tmp, format, args);
- + va_end(args);
- - debug_text[debug_y][command_line_pos+1] = c;
- + for (tmp_it = tmp.begin(); tmp_it != tmp.end(); ++tmp_it) {
- + dc_putc(*tmp_it);
- }
- -
- - gr_flip();
- }
- -
- -void debug_output( char c )
- +void dc_putc(char c)
- {
- - if ( c == '\t' ) {
- - int next_tab = ((debug_x/28)+1)*28;
- -
- - if ( next_tab >= DCOLS-1 ) {
- - debug_x=0;
- - debug_y++;
- - scroll_times++;
- - if ( debug_y >= DROWS ) {
- - int i;
- - for (i=1; i<DROWS; i++ ) {
- - strcpy_s( debug_text[i-1], debug_text[i] );
- - }
- - debug_y = DROWS-1;
- - debug_x = 0;
- - debug_text[debug_y][debug_x] = 0;
- - }
- - debug_text[debug_y][debug_x] = 0;
- + SCP_string* line_str = &(dc_buffer.back());
- + SCP_string temp_str;
- + int i;
- + int w;
- +
- + if (c == ' ') {
- + /**
- + * Push c onto the temp_str and get its gr_string width
- + *
- + * If we run out of room on the line, or
- + * If we run out of room on the screen, change c to a '\n' and let subsequent block handle it,
- + * Else, push the space onto the line and bail
- + */
- + temp_str = *line_str;
- + temp_str.push_back(c);
- + gr_get_string_size(&w, NULL, temp_str.c_str());
- +
- + if ((temp_str.size() >= DBCOLS) || (w > gr_screen.max_w)) {
- + c = '\n';
- +
- + } else {
- + lastwhite = temp_str.size();
- + *line_str = temp_str;
- return;
- }
- -
- - for ( ; debug_x < next_tab; ) {
- - debug_text[debug_y][debug_x++] = ' ';
- - }
- - debug_text[debug_y][debug_x] = 0;
- - return;
- }
- - if ( (c == '\n') || (debug_x >= DCOLS-1) ) {
- - debug_x=0;
- - debug_y++;
- - scroll_times++;
- - if ( debug_y >= DROWS ) {
- - int i;
- - for (i=1; i<DROWS; i++ ) {
- - strcpy_s( debug_text[i-1], debug_text[i] );
- - }
- - debug_y = DROWS-1;
- - debug_x = 0;
- - debug_text[debug_y][debug_x] = 0;
- - }
- - debug_text[debug_y][debug_x] = 0;
- - if ( c == '\n' ) {
- + if (c == '\t') {
- + /**
- + * Calculate how many spaces to put in to align tabs,
- + * Append temp_str with the spaces and get its gr_string width
- + *
- + * If we run out of room on the line, or
- + * If we run out of room on the screen, change c to a '\n' and let subsequent block handle it,
- + * Else, copy temp_str onto the line, update the lastwhite index, and bail
- + */
- + i = DTABS - (line_str->size() % DTABS);
- + temp_str = *line_str;
- + temp_str.append(i, ' ');
- + gr_get_string_size(&w, NULL, temp_str.c_str());
- +
- + if ((temp_str.size() >= DBCOLS) || (w > gr_screen.max_w)) {
- + c = '\n';
- +
- + } else {
- + lastwhite = temp_str.size();
- + *line_str = temp_str;
- return;
- }
- }
- - debug_text[debug_y][debug_x++] = c;
- - debug_text[debug_y][debug_x] = 0;
- -}
- -
- -void dc_printf(char *format, ...)
- -{
- - char tmp[DCOLS*DROWS];
- - va_list args;
- + if (c == '\n') {
- + /**
- + * Trash whatever char happens to be past (DBCOLS - 1),
- + * Push a blank line onto the dc_buffer from the bottom,
- + * Increment the scroller, if needed,
- + * Trash the topmost line(s) in the buffer,
- + * Reset the lastwhite index,
- + * Increment the lastline counter, and finally
- + * bail
- + */
- + if (line_str->size() > DBCOLS) {
- + line_str->resize(DBCOLS);
- + }
- + dc_buffer.push_back("");
- - va_start(args, format);
- - vsprintf(tmp, format, args);
- - va_end(args);
- + if ((dc_buffer.size() > DROWS) && (dc_scroll_y < SCROLL_Y_MAX)) {
- + dc_scroll_y++;
- + }
- - char *p = tmp;
- - while( *p != '\0' ) {
- - debug_output(*p);
- - p++;
- - }
- -}
- + while (dc_buffer.size() > DBROWS) {
- + dc_buffer.pop_front();
- + }
- -void debug_init()
- -{
- - int i;
- - if ( debug_inited ) {
- + lastwhite = 0;
- + lastline++;
- return;
- }
- - debug_inited = 1;
- + // By this point, c is probably a writable character
- + temp_str = *line_str;
- + temp_str.push_back(c);
- + gr_get_string_size(&w, NULL, temp_str.c_str());
- +
- + if ((temp_str.size() >= DBCOLS) || (w > gr_screen.max_w)) {
- + /**
- + * Word wrapping
- + * Save the word, clear the line of the word, push new line with the word on it
- + * Update scroll_y, if needed,
- + * Pop off old lines, and finally
- + * Push new character onto the new line
- + */
- + temp_str = line_str->substr(lastwhite);
- + line_str->resize(lastwhite);
- + dc_buffer.push_back(temp_str);
- + line_str = &dc_buffer.back();
- +
- + if ((dc_buffer.size() > DROWS) && (dc_scroll_y < SCROLL_Y_MAX)) {
- + dc_scroll_y++;
- + }
- - debug_x=0;
- - debug_y=0;
- + while (dc_buffer.size() > DBROWS) {
- + dc_buffer.pop_front();
- + }
- - for (i=0; i<DROWS; i++ ) {
- - debug_text[i][0] = 0;
- + lastwhite = 0;
- + lastline++;
- + line_str->push_back(c);
- + return;
- }
- - dc_printf("Debug console started.\n" );
- + // Else, just push the char onto the line
- + line_str->push_back(c);
- }
- -void debug_console( void (*_func)() )
- +bool dcmd_less(debug_command *first, debug_command *second)
- {
- - int done = 0;
- + return (strcmp(first->name, second->name) < 0);
- +}
- - scanner_init();
- +void debug_console(void (*_func)(void))
- +{
- + int done = 0;
- while( key_inkey() ) {
- os_poll();
- }
- if ( !debug_inited ) {
- - debug_init();
- + dc_init();
- }
- - debug_draw();
- + dc_draw(TRUE);
- while (!done) {
- // poll the os
- @@ -613,135 +501,98 @@ void debug_console( void (*_func)() )
- case KEY_SHIFTED+KEY_ENTER:
- case KEY_ESC:
- - done=1; break;
- + done = TRUE;
- + break;
- case KEY_BACKSP:
- - if ( command_line_pos > 0 ) {
- - command_line[--command_line_pos] = 0;
- + if (!dc_command_buf.empty()) {
- + dc_command_buf.erase(dc_command_buf.end() - 1);
- }
- break;
- case KEY_F3:
- - if ( last_oldcommand > -1 ) {
- - strcpy_s( command_line, oldcommand_line[last_oldcommand] );
- - command_line_pos = strlen(command_line);
- - command_line[command_line_pos] = 0;
- - }
- - break;
- -
- case KEY_UP:
- - command_scroll--;
- - if (command_scroll<0) {
- - command_scroll = last_oldcommand;
- + if (last_oldcommand < (dc_history.end() - 1)) {
- + ++last_oldcommand;
- }
- - if ( command_scroll > -1 ) {
- - strcpy_s( command_line, oldcommand_line[command_scroll] );
- - command_line_pos = strlen(command_line);
- - command_line[command_line_pos] = 0;
- - }
- + dc_command_buf = *last_oldcommand;
- break;
- case KEY_DOWN:
- - command_scroll++;
- - if (command_scroll>last_oldcommand) {
- - command_scroll = 0;
- - }
- - if (command_scroll>last_oldcommand) {
- - command_scroll = -1;
- + if (last_oldcommand > dc_history.begin()) {
- + --last_oldcommand;
- }
- - if ( command_scroll > -1 ) {
- - strcpy_s( command_line, oldcommand_line[command_scroll] );
- - command_line_pos = strlen(command_line);
- - command_line[command_line_pos] = 0;
- - }
- - break;
- - case KEY_ENTER: {
- - debug_output( '\n' );
- - debug_draw();
- -
- - debug_do_command(command_line);
- + dc_command_buf = *last_oldcommand;
- + break;
- - int i, found = 0;
- - for (i=0; i<=last_oldcommand; i++ ) {
- - if (!stricmp( oldcommand_line[i], command_line )) {
- - found = 1;
- - }
- - }
- - if ( !found ) {
- - if ( last_oldcommand < DEBUG_HISTORY-1 ) {
- - last_oldcommand++;
- - strcpy_s( oldcommand_line[last_oldcommand], command_line);
- - } else {
- - int iLoop;
- - for (iLoop=0; iLoop<last_oldcommand; iLoop++ ) {
- - strcpy_s( oldcommand_line[iLoop], oldcommand_line[iLoop+1] );
- - }
- - strcpy_s( oldcommand_line[last_oldcommand], command_line);
- - }
- + case KEY_PAGEUP:
- + if (dc_scroll_y > 1) {
- + dc_scroll_y--;
- }
- + break;
- - debug_output( '\n' );
- - command_line_pos = 0;
- - command_line[command_line_pos] = 0;
- + case KEY_PAGEDOWN:
- + if (dc_scroll_y < (DBROWS - DROWS)) {
- + dc_scroll_y++;
- + } else {
- + dc_scroll_y = (DBROWS - DROWS);
- + }
- + break;
- - command_scroll = 0;
- + case KEY_ENTER:
- + dc_scroll_y = (DBROWS - DROWS); // Set the scroll to look at the bottom
- + last_oldcommand = dc_history.begin(); // Reset the last oldcommand
- + lastline = 0; // Reset the line counter
- +
- + // Clear the command line on the window, but don't print the prompt until the command has processed
- + // Stuff a copy of the command line onto the history
- + // Search for the command
- + // If not found:
- + // abort,
- + // dc_printf("Error: Invalid or Missing command %s", cmd.c_str()), and
- + // dc_printf(dc_prompt) when ready for input
- + // Call the function for that command, and strip the cmd token from the command line string
- + if (dc_command_buf.empty()) {
- + dc_printf("No command given.\n");
- + break;
- + } // Else, continue to process the cmd_line
- +
- + // z64: Thread Note: Maybe lock a mutex here to allow a previous DCF to finish/abort before starting a new one
- + // z64: We'll just assume we won't be here unless a command has finished...
- + dc_history.push_front(dc_command_buf); // Push the command onto the history queue
- + last_oldcommand = dc_history.begin(); // Reset oldcommand
- +
- + while (dc_history.size() > DCMDS) {
- + dc_history.pop_back(); // Keep the commands less than or equal to DCMDS
- + }
- - }
- + dc_command_str = dc_command_buf; // Xfer to the command string for processing
- + dc_command_buf.resize(0); // Nullify the buffer
- + dc_printf("%s%s\n", dc_prompt, dc_command_str.c_str()); // Print the command w/ prompt.
- + dc_draw(FALSE); // Redraw the console without the command line.
- + dc_do_command(&dc_command_str); // Try to do the command
- break;
- - default: {
- - ubyte c = (ubyte)key_to_ascii(k);
- - if ( c != 255 ) {
- - command_line[command_line_pos++] = c;
- - command_line[command_line_pos] = 0;
- - }
- +
- + default:
- + // Not any of the control key codes, so it's probably a letter or number.
- + ubyte c = (ubyte)key_to_ascii(k);
- + if ((c != 255) && (dc_command_buf.size() < MAX_CLI_LEN)) {
- + dc_command_buf.push_back(c);
- }
- }
- - strcpy_s( debug_text[debug_y], ">" );
- - strcat_s( debug_text[debug_y], command_line );
- - debug_draw();
- -
- + // Do the passed function
- if ( _func ) {
- _func();
- }
- +
- + // All done, and ready for new entry
- + dc_draw(TRUE);
- }
- while( key_inkey() ) {
- os_poll();
- }
- }
- -
- -void debug_help()
- -{
- - int s, i;
- -
- - dc_printf( "Available functions:\n\n" );
- -
- - s = scroll_times;
- - for (i=0; i<Num_debug_commands; i++ ) {
- - dc_printf( " %s - %s\n", Debug_command[i]->name, Debug_command[i]->help );
- -
- - if ( scroll_times - s > DROWS - 3 ) {
- - int k;
- - dc_printf( " Press a key...B for back\n" );
- - debug_draw();
- - k = key_getch();
- - s = scroll_times;
- - if ( k == KEY_B ) {
- - i -= ((DROWS-3)*2);
- - if ( i <= 0 ) {
- - i = -1;
- - }
- - }
- - }
- - debug_draw();
- - }
- - dc_printf( "\n" );
- -
- - dc_printf( "Typing '? function_name' will give the current status.\n" );
- - dc_printf( "Typing 'function_name ?' will give help on the function.\n" );
- - dc_printf( "Typing ? or help will give you help.\n");
- - dc_printf( "F3 selects last command line.\n" );
- -}
- diff --git a/code/debugconsole/console.h b/code/debugconsole/console.h
- new file mode 100644
- index 0000000..c16246e
- --- /dev/null
- +++ b/code/debugconsole/console.h
- @@ -0,0 +1,268 @@
- +#ifndef _CONSOLE_H
- +#define _CONSOLE_H
- +/*
- + * z64555's debug console, created for the FreeSpace Source Code project
- + *
- + * Portions of this source code are based on works by Volition, Inc. circa 1999. You may not sell or otherwise
- + * commercially exploit the source or things you created based on the source.
- + */
- +
- +/**
- + * @file console.h
- + * @brief An overhauled/updated debug console to allow monitoring, testing, and general debugging of new features.
- + *
- + * @details
- + * 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 --)
- + */
- +
- +#include "debugconsole/consoleparse.h"
- +#include "globalincs/pstypes.h"
- +#include "globalincs/vmallocator.h"
- +
- +class debug_command;
- +
- +/**
- + * @def DCF
- + *
- + * @brief The potent DCF macro, used to define new debug commands for the console.
- + *
- + * @param function_name[in] The name of the function, as shown in the debug console
- + * @param help_txt[in] The short-help text, as shown as listed from the 'help' command
- + *
- + * @details
- + * 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 )
- + */
- +#define DCF(function_name, help_text) \
- + void dcf_##function_name(); \
- + debug_command dcmd_##function_name(#function_name, help_text, dcf_##function_name); \
- + void dcf_##function_name()
- +
- +/**
- + * @def Shortcut for debug commands that toggle a bool, such as Show_lightning
- + *
- + * @param [in] function_name Name of the function, as shown in the debug console
- + * @param [in] bool_variable Name of the variable to allow toggling.
- + */
- +#define DCF_BOOL(function_name, bool_variable) \
- + 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) bool_variable; \
- + 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)) { \
- + bool_variable ? (bool_variable = 0) : (bool_variable = 1); \
- + } else { \
- + bool_tmp ? (bool_variable = 1) : (bool_variable = 0); \
- + } \
- + dc_printf("%s set to %\ns", #bool_variable, (bool_variable ? "TRUE" : "FALSE")); \
- + }
- +
- +
- +/**
- + * @def Same as DCF_BOOL, but with custom help strings
- + *
- + * @param [in] function_name Name of the function, as shown in the debug console
- + * @param [in] bool_variable Name of the variable to allow toggling.
- + */
- +#define DCF_BOOL2(function_name, bool_variable, short_help, long_help) \
- + 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; \
- + } \
- + }
- +
- + /**
- + * @def Shortcut for single-variable setters/monitors
- + *
- + * @param [in] function_name
- + * @param [in] float_variable
- + * @param [in] short_help
- + */
- + #define DCF_FLOAT(function_name, float_variable, short_help) \
- + void dcf_##function_name(); \
- + debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
- + void dcf_##function_name() { \
- + float value; \
- + 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); \
- + }
- +
- + /**
- + * @def Shortcut for single-variable setters/monitors with lower/upper bounds clamping
- + *
- + * @param [in] function_name
- + * @param [in] float_variable
- + * @param [in] lower_bounds
- + * @param [in] upper_bounds
- + * @param [in] short_help
- + */
- + #define DCF_FLOAT2(function_name, float_variable, lower_bounds, upper_bounds, short_help) \
- + void dcf_##function_name(); \
- + debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
- + void dcf_##function_name() { \
- + float value; \
- + 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); \
- + CLAMP(float_variable, lower_bounds, upper_bounds); \
- + float_variable = value; \
- + dc_printf("%s set to %f\n", #float_variable, float_variable); \
- + }
- +
- + /**
- + * @def Shortcut for single-variable setters/monitors
- + *
- + * @param [in] function_name
- + * @param [in] int_variable
- + * @param [in] short_help
- + */
- + #define DCF_INT(function_name, int_variable, short_help) \
- + void dcf_##function_name(); \
- + debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
- + void dcf_##function_name() { \
- + int value; \
- + 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); \
- + }
- +
- + /**
- + * @def Shortcut for single-variable setters/monitors with lower/upper bounds clamping
- + *
- + * @param [in] function_name
- + * @param [in] int_variable
- + * @param [in] lower_bounds
- + * @param [in] upper_bounds
- + * @param [in] short_help
- + */
- + #define DCF_INT2(function_name, int_variable, lower_bounds, upper_bounds, short_help) \
- + void dcf_##function_name(); \
- + debug_command dcmd_##function_name(#function_name, short_help, dcf_##function_name ); \
- + void dcf_##function_name() { \
- + int value; \
- + 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); \
- + }
- +
- +/**
- + * @class debug_command
- + * @brief Class to aggregate a debug command with its name (as shown in the console) and short help.
- + *
- + * @details
- + * Note: Long help, as evoked by '<command> help', should be handled by the function itself. It is recommended
- + * that arguments that have sub-arguments be in their own function, so as to aide in organization and to keep the
- + * size of the command function down.
- + */
- +class debug_command {
- +public:
- + const char *name; //!< The name of the command, as shown in the debug console
- + const char *help; //!< The short help string, as shown by 'help <command>'
- + void (*func)(); //!< Pointer to the function that to run when this command is evoked
- +
- + /**
- + * @brief Adds a debug command to the debug_commands map, if it isn't in there already.
- + *
- + * @details The DCF macro more or less guarantees that a command won't be duplicated on compile time. But no harm in
- + * some extra caution.
- + */
- + debug_command(const char *name, const char *help, void (*func)());
- +};
- +
- +/**
- + * @class is_dcmd
- + * @brief Predicate class used to search for a dcmd by name
- + */
- +class is_dcmd {
- +public:
- + const char *name;
- +
- + is_dcmd(const char *_name) : name(_name) {};
- +
- + bool operator() (debug_command* dcmd)
- + {
- + return (strcmp(name, dcmd->name) == 0);
- + }
- +};
- +
- +extern bool Dc_debug_on;
- +extern uint lastline;
- +extern SCP_string dc_command_str; // The rest of the command line, from the end of the last processed arg on.
- +
- +/**
- + * @brief Pauses the output of a command and allows user to scroll through the output history.
- + *
- + * @details 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.
- + */
- +bool dc_pause_output(void);
- +
- +/**
- + * @brieft Prints the given char string to the debug console
- + * @details See the doc for std::printf() for formating and more details
- + */
- +void dc_printf(const char *format, ...);
- +
- +/**
- + * @brief Opens and processes the debug console. (Blocking call)
- + * @details TODO: Make this a non-blocking call so that the game can still run while the debug console is open.
- + */
- +void debug_console(void (*func)(void) = NULL);
- +
- +#endif // _CONSOLE_H
- \ No newline at end of file
- diff --git a/code/debugconsole/consolecmds.cpp b/code/debugconsole/consolecmds.cpp
- new file mode 100644
- index 0000000..25dd8c7
- --- /dev/null
- +++ b/code/debugconsole/consolecmds.cpp
- @@ -0,0 +1,123 @@
- +/*
- + * z64555's debug console
- + * Created for the FreeSpace Source Code project
- + *
- + * Portions of this source code are based on works by Volition, Inc. circa
- + * 1999. You may not sell or otherwise commercially exploit the source or things you
- + * created based on the source
- + */
- +
- +/**
- + * @file consolecmds.cpp
- + *
- + * @brief This file contains the "built-in" commands for the debug console, and is listed by the 'help' and '?' commands
- + *
- + * @details
- + * All other debug commands should be in their respective files and added to the console with the DCF macro. For
- + * further documentation, please see console.h
- + */
- +
- +#include "debugconsole/console.h"
- +#include "debugconsole/consoleparse.h"
- +#include "globalincs/pstypes.h"
- +#include "globalincs/vmallocator.h"
- +#include "io/key.h"
- +
- +#include <algorithm>
- +
- +// ========================= GLOBALS =========================
- +SCP_vector<debug_command*> dc_commands;
- +typedef SCP_vector<debug_command*>::iterator dc_commands_it;
- +
- +// ========================= LOCALS ==========================
- +// dcf_shell commands
- +void dc_shell_font( void );
- +void dc_shell_resize( void );
- +void dc_shell_resize_buf( void );
- +
- +// =================== class debug_command ===================
- +debug_command::debug_command(const char *_name, const char *_help, void (*_func)())
- + : name(_name), help(_help), func(_func)
- +{
- + dc_commands_it it = std::find_if(dc_commands.begin(), dc_commands.end(), is_dcmd(_name));
- +
- + if (it != dc_commands.end()) {
- + Int3(); // Command already exists! Somebody didn't use the DCF macro as they should've...
- + }
- +
- + dc_commands.push_back(this);
- +}
- +
- +// ============================== IMPLEMENTATIONS =============================
- +
- +DCF(debug, "Runs a command in debug mode.")
- +{
- + SCP_string command = "";
- + Dc_debug_on = true;
- +
- + dc_stuff_string_white(command);
- +
- + if (command == "") {
- + dc_printf("<debug> No command given\n");
- + return;
- + } // Else, command is present.
- +
- + dc_commands_it it = std::find_if(dc_commands.begin(), dc_commands.end(), is_dcmd(command.c_str()));
- +
- + if (it == dc_commands.end()) {
- + dc_printf("<debug> Command not found: '%s'\n", command.c_str());
- + return;
- + } // Else, command exists. Run it.
- +
- + dc_printf("<debug> Executing command: '%s'\n", command.c_str());
- + // try {
- + (*it)->func();
- + // } catch {
- + // }
- +
- + Dc_debug_on = false;
- +}
- +
- +DCF(help, "Displays the help list." )
- +{
- + extern uint DBROWS;
- +
- + SCP_string command = "";
- +
- + dc_maybe_stuff_string_white(command);
- + if ((command == "help") || (command == "man"))
- + {
- + // Moron filter :D
- + dc_printf("GTVA Command: Sorry pilot. You're on your own.\n");
- + return;
- +
- + } else if (command != "") {
- + dc_commands_it it = find_if(dc_commands.begin(), dc_commands.end(), is_dcmd(command.c_str()));
- +
- + if (it == dc_commands.end()) {
- + dc_printf("Command not found: '%s'\n", command.c_str());
- + return;
- + }
- +
- + dc_printf("%s\n", (*it)->help);
- + return;
- + } // Else, command line is empty, print out the help list
- +
- + dc_printf("FreeSpace Open Debug Console\n");
- + dc_printf(" These commands are defined internally.\n");
- + dc_printf(" Typing 'help function_name' will give the short help on the function.\n");
- + dc_printf(" Some functions may have detailed help, try passing \"help\" or \"--help\" to them.");
- + dc_printf(" F3 selects last command line. Up and Down arrow keys scroll through the command history\n");
- + dc_printf("\n");
- +
- + dc_printf(" Available commands:\n");
- + for (dc_commands_it it = dc_commands.begin(); it != dc_commands.end(); ++it) {
- + if (((lastline % DBROWS) == 0) && (lastline != 0)) {
- + dc_pause_output();
- + }
- +
- + dc_printf(" %s - %s\n", (*it)->name, (*it)->help);
- + }
- +}
- +
- +debug_command dc_man("man", "Also displays the help list", dcf_help);
- diff --git a/code/debugconsole/consoleparse.cpp b/code/debugconsole/consoleparse.cpp
- new file mode 100644
- index 0000000..7ab5c18
- --- /dev/null
- +++ b/code/debugconsole/consoleparse.cpp
- @@ -0,0 +1,1460 @@
- +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- +// Command-line parsing functions for z64555's debug console, created for the FreeSpace Source Code project
- +//
- +// Portions of this source code are based on works by Volition, Inc. circa 1999. You may not sell or otherwise
- +// commercially exploit the source or things you created based on the source.
- +//
- +// This file contains documentation on locally referenced functions. For documentation on globally referenced
- +// functions, see consoleparse.h
- +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- +
- +/////////////////
- +// Testing Goals
- +// Breakpoints are set at places that need testing:
- +// * the value of endptr strtol and strtoul needs to investigated, according to cplusplus.com, *endptr = end of the string that was successfully converted
- +// TODO: Make a fast version of the parse_long, parse_ulong, etc. That just checks the first 1-3 characters. The fast version will be used in retail builds while the slow/safe version will be in debug's
- +////////////////
- +#include "debugconsole/consoleparse.h"
- +
- +#include "debugconsole/console.h"
- +#include "globalincs/pstypes.h"
- +#include "parse/parselo.h"
- +
- +#include <algorithm>
- +#include <cmath>
- +#include <cstdarg>
- +#include <cstring>
- +#include <limits.h>
- +
- +
- +// ========================= LOCALS =========================
- +char Command_string[MAX_CLI_LEN]; //!< Command string buffer.
- +char *Cp = NULL; //!< Pointer to the commant string
- +
- +enum state_int {
- + si_start = 0,
- + si_end = 1,
- + si_invalid,
- + si_sign, //!< Sign character, '-' '+'
- + si_prefix, //!< prefix character sequence, 0b, 0o, or 0x
- + si_numeral, //!< Numeral state, 0 - 9
- + si_numeral_bin, //!< Numeral altstate, 0, 1
- + si_numeral_octal, //!< Numeral altstate, 0 - 7
- + si_numeral_hex //!< Numeral altstate, 0 - 9 and 'a' - 'f'
- +};
- +
- +enum state_float {
- + sf_start = 0,
- + sf_end = 1,
- + sf_invalid,
- + sf_sign, //!< Sign character for mantessa
- + sf_whole, //!< Whole value numeral
- + sf_decimal, //!< Decimal character
- + sf_fraction, //!< Fractional value numeral
- + sf_expprefix, //!< Exponent prefix, 'e', 'E'
- + sf_expsign, //!< Exponent sign
- + sf_exponent //!< Exponent value numeral
- +};
- +
- +bool ch_is_sign(char ch);
- +bool ch_is_numeral(char ch);
- +bool ch_is_decimal(char ch);
- +bool ch_is_binary(char ch);
- +bool ch_is_octal(char ch);
- +bool ch_is_hex(char ch);
- +
- +bool ch_is_prefix(char ch);
- +bool ch_is_binary_prefix(char ch);
- +bool ch_is_octal_prefix(char ch);
- +bool ch_is_hex_prefix(char ch);
- +bool ch_is_exp_prefix(char ch);
- +
- +/**
- + * @brief Returns/Advances past a single token
- + *
- + * @details Similar in operation to dc_stuff_string_white, but won't throw any error messages and will only grab the
- + * first word. (dc_stuff_string_white may grab quoted strings)
- + */
- +void dc_get_token(SCP_string &out_str);
- +
- +/**
- + * @brief Returns a single token, but does not advances Cp
- + *
- + * @details Similar in operation to dc_stuff_string_white, but won't throw any error messages and will only grab the
- + * first word. (dc_stuff_string_white may grab quoted strings).
- + */
- +void dc_get_token_no_advance(SCP_string &out_str);
- +
- +/**
- + * @brief Parses a double-precision floating point type. Supports, Whole, Fractional, and Mixed numbers, and supports
- + * scientific notation (exponent prefixed by 'e' or 'E').
- + *
- + * @param[in] ch Points to the start of the string to parse
- + * @param[in] type The expected type. is thrown along with ch when an unexpected/malformed float is found
- + *
- + * @ret The value of the parsed token
- + * @details
- + * The returned double may be cast to a single-precision float, but be sure to check it before doing so!
- + */
- +double dc_parse_double(const char *ch, dc_token type);
- +
- +/**
- + * @brief Parses a long integral type. Supports decimal, binary, octal, and hexidecimal strings.
- + *
- + * @param[in] ch Points to the start of the string to parse.
- + * @param[in] type The expected type. Is thrown along with ch when an unexpected/malformed integral is found
- + *
- + * @details
- + * ! Non-decimal values must be prefixed by their corresponding sequence. Binary: "0b", Octal: "0o", Hex: "0x"
- + *
- + * The returned long may be cast to a smaller integral, but be sure to check it before doing so!
- + *
- + * The only thing left making this function specific to the DC is the expected type. So, if you want to use this
- + * for parsing something other than the debug CL, you'll have to make a set of errParse classes that take a
- + * different expected type.
- + */
- +long dc_parse_long(const char *ch, dc_token type);
- +
- +/**
- + * @brief Parses an unsigned long integral type. Supports decimal, binary, octal, and hexidecimal strings.
- + *
- + * @param[in] ch Points to the start of the string to parse.
- + * @param[in] type The expected type. Is thrown along with ch when an unexpected/malformed integral is found
- + *
- + * @details
- + * ! Non-decimal values must be delimited by their corresponding sequence. Binary: "0b", Octal: "0o", Hex: "0x"
- + * The returned long may be cast to a smaller integral, but be sure to check it before doing so!
- + * The only thing left making this function specific to the DC is the expected type. So, if you want to use this
- + * for parsing something other than the debug CL, you'll have to make a set of errParse classes that take a
- + * different expected type.
- + */
- +ulong dc_parse_ulong(const char *ch, dc_token type);
- +
- +// State processes for dc_parse_double
- +state_float dc_parse_double_sign(const char* &ch_ptr, SCP_string &buffer_str);
- +state_float dc_parse_double_whole(const char* &ch_ptr, SCP_string &buffer_str);
- +state_float dc_parse_double_decimal(const char* &ch_ptr, SCP_string &buffer_str);
- +state_float dc_parse_double_fraction(const char* &ch_ptr, SCP_string &buffer_str);
- +state_float dc_parse_double_expprefix(const char* &ch_ptr, SCP_string &buffer_str);
- +state_float dc_parse_double_expsign(const char* &ch_ptr, SCP_string &buffer_str);
- +state_float dc_parse_double_exponent(const char* &ch_ptr, SCP_string &buffer_str);
- +
- +// State processes for dc_parse_long and dc_parse_ulong.
- +state_int dc_parse_long_prefix(const char* &ch_ptr, SCP_string &buffer_str, int &base);
- +state_int dc_parse_long_sign(const char* &ch_ptr, SCP_string &buffer_str);
- +state_int dc_parse_long_numeral(const char* &ch_ptr, SCP_string &buffer_str);
- +state_int dc_parse_long_numeral_bin(const char* &ch_ptr, SCP_string &buffer_str);
- +state_int dc_parse_long_numeral_hex(const char* &ch_ptr, SCP_string &buffer_str);
- +state_int dc_parse_long_numeral_octal(const char* &ch_ptr, SCP_string &buffer_str);
- +
- +
- +// ============================== IMPLEMENTATIONS =============================
- +inline
- +bool ch_is_sign(char ch)
- +{
- + return ((ch == '-') || (ch == '+'));
- +}
- +
- +inline
- +bool ch_is_numeral(char ch)
- +{
- + return ((ch >= '0') && (ch <= '9'));
- +}
- +
- +inline
- +bool ch_is_decimal(char ch)
- +{
- + return (ch == '.');
- +}
- +
- +inline
- +bool ch_is_binary(char ch)
- +{
- + return ((ch == '0') || (ch == '1'));
- +}
- +
- +inline
- +bool ch_is_octal(char ch)
- +{
- + return ((ch >= '0') && (ch <= '7'));
- +}
- +
- +inline
- +bool ch_is_hex(char ch)
- +{
- + return (((ch >= '0') && (ch <= '9')) || ((ch >= 'a') && (ch <= 'f')) || ((ch >= 'A') && (ch <= 'F')));
- +};
- +
- +inline
- +bool ch_is_prefix(char ch)
- +{
- + return (ch == '0');
- +}
- +
- +inline
- +bool ch_is_binary_prefix(char ch)
- +{
- + return ((ch == 'b') || (ch == 'B'));
- +}
- +
- +inline
- +bool ch_is_octal_prefix(char ch)
- +{
- + return ((ch == 'o') || (ch == 'O'));
- +}
- +
- +inline
- +bool ch_is_hex_prefix(char ch)
- +{
- + return ((ch == 'x') || (ch == 'X'));
- +}
- +
- +inline
- +bool ch_is_exp_prefix(char ch)
- +{
- + return ((ch == 'e') || (ch == 'E'));
- +}
- +
- +void dc_get_token(SCP_string &out_str) {
- + size_t count = 0;
- + char *c_ptr;
- +
- + Assert(Cp);
- +
- + dc_ignore_gray_space();
- +
- + out_str = "";
- + // Bail if we're at the terminator
- + if (*Cp == '\0') {
- + return;
- + }
- +
- + // Scan the string, stopping at grayspace, null terminator, or before we go over MAX_TOKEN_LENGTH
- + c_ptr = Cp;
- + while (!is_gray_space(*c_ptr) && (*c_ptr != '\0') && (count < MAX_TOKEN_LENGTH)) {
- + count++;
- + c_ptr++;
- + }
- +
- + // Copy string into out_str
- + out_str.assign(Cp, count);
- +
- + // Advance the parser pointer past what we copied
- + Cp = c_ptr;
- +}
- +
- +void dc_get_token_no_advance(SCP_string &out_str) {
- + size_t count = 0;
- + char *c_ptr;
- +
- + Assert(Cp);
- +
- + dc_ignore_gray_space();
- +
- + out_str = "";
- + // Bail if we're at the terminator
- + if (*Cp == '\0') {
- + return;
- + }
- +
- + // Scan the string, stopping at grayspace, null terminator, or before we go over MAX_TOKEN_LENGTH
- + c_ptr = Cp;
- + while (!is_gray_space(*c_ptr) && (*c_ptr != '\0') && (count < MAX_TOKEN_LENGTH)) {
- + count++;
- + c_ptr++;
- + }
- +
- + // Copy string into out_str
- + out_str.assign(Cp, count);
- +}
- +
- +void dc_ignore_white_space(void) {
- + while (is_white_space(*Cp) && (*Cp != '\0')) {
- + Cp++;
- + }
- +}
- +
- +void dc_ignore_gray_space(void) {
- + while (is_gray_space(*Cp) && (*Cp != '\0')) {
- + Cp++;
- + }
- +}
- +
- +bool dc_maybe_stuff_float(float *f)
- +{
- + dc_ignore_gray_space();
- +
- + if (*Cp != '\0') {
- + dc_stuff_float(f);
- + return true;
- +
- + } else {
- + *f = 0;
- + return false;
- + }
- +}
- +
- +bool dc_maybe_stuff_int(int *i)
- +{
- + dc_ignore_gray_space();
- +
- + if (*Cp != '\0') {
- + dc_stuff_int(i);
- + return true;
- + } else {
- + *i = 0;
- + return false;
- + }
- +}
- +
- +bool dc_maybe_stuff_uint(uint *i)
- +{
- + dc_ignore_gray_space();
- +
- + if (*Cp != '\0') {
- + dc_stuff_uint(i);
- + return true;
- + } else {
- + *i = 0;
- + return false;
- + }
- +}
- +
- +bool dc_maybe_stuff_ubyte(ubyte *i)
- +{
- + dc_ignore_gray_space();
- +
- + if (*Cp != '\0') {
- + dc_stuff_ubyte(i);
- + return true;
- + } else {
- + *i = 0;
- + return false;
- + }
- +}
- +
- +bool dc_maybe_stuff_boolean(bool *b)
- +{
- + dc_ignore_gray_space();
- +
- + if (*Cp != '\0') {
- + dc_stuff_boolean(b);
- + return true;
- + } else {
- + *b = false;
- + return false;
- + }
- +}
- +
- +bool dc_maybe_stuff_boolean(int *i)
- +{
- + dc_ignore_gray_space();
- +
- + if (*Cp != '\0') {
- + dc_stuff_boolean(i);
- + return true;
- + } else {
- + *i = 0;
- + return false;
- + }
- +}
- +
- +bool dc_maybe_stuff_string(char *out_str, size_t maxlen)
- +{
- + size_t count = 0;
- + char *c_ptr = Cp;
- +
- + Assert(Cp);
- + Assert(out_str);
- +
- + // Advance past grayspace, stopping at null terminator
- + while (is_gray_space(*c_ptr) && (*c_ptr != '\0')) {
- + c_ptr++;
- + }
- +
- + // Bail if we're at the terminator
- + if (*c_ptr == '\0') {
- + return false;
- + }
- +
- + // Scan the string, stopping at null terminator, or before we overflow
- + while ((*c_ptr != '\0') && (count < maxlen)) {
- + count++;
- + c_ptr++;
- + }
- +
- + // Bail if overflow
- + if (count == maxlen) {
- + throw errParse("", DCT_STRING);
- + }
- +
- + // Copy string into out_str
- + strncpy(out_str, Cp, count);
- +
- + // Advance the parser pointer past what we copied
- + Cp = c_ptr;
- +
- + return true;
- +}
- +
- +bool dc_maybe_stuff_string(SCP_string &out_str)
- +{
- + size_t count = 0;
- + char *c_ptr = Cp;
- +
- + Assert(Cp);
- +
- + // Advance past grayspace, stopping at null terminator
- + while (is_gray_space(*c_ptr) && (*c_ptr != '\0')) {
- + c_ptr++;
- + }
- +
- + // Bail if we're at the terminator
- + if (*c_ptr == '\0') {
- + return false;
- + }
- +
- + // Scan the string, stopping at null terminator, or before we overflow
- + while ((*c_ptr != '\0') && (count < out_str.max_size())) {
- + count++;
- + c_ptr++;
- + }
- +
- + // Bail if overflow
- + if (count == out_str.max_size()) {
- + return false;
- + }
- +
- + // Copy string into out_str
- + out_str.assign(Cp, count);
- +
- + // Advance the parser pointer past what we copied
- + Cp = c_ptr;
- +
- + return true;
- +}
- +
- +bool dc_maybe_stuff_string_white(char *str, size_t len)
- +{
- + dc_ignore_gray_space();
- +
- + if (*Cp != '\0') {
- + dc_stuff_string_white(str, len);
- + return true;
- + } else {
- + *str = '\0';
- + return false;
- + }
- +}
- +
- +bool dc_maybe_stuff_string_white(SCP_string &str)
- +{
- + dc_ignore_gray_space();
- +
- + if (*Cp != '\0') {
- + dc_stuff_string_white(str);
- + return true;
- + } else {
- + str = "";
- + return false;
- + }
- +}
- +
- +void dc_required_string(char *pstr)
- +{
- + char *str_found = NULL;
- +
- + dc_ignore_gray_space();
- +
- + if (strnicmp(pstr, Cp, strlen(pstr))) {
- + str_found = pstr;
- + }
- +
- + if (str_found != NULL) {
- + // Found a required string
- + if (Dc_debug_on) {
- + dc_printf("<debug> Found required string [%s]\n", str_found);
- + }
- +
- + Cp += strlen(str_found);
- + } else {
- + // Didn't find a required string.
- + SCP_string token;
- + dc_get_token_no_advance(token);
- + throw errParseString(token.c_str(), pstr);
- + }
- +}
- +
- +int dc_required_string_either(char *str1, char *str2)
- +{
- + char *str_found = NULL;
- + int i = -1;
- +
- + dc_ignore_gray_space();
- +
- + if (strncmp(str1, Cp, strlen(str1) == 0)) {
- + str_found = str1;
- + i = 0;
- + } else if (strncmp(str2, Cp, strlen(str2) == 0)) {
- + str_found = str2;
- + i = 1;
- + }
- +
- + if (i > -1) {
- + // Found a required string
- + if (Dc_debug_on) {
- + dc_printf("<debug> Found required string [%s]\n", str_found);
- + }
- +
- + Cp += strlen(str_found);
- + } else {
- + // Didn't find a required string.
- + SCP_string token;
- + dc_get_token_no_advance(token);
- + throw errParseString(token.c_str(), str1, str2);
- + }
- +
- + return i;
- +}
- +
- +int dc_required_string_any(const uint n, ...)
- +{
- + va_list vl;
- + SCP_vector<SCP_string> strings;
- + const char *str_found = NULL;
- + int i;
- +
- + dc_ignore_gray_space();
- +
- + // Populate the vector.
- + va_start(vl, n);
- + for (i = 0; i < n; ++i) {
- + strings.push_back(va_arg(vl, char *));
- + }
- + va_end(vl);
- +
- + // Search for the required string. If found, i = index of the string passed
- + for (i = 0; i < n; ++i) {
- + if (strcmp(Cp, strings[i].c_str()) == 0)
- + {
- + str_found = strings[i].c_str();
- + break;
- + }
- + }
- +
- + if (str_found != NULL) {
- + // Found a required string
- + if (Dc_debug_on) {
- + dc_printf("<debug> Found required string [%s}\n", str_found);
- + }
- +
- + Cp += strlen(str_found);
- + } else {
- + // Didn't find a required string.
- + SCP_string token;
- + dc_get_token_no_advance(token);
- + throw errParseString(token.c_str(), strings);
- + }
- +
- + return i;
- +}
- +
- +bool dc_optional_string(const char *pstr)
- +{
- + dc_ignore_gray_space();
- +
- + if (strncmp(pstr, Cp, strlen(pstr) != 0)) {
- + return false;
- + } // Else, optional string was found
- +
- + if (Dc_debug_on) {
- + dc_printf("<debug> Found optional string [%s]\n", pstr);
- + }
- +
- + Cp += strlen(pstr);
- + return true;
- +}
- +
- +bool dc_optional_string_either(const char *str1, const char *str2)
- +{
- + const char *str_found = NULL;
- +
- + dc_ignore_gray_space();
- +
- + if (strncmp(str1, Cp, strlen(str1)) == 0) {
- + str_found = str1;
- + } else if (strncmp(str2, Cp, strlen(str2)) == 0) {
- + str_found = str2;
- + } else {
- + return false;
- + }
- +
- + if (Dc_debug_on) {
- + dc_printf("<debug> Found optional string [%s]\n",str_found);
- + }
- +
- + Cp += strlen(str_found);
- + return true;;
- +}
- +
- +void dc_parse_init(SCP_string &str)
- +{
- + strcpy(Command_string, str.c_str());
- + Cp = Command_string;
- +}
- +
- +double dc_parse_double(const char *ch, dc_token type) {
- + const char *ch_ptr = ch;
- + char *end_ptr;
- + double ret;
- + state_float state = sf_start;
- + SCP_string buffer_str;
- +
- + while ((*ch_ptr != '\0') && is_white_space(*ch_ptr)) {
- + ch_ptr++;
- + }
- +
- + if (*ch_ptr == '\0') {
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_double] no argument found\n");
- + }
- + throw errParse("", type);
- + }
- +
- + do {
- + switch (state) {
- + case sf_start:
- + if (ch_is_sign(*ch_ptr)) {
- + state = sf_sign;
- + if (*ch_ptr == '-') {
- + buffer_str.push_back(*ch_ptr);
- + } // Else, sign is positive, and isn't needed on the buffer
- + ch_ptr++;
- +
- + } else if (ch_is_numeral(*ch_ptr)) {
- + state = sf_whole;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if (ch_is_decimal(*ch_ptr)) {
- + state = sf_decimal;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else {
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_double] Invalid character '%c' found in sf_start\n", *ch_ptr);
- + }
- + state = sf_invalid;
- +
- + }
- + break;
- + case sf_end:
- + if (buffer_str == "") {
- + state = sf_invalid;
- + } // Else, we can convert the token.
- + // Do nothing, and allow the while loop exit condition to trigger
- + break;
- + case sf_sign:
- + state = dc_parse_double_sign(ch_ptr, buffer_str);
- + break;
- +
- + case sf_whole:
- + state = dc_parse_double_whole(ch_ptr, buffer_str);
- + break;
- +
- + case sf_decimal:
- + state = dc_parse_double_decimal(ch_ptr, buffer_str);
- + break;
- +
- + case sf_fraction:
- + state = dc_parse_double_fraction(ch_ptr, buffer_str);
- + break;
- +
- + case sf_expprefix:
- + state = dc_parse_double_expprefix(ch_ptr, buffer_str);
- + break;
- +
- + case sf_expsign:
- + state = dc_parse_double_expsign(ch_ptr, buffer_str);
- + break;
- +
- + case sf_exponent:
- + state = dc_parse_double_exponent(ch_ptr, buffer_str);
- + break;
- +
- + case sf_invalid:
- + default:
- + throw errParse(ch, type);
- + }
- + } while (state != sf_end);
- +
- + ret = strtod(buffer_str.c_str(), &end_ptr);
- +
- + return ret;
- +}
- +
- +state_float dc_parse_double_sign(const char* &ch_ptr, SCP_string &buffer_str)
- +{
- + state_float state = sf_invalid;
- +
- + if (ch_is_numeral(*ch_ptr)) {
- + state = sf_whole;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if (ch_is_decimal(*ch_ptr)) {
- + state = sf_decimal;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else {
- + state = sf_invalid;
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_double] Invalid character '%c' found in sf_sign\n", *ch_ptr);
- + }
- + }
- +
- + return state;
- +}
- +
- +state_float dc_parse_double_whole(const char* &ch_ptr, SCP_string &buffer_str)
- +{
- + state_float state = sf_invalid;
- +
- + if (ch_is_numeral(*ch_ptr)) {
- + state = sf_whole;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if (ch_is_decimal(*ch_ptr)) {
- + state = sf_decimal;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if (ch_is_exp_prefix(*ch_ptr)) {
- + state = sf_expprefix;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if ((*ch_ptr == '\0') || is_white_space(*ch_ptr)) {
- + state = sf_end;
- +
- + } else {
- + state = sf_invalid;
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_double] Invalid character '%c' found in sf_whole\n", *ch_ptr);
- + }
- + }
- +
- + return state;
- +}
- +
- +state_float dc_parse_double_decimal(const char* &ch_ptr, SCP_string &buffer_str)
- +{
- + state_float state = sf_invalid;
- +
- + if (ch_is_numeral(*ch_ptr)) {
- + state = sf_fraction;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if (ch_is_exp_prefix(*ch_ptr)) {
- + state = sf_expprefix;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if ((*ch_ptr == '\0') || is_white_space(*ch_ptr)) {
- + state = sf_end;
- +
- + } else {
- + state = sf_invalid;
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_double] Invalid character '%c' found in sf_decimal\n", *ch_ptr);
- + }
- + }
- +
- + return state;
- +}
- +
- +state_float dc_parse_double_fraction(const char* &ch_ptr, SCP_string &buffer_str)
- +{
- + state_float state = sf_invalid;
- +
- + if (ch_is_numeral(*ch_ptr)) {
- + state = sf_fraction;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if (ch_is_exp_prefix(*ch_ptr)) {
- + state = sf_expprefix;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if ((*ch_ptr == '\0') || is_white_space(*ch_ptr)) {
- + state = sf_end;
- +
- + } else {
- + state = sf_invalid;
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_double] Invalid character '%c' found in sf_faction\n", *ch_ptr);
- + }
- + }
- +
- + return state;
- +}
- +
- +state_float dc_parse_double_expprefix(const char* &ch_ptr, SCP_string &buffer_str)
- +{
- + state_float state = sf_invalid;
- +
- + if (ch_is_sign(*ch_ptr)) {
- + state = sf_expsign;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if (ch_is_numeral(*ch_ptr)) {
- + state = sf_exponent;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else {
- + state = sf_invalid;
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_double] Invalid character '%c' found in sf_expprefix\n", *ch_ptr);
- + }
- + }
- +
- + return state;
- +}
- +
- +state_float dc_parse_double_expsign(const char* &ch_ptr, SCP_string &buffer_str)
- +{
- + state_float state = sf_invalid;
- +
- + if (ch_is_numeral(*ch_ptr)) {
- + state = sf_exponent;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else {
- + state = sf_invalid;
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_double] Invalid character '%c' found in sf_expsign\n", *ch_ptr);
- + }
- + }
- +
- + return state;
- +}
- +
- +state_float dc_parse_double_exponent(const char* &ch_ptr, SCP_string &buffer_str)
- +{
- + state_float state = sf_invalid;
- +
- + if (ch_is_numeral(*ch_ptr)) {
- + state = sf_exponent;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if ((*ch_ptr == '\0') || is_white_space(*ch_ptr)) {
- + state = sf_end;
- +
- + } else {
- + state = sf_invalid;
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_double] Invalid character '%c' found in sf_exponent\n", *ch_ptr);
- + }
- + }
- +
- + return state;
- +}
- +
- +long dc_parse_long(const char *ch, dc_token type) {
- + const char *ch_ptr = ch;
- + char *end_ptr = NULL;
- + int base = 10;
- + long ret;
- + state_int state = si_start;
- + SCP_string buffer_str;
- +
- + while ((*ch_ptr != '\0') && is_white_space(*ch_ptr)) {
- + ch_ptr++;
- + }
- +
- + if (*ch_ptr == '\0') {
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_long] no argument found\n");
- + }
- + throw errParse("", type);
- + }
- +
- + do {
- + switch (state) {
- + case si_start:
- + if (ch_is_sign(*ch_ptr)) {
- + state = si_sign;
- + if (*ch_ptr == '-') {
- + buffer_str.push_back(*ch_ptr);
- + } // Else, it's positive. Positive sign isn't needed for conversion
- + ch_ptr++;
- +
- + } else if (ch_is_prefix(*ch_ptr)) {
- + // prefixes must be checked before numeral, because they all start with a numeral zero
- + state = si_prefix;
- + ch_ptr++;
- +
- + } else if (ch_is_numeral(*ch_ptr)) {
- + state = si_numeral;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else {
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_long] Invalid character '%c' found in si_start\n", *ch_ptr);
- + }
- + state = si_invalid;
- +
- + }
- + break;
- + case si_end:
- + if (buffer_str == "") {
- + state = si_invalid;
- + } // Else, we can convert the token.
- + // Do nothing, and allow the while loop exit condition to trigger
- + break;
- +
- + case si_sign:
- + state = dc_parse_long_sign(ch_ptr, buffer_str);
- + break;
- +
- + case si_prefix:
- + state = dc_parse_long_prefix(ch_ptr, buffer_str, base);
- + break;
- +
- + case si_numeral_bin:
- + state = dc_parse_long_numeral_bin(ch_ptr, buffer_str);
- + break;
- +
- + case si_numeral_octal:
- + state = dc_parse_long_numeral_octal(ch_ptr, buffer_str);
- + break;
- +
- + case si_numeral_hex:
- + state = dc_parse_long_numeral_hex(ch_ptr, buffer_str);
- + break;
- +
- + case si_numeral:
- + state = dc_parse_long_numeral(ch_ptr, buffer_str);
- + break;
- +
- + case si_invalid:
- + default:
- + throw errParse(ch, type);
- + break;
- + }
- + } while (state != si_end);
- +
- + ret = strtol(buffer_str.c_str(), &end_ptr, base);
- +
- + // This last check can be omitted once I can verify the operation of strtol in this sense
- + if (*end_ptr != '\0') {
- + dc_printf("Error: Could not convert all of the buffer '%s'.\n", buffer_str.c_str());
- + if (Dc_debug_on) {
- + dc_printf("<debug> Buffer value: %s\n", buffer_str.c_str());
- + dc_printf("<debug> Return value: %i", ret);
- + }
- + throw errParse(ch, type);
- + }
- +
- + return ret;
- +}
- +
- +ulong dc_parse_ulong(const char *ch, dc_token type) {
- + const char *ch_ptr = ch;
- + char *end_ptr;
- + int base = 10;
- + ulong ret;
- + state_int state = si_start;
- + SCP_string buffer_str;
- +
- + while ((*ch_ptr != '\0') && is_white_space(*ch_ptr)) {
- + ch_ptr++;
- + }
- +
- + if (*ch_ptr == '\0') {
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_long] no argument found\n");
- + }
- + throw errParse("", type);
- + }
- +
- + do {
- + switch (state) {
- + case si_start:
- + if (ch_is_prefix(*ch_ptr)) {
- + // prefixes must be checked before numeral, because they all start with a numeral zero
- + state = si_prefix;
- + ch_ptr++;
- +
- + } else if (ch_is_numeral(*ch_ptr)) {
- + state = si_numeral;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else {
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_long] Invalid character '%c' found in si_start\n", *ch_ptr);
- + }
- + state = si_invalid;
- +
- + }
- + break;
- + case si_end:
- + if (buffer_str == "")
- + {
- + state = si_invalid;
- + } // Else, we can convert the token.
- + // Do nothing, and allow the while loop exit condition to trigger
- + break;
- +
- + case si_prefix:
- + state = dc_parse_long_prefix(ch_ptr, buffer_str, base);
- + break;
- +
- + case si_numeral_bin:
- + state = dc_parse_long_numeral_bin(ch_ptr, buffer_str);
- + break;
- +
- + case si_numeral_octal:
- + state = dc_parse_long_numeral_octal(ch_ptr, buffer_str);
- + break;
- +
- + case si_numeral_hex:
- + state = dc_parse_long_numeral_hex(ch_ptr, buffer_str);
- + break;
- +
- + case si_numeral:
- + state = dc_parse_long_numeral(ch_ptr, buffer_str);
- + break;
- +
- + case si_invalid:
- + default:
- + throw errParse(ch, type);
- + }
- + } while (state != si_end);
- +
- + ret = strtoul(buffer_str.c_str(), &end_ptr, base);
- +
- + // This last check can be omitted once I can verify the operation of strtol in this sense
- + if (end_ptr != ch_ptr) {
- + dc_printf("Error: Could not convert all of the buffer '%s'.\n", buffer_str.c_str());
- + if (Dc_debug_on) {
- + dc_printf("<debug> Buffer value: %s\n", buffer_str.c_str());
- + dc_printf("<debug> Return value: %i", ret);
- + }
- + throw errParse(ch, type);
- + }
- +
- + return ret;
- +}
- +
- +void dc_stuff_float(float *f)
- +{
- + double value_d;
- + SCP_string token;
- +
- + dc_ignore_gray_space();
- +
- + dc_get_token(token); // Grab the token
- + value_d = dc_parse_double(token.c_str(), DCT_FLOAT); // Parse and convert
- +
- + // Stuff value if within bounds
- + if ((abs(value_d) < FLT_MAX) && (abs(value_d) > FLT_MIN)) {
- + *f = value_d;
- + } else {
- + throw errParse(token.c_str(), DCT_FLOAT);
- + }
- +}
- +
- +void dc_stuff_int(int *i)
- +{
- + long value_l;
- + SCP_string token;
- +
- + dc_ignore_gray_space();
- +
- + dc_get_token(token);
- + value_l = dc_parse_long(token.c_str(), DCT_INT);
- +
- + if ((value_l < INT_MAX) && (value_l > INT_MIN)) {
- + *i = value_l;
- +
- + } else {
- + throw errParse(token.c_str(), DCT_INT);
- + }
- +}
- +
- +void dc_stuff_uint(uint *i)
- +{
- + ulong value_l;
- + SCP_string token;
- +
- + dc_ignore_gray_space();
- +
- + dc_get_token(token);
- + value_l = dc_parse_long(Cp, DCT_INT);
- +
- + if (value_l < UINT_MAX) {
- + *i = value_l;
- +
- + } else {
- + throw errParse(token.c_str(), DCT_INT);
- + }
- +}
- +
- +void dc_stuff_ubyte(ubyte *i)
- +{
- + ulong value_ul;
- + SCP_string token;
- +
- + dc_ignore_gray_space();
- +
- + dc_get_token(token);
- + value_ul = dc_parse_ulong(Cp, DCT_UBYTE);
- +
- + // Since some system's chars may be greater than 1 byte, we can't use UCHAR_MAX for a UBYTE
- + if ((value_ul <= 255) && (value_ul >= 0)) {
- + *i = value_ul;
- +
- + } else {
- + throw errParse(token.c_str(), DCT_UBYTE);
- + }
- +}
- +
- +void dc_stuff_boolean(bool *b)
- +{
- + SCP_string token;
- +
- + dc_get_token(token);
- +
- + if ((token == "yes")
- + || (token == "true")
- + || (token == "ja") // German
- + || (token == "Oui") // French
- + || (token == "si") // Spanish
- +// || (token == "ita vero") // Latin, not supported
- + || (token == "HIja") || (token == "HISLaH") // Klingon
- + || (token == "1"))
- + {
- + *b = true;
- +
- + } else if ((token == "no")
- + || (token == "false")
- + || (token == "nein") // German
- + || (token == "Non") // French
- +// || (token == "no") // Spanish, redundant with English "no"
- +// || (token == "minime") // Latin, not supported
- + || (token == "ghobe'") // Klingon
- + || (token == "0"))
- + {
- + *b = false;
- +
- + } else {
- + throw errParse(token.c_str(), DCT_BOOL);
- + }
- +}
- +
- +void dc_stuff_boolean(int *i)
- +{
- + bool value_b;
- +
- + dc_stuff_boolean(&value_b);
- +
- + value_b ? *i = 1 : *i = 0;
- +}
- +
- +void dc_stuff_string(char *out_str, size_t maxlen = MAX_TOKEN_LENGTH)
- +{
- + size_t count = 0;
- + char *c_ptr = Cp;
- + SCP_string token;
- +
- + Assert(Cp);
- + Assert(out_str);
- +
- + dc_ignore_gray_space();
- +
- + // Bail if we're at the terminator
- + if (*Cp == '\0') {
- + throw errParse("Nothing!", DCT_STRING);
- + }
- +
- + // Scan the string, stopping at null terminator, or before we overflow
- + c_ptr = Cp;
- + while ((*c_ptr != '\0') && (count < maxlen)) {
- + count++;
- + c_ptr++;
- + }
- +
- + // Bail if overflow
- + if (count == maxlen) {
- + token.assign(Cp, maxlen);
- + throw errParseOverflow(token.c_str(), maxlen);
- + }
- +
- + // Copy string into out_str
- + strncpy(out_str, Cp, count);
- +
- + // Advance the parser pointer past what we copied
- + Cp = c_ptr;
- +}
- +
- +void dc_stuff_string(SCP_string &out_str)
- +{
- + size_t count = 0;
- + char *c_ptr = Cp;
- +
- + Assert(Cp);
- +
- + dc_ignore_gray_space();
- +
- + // Bail if we're at the terminator
- + if (*Cp == '\0') {
- + throw errParse("Nothing!", DCT_STRING);
- + }
- +
- + // Scan the string, stopping at null terminator, or before we overflow
- + c_ptr = Cp;
- + while ((*c_ptr != '\0') && (count < out_str.max_size())) {
- + count++;
- + c_ptr++;
- + }
- +
- + // Bail if overflow
- + if ((count == out_str.max_size()) && (c_ptr != '\0')) {
- + throw errParse("SCP_string overflow!", DCT_STRING);
- + }
- +
- + // Copy string into out_str
- + out_str.assign(Cp, count);
- +
- + // Advance the parser pointer past what we copied
- + Cp = c_ptr;
- +}
- +
- +void dc_stuff_string_white(char *out_str, size_t maxlen)
- +{
- + size_t count = 0;
- + char *c_ptr = Cp;
- +
- + Assert(Cp);
- + Assert(out_str);
- +
- + dc_ignore_gray_space();
- +
- + // Bail if we're at the terminator
- + if (*Cp == '\0') {
- + throw errParse("Nothing!", DCT_STRING);
- + }
- +
- + // Scan the string, stopping at grayspace, null terminator, or before we overflow
- + c_ptr = Cp;
- + while (!is_gray_space(*c_ptr) && (*c_ptr != '\0') && (count < maxlen)) {
- + count++;
- + c_ptr++;
- + }
- +
- + // Bail if overflow
- + if (count == maxlen) {
- + throw errParse("", DCT_STRING);
- + }
- +
- + // Copy string into out_str
- + strncpy(out_str, Cp, count);
- +
- + // Advance the parser pointer past what we copied
- + Cp = c_ptr;
- +}
- +
- +void dc_stuff_string_white(SCP_string &out_str)
- +{
- + size_t count = 0;
- + char *c_ptr;
- +
- + Assert(Cp);
- +
- + dc_ignore_gray_space();
- +
- + // Bail if we're at the terminator
- + if (*Cp == '\0') {
- + throw errParse("Nothing!", DCT_STRING);
- + }
- +
- + // Scan the string, stopping at grayspace, null terminator, or before we overflow
- + c_ptr = Cp;
- + while (!is_gray_space(*c_ptr) && (*c_ptr != '\0') && (count < out_str.max_size())) {
- + count++;
- + c_ptr++;
- + }
- +
- + // Bail if overflow
- + if (count == out_str.max_size()) {
- + throw errParse("", DCT_STRING);
- + }
- +
- + // Copy string into out_str
- + out_str.assign(Cp, count);
- +
- + // Advance the parser pointer past what we copied
- + Cp = c_ptr;
- +}
- +
- +inline
- +state_int dc_parse_long_prefix(const char* &ch_ptr, SCP_string &buffer_str, int &base) {
- + state_int state = si_invalid;
- +
- + if (ch_is_binary_prefix(*ch_ptr)) {
- + state = si_numeral_bin;
- + base = 2;
- + ch_ptr++;
- +
- + } else if (ch_is_octal_prefix(*ch_ptr)) {
- + state = si_numeral_octal;
- + base = 8;
- + ch_ptr++;
- +
- + } else if (ch_is_hex_prefix(*ch_ptr)) {
- + state = si_numeral_hex;
- + base = 16;
- + ch_ptr++;
- +
- + } else if (ch_is_numeral(*ch_ptr)) {
- + // User passed something like 0123
- + // Just ignore the first 0, if the user passed something like 00001 then state si_numeral can handle it
- + state = si_numeral;
- + ch_ptr++;
- +
- + } else if ((*ch_ptr == '\0') || is_white_space(*ch_ptr)) {
- + // Just a 0 was passed.
- + buffer_str.push_back('0');
- + state = si_end;
- +
- + } else {
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_long] Invalid character '%c' found in si_prefix\n", *ch_ptr);
- + }
- + state = si_invalid;
- +
- + }
- + return state;
- +}
- +
- +inline
- +state_int dc_parse_long_sign(const char* &ch_ptr, SCP_string &buffer_str) {
- + state_int state;
- + if (ch_is_numeral(*ch_ptr)) {
- + state = si_numeral;
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if (ch_is_prefix(*ch_ptr)) {
- + state = si_prefix;
- + ch_ptr++;
- +
- + } else if ((*ch_ptr == '\0') || is_white_space(*ch_ptr)) {
- + // Error, no value found
- + state = si_invalid;
- +
- + } else {
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_long] Invalid character '%c' found in si_sign\n", *ch_ptr);
- + }
- + state = si_invalid;
- +
- + }
- + return state;
- +}
- +
- +inline
- +state_int dc_parse_long_numeral(const char* &ch_ptr, SCP_string &buffer_str) {
- + state_int state = si_numeral;
- +
- + if (ch_is_numeral(*ch_ptr)) {
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if ((*ch_ptr == '\0') || is_white_space(*ch_ptr)) {
- + state = si_end;
- +
- + } else {
- + // Invalid character, throw and bail
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_long] Invalid character '%c' found in si_numeral\n", *ch_ptr);
- + }
- + state = si_invalid;
- +
- + }
- + return state;
- +}
- +
- +inline
- +state_int dc_parse_long_numeral_bin(const char* &ch_ptr, SCP_string &buffer_str) {
- + state_int state = si_numeral_bin;
- +
- + if (ch_is_binary(*ch_ptr)) {
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if ((*ch_ptr == '\0') || is_white_space(*ch_ptr)) {
- + state = si_end;
- +
- + } else {
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_long] Invalid character '%c' found in si_numeral_bin\n", *ch_ptr);
- + }
- + state = si_invalid;
- +
- + }
- + return state;
- +}
- +
- +inline
- +state_int dc_parse_long_numeral_hex(const char* &ch_ptr, SCP_string &buffer_str) {
- + state_int state = si_numeral_hex;
- +
- + if (ch_is_hex(*ch_ptr)) {
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if ((*ch_ptr == '\0') || is_white_space(*ch_ptr)) {
- + state = si_end;
- +
- + } else {
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_long] Invalid character '%c' found in si_numeral_hex\n", *ch_ptr);
- + }
- + state = si_invalid;
- + }
- + return state;
- +}
- +
- +inline
- +state_int dc_parse_long_numeral_octal(const char* &ch_ptr, SCP_string &buffer_str) {
- + state_int state = si_numeral_octal;
- +
- + if (ch_is_octal(*ch_ptr)) {
- + buffer_str.push_back(*ch_ptr);
- + ch_ptr++;
- +
- + } else if ((*ch_ptr == '\0') || is_white_space(*ch_ptr)) {
- + state = si_end;
- +
- + } else {
- + // Invalid character, throw and bail
- + if (Dc_debug_on) {
- + dc_printf("<debug> [parse_long] Invalid character '%c' found in si_numeral_octal\n", *ch_ptr);
- + }
- + state = si_invalid;
- + }
- + return state;
- +}
- diff --git a/code/debugconsole/consoleparse.h b/code/debugconsole/consoleparse.h
- new file mode 100644
- index 0000000..57885b1
- --- /dev/null
- +++ b/code/debugconsole/consoleparse.h
- @@ -0,0 +1,477 @@
- +#ifndef _CONSOLEPARSE_H
- +#define _CONSOLEPARSE_H
- +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- +// Command-line parsing functions for z64555's debug console, created for the FreeSpace Source Code project
- +//
- +// Portions of this source code are based on works by Volition, Inc. circa 1999. You may not sell or otherwise
- +// commercially exploit the source or things you created based on the source.
- +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- +
- +/**
- + * @file consoleparse.h
- + * @brief Parsing functions for the command line. Previously known as the command line scanner
- + *
- + * @details A lot of functions here are blatently copied from parselo.h :D
- + */
- +
- +#include "globalincs/pstypes.h"
- +
- +#include <cstdarg>
- +
- +#define MAX_CLI_LEN 512
- +#define MAX_TOKEN_LENGTH 255
- +
- +enum dc_token {
- + DCT_NONE = 0, //!< No token
- + DCT_STRING, //!< String
- + DCT_FLOAT, //!< Floating point
- + DCT_INT, //!< Integral
- + DCT_UINT, //!< Unsigned Integral
- + DCT_BYTE, //!< Integral with values between -128 and 127
- + DCT_UBYTE, //!< Integral with values between 0 and 255
- + DCT_BOOL, //!< Integral or string evaluated as a boolean
- +
- + DCT_MAX_ITEMS //!< Maximum number of dc_token elements. Primarily used as an end value in loops
- +};
- +
- +/**
- + * Human readable versions of the dc_token's. Primarily used in error diagnosis
- + */
- +static
- +const char *token_str[DCT_MAX_ITEMS] =
- +{
- + "nothing",
- + "string",
- + "float",
- + "integer",
- + "unsigned integer",
- + "byte",
- + "unsigned byte",
- + "boolean"
- +};
- +
- +/**
- + * @class errParse
- + *
- + * @brief Class thrown when a required token is not found
- + *
- + * @details This is a basic parser error, it contains the token (a single word) that was found, and the expected token
- + * type. Some DCT's, such as the DCT_STRING's, have their own specific requirements for error handling, and as
- + * such get their own class derived from errParse. The catching routines should be able to catch the derived error
- + * objects, but if not, they can be caught by a routine looking for the base class and then be casted to their
- + * proper type.
- + */
- +class errParse {
- +public:
- + SCP_string found_token;
- + dc_token expected_type;
- +
- + /**
- + * @brief Invalid/Unexpected token constructor
- + * @param [in] found_str The token that was found
- + * @param [in] expected_dct The token type that was expected
- + */
- + errParse(const char *found_str, dc_token expected_dct)
- + : found_token(found_str), expected_type(expected_dct)
- + {
- + }
- +};
- +
- +/**
- + * @class errParseString
- + *
- + * @brief Class thrown when an expected string was not found. Can/should contain all of the expected strings.
- + */
- +class errParseString : public errParse
- +{
- +public:
- + SCP_vector<SCP_string> expected_tokens;
- +
- + /**
- + * @brief Invalid/Unexpected token constructor.
- + *
- + * @param [in] found_str The string that was found
- + * @param [in] str The token that was expected
- + */
- + errParseString(const char *found_str, char *str)
- + : errParse(found_str, DCT_STRING)
- + {
- + expected_tokens.push_back(str);
- + }
- +
- + /**
- + * @brief Invalid/Unexpected token constructor.
- + *
- + * @param [in] found_str The string that was found
- + * @param [in] str1 The first token that was expected
- + * @param [in] str2 The second token that was expected
- + */
- + errParseString(const char *found_str, char *str1, char *str2)
- + : errParse(found_str, DCT_STRING)
- + {
- + expected_tokens.push_back(str1);
- + expected_tokens.push_back(str2);
- + }
- +
- + /**
- + * @brief Invalid/Unexpected token constructor.
- + *
- + * @param [in] found_str The string that was found
- + * @param [in] n The number of strings that were expected
- + * @param [in] ... The strings that were expected
- + */
- + errParseString(const char *found_str, SCP_vector<SCP_string> &strings)
- + : errParse(found_str, DCT_STRING), expected_tokens(strings)
- + {
- + }
- +};
- +
- +/**
- + * @class errParseOverflow
- + *
- + * @brief Class thrown when the parsed string or token could not be stuffed into the smaller destination container
- + *
- + * @var found_str Contains the first 'len' valid characters.
- + */
- +class errParseOverflow : public errParse
- +{
- +public:
- + size_t len; //!< The size of the destination container
- +
- + errParseOverflow(const char *found_str, size_t _len)
- + : errParse(found_str, DCT_STRING), len(_len)
- + {
- + }
- +};
- +
- +/**
- + * @brief Initializes the DC command line parser
- + */
- +void dc_parse_init(SCP_string &str);
- +
- +/**
- + * @brief Advances the parser past whitespace characters
- + */
- +void dc_ignore_white_space(void);
- +
- +/**
- + * @brief Advances the parser past grayspace characters
- + */
- +void dc_ignore_gray_space(void);
- +
- +// Required/Optional Token
- +/**
- + * @brief Searches for a specified required string, throwing an errParse if not found.
- + *
- + * @param[in] pstr The string to search for
- + *
- + * @throws errParseString with the required string
- + */
- +void dc_required_string(char *pstr);
- +
- +/**
- + * @brief Searchs for either of the specified required strings, throwing an errParse if neither are found
- + *
- + * @param[in] str1 The first string to search for
- + * @param[in] str2 The second string to search for
- + *
- + * @retval 0 if str1 was found, or
- + * @retval 1 if str2 was found
- + *
- + * @throws errParseString with the required strings
- + */
- +int dc_required_string_either(char *str1, char *str2);
- +
- +/**
- + * @brief Searches for specified required strings
- + *
- + * @param[in] n The number of char[] or c_str's given
- + * @param[in] ... A comma delimited list of one or more required strings.
- + *
- + * @returns The index of the specified required strings (as if they were an array)
- + *
- + * @throws errParseString with the required strings
- + */
- +int dc_required_string_any(const uint n, ...);
- +
- +/**
- + * @brief Searches for an optional string
- + *
- + * @param[in] pstr The char[] to look for
- + *
- + * @retval true if the string was found,
- + * @retval false otherwise
- + */
- +bool dc_optional_string(const char *pstr);
- +
- +/**
- + * @brief Searches for an optional string and it's alias
- + *
- + * @param[in] str1 The char[] to look for
- + * @param[in] str2 The alternative char[] to look for
- + *
- + * @retval true if the string was found,
- + * @retval false otherwise
- + */
- +bool dc_optional_string_either(const char *str1, const char *str2);
- +
- +
- +// ==========================
- +// Stuffers
- +// ==========================
- +
- +/**
- + * @brief Stuffs a float to the given variable.
- + *
- + * @param[in] f The float variable to stuff to
- + *
- + * @throws errParse if an unexpected or otherwise malformed float string is found.
- + * @throws errParse if nothing was found
- + */
- +void dc_stuff_float(float *f);
- +
- +/**
- + * @brief Stuffs an int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats
- + *
- + * @param[in] i The int variable to stuff to
- + *
- + * @details The binary, hexadecimal, and octal formats must be prefixed by their associated string.
- + * Ex: "0xDEADBEEF" would be parsed properly while "DEADBEEF" would throw an error
- + *
- + * @throws errParse if an unexpected or otherwise malformed float string is found.
- + * @throws errParse if nothing was found
- + */
- +void dc_stuff_int(int *i);
- +
- +/**
- + * @brief Stuffs an unsigned int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats
- + *
- + * @param[in] i The unsigned int variable to stuff to
- + *
- + * @details The binary, hexadecimal, and octal formats must be prefixed by their associated string.
- + * Ex: "0xDEADBEEF" would be parsed properly while "DEADBEEF" would throw an error
- + *
- + * @throws errParse if an unexpected or otherwise malformed float string is found.
- + * @throws errParse if nothing was found
- + */
- +void dc_stuff_uint(uint *i);
- +
- +/**
- + * @brief Stuffs an unsigned byte to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats
- + *
- + * @param[in] i The ubyte variable to stuff to
- + *
- + * @details The binary, hexadecimal, and octal formats must be prefixed by their associated string.
- + * Ex: "0x0F" would be parsed properly while "0F" would throw an error
- + *
- + * @throws errParse if an unexpected or otherwise malformed float string is found.
- + * @throws errParse if nothing was found
- + */
- +void dc_stuff_ubyte(ubyte *i);
- +
- +/**
- + * @brief stuffs a boolean evaluated integer or string into the given variable.
- + *
- + * @param[in] b The bool variable to stuff to
- + *
- + * @details Supports a number of literal strings as true and false, including "true", "false", "yes", "no" and the
- + * yes/no equivalents in other languages supported in localization.
- + * TODO: Make a static string map to handle this instead of being hard-coded
- + *
- + * @throws errParse if an unexpected or otherwise malformed float string is found.
- + * @throws errParse if nothing was found
- + */
- +void dc_stuff_boolean(bool *b);
- +
- +/**
- + * @brief stuffs a boolean evaluated integer or string into the given variable.
- + *
- + * @param[in] i The int variable to stuff to. 0 is false, 1 is true
- + *
- + * @details Supports a number of literal strings as true and false, including "true", "false", "yes", "no" and the
- + * yes/no equivalents in other languages supported in localization.
- + * TODO: Make a static string map to handle this instead of being hard-coded
- + *
- + * @throws errParse if an unexpected or otherwise malformed float string is found.
- + * @throws errParse if nothing was found
- + */
- +void dc_stuff_boolean(int *i);
- +
- +/**
- + * @brief Stuffs a string to out_str from the command line, stopping at the end of the command line
- + *
- + * @param[out] out_str Destination string
- + * @param[in] maxlen Maximum length to copy. (maxlen <= sizeof(str)) && (maxlen <= MAX_TOKEN_LENGTH)
- + *
- + * @throws errParse when nothing left was found on the command line
- + * @throws errParseOverflow when parser cannot stuff the entirety of the found string into out_str
- + */
- +void dc_stuff_string(char *str, size_t maxlen);
- +
- +/**
- + * @brief Stuffs a string to out_str from the command line, stopping at the end of the command line
- + *
- + * @param[out] out_str Destination string
- + *
- + * @throws errParse when nothing left was found on the command line
- + */
- +void dc_stuff_string(SCP_string &str);
- +
- +/**
- + * @brief Stuffs a whitespace delimited string to out_str from the command line, stopping at the end of the command line
- + *
- + * @param[out] out_str Destination string
- + * @param[in] maxlen Maximum length to copy. (maxlen <= sizeof(str)) && (maxlen <= MAX_TOKEN_LENGTH)
- + *
- + * @throws errParse when nothing left was found on the command line
- + * @throws errParseOverflow when parser cannot stuff the entirety of the found string into out_str
- + */
- +void dc_stuff_string_white(char *str, size_t len);
- +
- +/**
- + * @brief Stuffs a whitespace delimited string to out_str from the command line, stopping at the end of the command line
- + *
- + * @param[out] out_str Destination string
- + * @param[in] maxlen Maximum length to copy. (maxlen <= sizeof(str)) && (maxlen <= MAX_TOKEN_LENGTH)
- + *
- + * @throws errParse when nothing left was found on the command line
- + */
- +void dc_stuff_string_white(SCP_string &str);
- +
- +/**
- + * @brief Tries to stuff a float from the Command_string.
- + *
- + * @param[in] f The float variable to maybe stuff.
- + *
- + * @details
- + * If there's nothing on the command line, *f = 0 and false is returned
- + *
- + * If there's something on the command line, and we're able to convert it, *f = the converted value, true is
- + * returned, and the parser is advanced past the token
- + *
- + * If there's something on command line, but we can't convert it, an errParse is thrown
- + */
- +bool dc_maybe_stuff_float(float *f);
- +
- +/**
- + * @brief Tries to stuff an int from the Command_string.
- + *
- + * @param[in] i The int variable to maybe stuff.
- + *
- + * @details
- + * If there's nothing on the command line, *i = 0 and false is returned
- + *
- + * If there's something on the command line, and we're able to convert it, *i = the converted value, true is
- + * returned, and the parser is advanced past the token
- + *
- + * If there's something on command line, but we can't convert it, an errParse is thrown
- + */
- +bool dc_maybe_stuff_int(int *i);
- +
- +/**
- + * @brief Tries to stuff an uint from the Command_string.
- + *
- + * @param[in] i The uint variable to maybe stuff.
- + *
- + * @details
- + * If there's nothing on the command line, *i = 0 and false is returned
- + *
- + * If there's something on the command line, and we're able to convert it, *i = the converted value, true is
- + * returned, and the parser is advanced past the token
- + *
- + * If there's something on command line, but we can't convert it, an errParse is thrown
- + */
- +bool dc_maybe_stuff_uint(uint *i);
- +
- +/**
- + * @brief Tries to stuff an ubyte from the Command_string.
- + *
- + * @param[in] i The ubyte variable to maybe stuff.
- + *
- + * @details
- + * If there's nothing on the command line, *i = 0 and false is returned
- + *
- + * If there's something on the command line, and we're able to convert it, *i = the converted value, true is
- + * returned, and the parser is advanced past the token
- + *
- + * If there's something on command line, but we can't convert it, an errParse is thrown
- + */
- +bool dc_maybe_stuff_ubyte(ubyte *i);
- +
- +/**
- + * @brief Tries to stuff a bool from the Command_string.
- + *
- + * @param[in] b The bool variable to maybe stuff.
- + *
- + * @details
- + * If there's nothing on the command line, *b = false and false is returned
- + *
- + * If there's something on the command line, and we're able to convert it, *b = the converted value, true is
- + * returned, and the parser is advanced past the token
- + *
- + * If there's something on command line, but we can't convert it, an errParse is thrown
- + */
- +bool dc_maybe_stuff_boolean(bool *b);
- +
- +/**
- + * @brief Tries to stuff an int with a bool value from the Command_string.
- + *
- + * @param[in] i The int variable to maybe stuff.
- + *
- + * @details
- + * If there's nothing on the command line, *i = 0 and false is returned
- + *
- + * If there's something on the command line, and we're able to convert it, *i = the converted value, true is
- + * returned, and the parser is advanced past the token
- + *
- + * If there's something on command line, but we can't convert it, an errParse is thrown
- + */
- +bool dc_maybe_stuff_boolean(int *i);
- +
- +/**
- + * @brief Tries to stuff a string to out_str from the command line, stopping at the end of the command line
- + *
- + * @param[out] out_str Destination string. If nothing was found, out_str = ""
- + * @param[in] len Maximum length to copy. (maxlen <= sizeof(str)) && (maxlen <= MAX_TOKEN_LENGTH)
- + *
- + * @retval true if the operation was successful,
- + * @retval false otherwise
- + *
- + * @throws errParseOverflow when parser cannot stuff the entirety of the found string into out_str
- + */
- +bool dc_maybe_stuff_string(char *str, size_t len);
- +
- +/**
- + * @brief Tries to stuff a string to out_str from the command line, stopping at the end of the command line
- + *
- + * @param[out] out_str Destination string. If nothing was found, out_str = ""
- + *
- + * @retval true if the operation was successful,
- + * @retval false otherwise
- + */
- +bool dc_maybe_stuff_string(SCP_string &str);
- +
- +/**
- + * @brief Tries to stuff a whitespace delimited string to out_str from the command line, stopping at the end of the command line
- + *
- + * @param[out] out_str Destination string. If nothing was found, out_str = ""
- + * @param[in] len Maximum length to copy. (maxlen <= sizeof(str)) && (maxlen <= MAX_TOKEN_LENGTH)
- + *
- + * @retval true if the operation was successful,
- + * @retval false otherwise
- + *
- + * @throws errParseOverflow when parser cannot stuff the entirety of the found string into out_str
- + */
- +bool dc_maybe_stuff_string_white(char *str, size_t len);
- +
- +/**
- + * @brief Tries to stuff a whitespace delimited string to out_str from the command line, stopping at the end of the command line
- + *
- + * @param[out] out_str Destination string. If nothing was found, out_str = ""
- + *
- + * @retval true if the operation was successful,
- + * @retval false otherwise
- + */
- +bool dc_maybe_stuff_string_white(SCP_string &str);
- +
- +#endif // _CONSOLEPARSE_H
- \ No newline at end of file
- diff --git a/code/freespace2/freespace.cpp b/code/freespace2/freespace.cpp
- index 7f9c686..dd533de 100644
- --- a/code/freespace2/freespace.cpp
- +++ b/code/freespace2/freespace.cpp
- @@ -33,6 +33,7 @@
- #include "cutscene/cutscenes.h"
- #include "cutscene/movie.h"
- #include "debris/debris.h"
- +#include "debugconsole/console.h"
- #include "exceptionhandler/exceptionhandler.h"
- #include "external_dll/trackirpublic.h" // header file for the TrackIR routines (Swifty)
- #include "fireball/fireballs.h"
- @@ -665,10 +666,9 @@ void big_explosion_flash(float flash)
- int Sun_drew = 0;
- float sn_glare_scale = 1.7f;
- -DCF(sn_glare, "")
- +DCF(sn_glare, "Sets the sun glare scale (Default is 1.7)")
- {
- - dc_get_arg(ARG_FLOAT);
- - sn_glare_scale = Dc_arg_float;
- + dc_stuff_float(&sn_glare_scale);
- }
- float Supernova_last_glare = 0.0f;
- @@ -1499,80 +1499,101 @@ DCF_BOOL(i_framerate, Interface_framerate )
- DCF(warp, "Tests warpin effect")
- {
- - if ( Dc_command ) {
- - bool warpin = true;
- - int idx = -1;
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Params: bool warpin, string Target = ""\n Warps in if true, out if false. Player is target unless specific ship is specified\n" );
- + return;
- + } // Else, process command
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if( Dc_arg_type & ARG_TRUE) warpin = true;
- - else if(Dc_arg_type & ARG_FALSE) warpin = false;
- + // TODO: Provide status flag
- - if(!(Dc_arg_type & ARG_NONE))
- - {
- - dc_get_arg(ARG_STRING|ARG_NONE);
- - if(Dc_arg_type & ARG_STRING)
- - {
- - idx = ship_name_lookup(Dc_arg);
- - if(idx > -1)
- - {
- - if(warpin)
- - shipfx_warpin_start(&Objects[Ships[idx].objnum]);
- - else
- - shipfx_warpout_start(&Objects[Ships[idx].objnum]);
- - }
- + bool warpin;
- + char target[MAX_NAME_LEN];
- + int idx = -1;
- +
- + dc_stuff_boolean(&warpin);
- + if (dc_maybe_stuff_string_white(target, MAX_NAME_LEN)) {
- + idx = ship_name_lookup(target);
- + } // Else, default target to player
- +
- + if (idx < 0) {
- + // Player is target
- + if (Player_ai->target_objnum > -1) {
- + if(warpin) {
- + shipfx_warpin_start(&Objects[Player_ai->target_objnum]);
- + } else {
- + shipfx_warpout_start(&Objects[Player_ai->target_objnum]);
- }
- }
- -
- - if(idx < 0)
- - {
- - if(Player_ai->target_objnum > -1)
- - {
- - if(warpin)
- - shipfx_warpin_start(&Objects[Player_ai->target_objnum]);
- - else
- - shipfx_warpout_start(&Objects[Player_ai->target_objnum]);
- - }
- + } else {
- + // Non-player is targer
- + if (warpin) {
- + shipfx_warpin_start(&Objects[Ships[idx].objnum]);
- + } else {
- + shipfx_warpout_start(&Objects[Ships[idx].objnum]);
- }
- - }
- - if ( Dc_help ) dc_printf( "Usage: Show_mem\nWarps in if true, out if false, player target unless specific ship is specified\n" );
- + }
- +
- }
- DCF(show_mem,"Toggles showing mem usage")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if ( Dc_arg_type & ARG_TRUE ) Show_mem = 1;
- - else if ( Dc_arg_type & ARG_FALSE ) Show_mem = 0;
- - else if ( Dc_arg_type & ARG_NONE ) Show_mem ^= 1;
- + bool process = true;
- - if ( Show_mem ) {
- - Show_cpu = 0;
- - }
- - }
- - if ( Dc_help ) dc_printf( "Usage: Show_mem\nSets show_mem to true or false. If nothing passed, then toggles it.\n" );
- - if ( Dc_status ) {
- - dc_printf( "Show_mem is %s\n", (Show_mem?"TRUE":"FALSE") );
- - dc_printf( "Show_cpu is %s\n", (Show_cpu?"TRUE":"FALSE") );
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: (optional) bool Show_mem\n If true, Show_mem is set and Show_cpu is cleared. If false, then Show_mem is cleared. If nothing passed, then toggle.\n" );
- + process = false;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Show_mem is %s\n", (Show_mem ? "TRUE" : "FALSE"));
- + dc_printf("Show_cpu is %s\n", (Show_cpu ? "TRUE" : "FALSE"));
- + process = false;
- + }
- +
- + if (!process) {
- + // Help and/or status was given, so don't process the command
- + return;
- + } // Else, process the command
- +
- + if (!dc_maybe_stuff_boolean(&Show_mem)) {
- + // Nothing passed, so toggle
- + Show_mem = !Show_mem;
- + } // Else, value was set/cleared by user
- +
- + // Can't show mem and cpu at same time
- + if (Show_mem) {
- + Show_cpu = false;
- }
- }
- DCF(show_cpu,"Toggles showing cpu usage")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if ( Dc_arg_type & ARG_TRUE ) Show_cpu = 1;
- - else if ( Dc_arg_type & ARG_FALSE ) Show_cpu = 0;
- - else if ( Dc_arg_type & ARG_NONE ) Show_cpu ^= 1;
- + bool process = true;
- - if ( Show_cpu ) {
- - Show_mem = 0;
- - }
- - }
- - if ( Dc_help ) dc_printf( "Usage: Show_cpu\nSets show_cpu to true or false. If nothing passed, then toggles it.\n" );
- - if ( Dc_status ) {
- - dc_printf( "Show_mem is %s\n", (Show_mem?"TRUE":"FALSE") );
- - dc_printf( "Show_cpu is %s\n", (Show_cpu?"TRUE":"FALSE") );
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: (optional) bool Show_cpu\n If true, Show_cpu is set and Show_mem is cleared. If false, then Show_cpu is cleared. If nothing passed, then toggle.\n" );
- + process = false;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Show_cpu is %s\n", (Show_cpu ? "TRUE" : "FALSE"));
- + dc_printf("Show_mem is %s\n", (Show_mem ? "TRUE" : "FALSE"));
- + process = false;
- + }
- + if (!process) {
- + // Help and/or status was given, so don't process the command
- + return;
- + } // Else, process the command
- +
- + if (!dc_maybe_stuff_boolean(&Show_cpu)) {
- + // Nothing passed, so toggle
- + Show_cpu = !Show_cpu;
- + } // Else, value was set/cleared by user
- +
- + // Can't show mem and cpu at same time
- + if (Show_cpu) {
- + Show_mem = false;
- }
- }
- @@ -1582,42 +1603,56 @@ DCF(show_cpu,"Toggles showing cpu usage")
- DCF(use_joy_mouse,"Makes joystick move mouse cursor")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if ( Dc_arg_type & ARG_TRUE ) Use_joy_mouse = 1;
- - else if ( Dc_arg_type & ARG_FALSE ) Use_joy_mouse = 0;
- - else if ( Dc_arg_type & ARG_NONE ) Use_joy_mouse ^= 1;
- - }
- - if ( Dc_help ) dc_printf( "Usage: use_joy_mouse [bool]\nSets use_joy_mouse to true or false. If nothing passed, then toggles it.\n" );
- - if ( Dc_status ) dc_printf( "use_joy_mouse is %s\n", (Use_joy_mouse?"TRUE":"FALSE") );
- + bool process = true;
- +
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: use_joy_mouse [bool]\nSets use_joy_mouse to true or false. If nothing passed, then toggles it.\n");
- + process = false;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("use_joy_mouse is %s\n", (Use_joy_mouse ? "TRUE" : "FALSE"));
- + process = false;
- + }
- +
- + if (!process) {
- + return;
- + }
- +
- + if(!dc_maybe_stuff_boolean(&Use_joy_mouse)) {
- + // Nothing passed, so toggle
- + Use_joy_mouse = !Use_joy_mouse;
- + } // Else, value was set/cleared by user
- os_config_write_uint( NULL, NOX("JoystickMovesCursor"), Use_joy_mouse );
- }
- -DCF(palette_flash,"Toggles palette flash effect on/off")
- -{
- - if ( Dc_command ) {
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if ( Dc_arg_type & ARG_TRUE ) Use_palette_flash = 1;
- - else if ( Dc_arg_type & ARG_FALSE ) Use_palette_flash = 0;
- - else if ( Dc_arg_type & ARG_NONE ) Use_palette_flash ^= 1;
- - }
- - if ( Dc_help ) dc_printf( "Usage: palette_flash [bool]\nSets palette_flash to true or false. If nothing passed, then toggles it.\n" );
- - if ( Dc_status ) dc_printf( "palette_flash is %s\n", (Use_palette_flash?"TRUE":"FALSE") );
- -}
- +DCF_BOOL(palette_flash, Use_palette_flash);
- int Use_low_mem = 0;
- DCF(low_mem,"Uses low memory settings regardless of RAM")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if ( Dc_arg_type & ARG_TRUE ) Use_low_mem = 1;
- - else if ( Dc_arg_type & ARG_FALSE ) Use_low_mem = 0;
- - else if ( Dc_arg_type & ARG_NONE ) Use_low_mem ^= 1;
- - }
- - if ( Dc_help ) dc_printf( "Usage: low_mem [bool]\nSets low_mem to true or false. If nothing passed, then toggles it.\n" );
- - if ( Dc_status ) dc_printf( "low_mem is %s\n", (Use_low_mem?"TRUE":"FALSE") );
- + bool process = true;
- +
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: low_mem [bool]\nSets low_mem to true or false. If nothing passed, then toggles it.\n");
- + process = false;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("low_mem is %s\n", (Use_low_mem ? "TRUE" : "FALSE"));
- + process = false;
- + }
- +
- + if (!process) {
- + return;
- + }
- +
- + if (!dc_maybe_stuff_boolean(&Use_low_mem)) {
- + // Nothing passed, so toggle
- + Use_low_mem = !Use_low_mem;
- + } // Else, value was set/cleared by user
- os_config_write_uint( NULL, NOX("LowMem"), Use_low_mem );
- }
- @@ -1627,14 +1662,26 @@ DCF(low_mem,"Uses low memory settings regardless of RAM")
- DCF(force_fullscreen, "Forces game to startup in fullscreen mode")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if ( Dc_arg_type & ARG_TRUE ) Use_fullscreen_at_startup = 1;
- - else if ( Dc_arg_type & ARG_FALSE ) Use_fullscreen_at_startup = 0;
- - else if ( Dc_arg_type & ARG_NONE ) Use_fullscreen_at_startup ^= 1;
- - }
- - if ( Dc_help ) dc_printf( "Usage: force_fullscreen [bool]\nSets force_fullscreen to true or false. If nothing passed, then toggles it.\n" );
- - if ( Dc_status ) dc_printf( "force_fullscreen is %s\n", (Use_fullscreen_at_startup?"TRUE":"FALSE") );
- + bool process = true;
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: low_mem [bool]\nSets low_mem to true or false. If nothing passed, then toggles it.\n");
- + process = false;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("low_mem is %s\n", (Use_fullscreen_at_startup ? "TRUE" : "FALSE"));
- + process = false;
- + }
- +
- + if (!process) {
- + return;
- + }
- +
- + if (dc_maybe_stuff_boolean(&Use_fullscreen_at_startup)) {
- + // Nothing passed, so toggle
- + Use_fullscreen_at_startup = !Use_fullscreen_at_startup;
- + } // Else, value was set/cleared by user
- +
- os_config_write_uint( NULL, NOX("ForceFullscreen"), Use_fullscreen_at_startup );
- }
- #endif
- @@ -1643,37 +1690,33 @@ int Framerate_delay = 0;
- float FreeSpace_gamma = 1.0f;
- -DCF(gamma,"Sets Gamma factor")
- +DCF(gamma,"Sets and saves Gamma Factor")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_FLOAT|ARG_NONE);
- - if ( Dc_arg_type & ARG_FLOAT ) {
- - FreeSpace_gamma = Dc_arg_float;
- - } else {
- - dc_printf( "Gamma reset to 1.0f\n" );
- - FreeSpace_gamma = 1.0f;
- - }
- - if ( FreeSpace_gamma < 0.1f ) {
- - FreeSpace_gamma = 0.1f;
- - } else if ( FreeSpace_gamma > 5.0f ) {
- - FreeSpace_gamma = 5.0f;
- - }
- - gr_set_gamma(FreeSpace_gamma);
- -
- - char tmp_gamma_string[32];
- - sprintf( tmp_gamma_string, NOX("%.2f"), FreeSpace_gamma );
- - os_config_write_string( NULL, NOX("Gamma"), tmp_gamma_string );
- - }
- -
- - if ( Dc_help ) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: gamma <float>\n" );
- dc_printf( "Sets gamma in range 1-3, no argument resets to default 1.2\n" );
- - Dc_status = 0; // don't print status if help is printed. Too messy.
- + return;
- }
- - if ( Dc_status ) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- dc_printf( "Gamma = %.2f\n", FreeSpace_gamma );
- + return;
- + }
- +
- + if (!dc_maybe_stuff_float(&FreeSpace_gamma)) {
- + dc_printf( "Gamma reset to 1.0f\n" );
- + FreeSpace_gamma = 1.0f;
- }
- + if ( FreeSpace_gamma < 0.1f ) {
- + FreeSpace_gamma = 0.1f;
- + } else if ( FreeSpace_gamma > 5.0f ) {
- + FreeSpace_gamma = 5.0f;
- + }
- + gr_set_gamma(FreeSpace_gamma);
- +
- + char tmp_gamma_string[32];
- + sprintf( tmp_gamma_string, NOX("%.2f"), FreeSpace_gamma );
- + os_config_write_string( NULL, NOX("Gamma"), tmp_gamma_string );
- }
- #ifdef APPLE_APP
- @@ -2399,33 +2442,54 @@ void game_show_time_left()
- DCF(ai_pause,"Pauses ai")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if ( Dc_arg_type & ARG_TRUE ) ai_paused = 1;
- - else if ( Dc_arg_type & ARG_FALSE ) ai_paused = 0;
- - else if ( Dc_arg_type & ARG_NONE ) ai_paused = !ai_paused;
- + bool process = true;
- +
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: ai_paused [bool]\nSets ai_paused to true or false. If nothing passed, then toggles it.\n" );
- + process = false;
- + }
- - if (ai_paused) {
- - obj_init_all_ships_physics();
- - }
- - }
- - if ( Dc_help ) dc_printf( "Usage: ai_paused [bool]\nSets ai_paused to true or false. If nothing passed, then toggles it.\n" );
- - if ( Dc_status ) dc_printf( "ai_paused is %s\n", (ai_paused?"TRUE":"FALSE") );
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf( "ai_paused is %s\n", (ai_paused?"TRUE":"FALSE") );
- + process = false;
- + }
- +
- + if (!process) {
- + return;
- + }
- +
- + if (!dc_maybe_stuff_boolean(&ai_paused)) {
- + ai_paused = !ai_paused;
- + }
- +
- + if (ai_paused) {
- + obj_init_all_ships_physics();
- + }
- }
- -DCF(single_step,"Single steps the game")
- +DCF(single_step,"Enables single step mode.")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if ( Dc_arg_type & ARG_TRUE ) game_single_step = 1;
- - else if ( Dc_arg_type & ARG_FALSE ) game_single_step = 0;
- - else if ( Dc_arg_type & ARG_NONE ) game_single_step = !game_single_step;
- + bool process = true;
- +
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: game_single_step [bool]\nEnables or disables single-step mode. If nothing passed, then toggles it.\nSingle-step mode will freeze the game, and will advance frame by frame with each key press\n");
- + process = false;
- + }
- - last_single_step = 0; // Make so single step waits a frame before stepping
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf( "ai_paused is %s\n", (game_single_step ? "TRUE" : "FALSE") );
- + process = false;
- + }
- - }
- - if ( Dc_help ) dc_printf( "Usage: single_step [bool]\nSets single_step to true or false. If nothing passed, then toggles it.\n" );
- - if ( Dc_status ) dc_printf( "single_step is %s\n", (game_single_step?"TRUE":"FALSE") );
- + if (!process) {
- + return;
- + }
- +
- + if (!dc_maybe_stuff_boolean(&game_single_step)) {
- + game_single_step = !game_single_step;
- + }
- +
- + last_single_step = 0; // Make so single step waits a frame before stepping
- }
- DCF_BOOL(physics_pause, physics_paused)
- @@ -2472,22 +2536,28 @@ int View_percent = 100;
- DCF(view, "Sets the percent of the 3d view to render.")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_INT);
- - if ( (Dc_arg_int >= 5 ) || (Dc_arg_int <= 100) ) {
- - View_percent = Dc_arg_int;
- - } else {
- - dc_printf( "Illegal value for view. (Must be from 5-100) \n\n");
- - Dc_help = 1;
- - }
- - }
- + bool process = true;
- + int value;
- - if ( Dc_help ) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf("Usage: view [n]\nwhere n is percent of view to show (5-100).\n");
- + process = false;
- }
- -
- - if ( Dc_status ) {
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- dc_printf("View is set to %d%%\n", View_percent );
- + process = false;
- + }
- +
- + if (!process) {
- + return;
- + }
- +
- + dc_stuff_int(&value);
- + if ( (value >= 5 ) && (value <= 100) ) {
- + View_percent = value;
- + } else {
- + dc_printf("Error: Outside legal range [5 - 100]");
- }
- }
- @@ -2814,65 +2884,86 @@ void do_timing_test(float frame_time)
- DCF(dcf_fov, "Change the field of view of the main camera")
- {
- camera *cam = Main_camera.getCamera();
- - if ( Dc_command )
- - {
- - if(cam == NULL)
- - return;
- + bool process = true;
- + float value;
- - dc_get_arg(ARG_FLOAT|ARG_NONE);
- - if ( Dc_arg_type & ARG_NONE ) {
- - cam->set_fov(VIEWER_ZOOM_DEFAULT);
- - dc_printf( "Zoom factor reset\n" );
- - }
- - if ( Dc_arg_type & ARG_FLOAT ) {
- - if (Dc_arg_float < 0.25f) {
- - cam->set_fov(0.25f);
- - dc_printf("Zoom factor pinned at 0.25.\n");
- - } else if (Dc_arg_float > 1.25f) {
- - cam->set_fov(1.25f);
- - dc_printf("Zoom factor pinned at 1.25.\n");
- - } else {
- - cam->set_fov(Dc_arg_float);
- - }
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: fov [factor]\nFactor is the zoom factor btwn .25 and 1.25\nNo parameter resets it to default.\n" );
- + process = false;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + if(cam == NULL) {
- + dc_printf("Camera unavailable.");
- + } else {
- + dc_printf("Zoom factor set to %6.3f (original = 0.5, John = 0.75)\n", cam->get_fov());
- }
- +
- + process = false;
- }
- - if ( Dc_help )
- - dc_printf( "Usage: fov [factor]\nFactor is the zoom factor btwn .25 and 1.25\nNo parameter resets it to default.\n" );
- + if ((cam == NULL) || (!process)) {
- + return;
- + }
- - if ( Dc_status )
- - {
- - if(cam == NULL)
- - dc_printf("Camera unavailable.");
- - else
- - dc_printf("Zoom factor set to %6.3f (original = 0.5, John = 0.75)", cam->get_fov());
- + if (!dc_maybe_stuff_float(&value)) {
- + // No value passed, use default
- + cam->set_fov(VIEWER_ZOOM_DEFAULT);
- + } else {
- + // Value passed, Clamp it to valid values
- + if (value < 0.25f) {
- + value = 0.25f;
- + dc_printf("Zoom factor clamped to 0.25\n");
- + } else if (value > 1.25f) {
- + value = 1.25f;
- + dc_printf("Zoom factor clamped to 1.25\n");
- + } else {
- + dc_printf("Zoom factor set to %6.3f\n", value);
- + }
- +
- + cam->set_fov(value);
- }
- }
- DCF(framerate_cap, "Sets the framerate cap")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_INT);
- - if ( (Dc_arg_int >= 1 ) || (Dc_arg_int <= 120) ) {
- - Framerate_cap = Dc_arg_int;
- - } else {
- - dc_printf( "Illegal value for framerate cap. (Must be from 1-120) \n\n");
- - Dc_help = 1;
- - }
- - }
- + bool process = true;
- - if ( Dc_help ) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf("Usage: framerate_cap [n]\nwhere n is the frames per second to cap framerate at.\n");
- dc_printf("If n is 0 or omitted, then the framerate cap is removed\n");
- dc_printf("[n] must be from 1 to 120.\n");
- + process = false;
- }
- -
- - if ( Dc_status ) {
- - if ( Framerate_cap )
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + if ( Framerate_cap ) {
- dc_printf("Framerate cap is set to %d fps\n", Framerate_cap );
- - else
- + } else {
- dc_printf("There is no framerate cap currently active.\n");
- + }
- +
- + process = false;
- + }
- +
- + if (!process) {
- + return;
- + }
- +
- + if (!dc_maybe_stuff_int(&Framerate_cap)) {
- + Framerate_cap = 0;
- + }
- +
- + if ((Framerate_cap < 0) || (Framerate_cap > 120)) {
- + dc_printf( "Illegal value for framerate cap. (Must be from 1-120) \n");
- + Framerate_cap = 0;
- + }
- +
- + if (Framerate_cap == 0) {
- + dc_printf("Framerate cap disabled");
- + } else {
- + dc_printf("Framerate cap is set to %d fps\n", Framerate_cap );
- }
- }
- @@ -3774,87 +3865,71 @@ void john_debug_stuff(vec3d *eye_pos, matrix *eye_orient)
- #ifndef NDEBUG
- // function to toggle state of dumping every frame into PCX when playing the game
- -DCF(dump_frames, "Starts/stop frame dumping at 15 hz")
- -{
- - if ( Dc_command ) {
- -
- - if ( Debug_dump_frames == 0 ) {
- - // Turn it on
- - Debug_dump_frames = 15;
- - Debug_dump_trigger = 0;
- - gr_dump_frame_start( Debug_dump_frame_num, DUMP_BUFFER_NUM_FRAMES );
- - dc_printf( "Frame dumping at 15 hz is now ON\n" );
- - } else {
- - // Turn it off
- - Debug_dump_frames = 0;
- - Debug_dump_trigger = 0;
- - gr_dump_frame_stop();
- - dc_printf( "Frame dumping is now OFF\n" );
- - }
- -
- +DCF(dump_frames, "Toggles On/off frame dumping at 15 hz")
- +{
- + if ( Debug_dump_frames == 0 ) {
- + // Turn it on
- + Debug_dump_frames = 15;
- + Debug_dump_trigger = 0;
- + gr_dump_frame_start( Debug_dump_frame_num, DUMP_BUFFER_NUM_FRAMES );
- + dc_printf( "Frame dumping at 15 hz is now ON\n" );
- + } else {
- + // Turn it off
- + Debug_dump_frames = 0;
- + Debug_dump_trigger = 0;
- + gr_dump_frame_stop();
- + dc_printf( "Frame dumping is now OFF\n" );
- }
- }
- DCF(dump_frames_trigger, "Starts/stop frame dumping at 15 hz")
- {
- - if ( Dc_command ) {
- -
- - if ( Debug_dump_frames == 0 ) {
- - // Turn it on
- - Debug_dump_frames = 15;
- - Debug_dump_trigger = 1;
- - gr_dump_frame_start( Debug_dump_frame_num, DUMP_BUFFER_NUM_FRAMES );
- - dc_printf( "Frame dumping at 15 hz is now ON\n" );
- - } else {
- - // Turn it off
- - Debug_dump_frames = 0;
- - Debug_dump_trigger = 0;
- - gr_dump_frame_stop();
- - dc_printf( "Frame dumping is now OFF\n" );
- - }
- -
- + if ( Debug_dump_frames == 0 ) {
- + // Turn it on
- + Debug_dump_frames = 15;
- + Debug_dump_trigger = 1;
- + gr_dump_frame_start( Debug_dump_frame_num, DUMP_BUFFER_NUM_FRAMES );
- + dc_printf( "Frame dumping at 15 hz is now ON\n" );
- + } else {
- + // Turn it off
- + Debug_dump_frames = 0;
- + Debug_dump_trigger = 0;
- + gr_dump_frame_stop();
- + dc_printf( "Frame dumping is now OFF\n" );
- }
- }
- DCF(dump_frames30, "Starts/stop frame dumping at 30 hz")
- {
- - if ( Dc_command ) {
- -
- - if ( Debug_dump_frames == 0 ) {
- - // Turn it on
- - Debug_dump_frames = 30;
- - Debug_dump_trigger = 0;
- - gr_dump_frame_start( Debug_dump_frame_num, DUMP_BUFFER_NUM_FRAMES );
- - dc_printf( "Frame dumping at 30 hz is now ON\n" );
- - } else {
- - // Turn it off
- - Debug_dump_frames = 0;
- - Debug_dump_trigger = 0;
- - gr_dump_frame_stop();
- - dc_printf( "Frame dumping is now OFF\n" );
- - }
- -
- + if ( Debug_dump_frames == 0 ) {
- + // Turn it on
- + Debug_dump_frames = 30;
- + Debug_dump_trigger = 0;
- + gr_dump_frame_start( Debug_dump_frame_num, DUMP_BUFFER_NUM_FRAMES );
- + dc_printf( "Frame dumping at 30 hz is now ON\n" );
- + } else {
- + // Turn it off
- + Debug_dump_frames = 0;
- + Debug_dump_trigger = 0;
- + gr_dump_frame_stop();
- + dc_printf( "Frame dumping is now OFF\n" );
- }
- }
- DCF(dump_frames30_trigger, "Starts/stop frame dumping at 30 hz")
- {
- - if ( Dc_command ) {
- -
- - if ( Debug_dump_frames == 0 ) {
- - // Turn it on
- - Debug_dump_frames = 30;
- - Debug_dump_trigger = 1;
- - gr_dump_frame_start( Debug_dump_frame_num, DUMP_BUFFER_NUM_FRAMES );
- - dc_printf( "Triggered frame dumping at 30 hz is now ON\n" );
- - } else {
- - // Turn it off
- - Debug_dump_frames = 0;
- - Debug_dump_trigger = 0;
- - gr_dump_frame_stop();
- - dc_printf( "Triggered frame dumping is now OFF\n" );
- - }
- -
- + if ( Debug_dump_frames == 0 ) {
- + // Turn it on
- + Debug_dump_frames = 30;
- + Debug_dump_trigger = 1;
- + gr_dump_frame_start( Debug_dump_frame_num, DUMP_BUFFER_NUM_FRAMES );
- + dc_printf( "Triggered frame dumping at 30 hz is now ON\n" );
- + } else {
- + // Turn it off
- + Debug_dump_frames = 0;
- + Debug_dump_trigger = 0;
- + gr_dump_frame_stop();
- + dc_printf( "Triggered frame dumping is now OFF\n" );
- }
- }
- @@ -6923,7 +6998,7 @@ void game_spew_pof_info()
- BAIL();
- }
- -DCF(pofspew, "")
- +DCF(pofspew, "Spews POF info without shutting down the game")
- {
- game_spew_pof_info();
- }
- diff --git a/code/gamehelp/contexthelp.cpp b/code/gamehelp/contexthelp.cpp
- index b16f2c2..9d25058 100644
- --- a/code/gamehelp/contexthelp.cpp
- +++ b/code/gamehelp/contexthelp.cpp
- @@ -19,6 +19,7 @@
- #include "localization/localize.h"
- #include "globalincs/alphacolors.h"
- #include "globalincs/systemvars.h"
- +#include "debugconsole/console.h"
- @@ -556,20 +557,14 @@ void help_overlay_blit(int overlay_id)
- // --------------------------------------------------
- // DEBUGGING STUFF
- // --------------------------------------------------
- -
- +// z64: These DCF's really need a do-over.
- DCF(help_reload, "Reloads help overlay data from help.tbl")
- {
- - if (Dc_command) {
- - parse_helptbl();
- - }
- -
- - if (Dc_help) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: sample\nCrashes your machine.\n" );
- }
- - if (Dc_status) {
- - dc_printf( "Yes, my master." );
- - }
- + parse_helptbl();
- }
- int h_textnum=0, h_amt=0, h_vtx = 0;
- @@ -630,150 +625,115 @@ void showplinepos(int plinenum)
- DCF(help_nudgetext_x, "Use to visually position overlay text.")
- {
- - if (Dc_command) {
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_textnum = Dc_arg_int;
- - }
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_amt = Dc_arg_int;
- - }
- - nudgetext_x(h_textnum, h_amt);
- - }
- - if (Dc_help) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: sample\nCrashes your machine.\n" );
- + return;
- }
- - if (Dc_status) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- showtextpos(h_textnum);
- + return;
- }
- +
- + dc_stuff_int(&h_textnum);
- + dc_stuff_int(&h_amt);
- +
- + nudgetext_x(h_textnum, h_amt);
- }
- DCF(help_nudgetext_y, "Use to visually position overlay text.")
- {
- - if (Dc_command) {
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_textnum = Dc_arg_int;
- - }
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_amt = Dc_arg_int;
- - }
- - nudgetext_y(h_textnum, h_amt);
- - }
- -
- - if (Dc_help) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: sample\nCrashes your machine.\n" );
- + return;
- }
- - if (Dc_status) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- showtextpos(h_textnum);
- + return;
- }
- +
- + dc_stuff_int(&h_textnum);
- + dc_stuff_int(&h_amt);
- +
- + nudgetext_y(h_textnum, h_amt);
- }
- DCF(help_nudgepline_x, "Use to visually position overlay polylines.")
- {
- - if (Dc_command) {
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_textnum = Dc_arg_int;
- - }
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_vtx = Dc_arg_int;
- - }
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_amt = Dc_arg_int;
- - }
- - nudgepline_x(h_textnum, h_vtx, h_amt);
- - }
- -
- - if (Dc_help) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: help_nudgepline [pline_number] [vertex_number] [distance]\n" );
- + return;
- }
- - if (Dc_status) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- showplinepos(h_textnum);
- + return;
- }
- +
- + dc_stuff_int(&h_textnum);
- + dc_stuff_int(&h_vtx);
- + dc_stuff_int(&h_amt);
- +
- + nudgepline_x(h_textnum, h_vtx, h_amt);
- }
- DCF(help_nudgepline_y, "Use to visually position overlay polylines.")
- {
- - if (Dc_command) {
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_textnum = Dc_arg_int;
- - }
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_vtx = Dc_arg_int;
- - }
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_amt = Dc_arg_int;
- - }
- - nudgepline_y(h_textnum, h_vtx, h_amt);
- - }
- -
- - if (Dc_help) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: help_nudgepline [pline_number] [vertex_number] [distance]\n" );
- + return;
- }
- - if (Dc_status) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- showplinepos(h_textnum);
- + return;
- }
- +
- + dc_stuff_int(&h_textnum);
- + dc_stuff_int(&h_vtx);
- + dc_stuff_int(&h_amt);
- +
- + nudgepline_y(h_textnum, h_vtx, h_amt);
- }
- DCF(help_nudgerbracket_x, "Use to visually position overlay right bracket.")
- {
- - if (Dc_command) {
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_textnum = Dc_arg_int;
- - }
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_amt = Dc_arg_int;
- - }
- - nudgerbracket_x(h_textnum, h_amt);
- - }
- -
- - if (Dc_help) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: help_nudgerbracket_x [num] [amount]\n" );
- + return;
- }
- - if (Dc_status) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- showrbracketpos(h_textnum);
- + return;
- }
- +
- + dc_stuff_int(&h_textnum);
- + dc_stuff_int(&h_amt);
- +
- + nudgerbracket_x(h_textnum, h_amt);
- }
- DCF(help_nudgerbracket_y, "Use to visually position overlay right bracket.")
- {
- - if (Dc_command) {
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_textnum = Dc_arg_int;
- - }
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_amt = Dc_arg_int;
- - }
- - nudgerbracket_y(h_textnum, h_amt);
- - }
- -
- - if (Dc_help) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: help_nudgerbracket_y [num] [amount]\n" );
- + return;
- }
- - if (Dc_status) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- showrbracketpos(h_textnum);
- + return;
- }
- +
- + dc_stuff_int(&h_textnum);
- + dc_stuff_int(&h_amt);
- +
- + nudgerbracket_y(h_textnum, h_amt);
- }
- @@ -781,46 +741,37 @@ DCF(help_nudgerbracket_y, "Use to visually position overlay right bracket.")
- DCF(help_nudgelbracket_x, "Use to visually position overlay left bracket.")
- {
- - if (Dc_command) {
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_textnum = Dc_arg_int;
- - }
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_amt = Dc_arg_int;
- - }
- - nudgelbracket_x(h_textnum, h_amt);
- - }
- - if (Dc_help) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: help_nudgelbracket_x [num] [amount]\n" );
- + return;
- }
- - if (Dc_status) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- showlbracketpos(h_textnum);
- + return;
- }
- +
- + dc_stuff_int(&h_textnum);
- + dc_stuff_int(&h_amt);
- +
- + nudgelbracket_x(h_textnum, h_amt);
- }
- DCF(help_nudgelbracket_y, "Use to visually position overlay left bracket.")
- {
- - if (Dc_command) {
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_textnum = Dc_arg_int;
- - }
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - h_amt = Dc_arg_int;
- - }
- - nudgelbracket_y(h_textnum, h_amt);
- - }
- -
- - if (Dc_help) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: help_nudgelbracket_y [num] [amount]\n" );
- + return;
- }
- - if (Dc_status) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- showlbracketpos(h_textnum);
- + return;
- }
- +
- + dc_stuff_int(&h_textnum);
- + dc_stuff_int(&h_amt);
- +
- + nudgelbracket_y(h_textnum, h_amt);
- }
- diff --git a/code/globalincs/pstypes.h b/code/globalincs/pstypes.h
- index 998e9f8..8e79d55 100644
- --- a/code/globalincs/pstypes.h
- +++ b/code/globalincs/pstypes.h
- @@ -319,113 +319,6 @@ extern int Fred_running; // Is Fred running, or FreeSpace?
- //======================================================================================
- -//====== D E B U G C O N S O L E S T U F F ========================
- -//======================================================================================
- -
- -// Here is a a sample command to toggle something that would
- -// be called by doing "toggle it" from the debug console command window/
- -
- -/*
- -DCF(toggle_it,"description")
- -{
- - if (Dc_command) {
- - This_var = !This_var;
- - }
- -
- - if (Dc_help) {
- - dc_printf( "Usage: sample\nToggles This_var on/off.\n" );
- - }
- -
- - if (Dc_status) {
- - dc_printf( "The status is %d.\n", This_var );
- - }
- -*/
- -
- -class debug_command {
- - public:
- - char *name;
- - char *help;
- - void (*func)();
- - debug_command(char *name,char *help,void (*func)()); // constructor
- -};
- -
- -#define DCF(function_name,help_text) \
- - void dcf_##function_name(); \
- - debug_command dc_##function_name(#function_name,help_text,dcf_##function_name); \
- - void dcf_##function_name()
- -
- -// Starts the debug console
- -extern void debug_console( void (*func)() = NULL );
- -
- -// The next three variables tell your function what to do. It should
- -// only change something if the dc_command is set. A minimal function
- -// needs to process the dc_command. Usually, these will be called in
- -// these combinations:
- -// dc_command=true, dc_status=true means process it and show status
- -// dc_help=true means show help only
- -// dc_status=true means show status only
- -// I would recommend doing this in each function:
- -// if (dc_command) { process command }
- -// if (dc_help) { print out help }
- -// if (dc_status) { print out status }
- -// with the last two being optional
- -
- -extern int Dc_command; // If this is set, then process the command
- -extern int Dc_help; // If this is set, then print out the help text in the form, "usage: ... \nLong description\n" );
- -extern int Dc_status; // If this is set, then print out the current status of the command.
- -
- -void dc_get_arg(uint flags); // Gets the next argument. If it doesn't match the flags, this function will print an error and not return.
- -extern char *Dc_arg; // The (lowercased) string value of the argument retrieved from dc_arg
- -extern char *Dc_arg_org; // Dc_arg before it got converted to lowercase
- -extern uint Dc_arg_type; // The type of dc_arg.
- -extern char *Dc_command_line; // The rest of the command line, from the end of the last processed arg on.
- -extern int Dc_arg_int; // If Dc_arg_type & ARG_INT or ARG_HEX is set, then this is the value
- -extern ubyte Dc_arg_ubyte; // If Dc_arg_type & ARG_UBYTE is set, then this is the value
- -extern float Dc_arg_float; // If Dc_arg_type & ARG_FLOAT is set, then this is the value
- -
- -// Outputs text to the console
- -void dc_printf( char *format, ... );
- -
- -// Each dc_arg_type can have one or more of these flags set.
- -// This is because some things can fit into two categories.
- -// Like 1 can be an integer, a float, a string, or a true boolean
- -// value.
- -#define ARG_NONE (1<<0) // no argument
- -#define ARG_ANY 0xFFFFFFFF // Anything.
- -#define ARG_STRING (1<<1) // any valid string
- -#define ARG_QUOTE (1<<2) // a quoted string
- -#define ARG_INT (1<<3) // a valid integer
- -#define ARG_FLOAT (1<<4) // a valid floating point number
- -
- -// some specific commonly used predefined types. Can add up to (1<<31)
- -#define ARG_HEX (1<<5) // a valid hexadecimal integer. Note that ARG_INT will always be set also in this case.
- -#define ARG_TRUE (1<<6) // on, true, non-zero number
- -#define ARG_FALSE (1<<7) // off, false, zero
- -#define ARG_PLUS (1<<8) // Plus sign
- -#define ARG_MINUS (1<<9) // Minus sign
- -#define ARG_COMMA (1<<10) // a comma
- -#define ARG_UBYTE (1<<11) // a valid ubyte
- -
- -// A shortcut for boolean only variables.
- -// Example:
- -// DCF_BOOL( lighting, Show_lighting )
- -//
- -#define DCF_BOOL( function_name, bool_variable ) \
- - void dcf_##function_name(); \
- - debug_command dc_##function_name(#function_name,"Toggles "#bool_variable,dcf_##function_name ); \
- - void dcf_##function_name() { \
- - if ( Dc_command ) { \
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE); \
- - if ( Dc_arg_type & ARG_TRUE ) bool_variable = 1; \
- - else if ( Dc_arg_type & ARG_FALSE ) bool_variable = 0; \
- - else if ( Dc_arg_type & ARG_NONE ) bool_variable ^= 1; \
- - } \
- - if ( Dc_help ) dc_printf( "Usage: %s [bool]\nSets %s to true or false. If nothing passed, then toggles it.\n", #function_name, #bool_variable ); \
- - if ( Dc_status ) dc_printf( "%s is %s\n", #function_name, (bool_variable?"TRUE":"FALSE") ); \
- -}
- -
- -
- -//======================================================================================
- //======================================================================================
- //======================================================================================
- diff --git a/code/globalincs/systemvars.cpp b/code/globalincs/systemvars.cpp
- index f7ac86c..72f6c21 100644
- --- a/code/globalincs/systemvars.cpp
- +++ b/code/globalincs/systemvars.cpp
- @@ -8,7 +8,7 @@
- */
- -
- +#include "debugconsole/console.h"
- #include "globalincs/pstypes.h"
- #include "globalincs/systemvars.h"
- #include "io/timer.h"
- @@ -248,73 +248,76 @@ int Monitor_inited = 0;
- char Monitor_filename[128];
- fix monitor_last_time = -1;
- -DCF(monitor,"Monitors game performace")
- +DCF(monitor,"Monitors game performace by saving to file")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_STRING|ARG_NONE);
- - if ( Dc_arg_type == ARG_NONE ) {
- - if ( Monitor_inited ) {
- - Monitor_inited = 0;
- + SCP_string filename;
- -/*
- - FILE *fp = fopen( Monitor_filename, "at" );
- - if ( fp ) {
- - fprintf( fp, "\n\n" );
- - fprintf( fp, "Name\tMin\tMax\tAvg\n" );
- - for (int i=0; i<Num_monitors; i++ ) {
- - if ( Monitor[i]->cnt > 0 ) {
- - fprintf( fp, "%s\t%d\t%d\t%d\n", Monitor[i]->name, Monitor[i]->min, Monitor[i]->max, Monitor[i]->sum / Monitor[i]->cnt );
- - } else {
- - fprintf( fp, "%s\t%d\t%d\t?\n", Monitor[i]->name, Monitor[i]->min, Monitor[i]->max );
- - }
- - }
- - fclose(fp);
- - }
- -*/
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: monitor [filename]\n");
- + dc_printf("Outputs monitoring info to [filename]. No filename turns it off\n" );
- + return;
- + }
- - dc_printf( "Monitor to file '%s' turned off\n", Monitor_filename );
- - } else {
- - dc_printf( "Monitor isn't on\n" );
- - }
- - } else {
- - if ( Monitor_inited ) {
- + if (dc_maybe_stuff_string_white(filename)) {
- + if ( Monitor_inited ) {
- dc_printf( "Monitor already on\n" );
- - } else {
- - Monitor_inited = 1;
- + } else {
- + Monitor_inited = 1;
- - strcpy_s( Monitor_filename, Dc_arg );
- + strcpy(Monitor_filename, filename.c_str());
- +
- + // Reset them all
- + int i;
- + for (i=0; i<Num_monitors; i++ ) {
- + Monitor[i]->value = 0;
- + Monitor[i]->sum = 0;
- + Monitor[i]->cnt = 0;
- + Monitor[i]->min = 0;
- + Monitor[i]->max = 0;
- + }
- - // Reset them all
- - int i;
- + FILE *fp = fopen( Monitor_filename, "wt" );
- + if ( fp ) {
- for (i=0; i<Num_monitors; i++ ) {
- - Monitor[i]->value = 0;
- - Monitor[i]->sum = 0;
- - Monitor[i]->cnt = 0;
- - Monitor[i]->min = 0;
- - Monitor[i]->max = 0;
- + if ( i > 0 ) {
- + fprintf( fp, "\t" );
- + }
- + fprintf( fp, "%s", Monitor[i]->name );
- +
- }
- + fprintf( fp, "\n" );
- + fclose(fp);
- + }
- + dc_printf( "Monitor outputting to file '%s'\n", Monitor_filename );
- + monitor_last_time = -1;
- + }
- +
- + } else {
- + // Turn off monitoring
- + if ( Monitor_inited ) {
- + Monitor_inited = 0;
- - FILE *fp = fopen( Monitor_filename, "wt" );
- - if ( fp ) {
- - for (i=0; i<Num_monitors; i++ ) {
- - if ( i > 0 ) {
- - fprintf( fp, "\t" );
- - }
- - fprintf( fp, "%s", Monitor[i]->name );
- -
- +/*
- + FILE *fp = fopen( Monitor_filename, "at" );
- + if ( fp ) {
- + fprintf( fp, "\n\n" );
- + fprintf( fp, "Name\tMin\tMax\tAvg\n" );
- + for (int i=0; i<Num_monitors; i++ ) {
- + if ( Monitor[i]->cnt > 0 ) {
- + fprintf( fp, "%s\t%d\t%d\t%d\n", Monitor[i]->name, Monitor[i]->min, Monitor[i]->max, Monitor[i]->sum / Monitor[i]->cnt );
- + } else {
- + fprintf( fp, "%s\t%d\t%d\t?\n", Monitor[i]->name, Monitor[i]->min, Monitor[i]->max );
- }
- - fprintf( fp, "\n" );
- - fclose(fp);
- }
- - dc_printf( "Monitor outputting to file '%s'\n", Monitor_filename );
- - monitor_last_time = -1;
- + fclose(fp);
- }
- +*/
- +
- + dc_printf( "Monitor to file '%s' turned off\n", Monitor_filename );
- + } else {
- + dc_printf( "Monitor isn't on\n" );
- }
- }
- - if ( Dc_help ) {
- - dc_printf( "Usage: monitor filename\nOutputs monitoring info to filename. No filename turns it off\n" );
- - }
- -
- }
- @@ -508,44 +511,41 @@ int current_detail_level()
- #ifndef NDEBUG
- DCF(detail_level,"Change the detail level")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_INT|ARG_NONE);
- - if ( Dc_arg_type & ARG_NONE ) {
- - Game_detail_level = 0;
- - dc_printf( "Detail level reset\n" );
- - }
- - if ( Dc_arg_type & ARG_INT ) {
- - Game_detail_level = Dc_arg_int;
- - }
- + int value;
- +
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: detail_level [n]\n");
- + dc_printf("[n] -- is detail level.\n");
- + dc_printf("\t0 is 'normal' detail,\n");
- + dc_printf("\tnegative values are lower, and\n");
- + dc_printf("\tpositive values are higher.\n\n");
- +
- + dc_printf("No parameter resets it to default.\n");
- + return;
- }
- - if ( Dc_help )
- - dc_printf( "Usage: detail_level [n]\nn is detail level. 0 normal, - lower, + higher, -2 to 2 usually\nNo parameter resets it to default.\n" );
- -
- - if ( Dc_status )
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- dc_printf("Detail level set to %d\n", Game_detail_level);
- + return;
- + }
- +
- + if (dc_maybe_stuff_int(&value)) {
- + Game_detail_level = value;
- + dc_printf("Detail level set to %i\n", Game_detail_level);
- +
- + } else {
- + Game_detail_level = 0;
- + dc_printf("Detail level reset\n");
- + }
- }
- DCF(detail, "Turns on/off parts of the game for speed testing" )
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_INT|ARG_NONE);
- - if ( Dc_arg_type & ARG_NONE ) {
- - if ( Game_detail_flags == DETAIL_DEFAULT ) {
- - Game_detail_flags = DETAIL_FLAG_CLEAR;
- - dc_printf( "Detail flags set lowest (except has screen clear)\n" );
- - } else {
- - Game_detail_flags = DETAIL_DEFAULT;
- - dc_printf( "Detail flags set highest\n" );
- - }
- - }
- - if ( Dc_arg_type & ARG_INT ) {
- - Game_detail_flags ^= Dc_arg_int;
- - }
- - }
- + int value;
- - if ( Dc_help ) {
- - dc_printf( "Usage: detail [n]\nn is detail bit to toggle.\n" );
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: detail [n]\n");
- + dc_printf("[n] is detail bit to toggle:\n" );
- dc_printf( " 1: draw the stars\n" );
- dc_printf( " 2: draw the nebulas\n" );
- dc_printf( " 4: draw the motion debris\n" );
- @@ -555,21 +555,38 @@ DCF(detail, "Turns on/off parts of the game for speed testing" )
- dc_printf( " 64: clear screen background after each frame\n" );
- dc_printf( " 128: draw hud stuff\n" );
- dc_printf( " 256: draw fireballs\n" );
- - dc_printf( " 512: do collision detection\n" );
- + dc_printf( " 512: do collision detection\n\n" );
- +
- + dc_printf("No argument will toggle between highest/lowest detail settings\n");
- + return;
- }
- - if ( Dc_status ) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- dc_printf("Detail flags set to 0x%08x\n", Game_detail_flags);
- - dc_printf( " 1: draw the stars: %s\n", (Game_detail_flags&1?"on":"off") );
- - dc_printf( " 2: draw the nebulas: %s\n", (Game_detail_flags&2?"on":"off") );
- - dc_printf( " 4: draw the motion debris: %s\n", (Game_detail_flags&4?"on":"off") );
- - dc_printf( " 8: draw planets: %s\n", (Game_detail_flags&8?"on":"off") );
- - dc_printf( " 16: draw models not as blobs: %s\n", (Game_detail_flags&16?"on":"off") );
- - dc_printf( " 32: draw lasers not as pixels: %s\n", (Game_detail_flags&32?"on":"off") );
- - dc_printf( " 64: clear screen background after each frame: %s\n", (Game_detail_flags&64?"on":"off") );
- - dc_printf( " 128: draw hud stuff: %s\n", (Game_detail_flags&128?"on":"off") );
- - dc_printf( " 256: draw fireballs: %s\n", (Game_detail_flags&256?"on":"off") );
- - dc_printf( " 512: do collision detection: %s\n", (Game_detail_flags&512?"on":"off") );
- + dc_printf( " 1: draw the stars: %s\n", ((Game_detail_flags & 1) ? "on" : "off"));
- + dc_printf( " 2: draw the nebulas: %s\n", ((Game_detail_flags & 2)?"on" : "off"));
- + dc_printf( " 4: draw the motion debris: %s\n", ((Game_detail_flags & 4) ? "on" : "off"));
- + dc_printf( " 8: draw planets: %s\n", ((Game_detail_flags & 8) ? "on" : "off"));
- + dc_printf( " 16: draw models not as blobs: %s\n", ((Game_detail_flags & 16) ? "on" : "off"));
- + dc_printf( " 32: draw lasers not as pixels: %s\n", ((Game_detail_flags & 32) ? "on" : "off"));
- + dc_printf( " 64: clear screen background after each frame: %s\n", ((Game_detail_flags & 64) ? "on" : "off"));
- + dc_printf( " 128: draw hud stuff: %s\n", ((Game_detail_flags & 128) ? "on" : "off"));
- + dc_printf( " 256: draw fireballs: %s\n", ((Game_detail_flags & 256) ? "on" : "off"));
- + dc_printf( " 512: do collision detection: %s\n", ((Game_detail_flags & 512) ? "on" : "off"));
- + return;
- + }
- +
- + if (dc_maybe_stuff_int(&value)) {
- + Game_detail_flags ^= value;
- +
- + } else {
- + if (Game_detail_flags == DETAIL_DEFAULT) {
- + Game_detail_flags = DETAIL_FLAG_CLEAR;
- + dc_printf( "Detail flags set lowest (except has screen clear)\n" );
- + } else {
- + Game_detail_flags = DETAIL_DEFAULT;
- + dc_printf( "Detail flags set highest\n" );
- + }
- }
- }
- #endif
- diff --git a/code/globalincs/vmallocator.h b/code/globalincs/vmallocator.h
- index 7cf2e37..1af80bc 100644
- --- a/code/globalincs/vmallocator.h
- +++ b/code/globalincs/vmallocator.h
- @@ -8,6 +8,7 @@
- #include <map>
- #include <string>
- #include <queue>
- +#include <deque>
- #if defined __GNUC__
- #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
- @@ -127,6 +128,9 @@ class SCP_multimap : public std::multimap<T, U, std::less<T>, SCP_vm_allocator<s
- template< typename T >
- class SCP_queue : public std::queue< T, std::deque< T, SCP_vm_allocator< T > > > { };
- +template< typename T >
- +class SCP_deque : public std::deque< T, SCP_vm_allocator< T > > { };
- +
- template <class T1, class T2>
- bool operator==(const SCP_vm_allocator<T1>&, const SCP_vm_allocator<T2>&) throw()
- {
- diff --git a/code/globalincs/windebug.cpp b/code/globalincs/windebug.cpp
- index c73057e..aaa5f83 100644
- --- a/code/globalincs/windebug.cpp
- +++ b/code/globalincs/windebug.cpp
- @@ -33,6 +33,7 @@
- #include "cmdline/cmdline.h"
- #include "parse/lua.h"
- #include "parse/parselo.h"
- +#include "debugconsole/console.h"
- #if defined( SHOW_CALL_STACK ) && defined( PDB_DEBUGGING )
- # include "globalincs/mspdb_callstack.h"
- @@ -1522,7 +1523,7 @@ void windebug_memwatch_init()
- #endif
- int Watch_malloc = 0;
- -DCF_BOOL(watch_malloc, Watch_malloc )
- +DCF_BOOL(watch_malloc, Watch_malloc );
- // Returns 0 if not enough RAM.
- int vm_init(int min_heap_size)
- diff --git a/code/graphics/2d.cpp b/code/graphics/2d.cpp
- index 454b88f..713a55a 100644
- --- a/code/graphics/2d.cpp
- +++ b/code/graphics/2d.cpp
- @@ -31,6 +31,7 @@
- #include "parse/scripting.h"
- #include "gamesequence/gamesequence.h" //WMC - for scripting hooks in gr_flip()
- #include "io/keycontrol.h" // m!m
- +#include "debugconsole/console.h"
- #if defined(SCP_UNIX) && !defined(__APPLE__)
- @@ -266,12 +267,9 @@ DCF(clear_color, "set clear color r, g, b")
- {
- ubyte r, g, b;
- - dc_get_arg(ARG_UBYTE);
- - r = Dc_arg_ubyte;
- - dc_get_arg(ARG_UBYTE);
- - g = Dc_arg_ubyte;
- - dc_get_arg(ARG_UBYTE);
- - b = Dc_arg_ubyte;
- + dc_stuff_ubyte(&r);
- + dc_stuff_ubyte(&g);
- + dc_stuff_ubyte(&b);
- // set the color
- gr_set_clear_color(r, g, b);
- diff --git a/code/graphics/gropengl.cpp b/code/graphics/gropengl.cpp
- index 4e781e7..2e7b716 100644
- --- a/code/graphics/gropengl.cpp
- +++ b/code/graphics/gropengl.cpp
- @@ -22,6 +22,7 @@
- #include "io/timer.h"
- #include "ddsutils/ddsutils.h"
- #include "model/model.h"
- +#include "debugconsole/console.h"
- #include "debugconsole/timerbar.h"
- #include "graphics/gropenglbmpman.h"
- #include "graphics/gropengllight.h"
- @@ -2078,56 +2079,61 @@ bool gr_opengl_init()
- DCF(ogl_minimize, "Minimizes opengl")
- {
- + bool minimize_ogl = false;
- +
- if ( gr_screen.mode != GR_OPENGL ) {
- dc_printf("Command only available in OpenGL mode.\n");
- return;
- }
- - if (Dc_command) {
- - dc_get_arg(ARG_TRUE);
- -
- - if ( Dc_arg_type & ARG_TRUE ) {
- - opengl_minimize();
- - }
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("[bool] If true is passed, then the OpenGL window will minimize.\n");
- + return;
- }
- + dc_stuff_boolean(&minimize_ogl);
- - if (Dc_help)
- - dc_printf("If set to true then the OpenGL window will minimize.\n");
- + if (minimize_ogl) {
- + opengl_minimize();
- + }
- }
- DCF(ogl_anisotropy, "toggles anisotropic filtering")
- {
- + bool process = true;
- + int value;
- +
- if ( gr_screen.mode != GR_OPENGL ) {
- dc_printf("Can only set anisotropic filter in OpenGL mode.\n");
- return;
- }
- - if ( Dc_command && !Is_Extension_Enabled(OGL_EXT_TEXTURE_FILTER_ANISOTROPIC) ) {
- - dc_printf("Error: Anisotropic filter is not settable!\n");
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Sets OpenGL anisotropic filtering level.\n");
- + dc_printf("GL_anisotropy [int] Valid values are 0 to %i. 0 turns off anisotropic filtering.\n", (int)opengl_get_max_anisotropy());
- + process = false;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Current anisotropic filter value is %i\n", (int)GL_anisotropy);
- + process = false;
- + }
- +
- + if (!process) {
- return;
- }
- - if ( Dc_command ) {
- - dc_get_arg(ARG_INT | ARG_NONE);
- + if ( !Is_Extension_Enabled(OGL_EXT_TEXTURE_FILTER_ANISOTROPIC) ) {
- + dc_printf("Error: Anisotropic filter is not settable!\n");
- + return;
- + }
- - if ( Dc_arg_type & ARG_NONE ) {
- + if (!dc_maybe_stuff_int(&value)) {
- + // No arg passed, set to default
- GL_anisotropy = 1.0f;
- // opengl_set_anisotropy();
- dc_printf("Anisotropic filter value reset to default level.\n");
- - }
- -
- - if ( Dc_arg_type & ARG_INT ) {
- - GL_anisotropy = (GLfloat)Dc_arg_float;
- + } else {
- + GL_anisotropy = (GLfloat)value;
- // opengl_set_anisotropy( (float)Dc_arg_float );
- - }
- - }
- -
- - if ( Dc_status ) {
- - dc_printf("Current anisotropic filter value is %i\n", (int)GL_anisotropy);
- - }
- -
- - if (Dc_help) {
- - dc_printf("Sets OpenGL anisotropic filtering level.\n");
- - dc_printf("Valid values are 1 to %i, or 0 to turn off.\n", (int)opengl_get_max_anisotropy());
- }
- }
- diff --git a/code/hud/hudlock.cpp b/code/hud/hudlock.cpp
- index fb7d58e..f8d3b61 100644
- --- a/code/hud/hudlock.cpp
- +++ b/code/hud/hudlock.cpp
- @@ -26,6 +26,7 @@
- #include "mission/missionparse.h"
- #include "iff_defs/iff_defs.h"
- #include "network/multi.h"
- +#include "debugconsole/console.h"
- vec3d lock_world_pos;
- @@ -333,7 +334,7 @@ int hud_lock_has_homing_point()
- }
- int Nebula_sec_range = 0;
- -DCF_BOOL(nebula_sec_range, Nebula_sec_range)
- +DCF_BOOL(nebula_sec_range, Nebula_sec_range);
- int hud_lock_world_pos_in_range(vec3d *target_world_pos, vec3d *vec_to_target)
- {
- diff --git a/code/io/joy.cpp b/code/io/joy.cpp
- index 6494873..6905903 100644
- --- a/code/io/joy.cpp
- +++ b/code/io/joy.cpp
- @@ -21,6 +21,7 @@
- #include "io/joy_ff.h"
- #include "directx/vdinput.h"
- #include "osapi/osapi.h"
- +#include "debugconsole/console.h"
- @@ -300,45 +301,51 @@ void joy_get_caps(int max)
- int joy_get_scaled_reading(int raw, int axn);
- int joy_get_unscaled_reading(int raw, int axn);
- -DCF(joytest, "Test joystick")
- +DCF(joytest, "Test joystick (X, Y)")
- {
- - if (Dc_command) {
- - while (!keyd_pressed[KEY_ESC]) {
- - int x, y, axis[JOY_NUM_AXES];
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Outputs the scaled reading of the joystick to a seperate window.\n");
- + dc_printf("Press ESC to end the test\n");
- + }
- - if (joy_num_sticks < 1)
- - return;
- + while (!keyd_pressed[KEY_ESC]) {
- + int x, y, axis[JOY_NUM_AXES];
- - joystick_read_raw_axis(JOY_NUM_AXES, axis);
- + if (joy_num_sticks < 1)
- + return;
- - x = joy_get_scaled_reading(axis[0], 0);
- - y = joy_get_scaled_reading(axis[1], 1);
- + joystick_read_raw_axis(JOY_NUM_AXES, axis);
- - mprintf(("X=%5d Y=%5d Calibrated X=%6d Y=%6d\n", axis[0], axis[1], x, y));
- - Sleep(100);
- - }
- + x = joy_get_scaled_reading(axis[0], 0);
- + y = joy_get_scaled_reading(axis[1], 1);
- +
- + mprintf(("X=%5d Y=%5d Calibrated X=%6d Y=%6d\n", axis[0], axis[1], x, y));
- + Sleep(100);
- }
- }
- -DCF(joytest2, "Test joystick (extended)")
- +DCF(joytest2, "Test joystick (X, Y, Z, Rx, Ry, Rz)")
- {
- - if (Dc_command) {
- - while (!keyd_pressed[KEY_ESC]) {
- - int x, y, z, r, axis[JOY_NUM_AXES];
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Outputs the scaled reading of the joystick to a seperate window.\n");
- + dc_printf("Press ESC to end the test\n");
- + }
- - if (joy_num_sticks < 1)
- - return;
- + while (!keyd_pressed[KEY_ESC]) {
- + int x, y, z, r, axis[JOY_NUM_AXES];
- - joystick_read_raw_axis(JOY_NUM_AXES, axis);
- + if (joy_num_sticks < 1)
- + return;
- - x = joy_get_scaled_reading(axis[0], 0);
- - y = joy_get_scaled_reading(axis[1], 1);
- - z = joy_get_unscaled_reading(axis[2], 2);
- - r = joy_get_scaled_reading(axis[3], 3);
- + joystick_read_raw_axis(JOY_NUM_AXES, axis);
- - mprintf(("X=%5d Y=%5d Z=%5d Rx=%5d Ry=%5d Rz=%5d Cal X=%6d Y=%6d Z=%6d R=%6d\n", axis[0], axis[1], axis[2], axis[3], axis[4], axis[5], x, y, z, r));
- - Sleep(100);
- - }
- + x = joy_get_scaled_reading(axis[0], 0);
- + y = joy_get_scaled_reading(axis[1], 1);
- + z = joy_get_unscaled_reading(axis[2], 2);
- + r = joy_get_scaled_reading(axis[3], 3);
- +
- + mprintf(("X=%5d Y=%5d Z=%5d Rx=%5d Ry=%5d Rz=%5d Cal X=%6d Y=%6d Z=%6d R=%6d\n", axis[0], axis[1], axis[2], axis[3], axis[4], axis[5], x, y, z, r));
- + Sleep(100);
- }
- }
- diff --git a/code/lighting/lighting.cpp b/code/lighting/lighting.cpp
- index 345c706..481e8b8 100644
- --- a/code/lighting/lighting.cpp
- +++ b/code/lighting/lighting.cpp
- @@ -15,6 +15,7 @@
- #include "globalincs/systemvars.h"
- #include "graphics/2d.h"
- #include "cmdline/cmdline.h"
- +#include "debugconsole/console.h"
- @@ -62,52 +63,11 @@ int Lighting_flag = 1;
- DCF(light,"Changes lighting parameters")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_STRING);
- - if ( !strcmp( Dc_arg, "ambient" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float < 0.0f) || (Dc_arg_float > 1.0f) ) {
- - Dc_help = 1;
- - } else {
- - Ambient_light = Dc_arg_float;
- - }
- - } else if ( !strcmp( Dc_arg, "reflect" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float < 0.0f) || (Dc_arg_float > 1.0f) ) {
- - Dc_help = 1;
- - } else {
- - Reflective_light = Dc_arg_float;
- - }
- - } else if ( !strcmp( Dc_arg, "default" )) {
- - Lighting_mode = LM_BRIGHTEN;
- - Ambient_light = AMBIENT_LIGHT_DEFAULT;
- - Reflective_light = REFLECTIVE_LIGHT_DEFAULT;
- - Lighting_flag = 0;
- - } else if ( !strcmp( Dc_arg, "mode" )) {
- - dc_get_arg(ARG_STRING);
- - if ( !strcmp(Dc_arg, "light") ) {
- - Lighting_mode = LM_BRIGHTEN;
- - } else if ( !strcmp(Dc_arg, "darken")) {
- - Lighting_mode = LM_DARKEN;
- - } else {
- - Dc_help = 1;
- - }
- - } else if ( !strcmp( Dc_arg, "dynamic" )) {
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if ( Dc_arg_type & ARG_TRUE ) Lighting_flag = 1;
- - else if ( Dc_arg_type & ARG_FALSE ) Lighting_flag = 0;
- - else if ( Dc_arg_type & ARG_NONE ) Lighting_flag ^= 1;
- - } else if ( !strcmp( Dc_arg, "on" ) ) {
- - Lighting_off = 0;
- - } else if ( !strcmp( Dc_arg, "off" ) ) {
- - Lighting_off = 1;
- - } else {
- - // print usage, not stats
- - Dc_help = 1;
- - }
- - }
- + SCP_string arg_str;
- + float val_f;
- + bool val_b;
- - if ( Dc_help ) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: light keyword\nWhere keyword can be in the following forms:\n" );
- dc_printf( "light on|off Turns all lighting on/off\n" );
- dc_printf( "light default Resets lighting to all default values\n" );
- @@ -117,18 +77,70 @@ DCF(light,"Changes lighting parameters")
- dc_printf( "light mode [light|darken] Changes the lighting mode.\n" );
- dc_printf( " Where 'light' means the global light adds light.\n");
- dc_printf( " and 'darken' means the global light subtracts light.\n");
- - Dc_status = 0; // don't print status if help is printed. Too messy.
- + return;
- }
- - if ( Dc_status ) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- dc_printf( "Ambient light is set to %.2f\n", Ambient_light );
- dc_printf( "Reflective light is set to %.2f\n", Reflective_light );
- dc_printf( "Dynamic lighting is: %s\n", (Lighting_flag?"on":"off") );
- - switch( Lighting_mode ) {
- - case LM_BRIGHTEN: dc_printf( "Lighting mode is: light\n" ); break;
- - case LM_DARKEN: dc_printf( "Lighting mode is: darken\n" ); break;
- - default: dc_printf( "Lighting mode is: UNKNOWN\n" ); break;
- + switch( Lighting_mode ) {
- + case LM_BRIGHTEN:
- + dc_printf( "Lighting mode is: light\n" );
- + break;
- + case LM_DARKEN:
- + dc_printf( "Lighting mode is: darken\n" );
- + break;
- + default:
- + dc_printf( "Lighting mode is: UNKNOWN\n" );
- + }
- + return;
- + }
- +
- + if (dc_optional_string("ambient")) {
- + dc_stuff_float(&val_f);
- + if ((val_f < 0.0f) || (val_f > 1.0f)) {
- + dc_printf(" Error: ambient value must be between 0.0 and 1.0\n");
- + } else {
- + Ambient_light = val_f;
- }
- +
- + } else if (dc_optional_string("reflect")) {
- + dc_stuff_float(&val_f);
- + if ( (val_f < 0.0f) || (val_f > 1.0f)) {
- + dc_printf(" Error: reflect value mus be between 0.0 and 1.0\n");
- + } else {
- + Reflective_light = val_f;
- + }
- +
- + } else if (dc_optional_string("default")) {
- + Lighting_mode = LM_BRIGHTEN;
- + Ambient_light = AMBIENT_LIGHT_DEFAULT;
- + Reflective_light = REFLECTIVE_LIGHT_DEFAULT;
- + Lighting_flag = 0;
- +
- + } else if (dc_optional_string("mode")) {
- + dc_stuff_string_white(arg_str);
- + if (arg_str == "light") {
- + Lighting_mode = LM_BRIGHTEN;
- +
- + } else if (arg_str == "darken") {
- + Lighting_mode = LM_DARKEN;
- +
- + } else {
- + dc_printf(" Error: unknown light mode: '%s'\n", arg_str.c_str());
- + }
- +
- + } else if (dc_optional_string("dynamic")) {
- + dc_stuff_boolean(&val_b);
- + Lighting_flag = val_b;
- +
- + } else if(dc_maybe_stuff_boolean(&Lighting_off)) {
- + Lighting_off = !Lighting_off;
- +
- + } else {
- + dc_stuff_string_white(arg_str);
- + dc_printf("Error: Unknown argument '%s'\n");
- }
- }
- diff --git a/code/menuui/playermenu.cpp b/code/menuui/playermenu.cpp
- index c224cf8..3f399bc 100644
- --- a/code/menuui/playermenu.cpp
- +++ b/code/menuui/playermenu.cpp
- @@ -31,6 +31,7 @@
- #include "parse/parselo.h"
- #include "cfile/cfile.h"
- #include "network/multi.h"
- +#include "debugconsole/console.h"
- // --------------------------------------------------------------------------------------------------------
- @@ -1236,39 +1237,37 @@ void player_select_cancel_create()
- DCF(bastion,"Sets the player to be on the bastion (or any other main hall)")
- {
- - if(gameseq_get_state() != GS_STATE_INITIAL_PLAYER_SELECT) {
- - dc_printf("This command can only be run in the initial player select screen.\n");
- + int idx;
- +
- + if (gameseq_get_state() != GS_STATE_INITIAL_PLAYER_SELECT) {
- + dc_printf("This command can only be run while the in the initial player select screen. \n");
- return;
- }
- - if (Dc_command) {
- - dc_get_arg(ARG_INT | ARG_NONE);
- -
- - if (Dc_arg_type & ARG_INT) {
- - int idx = Dc_arg_int;
- -
- - Assert(Main_hall_defines.at(gr_screen.res).size() < INT_MAX);
- - if (idx < 0 || idx >= (int) Main_hall_defines.at(gr_screen.res).size()) {
- - dc_printf("Main hall index out of range\n");
- - } else {
- - main_hall_get_name(Player_select_force_main_hall, idx);
- - dc_printf("Player is now on main hall '%d'\n", Player_select_force_main_hall.c_str());
- - }
- - } else {
- - Player_select_force_main_hall = "1";
- - dc_printf("Player is now on the Bastion... hopefully\n");
- - }
- - Dc_status = 0;
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: bastion [index]\n");
- + dc_printf(" [index] -- optional main hall index; if not supplied, defaults to 1\n");
- + return;
- }
- - if (Dc_help) {
- - dc_printf("Usage: bastion [index]\n");
- - dc_printf(" [index] -- optional main hall index; if not supplied, defaults to 1\n");
- - Dc_status = 0;
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Player is on main hall '%s'\n", Player_select_force_main_hall.c_str());
- + return;
- }
- - if (Dc_status) {
- - dc_printf("There is no current main hall, as the player has not been selected yet!\n");
- + if (dc_maybe_stuff_int(&idx)) {
- + Assert(Main_hall_defines.at(gr_screen.res).size() < INT_MAX);
- + if (idx < 0 || idx >= (int) Main_hall_defines.at(gr_screen.res).size()) {
- + dc_printf("Main hall index out of range\n");
- + } else {
- + main_hall_get_name(Player_select_force_main_hall, idx);
- + dc_printf("Player is now on main hall '%d'\n", Player_select_force_main_hall.c_str());
- + }
- +
- + } else {
- + // No argument passed
- + Player_select_force_main_hall = "1";
- + dc_printf("Player is now on the Bastion... hopefully\n");
- }
- }
- diff --git a/code/mission/missiongoals.cpp b/code/mission/missiongoals.cpp
- index e860491..5e355b4 100644
- --- a/code/mission/missiongoals.cpp
- +++ b/code/mission/missiongoals.cpp
- @@ -13,6 +13,7 @@
- #include "mission/missiongoals.h"
- #include "mission/missionlog.h"
- #include "missionui/missionscreencommon.h"
- +#include "debugconsole/console.h"
- #include "freespace2/freespace.h"
- #include "gamesequence/gamesequence.h"
- #include "hud/hud.h"
- @@ -1264,77 +1265,101 @@ void mission_goal_mark_events_complete()
- }
- // some debug console functions to help list and change the status of mission goals
- -DCF(show_mission_goals,"List and change the status of mission goals")
- +DCF(show_mission_goals,"Lists the status of mission goals")
- {
- int i, type;
- - if (Dc_command)
- - Dc_status = 1;
- -
- - if (Dc_help) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf("Usage: show_mission_goals\n\nList all mission goals and their current status.\n");
- - Dc_status = 0;
- - }
- -
- - if (Dc_status) {
- - for (i=0; i<Num_goals; i++) {
- - type = Mission_goals[i].type & GOAL_TYPE_MASK;
- - dc_printf("%2d. %32s(%10s) -- ", i, Mission_goals[i].name, Goal_type_text(type));
- - if ( Mission_goals[i].satisfied == GOAL_COMPLETE )
- - dc_printf("satisfied.\n");
- - else if ( Mission_goals[i].satisfied == GOAL_INCOMPLETE )
- - dc_printf("not satisfied\n");
- - else if ( Mission_goals[i].satisfied == GOAL_FAILED )
- - dc_printf("failed\n");
- - else
- - dc_printf("\t[unknown goal status].\n");
- - }
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + // Don't do anything, but advance the parser past the flag
- + }
- +
- + for (i=0; i<Num_goals; i++) {
- + type = Mission_goals[i].type & GOAL_TYPE_MASK;
- + dc_printf("%2d. %32s(%10s) -- ", i, Mission_goals[i].name, Goal_type_text(type));
- + if ( Mission_goals[i].satisfied == GOAL_COMPLETE )
- + dc_printf("satisfied.\n");
- + else if ( Mission_goals[i].satisfied == GOAL_INCOMPLETE )
- + dc_printf("unsatisfied\n");
- + else if ( Mission_goals[i].satisfied == GOAL_FAILED )
- + dc_printf("failed\n");
- + else
- + dc_printf("Warning! Mission goal %i is in an invalid state! (value: %i)", i, Mission_goals[i].satisfied);
- }
- +
- }
- //XSTR:OFF
- -DCF(change_mission_goal, "Change the mission goal")
- +DCF(change_mission_goal, "Changes the mission goal status")
- {
- int num;
- + bool val_b;
- + char *string;
- - if ( Dc_command ) {
- - dc_get_arg(ARG_INT);
- - if ( Dc_arg_int >= Num_goals ) {
- - dc_printf ("First parameter must be a valid goal number.\n");
- - return;
- - }
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: change_mission_goal <goal_num> [status]\n");
- + dc_printf("<goal_num> -- Integer number of goal to change. See show_mission_goals\n");
- + dc_printf("[status] -- Goal status to change to.\n\n");
- - num = Dc_arg_int;
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_STRING);
- - if ( Dc_arg_type & ARG_TRUE )
- - Mission_goals[num].satisfied = GOAL_COMPLETE;
- - else if ( Dc_arg_type & ARG_FALSE )
- - Mission_goals[num].satisfied = GOAL_FAILED;
- - else if ( Dc_arg_type & ARG_NONE )
- - Mission_goals[num].satisfied = GOAL_INCOMPLETE;
- - else if ( Dc_arg_type & ARG_STRING) {
- - if ( !stricmp(Dc_arg, "satisfied") )
- - Mission_goals[num].satisfied = GOAL_COMPLETE;
- - else if ( !stricmp( Dc_arg, "failed") )
- - Mission_goals[num].satisfied = GOAL_FAILED;
- - else if ( !stricmp( Dc_arg, "unknown") )
- - Mission_goals[num].satisfied = GOAL_INCOMPLETE;
- - else
- - dc_printf("Unknown status %s. Use 'satisfied', 'failed', or 'unknown'\n", Dc_arg);
- - }
- + dc_printf("The optional [status] field may be either a bool type or a string.\n");
- + dc_printf("\ttrue -- Goal status set to 'complete'\n");
- + dc_printf("\tfalse -- Goal status set to 'failed'\n\n");
- +
- + dc_printf("A string value of 'satisfied', 'failed', or 'unknown' will set the goal status to the respective state.\n");
- + dc_printf("If [status] is not given, then the goal status will be set to 'unknown'");
- +
- + dc_printf("Examples:\n");
- + dc_printf("\t'change_mission_goal 1 true' makes goal 1 as successful.\n");
- + dc_printf("\t'change_mission_goal 2' marks goal 2 as unknown/incomplete\n");
- + dc_printf("\t'change_mission_goal 0 satisfied' marks goal 0 as satisfied\n");
- + return;
- }
- - if ( Dc_help ) {
- - dc_printf("Usage: change_mission_goal <goal_num> <status>\n");
- - dc_printf("<goal_num> -- Integer number of goal to change. See show_mission_goals\n");
- - dc_printf("<status> -- [bool] where a true value makes the goal satisfied,\n");
- - dc_printf(" a false value makes the goal failed.\n");
- - dc_printf("The <status> field may also be one of 'satisfied', 'failed', or 'unknown'\n");
- - dc_printf("\nExamples:\n\n'change_mission_goal 1 true' makes goal 1 successful.\n");
- - dc_printf("'change_mission_goal 2' marks goal 2 not complete\n");
- - dc_printf("'change_mission_goal 0 satisfied' marks goal 0 as satisfied\n");
- - Dc_status = 0;
- + dc_stuff_int(&num);
- + if ( num >= Num_goals ) {
- + dc_printf (" Error: Invalid value for <goal_num>. Valid values: 0 - %i\n", Num_goals);
- + return;
- + }
- +
- + if (dc_optional_string("satisfied")) {
- + Mission_goals[num].satisfied = GOAL_COMPLETE;
- +
- + } else if (dc_optional_string("failed")) {
- + Mission_goals[num].satisfied = GOAL_FAILED;
- +
- + } else if (dc_optional_string("unsatisfied")) {
- + Mission_goals[num].satisfied = GOAL_INCOMPLETE;
- +
- + } else if (dc_maybe_stuff_boolean(&val_b)) {
- + val_b ? Mission_goals[num].satisfied = GOAL_COMPLETE : Mission_goals[num].satisfied = GOAL_FAILED;
- +
- + } else {
- + // No argument given
- + Mission_goals[num].satisfied = GOAL_INCOMPLETE;
- + }
- +
- + switch(Mission_goals[num].satisfied) {
- + case GOAL_COMPLETE:
- + string = "satisfied";
- + break;
- +
- + case GOAL_FAILED:
- + string = "failed";
- + break;
- +
- + case GOAL_INCOMPLETE:
- + string = "unsatisfied";
- + break;
- +
- + default:
- + dc_printf("Warning! Mission goal %i is in an invalid state! (value: %i)", num, Mission_goals[num].satisfied);
- + return;
- }
- + dc_printf("Mission goal %i set to '%s'\n", num, string);
- }
- //XSTR:ON
- diff --git a/code/model/modelinterp.cpp b/code/model/modelinterp.cpp
- index 54e33c7..948447f 100644
- --- a/code/model/modelinterp.cpp
- +++ b/code/model/modelinterp.cpp
- @@ -33,6 +33,7 @@
- #include "graphics/gropengllight.h"
- #include "ship/shipfx.h"
- #include "gamesequence/gamesequence.h"
- +#include "debugconsole/console.h"
- #include <limits.h>
- @@ -1941,19 +1942,20 @@ float Interp_depth_scale = 1500.0f;
- DCF(model_darkening,"Makes models darker with distance")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_FLOAT);
- - Interp_depth_scale = Dc_arg_float;
- - }
- -
- - if ( Dc_help ) {
- - dc_printf( "Usage: model_darkening float\n" );
- - Dc_status = 0; // don't print status if help is printed. Too messy.
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: model_darkening <float>\n" );
- + dc_printf("Sets the distance at which to start blacking out models (namely asteroids).\n");
- + return;
- }
- - if ( Dc_status ) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- dc_printf( "model_darkening = %.1f\n", Interp_depth_scale );
- + return;
- }
- +
- + dc_stuff_float(&Interp_depth_scale);
- +
- + dc_printf("model_darkening set to %.1f\n", Interp_depth_scale);
- }
- void model_render(int model_num, matrix *orient, vec3d * pos, uint flags, int objnum, int lighting_skip, int *replacement_textures)
- @@ -2116,8 +2118,13 @@ float model_find_closest_point( vec3d *outpnt, int model_num, int submodel_num,
- }
- int tiling = 1;
- -DCF(tiling, "")
- +DCF(tiling, "Toggles rendering of tiled textures (default is on)")
- {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Tiled textures are %s", tiling ? "ON" : "OFF");
- + return;
- + }
- +
- tiling = !tiling;
- if(tiling){
- dc_printf("Tiled textures\n");
- diff --git a/code/nebula/neb.cpp b/code/nebula/neb.cpp
- index d038741..135efd6 100644
- --- a/code/nebula/neb.cpp
- +++ b/code/nebula/neb.cpp
- @@ -24,6 +24,7 @@
- #include "mission/missionparse.h"
- #include "ship/ship.h"
- #include "cmdline/cmdline.h"
- +#include "debugconsole/console.h"
- // --------------------------------------------------------------------------------------------------------
- @@ -503,7 +504,7 @@ void neb2_page_in()
- // should we not render this object because its obscured by the nebula?
- int neb_skip_opt = 1;
- -DCF(neb_skip, "")
- +DCF(neb_skip, "Toggles culling of objects obscured by nebula")
- {
- neb_skip_opt = !neb_skip_opt;
- if (neb_skip_opt) {
- @@ -896,12 +897,14 @@ void neb2_regen()
- }
- }
- +/*
- + * TODO: remove this
- float max_area = 100000000.0f;
- DCF(max_area, "")
- {
- - dc_get_arg(ARG_FLOAT);
- - max_area = Dc_arg_float;
- + dc_stuff_float(&max_area);
- }
- +*/
- float g3_draw_rotated_bitmap_area(vertex *pnt, float angle, float rad, uint tmap_flags, float area);
- int neb_mode = 1;
- @@ -1443,7 +1446,7 @@ int neb2_get_bitmap()
- }
- // nebula DCF functions ------------------------------------------------------
- -
- +// TODO: With the new debug parser in place, most of these sub-commands can now be handled by neb2. This should clear up the DCF list a bit
- DCF(neb2, "list nebula console commands")
- {
- // dc_printf("neb2_fog <X> <float> <float> : set near and far fog planes for ship type X\n");
- @@ -1463,7 +1466,7 @@ DCF(neb2, "list nebula console commands")
- dc_printf("neb2_cinner : poof cube inner dimension\n");
- dc_printf("neb2_couter : poof cube outer dimension\n");
- dc_printf("neb2_jitter : poof jitter\n");
- - dc_printf("neb2_mode : switch between no nebula, polygon background, pof background, lame or HTL rendering (0, 1, 2, 3 and 4 respectively)\n\n");
- + dc_printf("neb2_mode : switch between no nebula, polygon background, pof background, lame, or HTL rendering (0, 1, 2, 3 and 4 respectively)\n\n");
- dc_printf("neb2_ff : flash fade/sec\n");
- dc_printf("neb2_background : rgb background color\n");
- dc_printf("neb2_fog_color : rgb fog color\n");
- @@ -1471,95 +1474,91 @@ DCF(neb2, "list nebula console commands")
- // dc_printf("neb2_fog_vals : display all the current settings for all above values\n");
- }
- -DCF(neb2_prad, "")
- +DCF(neb2_prad, "set cloud poof radius")
- {
- - dc_get_arg(ARG_FLOAT);
- - Nd->prad = Dc_arg_float;
- + dc_stuff_float(&Nd->prad);
- }
- -DCF(neb2_cdim, "")
- +DCF(neb2_cdim, "poof cube dimension")
- {
- - dc_get_arg(ARG_FLOAT);
- - Nd->cube_dim = Dc_arg_float;
- + dc_stuff_float(&Nd->cube_dim);
- }
- -DCF(neb2_cinner, "")
- +DCF(neb2_cinner, "poof cube inner dimension")
- {
- - dc_get_arg(ARG_FLOAT);
- - Nd->cube_inner = Dc_arg_float;
- + dc_stuff_float(&Nd->cube_inner);
- }
- -DCF(neb2_couter, "")
- +DCF(neb2_couter, "poof cube outer dimension")
- {
- - dc_get_arg(ARG_FLOAT);
- - Nd->cube_outer = Dc_arg_float;
- + dc_stuff_float(&Nd->cube_outer);
- }
- -DCF(neb2_jitter, "")
- +DCF(neb2_jitter, "poof jitter")
- {
- - dc_get_arg(ARG_FLOAT);
- - Nd->hj = Nd->dj = Nd->wj = Dc_arg_float;
- + float value;
- + dc_stuff_float(&value);
- + Nd->hj = Nd->dj = Nd->wj = value;
- }
- -DCF(neb2_max_alpha, "")
- +DCF(neb2_max_alpha, "max alpha value (0.0 to 1.0) for cloud poofs.")
- {
- - dc_get_arg(ARG_FLOAT);
- - Nd->max_alpha_glide = Dc_arg_float;
- + dc_stuff_float(&Nd->max_alpha_glide);
- }
- -DCF(neb2_break_alpha, "")
- +DCF(neb2_break_alpha, "alpha value (0.0 to 1.0) at which faded polygons are not drawn.")
- {
- - dc_get_arg(ARG_FLOAT);
- - Nd->break_alpha = Dc_arg_float;
- + dc_stuff_float(&Nd->break_alpha);
- }
- -DCF(neb2_break_off, "")
- +DCF(neb2_break_off, "how many pixels offscreen (left, right, top, bottom) when a cloud poof becomes fully transparent.")
- {
- - dc_get_arg(ARG_INT);
- - Nd->break_y = (float)Dc_arg_int;
- - Nd->break_x = Nd->break_y * 1.3333f;
- + int value;
- + dc_stuff_int(&value);
- + Nd->break_y = (float)value;
- + Nd->break_x = Nd->break_y * gr_screen.aspect;
- }
- -DCF(neb2_smooth, "")
- +DCF(neb2_smooth, "magic fog smoothing modes (0 - 3)")
- {
- int index;
- - dc_get_arg(ARG_INT);
- - index = Dc_arg_int;
- + dc_stuff_int(&index);
- if ( (index >= 0) && (index <= 3) ) {
- wacky_scheme = index;
- + } else {
- + dc_printf("Invalid smooth mode %i", index);
- }
- }
- -DCF(neb2_select, "")
- +DCF(neb2_select, "Enables/disables a poof bitmap")
- {
- - dc_get_arg(ARG_INT);
- - int bmap = Dc_arg_int;
- + int bmap;
- + bool val_b;
- +
- + dc_stuff_int(&bmap);
- +
- if ( (bmap >= 0) && (bmap < Neb2_poof_count) ) {
- - dc_get_arg(ARG_INT);
- - if (Dc_arg_int) {
- - Neb2_poof_flags |= (1<<bmap);
- - } else {
- - Neb2_poof_flags &= ~(1<<bmap);
- - }
- + dc_stuff_boolean(&val_b);
- +
- + val_b ? (Neb2_poof_flags |= (1<<bmap)) : (Neb2_poof_flags &= ~(1<<bmap));
- }
- }
- -DCF(neb2_rot, "")
- +DCF(neb2_rot, "set max rotation speed for poofs")
- {
- - dc_get_arg(ARG_FLOAT);
- - max_rotation = Dc_arg_float;
- + dc_stuff_float(&max_rotation);
- }
- -DCF(neb2_ff, "")
- +DCF(neb2_ff, "flash fade/sec")
- {
- - dc_get_arg(ARG_FLOAT);
- - neb2_flash_fade = Dc_arg_float;
- + dc_stuff_float(&neb2_flash_fade);
- }
- -DCF(neb2_mode, "")
- +DCF(neb2_mode, "Switches nebula render modes")
- {
- - dc_get_arg(ARG_INT);
- + int mode;
- + dc_stuff_int(&mode);
- - switch (Dc_arg_int) {
- + switch (mode) {
- case NEB2_RENDER_NONE:
- Neb2_render_mode = NEB2_RENDER_NONE;
- break;
- @@ -1586,39 +1585,32 @@ DCF(neb2_mode, "")
- }
- }
- -DCF(neb2_slices, "")
- +DCF(neb2_slices, "Sets how many 'slices' are used in the nebula")
- {
- - dc_get_arg(ARG_INT);
- - Neb2_slices = Dc_arg_int;
- + dc_stuff_int(&Neb2_slices);
- neb2_eye_changed();
- }
- -DCF(neb2_background, "")
- +DCF(neb2_background, "Sets the RGB background color (lame rendering)")
- {
- int r, g, b;
- - dc_get_arg(ARG_INT);
- - r = Dc_arg_int;
- - dc_get_arg(ARG_INT);
- - g = Dc_arg_int;
- - dc_get_arg(ARG_INT);
- - b = Dc_arg_int;
- + dc_stuff_int(&r);
- + dc_stuff_int(&g);
- + dc_stuff_int(&b);
- Neb2_background_color[0] = r;
- Neb2_background_color[1] = g;
- Neb2_background_color[2] = b;
- }
- -DCF(neb2_fog_color, "")
- +DCF(neb2_fog_color, "Sets the RGB fog color (HTL)")
- {
- ubyte r, g, b;
- - dc_get_arg(ARG_UBYTE);
- - r = Dc_arg_ubyte;
- - dc_get_arg(ARG_UBYTE);
- - g = Dc_arg_ubyte;
- - dc_get_arg(ARG_UBYTE);
- - b = Dc_arg_ubyte;
- + dc_stuff_ubyte(&r);
- + dc_stuff_ubyte(&g);
- + dc_stuff_ubyte(&b);
- Neb2_fog_color_r = r;
- Neb2_fog_color_g = g;
- diff --git a/code/nebula/neblightning.cpp b/code/nebula/neblightning.cpp
- index f311e4a..b189349 100644
- --- a/code/nebula/neblightning.cpp
- +++ b/code/nebula/neblightning.cpp
- @@ -13,6 +13,7 @@
- #include "parse/parselo.h"
- #include "globalincs/linklist.h"
- #include "io/timer.h"
- +#include "debugconsole/console.h"
- #include "freespace2/freespace.h"
- #include "gamesnd/gamesnd.h"
- #include "render/3d.h"
- @@ -81,52 +82,43 @@ vec3d Nebl_bolt_strike; // strike point of the bolt being generated
- storm_type *Storm = NULL;
- // vars
- -DCF(b_scale, "")
- +DCF(b_scale, "Sets the scale factor for debug nebula bolts")
- {
- - dc_get_arg(ARG_FLOAT);
- - Bolt_types[DEBUG_BOLT].b_scale = Dc_arg_float;
- + dc_stuff_float(&Bolt_types[DEBUG_BOLT].b_scale);
- }
- -DCF(b_rand, "")
- +DCF(b_rand, "Sets the randomness factor for debug nebula bolts")
- {
- - dc_get_arg(ARG_FLOAT);
- - Bolt_types[DEBUG_BOLT].b_rand = Dc_arg_float;
- + dc_stuff_float(&Bolt_types[DEBUG_BOLT].b_rand);
- }
- -DCF(b_shrink, "")
- +DCF(b_shrink, "Sets the shrink factor for debug nebula bolts")
- {
- - dc_get_arg(ARG_FLOAT);
- - Bolt_types[DEBUG_BOLT].b_shrink = Dc_arg_float;
- + dc_stuff_float(&Bolt_types[DEBUG_BOLT].b_shrink);
- }
- -DCF(b_poly_pct, "")
- +DCF(b_poly_pct, "Sets b_poly_pct")
- {
- - dc_get_arg(ARG_FLOAT);
- - Bolt_types[DEBUG_BOLT].b_poly_pct = Dc_arg_float;
- + dc_stuff_float(&Bolt_types[DEBUG_BOLT].b_poly_pct);
- }
- -DCF(b_add, "")
- +DCF(b_add, "Sets b_add")
- {
- - dc_get_arg(ARG_FLOAT);
- - Bolt_types[DEBUG_BOLT].b_add = Dc_arg_float;
- + dc_stuff_float(&Bolt_types[DEBUG_BOLT].b_add);
- }
- -DCF(b_strikes, "")
- +DCF(b_strikes, "Sets num_strikes")
- {
- - dc_get_arg(ARG_INT);
- - Bolt_types[DEBUG_BOLT].num_strikes = Dc_arg_int;
- + dc_stuff_int(&Bolt_types[DEBUG_BOLT].num_strikes);
- }
- -DCF(b_noise, "")
- +DCF(b_noise, "Sets noise factor")
- {
- - dc_get_arg(ARG_FLOAT);
- - Bolt_types[DEBUG_BOLT].noise = Dc_arg_float;
- + dc_stuff_float(&Bolt_types[DEBUG_BOLT].noise);
- }
- -DCF(b_bright, "")
- +DCF(b_bright, "Sets brightness factor")
- {
- - dc_get_arg(ARG_FLOAT);
- - Bolt_types[DEBUG_BOLT].b_bright = Dc_arg_float;
- + dc_stuff_float(&Bolt_types[DEBUG_BOLT].b_bright);
- }
- -DCF(b_lifetime, "")
- +DCF(b_lifetime, "Sets lifetime duration")
- {
- - dc_get_arg(ARG_INT);
- - Bolt_types[DEBUG_BOLT].lifetime = Dc_arg_int;
- + dc_stuff_int(&Bolt_types[DEBUG_BOLT].lifetime);
- }
- -DCF(b_list, "")
- +DCF(b_list, "Displays status of debug lightning commands")
- {
- dc_printf("Debug lightning bolt settings :\n");
- @@ -144,12 +136,12 @@ DCF(b_list, "")
- // nebula lightning intensity (0.0 to 1.0)
- float Nebl_intensity = 0.6667f;
- -DCF(lightning_intensity, "")
- +DCF(lightning_intensity, "Sets lightning intensity between 0.0 and 1.0 (Default is 0.6667)")
- {
- - dc_get_arg(ARG_FLOAT);
- - float val = Dc_arg_float;
- -
- - CLAMP(val, 0.0f, 1.0f);
- + float val;
- + dc_stuff_float(&val);
- +
- + CLAMP(val, 0.0f, 1.0f);
- Nebl_intensity = 1.0f - val;
- }
- diff --git a/code/network/multi.cpp b/code/network/multi.cpp
- index 93d18c1..95fff3b 100644
- --- a/code/network/multi.cpp
- +++ b/code/network/multi.cpp
- @@ -48,6 +48,7 @@
- #include "cfile/cfile.h"
- #include "fs2netd/fs2netd_client.h"
- #include "pilotfile/pilotfile.h"
- +#include "debugconsole/console.h"
- @@ -1105,14 +1106,15 @@ void multi_process_incoming()
- //
- int eye_tog = 1;
- -DCF(eye_tog, "")
- +DCF(eye_tog, "Toggles setting of the local player eyepoint on every frame (Multiplayer)")
- {
- - eye_tog = !eye_tog;
- - if(eye_tog){
- - dc_printf("proper eye stuff on\n");
- - } else {
- - dc_printf("proper eye stuff off\n");
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("proper eye stuff is %s\n", eye_tog ? "ON" : "OFF");
- + return;
- }
- +
- + eye_tog = !eye_tog;
- + dc_printf("proper eye stuff is %s\n", eye_tog ? "ON" : "OFF");
- }
- void multi_do_frame()
- @@ -1772,13 +1774,14 @@ void multi_reset_timestamps()
- }
- // netgame debug flags for debug console stuff
- -DCF(netd, "change/list netgame debug flags")
- +DCF(netd, "change netgame debug flags (Mulitplayer)")
- {
- - dc_get_arg(ARG_INT);
- + int value;
- + dc_stuff_int(&value);
- - // if we got an integer, and we're the server, change flags
- - if((Dc_arg_type & ARG_INT) && (Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) && (Dc_arg_int <= 7)){
- - Netgame.debug_flags ^= (1<<Dc_arg_int);
- + // if we're the server, change flags
- + if ((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) && (value <= 7)) {
- + Netgame.debug_flags ^= (1 << value);
- }
- // display network flags
- diff --git a/code/network/multi_kick.cpp b/code/network/multi_kick.cpp
- index 86e3227..3c95d17 100644
- --- a/code/network/multi_kick.cpp
- +++ b/code/network/multi_kick.cpp
- @@ -18,6 +18,7 @@
- #include "freespace2/freespace.h"
- #include "playerman/player.h"
- #include "io/timer.h"
- +#include "debugconsole/console.h"
- // ----------------------------------------------------------------------------------
- @@ -137,18 +138,14 @@ int multi_kick_is_banned(net_addr *addr)
- void multi_dcf_kick()
- {
- int player_num,idx;
- + SCP_string arg;
- // get the callsign of the player to kick
- - dc_get_arg(ARG_STRING);
- -
- - if(Dc_arg[0] == '\0'){
- - dc_printf("Invalid player callsign!\n");
- - return ;
- - }
- + dc_stuff_string(arg);
- player_num = -1;
- for(idx=0;idx<MAX_PLAYERS;idx++){
- - if(MULTI_CONNECTED(Net_players[idx]) && (stricmp(Net_players[idx].m_player->callsign,Dc_arg)==0)){
- + if(MULTI_CONNECTED(Net_players[idx]) && (stricmp(Net_players[idx].m_player->callsign, arg.c_str()) == 0)) {
- player_num = idx;
- break;
- }
- @@ -156,7 +153,7 @@ void multi_dcf_kick()
- // if we didn't find the player, notify of the results
- if(player_num == -1){
- - dc_printf("Could not find player %s to kick!",Dc_arg);
- + dc_printf("Could not find player %s to kick!", arg.c_str());
- }
- // if we found the guy, then try and kick him
- else {
- diff --git a/code/network/multi_obj.cpp b/code/network/multi_obj.cpp
- index 1b7941c..4c421f7 100644
- --- a/code/network/multi_obj.cpp
- +++ b/code/network/multi_obj.cpp
- @@ -26,6 +26,7 @@
- #include "physics/physics.h"
- #include "ship/afterburner.h"
- #include "cfile/cfile.h"
- +#include "debugconsole/console.h"
- // ---------------------------------------------------------------------------------------------------
- @@ -1569,10 +1570,21 @@ int OO_server_rate_stamp = -1;
- // bandwidth granularity
- int OO_gran = 1;
- -DCF(oog, "")
- +DCF(oog, "Sets bandwidth granularity (Multiplayer)")
- {
- - dc_get_arg(ARG_INT);
- - OO_gran = Dc_arg_int;
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: oog <OO_gran>\n");
- + dc_printf("Sets bandwidth granularity\n");
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Current Granularity is '%i' (default is 1)", OO_gran);
- + return;
- + }
- +
- + dc_stuff_int(&OO_gran);
- + dc_printf("Ganularity set to %i", OO_gran);
- }
- // process datarate limiting stuff for the server
- @@ -1939,10 +1951,21 @@ void multi_oo_interp(object *objp)
- }
- float oo_error = 0.8f;
- -DCF(oo_error, "")
- +DCF(oo_error, "Sets error factor for flight path prediction physics (Multiplayer)")
- {
- - dc_get_arg(ARG_FLOAT);
- - oo_error = Dc_arg_float;
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: oo_error <value>\n");
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("oo_error is currently %f", oo_error);
- + return;
- + }
- +
- + dc_stuff_float(&oo_error);
- +
- + dc_printf("oo_error set to %f", oo_error);
- }
- void multi_oo_calc_interp_splines(int ship_index, vec3d *cur_pos, matrix *cur_orient, physics_info *cur_phys_info, vec3d *new_pos, matrix *new_orient, physics_info *new_phys_info)
- @@ -1994,14 +2017,16 @@ void oo_update_time()
- }
- int display_oo_bez = 0;
- -DCF(bez, "")
- +DCF(bez, "Toggles rendering of player ship trajectory interpolation splines (Multiplayer) *disabled*")
- {
- - display_oo_bez = !display_oo_bez;
- - if(display_oo_bez){
- - dc_printf("Showing interp splines");
- - } else {
- - dc_printf("Not showing interp splines");
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Rendering of interpolation splines is '%s'", display_oo_bez ? "ON" : "OFF");
- + return;
- }
- +
- + display_oo_bez = !display_oo_bez;
- +
- + dc_printf("%showing interp splines", display_oo_bez ? "S" : "Not s");
- }
- void oo_display()
- diff --git a/code/network/multi_pxo.cpp b/code/network/multi_pxo.cpp
- index fc562c6..39307d3 100644
- --- a/code/network/multi_pxo.cpp
- +++ b/code/network/multi_pxo.cpp
- @@ -42,6 +42,7 @@
- #include "playerman/player.h"
- #include "fs2netd/fs2netd_client.h"
- #include "menuui/mainhallmenu.h"
- +#include "debugconsole/console.h"
- @@ -461,14 +462,15 @@ void multi_pxo_scroll_players_down();
- // get the absolute index of the displayed items which our currently selected one is
- int multi_pxo_get_select_index();
- -DCF(players, "")
- +DCF(players, "Adds the specified number of bogus players to the PXO listing (Multiplayer)")
- {
- char name[512] = "";
- -
- + int i;
- // add a bunch of bogus players
- - dc_get_arg(ARG_INT);
- - for(int idx=0; idx<Dc_arg_int; idx++){
- - sprintf(name, "player %d", idx);
- + dc_stuff_int(&i);
- +
- + for(int idx = 0; idx < i; idx++){
- + sprintf(name, "bogus player %d", idx);
- multi_pxo_add_player(name);
- }
- }
- diff --git a/code/network/multi_voice.cpp b/code/network/multi_voice.cpp
- index ac8f6de..ee9b794 100644
- --- a/code/network/multi_voice.cpp
- +++ b/code/network/multi_voice.cpp
- @@ -22,7 +22,7 @@
- #include "menuui/optionsmenumulti.h"
- #include "network/multi.h"
- #include "playerman/player.h"
- -
- +#include "debugconsole/console.h"
- // --------------------------------------------------------------------------------------------------
- @@ -483,16 +483,17 @@ void multi_voice_process()
- // voice settings debug console function
- void multi_voice_dcf()
- {
- - dc_get_arg(ARG_STRING);
- + SCP_string arg;
- + int value;
- +
- + dc_stuff_string_white(arg);
- // set the quality of sound
- - if (strcmp(Dc_arg, NOX("qos")) == 0) {
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - if((Dc_arg_int >= 1) && (Dc_arg_int <= 10) && (Net_player->flags & NETINFO_FLAG_AM_MASTER)){
- - multi_voice_set_vars(Dc_arg_int,-1);
- - dc_printf("Quality of sound : %d\n",Dc_arg_int);
- - }
- + if (arg == NOX("qos")) {
- + dc_stuff_int(&value);
- + if((value >= 1) && (value <= 10) && (Net_player->flags & NETINFO_FLAG_AM_MASTER)){
- + multi_voice_set_vars(value,-1);
- + dc_printf("Quality of sound : %d\n", value);
- }
- }
- }
- diff --git a/code/network/multilag.cpp b/code/network/multilag.cpp
- index de8a524..9e10441 100644
- --- a/code/network/multilag.cpp
- +++ b/code/network/multilag.cpp
- @@ -18,6 +18,7 @@
- #include "io/timer.h"
- #include "globalincs/linklist.h"
- #include "network/psnet2.h"
- +#include "debugconsole/console.h"
- @@ -392,6 +393,7 @@ void multi_lag_put_free(lag_buf *buf)
- Lag_buf_count--;
- }
- +// Help and status provider for the lag-loss system
- void multi_lagloss_dcf()
- {
- // if the lag system isn't inited, don't do anything
- @@ -400,183 +402,290 @@ void multi_lagloss_dcf()
- return;
- }
- + // display status of lag system
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Lag system status:\n");
- + // display lag settings
- + dc_printf("Lag : \n");
- + dc_printf("Base \t\tMin \t\tMax \t\tStreak\n");
- + dc_printf("%f\t\t%f\t\t%f\t\t%f\n\n", Multi_lag_base, Multi_lag_min, Multi_lag_max, Multi_streak_time);
- +
- + // display loss settings
- + dc_printf("Loss : \n");
- + dc_printf("Base \t\tMin \t\tMax\n");
- + dc_printf("%f\t\t%f\t\t%f\n", Multi_loss_base, Multi_loss_min, Multi_loss_max);
- + return;
- + }
- +
- // display all available commands
- - dc_printf("Usage :\nlag <ms> (-1 to disable)\nlag_min <ms>\nlag_max <ms>\nloss <0-100> (-1 to disable)\nloss_min <0-100>\nloss_max <0-100>\nlag_streak <ms>\nlagloss\n");
- + dc_printf("Lag system commands\n\n");
- +
- + dc_printf("Usage :\n");
- + dc_printf("lag <ms>\n");
- + dc_printf("\tSets the lag base value if <ms> is within the max and min limits (see lag_min and lag_max)\n");
- + dc_printf("\tIf <ms> is outside of the max and min limits, then nothing is done\n");
- + dc_printf("\tIf <ms> is negative, then lag simulation is turned off\n\n");
- +
- + dc_printf("lag_min <ms>\n");
- + dc_printf("\tSets the lag min value if <ms> is less than the base value\n");
- + dc_printf("\tIf <ms> is outside the base or max values, then nothing is done\n");
- + dc_printf("\tIf <ms> is negative, then the min limit is removed\n\n");
- +
- + dc_printf("lag_max <ms>\n");
- + dc_printf("\tSets the lag max value if <ms> is greater than the base value\n");
- + dc_printf("\tIf <ms> is outside the base or min values, then nothing is done\n");
- + dc_printf("\tIf <ms> is negative, then the max limit is removed\n\n");
- +
- + dc_printf("loss <0-100> (-1 to disable)\n");
- + dc_printf("\tSimilar to lag, but applies value to loss base value\n\n");
- +
- + dc_printf("loss_min <0-100>\n");
- + dc_printf("\tSimilar to lag_min, but applies value to loss min value\n\n");
- +
- + dc_printf("loss_max <0-100>\n");
- + dc_printf("\tSimilar to lag_max, but applies value to loss max value\n\n");
- - // display lag settings
- - dc_printf("Lag : ");
- - dc_printf("\n Base %d\n Min %d\n Max %d\n Streak %d\n", Multi_lag_base, Multi_lag_min, Multi_lag_max, Multi_streak_time);
- - // display loss settings
- - dc_printf("Loss : ");
- - dc_printf("\n Base %f\n Min %f\n Max %f\n", Multi_loss_base, Multi_loss_min, Multi_loss_max);
- + dc_printf("lag_streak <ms>\n");
- + dc_printf("\tSets the duration of lag streaks where the lag is consistant for <ms>\n");
- + dc_printf("\tEx: A value of 2000 would result in lag streaks that last 2 seconds each\n\n");
- +
- + dc_printf("lagloss\n");
- + dc_printf("\tDisplays this text. Passing --status will display the status of the entire lag system");
- }
- -DCF(lag, "")
- +DCF(lag, "Sets the lag base value (Muliplayer)")
- {
- + int value;
- +
- // if the lag system isn't inited, don't do anything
- if(!Multi_lag_inited){
- dc_printf("Lag System Not Initialized!\n");
- return;
- }
- - dc_get_arg(ARG_INT);
- + if (dc_optional_string_either("help", "--help")) {
- + multi_lagloss_dcf();
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Lag base value is currently %i\n", Multi_lag_base);
- + return;
- + }
- +
- + dc_stuff_int(&value);
- // parse the argument and change things around accordingly
- - if(Dc_arg_type & ARG_INT){
- - if(Dc_arg_int < 0){
- - // switch the lag sim off
- - Multi_lag_base = -1;
- - Multi_lag_min = -1;
- - Multi_lag_max = -1;
- - dc_printf("Turning simulated lag off\n");
- - multi_lagloss_dcf();
- - } else if((Multi_lag_max >= 0) && (Dc_arg_int > Multi_lag_max)){
- - dc_printf("Base value greater than max value, ignoring...");
- - } else if((Multi_lag_min >= 0) && (Dc_arg_int < Multi_lag_min)){
- - dc_printf("Base value smaller than min value, ignoring...");
- - } else {
- - Multi_lag_base = Dc_arg_int;
- - multi_lagloss_dcf();
- - }
- - }
- + if (value < 0) {
- + // switch the lag sim off
- + Multi_lag_base = -1;
- + Multi_lag_min = -1;
- + Multi_lag_max = -1;
- + dc_printf("Turning simulated lag off\n");
- + multi_lagloss_dcf();
- +
- + } else if ((Multi_lag_max >= 0) && (value > Multi_lag_max)) {
- + dc_printf("Base value greater than max value, ignoring...");
- +
- + } else if ((Multi_lag_min >= 0) && (value < Multi_lag_min)) {
- + dc_printf("Base value smaller than min value, ignoring...");
- +
- + } else {
- +
- + Multi_lag_base = value;
- + multi_lagloss_dcf();
- + dc_printf("Base value set to %i", value);
- + }
- }
- -DCF(lag_min, "")
- +DCF(lag_min, "Sets the lag min value (Multiplayer)")
- {
- + int value;
- +
- // if the lag system isn't inited, don't do anything
- if(!Multi_lag_inited){
- dc_printf("Lag System Not Initialized!\n");
- return;
- }
- - dc_get_arg(ARG_INT);
- + if (dc_optional_string_either("help", "--help")) {
- + multi_lagloss_dcf();
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Lag min value is currently %i\n", Multi_lag_min);
- + }
- +
- + dc_stuff_int(&value);
- // parse the argument and change things around accordingly
- - if(Dc_arg_type & ARG_INT){
- - if(Dc_arg_int > Multi_lag_base){
- - dc_printf("Min value greater than base value, ignoring...");
- - } else {
- - if(Dc_arg_int < 0){
- - Multi_lag_min = -1;
- - } else {
- - Multi_lag_min = Dc_arg_int;
- - }
- - multi_lagloss_dcf();
- - }
- - }
- +
- + if (value > Multi_lag_base) {
- + dc_printf("Min value greater than base value, ignoring...");
- + return;
- +
- + } else if (value < 0) {
- + Multi_lag_min = -1;
- +
- + } else {
- + Multi_lag_min = value;
- + }
- + dc_printf("Lag min value set to %i\n", Multi_lag_min);
- }
- -DCF(lag_max, "")
- +DCF(lag_max, "Sets the lag max value (Multiplayer)")
- {
- + int value;
- +
- // if the lag system isn't inited, don't do anything
- - if(!Multi_lag_inited){
- + if (!Multi_lag_inited) {
- dc_printf("Lag System Not Initialized!\n");
- return;
- }
- + if (dc_optional_string_either("help", "--help")) {
- + multi_lagloss_dcf();
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Lag max value is currently %i\n", Multi_lag_max);
- + return;
- + }
- +
- // parse the argument and change things around accordingly
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - if((Dc_arg >=0) && (Dc_arg_int < Multi_lag_base)){
- - dc_printf("Max value smaller than base value, ignoring...");
- - } else {
- - if(Dc_arg_int < 0){
- - Multi_lag_max = -1;
- - } else {
- - Multi_lag_max = Dc_arg_int;
- - }
- - multi_lagloss_dcf();
- - }
- - }
- + dc_stuff_int(&value);
- +
- + if ((value >= 0) && (value < Multi_lag_base)) {
- + dc_printf("Max value smaller than base value, ignoring...");
- +
- + } else if (value < 0) {
- + Multi_lag_max = -1;
- +
- + } else {
- + Multi_lag_max = value;
- + }
- + dc_printf("Lag max value set to %i\n", Multi_lag_max);
- }
- -DCF(loss, "")
- +DCF(loss, "Sets the loss base value (Multiplayer)")
- {
- + int val_i;
- + float val_f;
- +
- // if the lag system isn't inited, don't do anything
- if(!Multi_lag_inited){
- dc_printf("Lag System Not Initialized!\n");
- return;
- }
- + if (dc_optional_string_either("help", "--help")) {
- + multi_lagloss_dcf();
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Loss value is currently %i percent", Multi_loss_base);
- + return;
- + }
- +
- // parse the argument and change things around accordingly
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - float val = (float)Dc_arg_int / 100.0f;
- -
- - if(Dc_arg_int > 100){
- - dc_printf("Illegal loss base value, ignoring...");
- - } else if(Dc_arg_int < 0){
- - // switch the loss sim off
- - dc_printf("Turning simulated loss off\n");
- - Multi_loss_base = -1.0f;
- - Multi_loss_min = -1.0f;
- - Multi_loss_max = -1.0f;
- - multi_lagloss_dcf();
- - } else if((Multi_loss_max >= 0.0f) && (val > Multi_loss_max)){
- - dc_printf("Base value greater than max value, ignoring...");
- - } else if((Multi_loss_min >= 0.0f) && (val < Multi_loss_min)){
- - dc_printf("Base value smaller than min value, ignoring...");
- - } else {
- - Multi_loss_base = val;
- - multi_lagloss_dcf();
- - }
- - }
- + dc_stuff_int(&val_i);
- +
- + val_f = (float)val_i / 100.0f;
- +
- + if(val_i > 100){
- + dc_printf("Illegal loss base value, ignoring...");
- + } else if (val_i < 0){
- + // switch the loss sim off
- + dc_printf("Turning simulated loss off\n");
- + Multi_loss_base = -1.0f;
- + Multi_loss_min = -1.0f;
- + Multi_loss_max = -1.0f;
- +
- + } else if((Multi_loss_max >= 0.0f) && (val_f > Multi_loss_max)){
- + dc_printf("Base value greater than max value, ignoring...");
- +
- + } else if((Multi_loss_min >= 0.0f) && (val_f < Multi_loss_min)){
- + dc_printf("Base value smaller than min value, ignoring...");
- +
- + } else {
- + Multi_loss_base = val_f;
- + }
- }
- -DCF(loss_min, "")
- +DCF(loss_min, "Sets the loss min value (Multiplayer)")
- {
- + int val_i;
- + float val_f;
- +
- // if the lag system isn't inited, don't do anything
- if(!Multi_lag_inited){
- dc_printf("Lag System Not Initialized!\n");
- return;
- }
- + if (dc_optional_string_either("help", "--help")) {
- + multi_lagloss_dcf();
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("loss_min value is currently %f percent", Multi_loss_min);
- + }
- +
- // parse the argument and change things around accordingly
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - float val = (float)Dc_arg_int / 100.0f;
- + dc_stuff_int(&val_i);
- +
- + val_f = (float)val_i / 100.0f;
- - if(val > Multi_loss_base){
- - dc_printf("Min value greater than base value, ignoring...");
- + if(val_f > Multi_loss_base){
- + dc_printf("Min value greater than base value, ignoring...");
- + } else {
- + // otherwise set the value
- + if (val_f < 0) {
- + Multi_loss_min = -1.0f;
- } else {
- - // otherwise set the value
- - if(Dc_arg_int < 0){
- - Multi_loss_min = -1.0f;
- - } else {
- - Multi_loss_min = val;
- - }
- - multi_lagloss_dcf();
- + Multi_loss_min = val_f;
- }
- }
- }
- -DCF(loss_max, "")
- -{
- +DCF(loss_max, "Sets the loss max value (Multiplayer)")
- +{
- + int val_i;
- + float val_f;
- // if the lag system isn't inited, don't do anything
- if(!Multi_lag_inited){
- dc_printf("Lag System Not Initialized!\n");
- return;
- }
- + if (dc_optional_string_either("help", "--help")) {
- + multi_lagloss_dcf();
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("loss_max value is currently %f percent", Multi_loss_max);
- + }
- +
- // parse the argument and change things around accordingly
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - float val = (float)Dc_arg_int / 100.0f;
- + dc_stuff_int(&val_i);
- + val_f = (float)val_i / 100.0f;
- - if(val < Multi_loss_base){
- - dc_printf("Max value smaller than base value, ignoring...");
- + if (val_f < Multi_loss_base) {
- + dc_printf("Max value smaller than base value, ignoring...");
- + } else {
- + // otherwise set the value
- + if (val_f < 0) {
- + Multi_loss_max = -1.0f;
- } else {
- - // otherwise set the value
- - if(Dc_arg_int < 0){
- - Multi_loss_max = -1.0f;
- - } else {
- - Multi_loss_min = val;
- - }
- - multi_lagloss_dcf();
- + Multi_loss_max = val_f;
- }
- - }
- + }
- }
- -DCF(lagloss, "")
- +DCF(lagloss, "Help provider for the lag system (Multiplayer)")
- {
- // if the lag system isn't inited, don't do anything
- if(!Multi_lag_inited){
- @@ -587,29 +696,46 @@ DCF(lagloss, "")
- multi_lagloss_dcf();
- }
- -DCF(lag_streak, "")
- +DCF(lag_streak, "Sets the duration of lag streaks (Multiplayer)")
- {
- + int val;
- +
- // if the lag system isn't inited, don't do anything
- - if(!Multi_lag_inited){
- + if (!Multi_lag_inited) {
- dc_printf("Lag System Not Initialized!\n");
- return;
- }
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - if(Dc_arg_int >= 0){
- - Multi_streak_time = Dc_arg_int;
- - }
- + if (dc_optional_string_either("help", "--help")) {
- + multi_lagloss_dcf();
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("lag_streak value is currently %i", Multi_streak_time);
- + return;
- + }
- +
- + dc_stuff_int(&val);
- + if(val >= 0){
- + Multi_streak_time = val;
- + } else {
- + dc_printf("Ignoring invalid value (must be non-negative)\n");
- }
- }
- -DCF(lag_bad, "")
- +DCF(lag_bad, "Lag system shortcut - Sets for 'bad' lag simulation (Multiplayer)")
- {
- // if the lag system isn't inited, don't do anything
- if(!Multi_lag_inited){
- dc_printf("Lag System Not Initialized!\n");
- return;
- }
- +
- + if (dc_optional_string_either("help", "--help")) {
- + multi_lagloss_dcf();
- + return;
- + }
- dc_printf("Setting bad lag/loss parameters\n");
- @@ -627,7 +753,7 @@ DCF(lag_bad, "")
- Multi_current_streak = -1;
- }
- -DCF(lag_avg, "")
- +DCF(lag_avg, "Lag system shortcut - Sets for 'average' lag simulation (Multiplayer)")
- {
- // if the lag system isn't inited, don't do anything
- if(!Multi_lag_inited){
- @@ -635,6 +761,11 @@ DCF(lag_avg, "")
- return;
- }
- + if (dc_optional_string_either("help", "--help")) {
- + multi_lagloss_dcf();
- + return;
- + }
- +
- dc_printf("Setting avg lag/loss parameters\n");
- // set good lagloss parameters
- @@ -651,7 +782,7 @@ DCF(lag_avg, "")
- Multi_current_streak = -1;
- }
- -DCF(lag_good, "")
- +DCF(lag_good, "Lag system shortcut - Sets for 'good' lag simulation (Multiplayer)")
- {
- // if the lag system isn't inited, don't do anything
- if(!Multi_lag_inited){
- @@ -659,6 +790,11 @@ DCF(lag_good, "")
- return;
- }
- + if (dc_optional_string_either("help", "--help")) {
- + multi_lagloss_dcf();
- + return;
- + }
- +
- dc_printf("Setting good lag/loss parameters\n");
- // set good lagloss parameters
- diff --git a/code/network/multiui.cpp b/code/network/multiui.cpp
- index ba601d9..9f28f47 100644
- --- a/code/network/multiui.cpp
- +++ b/code/network/multiui.cpp
- @@ -64,6 +64,7 @@
- #include "cfile/cfile.h"
- #include "fs2netd/fs2netd_client.h"
- #include "menuui/mainhallmenu.h"
- +#include "debugconsole/console.h"
- #include <algorithm>
- @@ -754,13 +755,20 @@ int multi_join_maybe_warn();
- int multi_join_warn_pxo();
- void multi_join_blit_protocol();
- -DCF(mj_make, "")
- +DCF(mj_make, "Makes a multijoin game? (Multiplayer)")
- {
- active_game ag, *newitem;
- int idx;
- + int idx_max;
- - dc_get_arg(ARG_INT);
- - for(idx=0; idx<Dc_arg_int; idx++){
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: mj_make <num_games>\n");
- + return;
- + }
- +
- + dc_stuff_int(&idx_max);
- +
- + for(idx = 0; idx < idx_max; idx++){
- // stuff some fake info
- memset(&ag, 0, sizeof(active_game));
- sprintf(ag.name, "Game %d", idx);
- @@ -776,7 +784,7 @@ DCF(mj_make, "")
- if(newitem != NULL){
- // newitem->heard_from_timer = timestamp((int)frand_range(500.0f, 10000.0f));
- }
- - }
- + }
- }
- void multi_join_notify_new_game()
- diff --git a/code/network/multiutil.cpp b/code/network/multiutil.cpp
- index fb05620..05f817f 100644
- --- a/code/network/multiutil.cpp
- +++ b/code/network/multiutil.cpp
- @@ -77,6 +77,7 @@
- #include "network/multi_rate.h"
- #include "fs2netd/fs2netd_client.h"
- #include "parse/parselo.h"
- +#include "debugconsole/console.h"
- extern int ascii_table[];
- extern int shifted_ascii_table[];
- @@ -3198,65 +3199,73 @@ short multi_get_new_id()
- // ------------------------------------
- //XSTR:OFF
- -DCF(multi,"changes multiplayer settings")
- +DCF(multi,"changes multiplayer settings (Multiplayer)")
- {
- - if(Dc_command){
- - dc_get_arg(ARG_STRING);
- -
- - if(strcmp(Dc_arg, "kick")==0){ // kick a player
- - multi_dcf_kick();
- + if (dc_optional_string("kick")) {
- + // kick a player
- + multi_dcf_kick();
- +
- #ifndef NDEBUG
- - } else if(strcmp(Dc_arg, "stats")==0) {
- - // multi_toggle_stats();
- - } else if(strcmp(Dc_arg, "show_stats")==0) {
- - // multi_show_basic_stats(0);
- - } else if(strcmp(Dc_arg, "dump_stats")==0) {
- - // multi_show_basic_stats(1);
- + } else if (dc_optional_string("stats")) {
- + // multi_toggle_stats();
- +
- + } else if (dc_optional_string("show_stats")) {
- + // multi_show_basic_stats(0);
- +
- + } else if (dc_optional_string("dump_stats")) {
- + // multi_show_basic_stats(1);
- #endif
- - } else if(strcmp(Dc_arg, "voice")==0){ // settings for multiplayer voice
- - multi_voice_dcf();
- - } else if(strcmp(Dc_arg, "respawn_chump")==0){ // set a really large # of respawns
- - if((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_GAME_HOST)){
- - Netgame.respawn = 9999;
- - Netgame.options.respawn = 9999;
- -
- - // if i'm the server, send a netgame update
- - if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
- - send_netgame_update_packet();
- - }
- - }
- - } else if(strcmp(Dc_arg, "ss_leaders")==0){ // only host or team captains can modify ships
- - if((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_GAME_HOST)){
- - Netgame.options.flags |= MSO_FLAG_SS_LEADERS;
- - multi_options_update_netgame();
- - }
- - } else if(strcmp(Dc_arg, "make_players")==0){
- +
- + } else if (dc_optional_string("voice")) {
- + // settings for multiplayer voice
- + multi_voice_dcf();
- +
- + } else if (dc_optional_string("respawn_chump")){
- + // set a really large # of respawns
- + if((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_GAME_HOST)) {
- + Netgame.respawn = 9999;
- + Netgame.options.respawn = 9999;
- +
- + // if i'm the server, send a netgame update
- + if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
- + send_netgame_update_packet();
- + }
- + }
- +
- + } else if (dc_optional_string("ss_leaders")) {
- + // only host or team captains can modify ships
- + if((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_GAME_HOST)) {
- + Netgame.options.flags |= MSO_FLAG_SS_LEADERS;
- + multi_options_update_netgame();
- + }
- +
- + } else if (dc_optional_string("make_players")) {
- #ifndef NDEBUG
- - multi_make_fake_players(MAX_PLAYERS);
- + multi_make_fake_players(MAX_PLAYERS);
- #endif
- - } else if(strcmp(Dc_arg, "givecd")==0){
- - extern int Multi_has_cd;
- - Multi_has_cd = 1;
- - } else if(strcmp(Dc_arg, "oo")==0){
- - int new_flags = -1;
- -
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - new_flags = Dc_arg_int;
- - }
- - dc_printf("Interesting flags\nPos : %d\nVelocity : %d\nDesired vel : %d\nOrient : %d\nRotvel : %d\nDesired rotvel %d\n",
- - 1<<0, 1<<7, 1<<8, 1<<1, 1<<9, 1<<10);
- - } else if(strcmp(Dc_arg, "oo_sort")==0){
- - extern int OO_sort;
- + } else if (dc_optional_string("givecd")) {
- + extern int Multi_has_cd;
- + Multi_has_cd = 1;
- - OO_sort = !OO_sort;
- - if(OO_sort){
- - dc_printf("Network object sorting ENABLED\n");
- - } else {
- - dc_printf("Network object sorting DISABLED\n");
- - }
- - }
- + } else if (dc_optional_string("oo")) {
- + int new_flags = -1;
- +
- + dc_maybe_stuff_int(&new_flags);
- +
- + dc_printf("Interesting flags\n");
- + dc_printf("Pos : %d\n", 1 << 0);
- + dc_printf("Velocity : %d\n", 1 << 7);
- + dc_printf("Desired vel : %d\n", 1 << 8);
- + dc_printf("Orient : %d\n", 1 << 1);
- + dc_printf("Rotvel : %d\n", 1 << 9);
- + dc_printf("Desired rotvel : %d\n", 1 << 10);
- +
- + } else if (dc_optional_string("oo_sort")) {
- + extern int OO_sort;
- +
- + OO_sort = !OO_sort;
- + dc_printf("Network object sorting %s\n", OO_sort ? "ENABLED" : "DISABLED");
- }
- }
- @@ -3447,19 +3456,20 @@ Done:
- }
- */
- -DCF(pxospew,"spew PXO 32 bit checksums for all visible mission files")
- +DCF(pxospew,"spew PXO 32 bit checksums for all visible mission files (Multiplayer)")
- {
- int max_files;
- + char file_str[MAX_NAME_LEN];
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - max_files = Dc_arg_int;
- -
- - dc_get_arg(ARG_STRING);
- - if(Dc_arg_type & ARG_STRING){
- - multi_spew_pxo_checksums(max_files, Dc_arg);
- - }
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: pxospew <max_files> <filename>\n");
- + return;
- }
- +
- + dc_stuff_int(&max_files);
- + dc_stuff_string_white(file_str, MAX_NAME_LEN);
- +
- + multi_spew_pxo_checksums(max_files, file_str);
- }
- diff --git a/code/object/collideshipship.cpp b/code/object/collideshipship.cpp
- index d799ab1..009548a 100644
- --- a/code/object/collideshipship.cpp
- +++ b/code/object/collideshipship.cpp
- @@ -27,6 +27,7 @@
- #include "object/objectdock.h"
- #include "object/objectshield.h"
- #include "parse/scripting.h"
- +#include "debugconsole/console.h"
- #define COLLIDE_DEBUG
- diff --git a/code/object/object.cpp b/code/object/object.cpp
- index 50b08e5..73fa7d0 100644
- --- a/code/object/object.cpp
- +++ b/code/object/object.cpp
- @@ -41,6 +41,7 @@
- #include "weapon/shockwave.h"
- #include "weapon/swarm.h"
- #include "weapon/weapon.h"
- +#include "debugconsole/console.h"
- diff --git a/code/object/objectsnd.cpp b/code/object/objectsnd.cpp
- index 498517c..64c3270 100644
- --- a/code/object/objectsnd.cpp
- +++ b/code/object/objectsnd.cpp
- @@ -22,7 +22,7 @@
- #include "render/3d.h"
- #include "io/joy_ff.h"
- #include "species_defs/species_defs.h"
- -
- +#include "debugconsole/console.h"
- // // --mharris port hack--
- @@ -96,62 +96,65 @@ void obj_snd_source_pos(vec3d *sound_pos, obj_snd *osp)
- //XSTR:OFF
- DCF(objsnd, "Persistent sound stuff" )
- {
- - char buf1[16], buf2[64];
- - obj_snd *osp;
- + char buf1[4];
- + char buf2[MAX_NAME_LEN];
- + obj_snd *osp;
- + SCP_string arg;
- +
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf ("Usage: objsnd [-list]\n");
- + dc_printf ("[-list] -- displays status of all objects with linked sounds\n");
- + dc_printf ("with no parameters, object sounds are toggled on/off\n");
- + return;
- + }
- - if ( Dc_command ) {
- - dc_get_arg(ARG_STRING|ARG_NONE);
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf( "Object sounds are: %s\n", (Obj_snd_enabled?"ON":"OFF") );
- + }
- +
- + if (dc_optional_string("-list")) {
- + for ( osp = GET_FIRST(&obj_snd_list); osp !=END_OF_LIST(&obj_snd_list); osp = GET_NEXT(osp) ) {
- + vec3d source_pos;
- + float distance;
- - if ( Dc_arg_type & ARG_NONE ) {
- - if ( Obj_snd_enabled == TRUE ) {
- - obj_snd_stop_all();
- - Obj_snd_enabled = FALSE;
- + Assert(osp != NULL);
- + if ( osp->instance == -1 ) {
- + continue;
- + //sprintf(buf1,"OFF");
- + } else {
- + sprintf(buf1,"ON");
- + }
- +
- + if ( Objects[osp->objnum].type == OBJ_SHIP ) {
- + strcpy_s(buf2, Ships[Objects[osp->objnum].instance].ship_name);
- + }
- + else if ( Objects[osp->objnum].type == OBJ_DEBRIS ) {
- + sprintf(buf2, "Debris");
- }
- else {
- - Obj_snd_enabled = TRUE;
- + sprintf(buf2, "Unknown");
- }
- - }
- - if ( !stricmp( Dc_arg, "list" )) {
- - for ( osp = GET_FIRST(&obj_snd_list); osp !=END_OF_LIST(&obj_snd_list); osp = GET_NEXT(osp) ) {
- - Assert(osp != NULL);
- - if ( osp->instance == -1 ) {
- - continue;
- - //sprintf(buf1,"OFF");
- - } else {
- - sprintf(buf1,"ON");
- - }
- - if ( Objects[osp->objnum].type == OBJ_SHIP ) {
- - strcpy_s(buf2, Ships[Objects[osp->objnum].instance].ship_name);
- - }
- - else if ( Objects[osp->objnum].type == OBJ_DEBRIS ) {
- - sprintf(buf2, "Debris");
- - }
- - else {
- - sprintf(buf2, "Unknown");
- - }
- + obj_snd_source_pos(&source_pos, osp);
- + distance = vm_vec_dist_quick( &source_pos, &View_position );
- - vec3d source_pos;
- - float distance;
- -
- - obj_snd_source_pos(&source_pos, osp);
- - distance = vm_vec_dist_quick( &source_pos, &View_position );
- -
- - dc_printf("Object %d => name: %s vol: %.2f pan: %.2f dist: %.2f status: %s\n", osp->objnum, buf2, osp->vol, osp->pan, distance, buf1);
- - } // end for
- - dc_printf("Number object-linked sounds playing: %d\n", Num_obj_sounds_playing);
- - }
- - }
- + dc_printf("Object %d => name: %s vol: %.2f pan: %.2f dist: %.2f status: %s\n", osp->objnum, buf2, osp->vol, osp->pan, distance, buf1);
- + } // end for
- - if ( Dc_help ) {
- - dc_printf ("Usage: objsnd [list]\n");
- - dc_printf ("[list] -- displays status of all objects with linked sounds\n");
- - dc_printf ("with no parameters, object sounds are toggled on/off\n");
- - Dc_status = 0;
- + dc_printf("Number object-linked sounds playing: %d\n", Num_obj_sounds_playing);
- + return;
- }
- - if ( Dc_status ) {
- - dc_printf( "Object sounds are: %s\n", (Obj_snd_enabled?"ON":"OFF") );
- + if (!dc_maybe_stuff_string_white(arg)) {
- + // No arguments, toggle snd on/off
- + if ( Obj_snd_enabled == TRUE ) {
- + obj_snd_stop_all();
- + Obj_snd_enabled = FALSE;
- + } else {
- + Obj_snd_enabled = TRUE;
- + }
- + } else {
- + dc_printf("Unknown argument '%s'\n", arg.c_str());
- }
- }
- //XSTR:ON
- diff --git a/code/palman/palman.cpp b/code/palman/palman.cpp
- index cdb18ec..dee89aa 100644
- --- a/code/palman/palman.cpp
- +++ b/code/palman/palman.cpp
- @@ -11,6 +11,7 @@
- #include "palman/palman.h"
- #include "bmpman/bmpman.h"
- +#include "debugconsole/console.h"
- #include "pcxutils/pcxutils.h"
- #include "parse/parselo.h"
- #include "graphics/grinternal.h"
- @@ -165,17 +166,14 @@ void palette_load_table( const char * filename )
- DCF(palette,"Loads a new palette")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_STRING|ARG_NONE);
- - if ( Dc_arg_type == ARG_NONE ) {
- - } else {
- - palette_load_table( Dc_arg );
- - }
- - }
- - if ( Dc_help ) {
- - dc_printf( "Usage: palette filename\nLoads the palette file.\n" );
- + char palette_file[MAX_FILENAME_LEN];
- +
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: palette <filename>\nLoads the palette file.\n" );
- }
- + dc_stuff_string_white(palette_file, MAX_FILENAME_LEN);
- + palette_load_table(palette_file);
- }
- int Palman_allow_any_color = 0;
- diff --git a/code/parse/sexp.cpp b/code/parse/sexp.cpp
- index 80514a7..5abf1ef 100644
- --- a/code/parse/sexp.cpp
- +++ b/code/parse/sexp.cpp
- @@ -96,6 +96,7 @@
- #include "mod_table/mod_table.h"
- #include "ship/afterburner.h"
- #include "globalincs/alphacolors.h"
- +#include "debugconsole/console.h"
- #ifndef NDEBUG
- #include "hud/hudmessage.h"
- @@ -24558,40 +24559,38 @@ int run_sexp(const char* sexpression)
- return sexp_val;
- }
- -DCF(sexpc, "Always runs the given sexp command ")
- +DCF(sexpc, "Always runs the given sexp command (Warning! There is no undo for this!)")
- {
- - if ( Dc_command ) {
- - if (Dc_command_line != NULL) {
- - char buf[8192];
- - snprintf(buf, 8191, "( when ( true ) ( %s ) )", Dc_command_line);
- -
- - int sexp_val = run_sexp( buf );
- - dc_printf("SEXP '%s' run, sexp_val = %d\n", buf, sexp_val);
- - do {
- - dc_get_arg(ARG_ANY);
- - } while (Dc_arg_type != ARG_NONE);
- - }
- - }
- - if ( Dc_help ) {
- + SCP_string sexp;
- + SCP_string sexp_always;
- +
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: sexpc sexpression\n. Always runs the given sexp as '( when ( true ) ( sexp ) )' .\n" );
- + return;
- }
- +
- + dc_stuff_string(sexp);
- +
- + sprintf(sexp_always, "( when ( true ) ( %s ) )", sexp.c_str());
- +
- + int sexp_val = run_sexp(sexp_always.c_str());
- + dc_printf("SEXP '%s' run, sexp_val = %d\n", sexp_always.c_str(), sexp_val);
- }
- DCF(sexp,"Runs the given sexp")
- {
- - if ( Dc_command ) {
- - if (Dc_command_line != NULL) {
- - int sexp_val = run_sexp( Dc_command_line );
- - dc_printf("SEXP '%s' run, sexp_val = %d\n", Dc_command_line, sexp_val);
- - do {
- - dc_get_arg(ARG_ANY);
- - } while (Dc_arg_type != ARG_NONE);
- - }
- - }
- - if ( Dc_help ) {
- + SCP_string sexp;
- +
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: sexp 'sexpression'\n. Runs the given sexp.\n");
- + return;
- }
- +
- + dc_stuff_string(sexp);
- +
- + int sexp_val = run_sexp(sexp.c_str());
- + dc_printf("SEXP '%s' run, sexp_val = %d\n", dc_command_str.c_str(), sexp_val);
- }
- diff --git a/code/particle/particle.cpp b/code/particle/particle.cpp
- index 22afb30..c28ef40 100644
- --- a/code/particle/particle.cpp
- +++ b/code/particle/particle.cpp
- @@ -17,6 +17,7 @@
- #include "object/object.h"
- #include "cmdline/cmdline.h"
- #include "graphics/grbatch.h"
- +#include "debugconsole/console.h"
- #ifndef NDEBUG
- #include "io/timer.h"
- @@ -90,18 +91,7 @@ void particle_page_in()
- bm_page_in_texture( Anim_bitmap_id_smoke2 );
- }
- -DCF(particles,"Turns particles on/off")
- -{
- - if ( Dc_command ) {
- - dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);
- - if ( Dc_arg_type & ARG_TRUE ) Particles_enabled = 1;
- - else if ( Dc_arg_type & ARG_FALSE ) Particles_enabled = 0;
- - else if ( Dc_arg_type & ARG_NONE ) Particles_enabled ^= 1;
- - }
- - if ( Dc_help ) dc_printf( "Usage: particles [bool]\nTurns particle system on/off. If nothing passed, then toggles it.\n" );
- - if ( Dc_status ) dc_printf( "particles are %s\n", (Particles_enabled?"ON":"OFF") );
- -}
- -
- +DCF_BOOL2(particles, Particles_enabled, "Turns particles on/off", "Usage: particles [bool]\nTurns particle system on/off. If nothing passed, then toggles it.\n");
- int Num_particles_hwm = 0;
- diff --git a/code/playerman/playercontrol.cpp b/code/playerman/playercontrol.cpp
- index 6eebd3f..60b65a8 100644
- --- a/code/playerman/playercontrol.cpp
- +++ b/code/playerman/playercontrol.cpp
- @@ -34,6 +34,7 @@
- #include "network/multiutil.h"
- #include "network/multi_obj.h"
- #include "parse/parselo.h"
- +#include "debugconsole/console.h"
- #ifndef NDEBUG
- #include "io/key.h"
- @@ -286,10 +287,16 @@ void do_view_chase(float frame_time)
- float camera_zoom_scale = 1.0f;
- -DCF(camera_speed, "")
- +DCF(camera_speed, "Sets the camera zoom scale")
- {
- - dc_get_arg(ARG_FLOAT);
- - camera_zoom_scale = Dc_arg_float;
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Camera zoom scale is %f\n", camera_zoom_scale);
- + return;
- + }
- +
- + dc_stuff_float(&camera_zoom_scale);
- +
- + dc_printf("Camera zoom scale set to %f\n", camera_zoom_scale);
- }
- void do_view_external(float frame_time)
- diff --git a/code/radar/radarsetup.cpp b/code/radar/radarsetup.cpp
- index b065092..a4e51d2 100644
- --- a/code/radar/radarsetup.cpp
- +++ b/code/radar/radarsetup.cpp
- @@ -31,6 +31,7 @@
- #include "radar/radarsetup.h"
- #include "iff_defs/iff_defs.h"
- #include "globalincs/linklist.h"
- +#include "debugconsole/console.h"
- int Radar_static_looping = -1;
- @@ -84,7 +85,7 @@ extern int radar_iff_color[5][2][4];
- int See_all = 0;
- -DCF_BOOL(see_all, See_all)
- +DCF_BOOL(see_all, See_all);
- static const char radar_default_filenames[2][16]=
- {
- diff --git a/code/render/3dlaser.cpp b/code/render/3dlaser.cpp
- index 0a0156c..45e479a 100644
- --- a/code/render/3dlaser.cpp
- +++ b/code/render/3dlaser.cpp
- @@ -14,6 +14,7 @@
- #include "globalincs/systemvars.h"
- #include "io/key.h"
- #include "cmdline/cmdline.h"
- +#include "debugconsole/console.h"
- diff --git a/code/ship/ship.cpp b/code/ship/ship.cpp
- index 4e081ce..0516cae 100644
- --- a/code/ship/ship.cpp
- +++ b/code/ship/ship.cpp
- @@ -80,6 +80,7 @@
- #include "graphics/gropenglshader.h"
- #include "model/model.h"
- #include "mod_table/mod_table.h"
- +#include "debugconsole/console.h"
- #define NUM_SHIP_SUBSYSTEM_SETS 20 // number of subobject sets to use (because of the fact that it's a linked list,
- @@ -8356,10 +8357,14 @@ int ship_subsys_disrupted(ship *sp, int type)
- }
- float Decay_rate = 1.0f / 120.0f;
- -DCF(lethality_decay, "time in sec to return from 100 to 0")
- +DCF(lethality_decay, "Sets ship lethality_decay, or the time in sec to go from 100 to 0 health (default is 1/120)")
- {
- - dc_get_arg(ARG_FLOAT);
- - Decay_rate = Dc_arg_float;
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Decay rate is currently %f\n", Decay_rate);
- + return;
- + }
- +
- + dc_stuff_float(&Decay_rate);
- }
- float min_lethality = 0.0f;
- @@ -9865,31 +9870,44 @@ float t_len = 10.0f;
- float t_vel = 0.2f;
- float t_min = 150.0f;
- float t_max = 300.0f;
- -DCF(t_rad, "")
- +DCF(t_rad, "Sets weapon tracer radius")
- {
- - dc_get_arg(ARG_FLOAT);
- - t_rad = Dc_arg_float;
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("t_rad : %f\n", t_rad);
- + return;
- + }
- +
- + dc_stuff_float(&t_rad);
- }
- -DCF(t_len, "")
- +DCF(t_len, "Sets weapon tracer length")
- {
- - dc_get_arg(ARG_FLOAT);
- - t_len = Dc_arg_float;
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("t_len : %f\n", t_len);
- + return;
- + }
- +
- + dc_stuff_float(&t_len);
- }
- -DCF(t_vel, "")
- +DCF(t_vel, "Sets weapon tracer velocity")
- {
- - dc_get_arg(ARG_FLOAT);
- - t_vel = Dc_arg_float;
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("t_vel : %f\n", t_vel);
- + return;
- + }
- +
- + dc_stuff_float(&t_vel);
- }
- +/*
- + TODO: These two DCF's (and variables) are unused
- DCF(t_min, "")
- {
- - dc_get_arg(ARG_FLOAT);
- - t_min = Dc_arg_float;
- + dc_stuff_float(&t_min);
- }
- DCF(t_max, "")
- {
- - dc_get_arg(ARG_FLOAT);
- - t_max = Dc_arg_float;
- + dc_stuff_float(&t_max);
- }
- +*/
- void ship_fire_tracer(int weapon_objnum)
- {
- particle_info pinfo;
- @@ -13611,26 +13629,25 @@ void ship_assign_sound_all()
- */
- DCF(set_shield,"Change player ship shield strength")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_FLOAT|ARG_NONE);
- -
- - if ( Dc_arg_type & ARG_FLOAT ) {
- - CLAMP(Dc_arg_float, 0.0f, 1.0f);
- - shield_set_strength(Player_obj, Dc_arg_float * Player_ship->ship_max_shield_strength);
- - dc_printf("Shields set to %.2f\n", shield_get_strength(Player_obj) );
- - }
- - }
- + float value;
- - if ( Dc_help ) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf ("Usage: set_shield [num]\n");
- dc_printf ("[num] -- shield percentage 0.0 -> 1.0 of max\n");
- - dc_printf ("with no parameters, displays shield strength\n");
- - Dc_status = 0;
- + return;
- }
- - if ( Dc_status ) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- dc_printf( "Shields are currently %.2f", shield_get_strength(Player_obj) );
- + return;
- }
- +
- + dc_stuff_float(&value);
- +
- + CLAMP(value, 0.0f, 1.0f);
- +
- + shield_set_strength(Player_obj, value * Player_ship->ship_max_shield_strength);
- + dc_printf("Shields set to %.2f\n", shield_get_strength(Player_obj) );
- }
- /**
- @@ -13638,26 +13655,24 @@ DCF(set_shield,"Change player ship shield strength")
- */
- DCF(set_hull, "Change player ship hull strength")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_FLOAT|ARG_NONE);
- -
- - if ( Dc_arg_type & ARG_FLOAT ) {
- - CLAMP(Dc_arg_float, 0.0f, 1.0f);
- - Player_obj->hull_strength = Dc_arg_float * Player_ship->ship_max_hull_strength;
- - dc_printf("Hull set to %.2f\n", Player_obj->hull_strength );
- - }
- - }
- -
- - if ( Dc_help ) {
- + float value;
- +
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf ("Usage: set_hull [num]\n");
- dc_printf ("[num] -- hull percentage 0.0 -> 1.0 of max\n");
- - dc_printf ("with no parameters, displays hull strength\n");
- - Dc_status = 0;
- + return;
- }
- - if ( Dc_status ) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- dc_printf( "Hull is currently %.2f", Player_obj->hull_strength );
- + return;
- }
- +
- + dc_stuff_float(&value);
- +
- + CLAMP(value, 0.0f, 1.0f);
- + Player_obj->hull_strength = value * Player_ship->ship_max_hull_strength;
- + dc_printf("Hull set to %.2f\n", Player_obj->hull_strength );
- }
- /**
- @@ -13666,70 +13681,65 @@ DCF(set_hull, "Change player ship hull strength")
- //XSTR:OFF
- DCF(set_subsys, "Set the strength of a particular subsystem on player ship" )
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_STRING);
- - if ( !subsystem_stricmp( Dc_arg, "weapons" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float < 0.0f) || (Dc_arg_float > 1.0f) ) {
- - Dc_help = 1;
- - } else {
- - ship_set_subsystem_strength( Player_ship, SUBSYSTEM_WEAPONS, Dc_arg_float );
- - }
- - } else if ( !subsystem_stricmp( Dc_arg, "engine" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float < 0.0f) || (Dc_arg_float > 1.0f) ) {
- - Dc_help = 1;
- - } else {
- - ship_set_subsystem_strength( Player_ship, SUBSYSTEM_ENGINE, Dc_arg_float );
- - if ( Dc_arg_float < ENGINE_MIN_STR ) {
- - Player_ship->flags |= SF_DISABLED; // add the disabled flag
- - } else {
- - Player_ship->flags &= (~SF_DISABLED); // add the disabled flag
- - }
- - }
- - } else if ( !subsystem_stricmp( Dc_arg, "sensors" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float < 0.0f) || (Dc_arg_float > 1.0f) ) {
- - Dc_help = 1;
- - } else {
- - ship_set_subsystem_strength( Player_ship, SUBSYSTEM_SENSORS, Dc_arg_float );
- - }
- - } else if ( !subsystem_stricmp( Dc_arg, "communication" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float < 0.0f) || (Dc_arg_float > 1.0f) ) {
- - Dc_help = 1;
- - } else {
- - ship_set_subsystem_strength( Player_ship, SUBSYSTEM_COMMUNICATION, Dc_arg_float );
- - }
- - } else if ( !subsystem_stricmp( Dc_arg, "navigation" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float < 0.0f) || (Dc_arg_float > 1.0f) ) {
- - Dc_help = 1;
- - } else {
- - ship_set_subsystem_strength( Player_ship, SUBSYSTEM_NAVIGATION, Dc_arg_float );
- - }
- - } else if ( !subsystem_stricmp( Dc_arg, "radar" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float < 0.0f) || (Dc_arg_float > 1.0f) ) {
- - Dc_help = 1;
- - } else {
- - ship_set_subsystem_strength( Player_ship, SUBSYSTEM_RADAR, Dc_arg_float );
- - }
- - } else {
- - // print usage
- - Dc_help = 1;
- - }
- + SCP_string arg;
- + int subsystem = SUBSYSTEM_NONE;
- + float val_f;
- +
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: set_subsys <type> [--status] <strength>\n");
- + dc_printf("<type> is any of the following:\n");
- + dc_printf("\tweapons\n");
- + dc_printf("\tengine\n");
- + dc_printf("\tsensors\n");
- + dc_printf("\tcommunication\n");
- + dc_printf("\tnavigation\n");
- + dc_printf("\tradar\n\n");
- +
- + dc_printf("[--status] will display status of that subsystem\n\n");
- +
- + dc_printf("<strength> is any value between 0 and 1.0\n");
- + return;
- }
- - if ( Dc_help ) {
- - dc_printf( "Usage: set_subsys type X\nWhere X is value between 0 and 1.0, and type can be:\n" );
- - dc_printf( "weapons\n" );
- - dc_printf( "engine\n" );
- - dc_printf( "sensors\n" );
- - dc_printf( "communication\n" );
- - dc_printf( "navigation\n" );
- - dc_printf( "radar\n" );
- - Dc_status = 0; // don't print status if help is printed. Too messy.
- + dc_stuff_string_white(arg);
- +
- + if (arg == "weapons") {
- + subsystem = SUBSYSTEM_WEAPONS;
- +
- + } else if (arg == "engine") {
- + subsystem = SUBSYSTEM_ENGINE;
- +
- + } else if (arg == "sensors") {
- + subsystem = SUBSYSTEM_SENSORS;
- +
- + } else if (arg == "communication") {
- + subsystem = SUBSYSTEM_COMMUNICATION;
- +
- + } else if (arg == "navigation") {
- + subsystem = SUBSYSTEM_NAVIGATION;
- +
- + } else if (arg == "radar") {
- + subsystem = SUBSYSTEM_RADAR;
- +
- + } else {
- + dc_printf("Erro: Unknown argument '%s'\n", arg.c_str());
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Subsystem '%s' is at %f strength\n", arg.c_str(), ship_get_subsystem_strength(Player_ship, subsystem));
- +
- + } else {
- + // Set the subsystem strength
- + dc_stuff_float(&val_f);
- +
- + CLAMP(val_f, 0.0, 1.0);
- + ship_set_subsystem_strength( Player_ship, subsystem, val_f );
- +
- + if (subsystem == SUBSYSTEM_ENGINE) {
- + // If subsystem is an engine, set/clear the disabled flag
- + (val_f < ENGINE_MIN_STR) ? (Player_ship->flags |= SF_DISABLED) : (Player_ship->flags &= (~SF_DISABLED));
- + }
- }
- }
- //XSTR:ON
- @@ -16420,11 +16430,11 @@ int ship_get_texture(int bitmap)
- // update artillery lock info
- #define CLEAR_ARTILLERY_AND_CONTINUE() { if(aip != NULL){ aip->artillery_objnum = -1; aip->artillery_sig = -1; aip->artillery_lock_time = 0.0f;} continue; }
- float artillery_dist = 10.0f;
- -DCF(art, "")
- +DCF(art, "Sets artillery disance")
- {
- - dc_get_arg(ARG_FLOAT);
- - artillery_dist = Dc_arg_float;
- + dc_stuff_float(&artillery_dist);
- }
- +
- void ship_update_artillery_lock()
- {
- ai_info *aip = NULL;
- diff --git a/code/ship/shipfx.cpp b/code/ship/shipfx.cpp
- index 6a656f6..ecea0fb 100644
- --- a/code/ship/shipfx.cpp
- +++ b/code/ship/shipfx.cpp
- @@ -40,6 +40,7 @@
- #include "bmpman/bmpman.h"
- #include "model/model.h"
- #include "cmdline/cmdline.h"
- +#include "debugconsole/console.h"
- #ifndef NDEBUG
- @@ -1355,42 +1356,58 @@ void shipfx_flash_do_frame(float frametime)
- }
- float Particle_width = 1.2f;
- -DCF(particle_width, "Multiplier for angular width of the particle spew")
- +DCF(particle_width, "Sets multiplier for angular width of the particle spew ( 0 - 5)")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float >= 0 ) && (Dc_arg_float <= 5) ) {
- - Particle_width = Dc_arg_float;
- - } else {
- - dc_printf( "Illegal value for particle width. (Must be from 0-5) \n\n");
- - }
- + float value;
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Particle_width : %f\n", Particle_width);
- + return;
- }
- +
- + dc_stuff_float(&value);
- +
- + CLAMP(value, 0.0, 5.0);
- + Particle_width = value;
- +
- + dc_printf("Particle_width set to %f\n", Particle_width);
- }
- float Particle_number = 1.2f;
- -DCF(particle_num, "Multiplier for the number of particles created")
- +DCF(particle_num, "Sets multiplier for the number of particles created")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float >= 0 ) && (Dc_arg_float <= 5) ) {
- - Particle_number = Dc_arg_float;
- - } else {
- - dc_printf( "Illegal value for particle num. (Must be from 0-5) \n\n");
- - }
- +
- + float value;
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Particle_number : %f\n", Particle_number);
- + return;
- }
- +
- + dc_stuff_float(&value);
- +
- + CLAMP(value, 0.0, 5.0);
- + Particle_number = value;
- +
- + dc_printf("Particle_number set to %f\n", Particle_number);
- }
- float Particle_life = 1.2f;
- DCF(particle_life, "Multiplier for the lifetime of particles created")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float >= 0 ) && (Dc_arg_float <= 5) ) {
- - Particle_life = Dc_arg_float;
- - } else {
- - dc_printf( "Illegal value for particle life. (Must be from 0-5) \n\n");
- - }
- + float value;
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Particle_life : %f\n", Particle_life);
- + return;
- }
- +
- + dc_stuff_float(&value);
- +
- + CLAMP(value, 0.0, 5.0);
- + Particle_life = value;
- +
- + dc_printf("Particle_life set to %f\n", Particle_life);
- }
- // Make sparks fly off of ship n.
- @@ -1602,16 +1619,20 @@ int Bs_exp_fire_low = 1;
- float Bs_exp_fire_time_mult = 1.0f;
- DCF_BOOL(bs_exp_fire_low, Bs_exp_fire_low)
- -DCF(bs_exp_fire_time_mult, "Multiplier time between fireball in big ship explosion")
- +DCF(bs_exp_fire_time_mult, "Sets multiplier time between fireball in big ship explosion")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float >= 0.1 ) && (Dc_arg_float <= 5) ) {
- - Bs_exp_fire_time_mult = Dc_arg_float;
- - } else {
- - dc_printf( "Illegal value for bs_exp_fire_time_mult. (Must be from 0.1-5) \n\n");
- - }
- + float value;
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Bs_exp_fire_time_mult : %f\n", Bs_exp_fire_time_mult);
- + return;
- }
- +
- + dc_stuff_float(&value);
- +
- + CLAMP(value, 0.1f, 5.0f);
- + Bs_exp_fire_time_mult = value;
- + dc_printf("Bs_exp_fire_time_mult set to %f\n", Bs_exp_fire_time_mult);
- }
- diff --git a/code/sound/sound.cpp b/code/sound/sound.cpp
- index ddb2cbf..1a15fb1 100644
- --- a/code/sound/sound.cpp
- +++ b/code/sound/sound.cpp
- @@ -15,6 +15,7 @@
- #include "cmdline/cmdline.h"
- #include "osapi/osapi.h"
- #include "globalincs/vmallocator.h"
- +#include "debugconsole/console.h"
- #include "gamesnd/gamesnd.h"
- #include "globalincs/alphacolors.h"
- @@ -200,14 +201,15 @@ void snd_spew_info()
- }
- int Sound_spew = 0;
- -DCF(show_sounds, "")
- +DCF(show_sounds, "Toggles display of sound debug info")
- {
- - Sound_spew = !Sound_spew;
- - if(Sound_spew){
- - dc_printf("Sound debug info ON");
- - } else {
- - dc_printf("Sound debug info OFF");
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Sound debug info is %s", (Sound_spew ? "ON" : "OFF"));
- + return;
- }
- +
- + Sound_spew = !Sound_spew;
- + dc_printf("Sound debug info is %s", (Sound_spew ? "ON" : "OFF"));
- }
- void snd_spew_debug_info()
- {
- diff --git a/code/starfield/nebula.cpp b/code/starfield/nebula.cpp
- index a43ab9b..4187ae0 100644
- --- a/code/starfield/nebula.cpp
- +++ b/code/starfield/nebula.cpp
- @@ -15,7 +15,7 @@
- #include "mission/missionparse.h"
- #include "nebula/neb.h"
- #include "cfile/cfile.h"
- -
- +#include "debugconsole/console.h"
- #define MAX_TRIS 200
- @@ -215,17 +215,19 @@ void nebula_render()
- DCF(nebula,"Loads a different nebula")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_STRING|ARG_NONE);
- - if ( Dc_arg_type == ARG_NONE ) {
- - nebula_close();
- - } else {
- - nebula_init( Dc_arg );
- - }
- + char filename[MAX_NAME_LEN];
- +
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: nebula [filename]\n");
- + dc_printf("Loads the nebula file. No filename takes away nebula\n" );
- + return;
- + }
- +
- + if (dc_maybe_stuff_string_white(filename, MAX_NAME_LEN)) {
- + nebula_init(filename);
- + } else {
- + nebula_close();
- }
- - if ( Dc_help ) {
- - dc_printf( "Usage: nebula filename\nLoads the nebula file. No filename takes away nebula\n" );
- - }
- }
- diff --git a/code/starfield/starfield.cpp b/code/starfield/starfield.cpp
- index 4a08d5d..0df45a7 100644
- --- a/code/starfield/starfield.cpp
- +++ b/code/starfield/starfield.cpp
- @@ -25,6 +25,7 @@
- #include "parse/parselo.h"
- #include "hud/hud.h"
- #include "hud/hudtarget.h"
- +#include "debugconsole/console.h"
- #define MAX_DEBRIS_VCLIPS 4
- @@ -866,75 +867,11 @@ uint Star_flags = STAR_FLAG_DEFAULT;
- //XSTR:OFF
- DCF(stars,"Set parameters for starfield")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_STRING);
- - if ( !strcmp( Dc_arg, "tail" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float < 0.0f) || (Dc_arg_float > 1.0f) ) {
- - Dc_help = 1;
- - } else {
- - Star_amount = Dc_arg_float;
- - }
- - } else if ( !strcmp( Dc_arg, "len" )) {
- - dc_get_arg(ARG_FLOAT);
- - Star_max_length = Dc_arg_float;
- - } else if ( !strcmp( Dc_arg, "dim" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( Dc_arg_float < 0.0f ) {
- - Dc_help = 1;
- - } else {
- - Star_dim = Dc_arg_float;
- - }
- - } else if ( !strcmp( Dc_arg, "flag" )) {
- - dc_get_arg(ARG_STRING);
- - if ( !strcmp( Dc_arg, "tail" )) {
- - Star_flags ^= STAR_FLAG_TAIL;
- - } else if ( !strcmp( Dc_arg, "dim" )) {
- - Star_flags ^= STAR_FLAG_DIM;
- - } else if ( !strcmp( Dc_arg, "aa" )) {
- - Star_flags ^= STAR_FLAG_ANTIALIAS;
- - } else {
- - Dc_help = 1;
- - }
- - } else if ( !strcmp( Dc_arg, "cap" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( (Dc_arg_float < 0.0f) || (Dc_arg_float > 255.0f) ) {
- - Dc_help = 1;
- - } else {
- - Star_cap = Dc_arg_float;
- - }
- - } else if ( !strcmp( Dc_arg, "m0" )) {
- - Star_amount = 0.0f;
- - Star_dim = 0.0f;
- - Star_cap = 0.0f;
- - Star_flags = 0;
- - Star_max_length = STAR_MAX_LENGTH_DEFAULT;
- - } else if ( !strcmp( Dc_arg, "m1" ) || !strcmp( Dc_arg, "default" )) {
- - Star_amount = STAR_AMOUNT_DEFAULT;
- - Star_dim = STAR_DIM_DEFAULT;
- - Star_cap = STAR_CAP_DEFAULT;
- - Star_flags = STAR_FLAG_DEFAULT;
- - Star_max_length = STAR_MAX_LENGTH_DEFAULT;
- - } else if ( !strcmp( Dc_arg, "m2" )) {
- - Star_amount = 0.75f;
- - Star_dim = 20.0f;
- - Star_cap = 75.0f;
- - Star_flags = STAR_FLAG_TAIL|STAR_FLAG_DIM|STAR_FLAG_ANTIALIAS;
- - Star_max_length = STAR_MAX_LENGTH_DEFAULT;
- - } else if ( !strcmp( Dc_arg, "num" )) {
- - dc_get_arg(ARG_INT);
- - if ( (Dc_arg_int < 0) || (Dc_arg_int > MAX_STARS) ) {
- - Dc_help = 1;
- - } else {
- - Num_stars = Dc_arg_int;
- - }
- - } else {
- - // print usage, not stats
- - Dc_help = 1;
- - }
- - }
- + SCP_string arg;
- + float val_f;
- + int val_i;
- - if ( Dc_help ) {
- + if (dc_optional_string_either("help", "--help")) {
- dc_printf( "Usage: stars keyword\nWhere keyword can be in the following forms:\n" );
- dc_printf( "stars default Resets stars to all default values\n" );
- dc_printf( "stars num X Sets number of stars to X. Between 0 and %d.\n", MAX_STARS );
- @@ -949,21 +886,105 @@ DCF(stars,"Set parameters for starfield")
- dc_printf( "\nHINT: set cap to 0 to get dim rate and tail down, then use\n" );
- dc_printf( "cap to keep the lines from going away when moving too fast.\n" );
- dc_printf( "\nUse '? stars' to see current values.\n" );
- - Dc_status = 0; // don't print status if help is printed. Too messy.
- + return; // don't print status if help is printed. Too messy.
- }
- - if ( Dc_status ) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- dc_printf( "Num_stars: %d\n", Num_stars );
- dc_printf( "Tail: %.2f\n", Star_amount );
- - dc_printf( "Dim: %.2f\n", Star_dim );
- - dc_printf( "Cap: %.2f\n", Star_cap );
- + dc_printf( "Dim : %.2f\n", Star_dim );
- + dc_printf( "Cap : %.2f\n", Star_cap );
- dc_printf( "Max length: %.2f\n", Star_max_length );
- dc_printf( "Flags:\n" );
- - dc_printf( " Tail: %s\n", (Star_flags&STAR_FLAG_TAIL?"On":"Off") );
- - dc_printf( " Dim: %s\n", (Star_flags&STAR_FLAG_DIM?"On":"Off") );
- + dc_printf( " Tail : %s\n", (Star_flags&STAR_FLAG_TAIL?"On":"Off") );
- + dc_printf( " Dim : %s\n", (Star_flags&STAR_FLAG_DIM?"On":"Off") );
- dc_printf( " Antialias: %s\n", (Star_flags&STAR_FLAG_ANTIALIAS?"On":"Off") );
- dc_printf( "\nTHESE AREN'T SAVED TO DISK, SO IF YOU TWEAK\n" );
- dc_printf( "THESE AND LIKE THEM, WRITE THEM DOWN!!\n" );
- + return;
- + }
- +
- + dc_stuff_string_white(arg);
- + // "stars default" is handled by "stars m1"
- + if (arg == "num") {
- + dc_stuff_int(&val_i);
- +
- + CLAMP(val_i, 0, MAX_STARS);
- + Num_stars = val_i;
- +
- + dc_printf("Num_stars set to %i\n", Num_stars);
- +
- + } else if (arg == "tail") {
- + dc_stuff_float(&val_f);
- + CLAMP(val_f, 0.0, 1.0);
- + Star_amount = val_f;
- +
- + dc_printf("Star_amount set to %f\n", Star_amount);
- +
- + } else if (arg == "dim") {
- + dc_stuff_float(&val_f);
- +
- + if (val_f > 0.0f ) {
- + Star_dim = val_f;
- + dc_printf("Star_dim set to %f\n", Star_dim);
- +
- + } else {
- + dc_printf("Error: Star_dim value must be non-negative\n");
- + }
- +
- + } else if (arg == "cap") {
- + dc_stuff_float(&val_f);
- + CLAMP(val_f, 0.0, 255);
- + Star_cap = val_f;
- +
- + dc_printf("Star_cap set to %f\n", Star_cap);
- +
- + } else if (arg == "len") {
- + dc_stuff_float(&Star_max_length);
- +
- + dc_printf("Star_max_length set to %f\n", Star_max_length);
- +
- + } else if (arg == "m0") {
- + Star_amount = 0.0f;
- + Star_dim = 0.0f;
- + Star_cap = 0.0f;
- + Star_flags = 0;
- + Star_max_length = STAR_MAX_LENGTH_DEFAULT;
- +
- + dc_printf("Starfield set: Old 'pixel type' crappy stars. flags=none\n");
- +
- + } else if ((arg == "m1") || (arg == "default")) {
- + Star_amount = STAR_AMOUNT_DEFAULT;
- + Star_dim = STAR_DIM_DEFAULT;
- + Star_cap = STAR_CAP_DEFAULT;
- + Star_flags = STAR_FLAG_DEFAULT;
- + Star_max_length = STAR_MAX_LENGTH_DEFAULT;
- +
- + dc_printf("Starfield set: (default) tail=.75, dim=20.0, cap=75.0, flags=dim,tail\n");
- +
- + } else if (arg == "m2") {
- + Star_amount = 0.75f;
- + Star_dim = 20.0f;
- + Star_cap = 75.0f;
- + Star_flags = STAR_FLAG_TAIL|STAR_FLAG_DIM|STAR_FLAG_ANTIALIAS;
- + Star_max_length = STAR_MAX_LENGTH_DEFAULT;
- +
- + dc_printf("Starfield set: tail=.75, dim=20.0, cap=75.0, flags=dim,tail,aa\n");
- +
- + } else if (arg == "flag") {
- + dc_stuff_string_white(arg);
- + if (arg == "tail") {
- + Star_flags ^= STAR_FLAG_TAIL;
- + } else if (arg == "dim" ) {
- + Star_flags ^= STAR_FLAG_DIM;
- + } else if (arg == "aa" ) {
- + Star_flags ^= STAR_FLAG_ANTIALIAS;
- + } else {
- + dc_printf("Error: unknown flag argument '%s'\n", arg.c_str());
- + }
- +
- + } else {
- + dc_printf("Error: Unknown argument '%s'", arg.c_str());
- }
- }
- //XSTR:ON
- @@ -1284,39 +1305,44 @@ float Subspace_glow_rate = 1.0f;
- //XSTR:OFF
- DCF(subspace_set,"Set parameters for subspace effect")
- {
- - if ( Dc_command ) {
- - dc_get_arg(ARG_STRING);
- - if ( !strcmp( Dc_arg, "u" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( Dc_arg_float < 0.0f ) {
- - Dc_help = 1;
- - } else {
- - subspace_u_speed = Dc_arg_float;
- - }
- - } else if ( !strcmp( Dc_arg, "v" )) {
- - dc_get_arg(ARG_FLOAT);
- - if ( Dc_arg_float < 0.0f ) {
- - Dc_help = 1;
- - } else {
- - subspace_v_speed = Dc_arg_float;
- - }
- - } else {
- - // print usage, not stats
- - Dc_help = 1;
- - }
- - }
- -
- - if ( Dc_help ) {
- - dc_printf( "Usage: subspace keyword\nWhere keyword can be in the following forms:\n" );
- - dc_printf( "subspace u X Where X is how fast u moves.\n", MAX_STARS );
- - dc_printf( "subspace v X Where X is how fast v moves.\n" );
- - dc_printf( "\nUse '? subspace' to see current values.\n" );
- - Dc_status = 0; // don't print status if help is printed. Too messy.
- + SCP_string arg;
- + float value;
- +
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf( "Usage: subspace [--status] <axis> <speed>\n");
- + dc_printf("[--status] -- Displays the current speeds for both axes\n");
- + dc_printf("<axis> -- May be either 'u' or 'v', and corresponds to the texture axis\n");
- + dc_printf("<speed> -- is the speed along the axis that the texture is moved\n");
- + return;
- }
- - if ( Dc_status ) {
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- dc_printf( "u: %.2f\n", subspace_u_speed );
- dc_printf( "v: %.2f\n", subspace_v_speed );
- + return;
- + }
- +
- + dc_stuff_string_white(arg);
- + if (arg == "u") {
- + dc_stuff_float(&value);
- +
- + if ( value < 0.0f ) {
- + dc_printf("Error: speed must be non-negative");
- + return;
- + }
- + subspace_u_speed = value;
- +
- + } else if (arg == "v") {
- + dc_stuff_float(&value);
- +
- + if (value < 0.0f) {
- + dc_printf("Error: speed must be non-negative");
- + return;
- + }
- + subspace_v_speed = value;
- +
- + } else {
- + dc_printf("Error: Unknown axis '%s'", arg.c_str());
- }
- }
- //XSTR:ON
- diff --git a/code/starfield/supernova.cpp b/code/starfield/supernova.cpp
- index 7a1c420..058ce66 100644
- --- a/code/starfield/supernova.cpp
- +++ b/code/starfield/supernova.cpp
- @@ -21,6 +21,7 @@
- #include "gamesequence/gamesequence.h"
- #include "gamesnd/gamesnd.h"
- #include "cmdline/cmdline.h"
- +#include "debugconsole/console.h"
- // --------------------------------------------------------------------------------------------------------------------------
- // SUPERNOVA DEFINES/VARS
- @@ -116,11 +117,8 @@ void supernova_stop()
- int sn_particles = 100;
- -DCF(sn_part, "")
- -{
- - dc_get_arg(ARG_INT);
- - sn_particles = Dc_arg_int;
- -}
- +DCF_INT2(sn_part, sn_particles, 0, INT_MAX, "Sets number of supernova particles (default is 100)");
- +
- void supernova_do_particles()
- {
- int idx;
- @@ -181,11 +179,7 @@ void supernova_do_particles()
- // call once per frame
- float sn_shudder = 0.45f;
- -DCF(sn_shud, "")
- -{
- - dc_get_arg(ARG_FLOAT);
- - sn_shudder = Dc_arg_float;
- -}
- +DCF_FLOAT2(sn_shud, sn_shudder, 0.0, FLT_MAX, "Sets camera shudder rate for being in supernova shockwave (default is 0.45)");
- void supernova_process()
- {
- @@ -318,17 +312,10 @@ int supernova_camera_cut()
- // get view params from supernova
- float sn_distance = 300.0f; // shockwave moving at 1000/ms ?
- float sn_cam_distance = 25.0f;
- -DCF(sn_dist, "")
- -{
- - dc_get_arg(ARG_FLOAT);
- - sn_distance = Dc_arg_float;
- -}
- +DCF_FLOAT2(sn_dist, sn_distance, 0.0, FLT_MAX, "Sets supernova shockwave distance (default is 300.0f)");
- -DCF(sn_cam_dist, "")
- -{
- - dc_get_arg(ARG_FLOAT);
- - sn_cam_distance = Dc_arg_float;
- -}
- +
- +DCF_FLOAT2(sn_cam_dist, sn_cam_distance, 0.0, FLT_MAX, "Sets supernova camera distance (default is 25.0f)");
- void supernova_get_eye(vec3d *eye_pos, matrix *eye_orient)
- {
- diff --git a/code/stats/medals.cpp b/code/stats/medals.cpp
- index 34e0bc5..98a5df8 100644
- --- a/code/stats/medals.cpp
- +++ b/code/stats/medals.cpp
- @@ -21,6 +21,7 @@
- #include "globalincs/alphacolors.h"
- #include "localization/localize.h"
- #include "parse/parselo.h"
- +#include "debugconsole/console.h"
- #ifndef NDEBUG
- #include "cmdline/cmdline.h"
- @@ -437,78 +438,17 @@ void parse_medal_tbl()
- DCF(medals, "Grant or revoke medals")
- {
- int i;
- + int idx;
- - if (Dc_command)
- - {
- - dc_get_arg(ARG_STRING | ARG_INT | ARG_NONE);
- -
- - if (Dc_arg_type & ARG_INT)
- - {
- - int idx = Dc_arg_int;
- -
- - if (idx < 0 || idx >= Num_medals)
- - {
- - dc_printf("Medal index %d is out of range\n", idx);
- - return;
- - }
- -
- - dc_printf("Granted %s\n", Medals[idx].name);
- - Player->stats.medal_counts[idx]++;
- - }
- - else if (Dc_arg_type & ARG_STRING)
- - {
- - if (!strcmp(Dc_arg, "all"))
- - {
- - for (i = 0; i < Num_medals; i++)
- - Player->stats.medal_counts[i]++;
- -
- - dc_printf("Granted all medals\n");
- - }
- - else if (!strcmp(Dc_arg, "clear"))
- - {
- - for (i = 0; i < Num_medals; i++)
- - Player->stats.medal_counts[i] = 0;
- -
- - dc_printf("Cleared all medals\n");
- - }
- - else if (!strcmp(Dc_arg, "demote"))
- - {
- - if (Player->stats.rank > 0)
- - Player->stats.rank--;
- -
- - dc_printf("Demoted to %s\n", Ranks[Player->stats.rank].name);
- - }
- - else if (!strcmp(Dc_arg, "promote"))
- - {
- - if (Player->stats.rank < MAX_FREESPACE2_RANK)
- - Player->stats.rank++;
- -
- - dc_printf("Promoted to %s\n", Ranks[Player->stats.rank].name);
- - }
- - else
- - {
- - Dc_help = 1;
- - }
- - }
- - else
- - {
- - dc_printf("The following medals are available:\n");
- - for (i = 0; i < Num_medals; i++)
- - dc_printf("%d: %s\n", i, Medals[i].name);
- - }
- -
- - Dc_status = 0;
- - }
- -
- - if (Dc_help)
- + if (dc_optional_string_either("help", "--help"))
- {
- - dc_printf ("Usage: gimmemedals all | clear | promote | demote | [index]\n");
- + dc_printf ("Usage: medals all | clear | promote | demote | [index]\n");
- dc_printf (" [index] -- index of medal to grant\n");
- dc_printf (" with no parameters, displays the available medals\n");
- - Dc_status = 0;
- + return;
- }
- - if (Dc_status)
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?"))
- {
- dc_printf("You have the following medals:\n");
- @@ -518,6 +458,53 @@ DCF(medals, "Grant or revoke medals")
- dc_printf("%d %s\n", Player->stats.medal_counts[i], Medals[i].name);
- }
- dc_printf("%s\n", Ranks[Player->stats.rank].name);
- + return;
- + }
- +
- + if (dc_optional_string("all")) {
- + for (i = 0; i < Num_medals; i++) {
- + Player->stats.medal_counts[i]++;
- + }
- + dc_printf("Granted all medals\n");
- + return;
- +
- + } else if (dc_optional_string("clear")) {
- + for (i = 0; i < Num_medals; i++) {
- + Player->stats.medal_counts[i] = 0;
- + }
- + dc_printf("Cleared all medals\n");
- + return;
- +
- + } else if (dc_optional_string("promote")) {
- + if (Player->stats.rank < MAX_FREESPACE2_RANK) {
- + Player->stats.rank++;
- + }
- + dc_printf("Promoted to %s\n", Ranks[Player->stats.rank].name);
- + return;
- +
- + } else if (dc_optional_string("demote")) {
- + if (Player->stats.rank > 0) {
- + Player->stats.rank--;
- + }
- + dc_printf("Demoted to %s\n", Ranks[Player->stats.rank].name);
- + return;
- + }
- +
- + if (dc_maybe_stuff_int(&idx)) {
- + if (idx < 0 || idx >= Num_medals)
- + {
- + dc_printf("Medal index %d is out of range\n", idx);
- + return;
- + }
- +
- + dc_printf("Granted %s\n", Medals[idx].name);
- + Player->stats.medal_counts[idx]++;
- + return;
- + }
- +
- + dc_printf("The following medals are available:\n");
- + for (i = 0; i < Num_medals; i++) {
- + dc_printf("%d: %s\n", i, Medals[i].name);
- }
- }
- diff --git a/code/stats/scoring.cpp b/code/stats/scoring.cpp
- index c617635..08b4d25 100644
- --- a/code/stats/scoring.cpp
- +++ b/code/stats/scoring.cpp
- @@ -31,6 +31,7 @@
- #include "network/multi_pmsg.h"
- #include "ai/ai_profiles.h"
- #include "pilotfile/pilotfile.h"
- +#include "debugconsole/console.h"
- /*
- // uncomment to get extra debug messages when a player scores
- @@ -1509,20 +1510,42 @@ void scoring_bash_rank(player *pl,int rank)
- pl->stats.rank = rank;
- }
- -DCF(rank, "changes scoring vars")
- +DCF(rank, "changes player rank")
- {
- - if(Dc_command){
- - dc_get_arg(ARG_INT);
- -
- - // parse the argument and change things around accordingly
- - if((Dc_arg_type & ARG_INT) && (Player != NULL)){
- - scoring_bash_rank(Player,Dc_arg_int);
- - }
- + int rank;
- +
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Usage: rank <index>\n");
- + dc_printf(" <index> The rank index you wish to have. For retail ranks, these correspond to:\n");
- + dc_printf("\t0 : Ensign\n");
- + dc_printf("\t1 : Lieutenant Junior Grade\n");
- + dc_printf("\t2 : Lietenant\n");
- + dc_printf("\t3 : Lieutenant Commander\n");
- + dc_printf("\t4 : Commander\n");
- + dc_printf("\t5 : Captain\n");
- + dc_printf("\t6 : Commodore\n");
- + dc_printf("\t7 : Rear Admiral\n");
- + dc_printf("\t8 : Vice Admiral\n");
- + dc_printf("\t9 : Admiral\n\n");
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + if (Player != NULL) {
- + dc_printf("Current rank is %i\n", Player->stats.rank);
- + } else {
- + dc_printf("Error! Current Player not active or loaded\n");
- + }
- + }
- +
- + dc_stuff_int(&rank);
- +
- + // parse the argument and change things around accordingly
- + if (Player != NULL) {
- + scoring_bash_rank(Player, rank);
- + } else {
- + dc_printf("Error! Current Player not active or loaded\n");
- }
- - dc_printf("Usage\n0 : Ensign\n1 : Lieutenant Junior Grade\n");
- - dc_printf("2 : Lietenant\n3 : Lieutenant Commander\n");
- - dc_printf("4 : Commander\n5 : Captain\n6 : Commodore\n");
- - dc_printf("7 : Rear Admiral\n8 : Vice Admiral\n9 : Admiral");
- }
- void scoreing_close()
- diff --git a/code/weapon/beam.cpp b/code/weapon/beam.cpp
- index abfe402..a6009ba 100644
- --- a/code/weapon/beam.cpp
- +++ b/code/weapon/beam.cpp
- @@ -36,6 +36,7 @@
- #include "globalincs/globals.h"
- #include "cmdline/cmdline.h"
- #include "parse/scripting.h"
- +#include "debugconsole/console.h"
- extern int Cmdline_nohtl;
- // ------------------------------------------------------------------------------------------------
- @@ -119,20 +120,22 @@ float b_whack_small = 2000.0f; // used to be 500.0f with the retail whack bug
- float b_whack_big = 10000.0f; // used to be 1500.0f with the retail whack bug
- float b_whack_damage = 150.0f;
- -DCF(b_whack_small, "")
- +DCF(b_whack_small, "Sets the whack factor for small whacks (Default is 2000f)")
- {
- - dc_get_arg(ARG_FLOAT);
- - b_whack_small = Dc_arg_float;
- + dc_stuff_float(&b_whack_small);
- }
- -DCF(b_whack_big, "")
- +DCF(b_whack_big, "Sets the whack factor for big whacks (Default is 10000f)")
- {
- - dc_get_arg(ARG_FLOAT);
- - b_whack_big = Dc_arg_float;
- + dc_stuff_float(&b_whack_big);
- }
- -DCF(b_whack_damage, "")
- +DCF(b_whack_damage, "Sets the whack damage threshold (Default is 150f)")
- {
- - dc_get_arg(ARG_FLOAT);
- - b_whack_damage = Dc_arg_float;
- + if (dc_optional_string_either("help", "--help")) {
- + dc_printf("Sets the threshold to determine whether a big whack or a small whack should be applied. Values equal or greater than this threshold will trigger a big whack, while smaller values will trigger a small whack\n");
- + return;
- + }
- +
- + dc_stuff_float(&b_whack_damage);
- }
- @@ -1254,10 +1257,9 @@ void beam_render(beam *b, float u_offset)
- // generate particles for the muzzle glow
- int hack_time = 100;
- -DCF(h_time, "")
- +DCF(h_time, "Sets the hack time for beam muzzle glow (Default is 100)")
- {
- - dc_get_arg(ARG_INT);
- - hack_time = Dc_arg_int;
- + dc_stuff_int(&hack_time);
- }
- void beam_generate_muzzle_particles(beam *b)
- @@ -1479,10 +1481,9 @@ void beam_calc_facing_pts( vec3d *top, vec3d *bot, vec3d *fvec, vec3d *pos, floa
- // light scale factor
- float blight = 25.5f;
- -DCF(blight, "")
- +DCF(blight, "Sets the beam light scale factor (Default is 25.5f)")
- {
- - dc_get_arg(ARG_FLOAT);
- - blight = Dc_arg_float;
- + dc_stuff_float(&blight);
- }
- // call to add a light source to a small object
- @@ -3446,12 +3447,11 @@ int beam_will_tool_target(beam *b, object *objp)
- }
- float beam_accuracy = 1.0f;
- -DCF(b_aim, "")
- +DCF(b_aim, "Adjusts the beam accuracy factor (Default is 1.0f)")
- {
- - dc_get_arg(ARG_FLOAT);
- - beam_accuracy = Dc_arg_float;
- + dc_stuff_float(&beam_accuracy);
- }
- -DCF(beam_list, "")
- +DCF(beam_list, "Lists all beams")
- {
- int idx;
- int b_count = 0;
- diff --git a/code/weapon/corkscrew.cpp b/code/weapon/corkscrew.cpp
- index 9552ff0..c84195f 100644
- --- a/code/weapon/corkscrew.cpp
- +++ b/code/weapon/corkscrew.cpp
- @@ -15,6 +15,7 @@
- #include "io/timer.h"
- #include "freespace2/freespace.h" // for Missiontime
- #include "object/object.h"
- +#include "debugconsole/console.h"
- @@ -293,41 +294,25 @@ DCF(cscrew, "Listing of corkscrew missile debug console functions")
- DCF(cscrew_delay, "Change the delay between corkscrew firing")
- {
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - Corkscrew_missile_delay = Dc_arg_int;
- - }
- -
- + dc_stuff_int(&Corkscrew_missile_delay);
- cscrew_display_dcf();
- }
- DCF(cscrew_count, "Change the # of corkscrew missiles fired")
- {
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - Corkscrew_num_missiles_fired = Dc_arg_int;
- - }
- -
- + dc_stuff_int(&Corkscrew_num_missiles_fired);
- cscrew_display_dcf();
- }
- DCF(cscrew_radius, "Change the radius of corkscrew missiles")
- {
- - dc_get_arg(ARG_FLOAT);
- - if(Dc_arg_type & ARG_FLOAT){
- - Corkscrew_radius = Dc_arg_float;
- - }
- -
- + dc_stuff_float(&Corkscrew_radius);
- cscrew_display_dcf();
- }
- DCF(cscrew_twist, "Change the rate of the corkscrew twist")
- {
- - dc_get_arg(ARG_FLOAT);
- - if(Dc_arg_type & ARG_FLOAT){
- - Corkscrew_twist = Dc_arg_float;
- - }
- -
- + dc_stuff_float(&Corkscrew_twist);
- cscrew_display_dcf();
- }
- @@ -354,11 +339,7 @@ DCF(cscrew_shrink, "Shrink the radius of every other missile")
- DCF(cscrew_shrinkval, "Change the rate at which the radii shrink")
- {
- - dc_get_arg(ARG_FLOAT);
- - if(Dc_arg_type & ARG_FLOAT){
- - Corkscrew_shrink_val = Dc_arg_float;
- - }
- -
- + dc_stuff_float(&Corkscrew_shrink_val);
- cscrew_display_dcf();
- }
- diff --git a/code/weapon/emp.cpp b/code/weapon/emp.cpp
- index ea4e79c..b1cff29 100644
- --- a/code/weapon/emp.cpp
- +++ b/code/weapon/emp.cpp
- @@ -26,6 +26,7 @@
- #include "iff_defs/iff_defs.h"
- #include "network/multimsgs.h"
- #include "network/multi.h"
- +#include "debugconsole/console.h"
- @@ -637,13 +638,12 @@ float emp_current_intensity()
- DCF(zap, "zap a ship with an EMP effect")
- {
- int shipnum;
- + char ship_str[NAME_LENGTH];
- - dc_get_arg(ARG_STRING);
- - if(Dc_arg_type & ARG_STRING){
- - shipnum = ship_name_lookup(Dc_arg, 1);
- + dc_stuff_string_white(ship_str, NAME_LENGTH);
- + shipnum = ship_name_lookup(ship_str, 1);
- - if(shipnum >= 0){
- - emp_start_ship(&Objects[Ships[shipnum].objnum], 500.0f, 10.0f);
- - }
- + if(shipnum >= 0){
- + emp_start_ship(&Objects[Ships[shipnum].objnum], 500.0f, 10.0f);
- }
- }
- diff --git a/code/weapon/weapons.cpp b/code/weapon/weapons.cpp
- index f9c6917..e445c53 100644
- --- a/code/weapon/weapons.cpp
- +++ b/code/weapon/weapons.cpp
- @@ -47,6 +47,7 @@
- #include "parse/scripting.h"
- #include "stats/scoring.h"
- #include "mod_table/mod_table.h"
- +#include "debugconsole/console.h"
- #ifndef NDEBUG
- @@ -6665,75 +6666,137 @@ void weapon_maybe_spew_particle(object *obj)
- /**
- * Debug console functionality
- */
- -void pspew_display_dcf()
- +void dcf_pspew();
- +DCF(pspew_count, "Number of particles spewed at a time")
- {
- - dc_printf("Particle spew settings\n\n");
- - dc_printf("Particle spew count (pspew_count) : %d\n", Weapon_particle_spew_count);
- - dc_printf("Particle spew time (pspew_time) : %d\n", Weapon_particle_spew_time);
- - dc_printf("Particle spew velocity (pspew_vel) : %f\n", Weapon_particle_spew_vel);
- - dc_printf("Particle spew size (pspew_size) : %f\n", Weapon_particle_spew_radius);
- - dc_printf("Particle spew lifetime (pspew_life) : %f\n", Weapon_particle_spew_lifetime);
- - dc_printf("Particle spew scale (psnew_scale) : %f\n", Weapon_particle_spew_scale);
- -}
- + if (dc_optional_string_either("help", "--help")) {
- + dcf_pspew();
- + return;
- + }
- -DCF(pspew_count, "Number of particles spewed at a time")
- -{
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - Weapon_particle_spew_count = Dc_arg_int;
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Partical count is %i\n", Weapon_particle_spew_count);
- + return;
- }
- - pspew_display_dcf();
- + dc_stuff_int(&Weapon_particle_spew_count);
- +
- + dc_printf("Partical count set to %i\n", Weapon_particle_spew_count);
- }
- DCF(pspew_time, "Time between particle spews")
- -{
- - dc_get_arg(ARG_INT);
- - if(Dc_arg_type & ARG_INT){
- - Weapon_particle_spew_time = Dc_arg_int;
- +{
- + if (dc_optional_string_either("help", "--help")) {
- + dcf_pspew();
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Particle spawn period is %i\n", Weapon_particle_spew_time);
- + return;
- }
- - pspew_display_dcf();
- + dc_stuff_int(&Weapon_particle_spew_time);
- +
- + dc_printf("Particle spawn period set to %i\n", Weapon_particle_spew_time);
- }
- DCF(pspew_vel, "Relative velocity of particles (0.0 - 1.0)")
- -{
- - dc_get_arg(ARG_FLOAT);
- - if(Dc_arg_type & ARG_FLOAT){
- - Weapon_particle_spew_vel = Dc_arg_float;
- +{
- + if (dc_optional_string_either("help", "--help")) {
- + dcf_pspew();
- + return;
- }
- - pspew_display_dcf();
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Particle relative velocity is %f\n", Weapon_particle_spew_vel);
- + return;
- + }
- +
- + dc_stuff_float(&Weapon_particle_spew_vel);
- +
- + dc_printf("Particle relative velocity set to %f\n", Weapon_particle_spew_vel);
- }
- DCF(pspew_size, "Size of spewed particles")
- -{
- - dc_get_arg(ARG_FLOAT);
- - if(Dc_arg_type & ARG_FLOAT){
- - Weapon_particle_spew_radius = Dc_arg_float;
- +{
- + if (dc_optional_string_either("help", "--help")) {
- + dcf_pspew();
- + return;
- + }
- +
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Particle size is %f\n", Weapon_particle_spew_radius);
- + return;
- }
- - pspew_display_dcf();
- + dc_stuff_float(&Weapon_particle_spew_radius);
- +
- + dc_printf("Particle size set to %f\n", Weapon_particle_spew_radius);
- }
- DCF(pspew_life, "Lifetime of spewed particles")
- -{
- - dc_get_arg(ARG_FLOAT);
- - if(Dc_arg_type & ARG_FLOAT){
- - Weapon_particle_spew_lifetime = Dc_arg_float;
- +{
- + if (dc_optional_string_either("help", "--help")) {
- + dcf_pspew();
- + return;
- }
- - pspew_display_dcf();
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Particle lifetime is %f\n", Weapon_particle_spew_lifetime);
- + return;
- + }
- +
- + dc_stuff_float(&Weapon_particle_spew_lifetime);
- +
- + dc_printf("Particle lifetime set to %f\n", Weapon_particle_spew_lifetime);
- }
- DCF(pspew_scale, "How far away particles are from the weapon path")
- -{
- - dc_get_arg(ARG_FLOAT);
- - if(Dc_arg_type & ARG_FLOAT){
- - Weapon_particle_spew_scale = Dc_arg_float;
- +{
- + if (dc_optional_string_either("help", "--help")) {
- + dcf_pspew();
- + return;
- }
- - pspew_display_dcf();
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Particle scale is %f\n", Weapon_particle_spew_scale);
- + }
- +
- + dc_stuff_float(&Weapon_particle_spew_scale);
- +
- + dc_printf("Particle scale set to %f\n", Weapon_particle_spew_scale);
- +}
- +
- +// Help and Status provider
- +DCF(pspew, "Particle spew help and status provider")
- +{
- + if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
- + dc_printf("Particle spew settings\n\n");
- +
- + dc_printf(" Count (pspew_count) : %d\n", Weapon_particle_spew_count);
- + dc_printf(" Time (pspew_time) : %d\n", Weapon_particle_spew_time);
- + dc_printf(" Velocity (pspew_vel) : %f\n", Weapon_particle_spew_vel);
- + dc_printf(" Size (pspew_size) : %f\n", Weapon_particle_spew_radius);
- + dc_printf(" Lifetime (pspew_life) : %f\n", Weapon_particle_spew_lifetime);
- + dc_printf(" Scale (psnew_scale) : %f\n", Weapon_particle_spew_scale);
- + return;
- + }
- +
- + dc_printf("Available particlar spew commands:\n");
- + dc_printf("pspew_count : %s\n", dcmd_pspew_count.help);
- + dc_printf("pspew_time : %s\n", dcmd_pspew_time.help);
- + dc_printf("pspew_vel : %s\n", dcmd_pspew_vel.help);
- + dc_printf("pspew_size : %s\n", dcmd_pspew_size.help);
- + dc_printf("pspew_life : %s\n", dcmd_pspew_life.help);
- + dc_printf("pspew_scale : %s\n\n", dcmd_pspew_scale.help);
- +
- + dc_printf("To view status of all pspew settings, type in 'pspew --status'.\n");
- + dc_printf("Passing '--status' as an argument to any of the individual spew commands will show the status of that variable only.\n\n");
- +
- + dc_printf("These commands adjust the various properties of the particle spew system, which is used by weapons when they are fired, are in-flight, and die (either by impact or by end of life time.\n");
- + dc_printf("Generally, a large particle count with small size and scale will result in a nice dense particle spew.\n");
- + dc_printf("Be advised, this effect is applied to _ALL_ weapons, and as such may drastically reduce framerates on lower powered platforms.\n");
- }
- /**
- diff --git a/code/windows_stub/stubs.cpp b/code/windows_stub/stubs.cpp
- index e85f25e..9eaee5e 100644
- --- a/code/windows_stub/stubs.cpp
- +++ b/code/windows_stub/stubs.cpp
- @@ -23,6 +23,7 @@
- #include "globalincs/pstypes.h"
- #include "parse/lua.h"
- #include "cmdline/cmdline.h"
- +#include "debugconsole/console.h"
- bool env_enabled = false;
- bool cell_enabled = false;
- diff --git a/projects/MSVC_2011/code.vcxproj b/projects/MSVC_2011/code.vcxproj
- index b116c54..d0b2fa0 100644
- --- a/projects/MSVC_2011/code.vcxproj
- +++ b/projects/MSVC_2011/code.vcxproj
- @@ -529,6 +529,9 @@
- <ClCompile Include="..\..\code\cutscene\oggplayer.cpp" />
- <ClCompile Include="..\..\code\Debris\debris.cpp" />
- <ClCompile Include="..\..\code\DebugConsole\console.cpp" />
- + <ClCompile Include="..\..\code\debugconsole\consolecmds.cpp" />
- + <ClCompile Include="..\..\code\debugconsole\consoleparse.cpp" />
- + <ClCompile Include="..\..\code\debugconsole\timerbar.cpp" />
- <ClCompile Include="..\..\code\fireball\fireballs.cpp" />
- <ClCompile Include="..\..\code\fireball\warpineffect.cpp" />
- <ClCompile Include="..\..\code\gamehelp\contexthelp.cpp" />
- @@ -808,6 +811,9 @@
- <ClInclude Include="..\..\code\cutscene\mvelib.h" />
- <ClInclude Include="..\..\code\cutscene\oggplayer.h" />
- <ClInclude Include="..\..\code\Debris\debris.h" />
- + <ClInclude Include="..\..\code\debugconsole\console.h" />
- + <ClInclude Include="..\..\code\debugconsole\consoleparse.h" />
- + <ClInclude Include="..\..\code\debugconsole\timerbar.h" />
- <ClInclude Include="..\..\code\DirectX\vasync.h" />
- <ClInclude Include="..\..\code\DirectX\vdinput.h" />
- <ClInclude Include="..\..\code\DirectX\vdplay.h" />
- @@ -1097,4 +1103,4 @@
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
- <ImportGroup Label="ExtensionTargets">
- </ImportGroup>
- -</Project>
- \ No newline at end of file
- +</Project>
- diff --git a/projects/MSVC_2011/code.vcxproj.filters b/projects/MSVC_2011/code.vcxproj.filters
- index 932dc5b..8eb6e53 100644
- --- a/projects/MSVC_2011/code.vcxproj.filters
- +++ b/projects/MSVC_2011/code.vcxproj.filters
- @@ -1056,6 +1056,15 @@
- <ClCompile Include="..\..\code\globalincs\profiling.cpp">
- <Filter>GlobalIncs</Filter>
- </ClCompile>
- + <ClCompile Include="..\..\code\debugconsole\consolecmds.cpp">
- + <Filter>DebugConsole</Filter>
- + </ClCompile>
- + <ClCompile Include="..\..\code\debugconsole\consoleparse.cpp">
- + <Filter>DebugConsole</Filter>
- + </ClCompile>
- + <ClCompile Include="..\..\code\debugconsole\timerbar.cpp">
- + <Filter>DebugConsole</Filter>
- + </ClCompile>
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="..\..\code\ai\ai.h">
- @@ -1855,6 +1864,15 @@
- </ClInclude>
- <ClInclude Include="..\..\code\PilotFile\pilotfile.h">
- <Filter>PilotFile</Filter>
- + <ClInclude Include="..\..\code\debugconsole\console.h">
- + <Filter>DebugConsole</Filter>
- + </ClInclude>
- + <ClInclude Include="..\..\code\debugconsole\consoleparse.h">
- + <Filter>DebugConsole</Filter>
- + </ClInclude>
- + <ClInclude Include="..\..\code\debugconsole\timerbar.h">
- + <Filter>DebugConsole</Filter>
- + </ClInclude>
- </ClInclude>
- </ItemGroup>
- <ItemGroup>
- @@ -1873,4 +1891,4 @@
- <Filter>Sound</Filter>
- </CustomBuild>
- </ItemGroup>
- -</Project>
- \ No newline at end of file
- +</Project>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement