provide some debug developer controls - part 1

This commit is contained in:
nhmall
2018-05-10 10:05:29 -04:00
parent 4dd535cbd2
commit 702154529f
6 changed files with 108 additions and 16 deletions

View File

@@ -26,7 +26,7 @@ E void NDECL(display_gamewindows);
E void NDECL(newgame);
E void FDECL(welcome, (BOOLEAN_P));
E time_t NDECL(get_realtime);
E boolean FDECL(argcheck, (int, char **, enum earlyarg));
E int FDECL(argcheck, (int, char **, enum earlyarg));
/* ### apply.c ### */

View File

@@ -221,6 +221,16 @@ enum getloc_filters {
NUM_GFILTER
};
struct debug_flags {
boolean test;
#ifdef TTY_GRAPHICS
boolean ttystatus;
#endif
#ifdef WIN32
boolean immediateflips;
#endif
};
struct instance_flags {
/* stuff that really isn't option or platform related. They are
* set and cleared during the game to control the internal
@@ -423,6 +433,7 @@ struct instance_flags {
short mines_prize_type; /* luckstone */
short soko_prize_type1; /* bag of holding or */
short soko_prize_type2; /* amulet of reflection */
struct debug_flags debug;
};
/*

View File

@@ -6,6 +6,7 @@
/* various code that was replicated in *main.c */
#include "hack.h"
#include <ctype.h>
#ifndef NO_SIGNAL
#include <signal.h>
@@ -16,6 +17,7 @@ STATIC_DCL void NDECL(do_positionbar);
#endif
STATIC_DCL void FDECL(regen_hp, (int));
STATIC_DCL void FDECL(interrupt_multi, (const char *));
STATIC_DCL void FDECL(debug_fields, (const char *));
void
moveloop(resuming)
@@ -752,11 +754,18 @@ const char *msg;
*/
static struct early_opt earlyopts[] = {
{ARG_DEBUG, "debug", 5, FALSE},
{ARG_DEBUG, "debug", 5, TRUE},
{ARG_VERSION, "version", 4, TRUE},
};
boolean
/*
* Returns:
* 0 = no match
* 1 = found and skip past this argument
* 2 = found and trigger immediate exit
*/
int
argcheck(argc, argv, e_arg)
int argc;
char *argv[];
@@ -774,7 +783,7 @@ enum earlyarg e_arg;
if ((idx >= SIZE(earlyopts)) || (argc <= 1))
return FALSE;
for (i = 1; i < argc; ++i) {
for (i = 0; i < argc; ++i) {
if (argv[i][0] != '-')
continue;
if (argv[i][1] == '-') {
@@ -789,15 +798,20 @@ enum earlyarg e_arg;
}
if (match) {
const char *extended_opt = index(userea,':');
if (!extended_opt)
extended_opt = index(userea, '=');
switch(e_arg) {
case ARG_DEBUG:
if (extended_opt) {
extended_opt++;
debug_fields(extended_opt);
}
return 1;
break;
case ARG_VERSION: {
boolean insert_into_pastebuf = FALSE;
const char *extended_opt = index(userea,':');
if (!extended_opt)
extended_opt = index(userea, '=');
if (extended_opt) {
extended_opt++;
@@ -812,7 +826,7 @@ enum earlyarg e_arg;
}
}
early_version_info(insert_into_pastebuf);
return TRUE;
return 2;
break;
}
default:
@@ -822,4 +836,63 @@ enum earlyarg e_arg;
return FALSE;
}
/*
* These are internal controls to aid developers with
* testing and debugging particular aspects of the code.
* They are not player options and the only place they
* are documented is right here. No gameplay is altered.
*
* test - test whether this parser is working
* ttystatus - TTY:
* immediateflips - WIN32: turn off display performance
* optimization so that display output
* can be debugged without buffering.
*/
void
debug_fields(opts)
const char *opts;
{
char *op;
boolean negated = FALSE;
boolean retval = TRUE;
while ((op = index(opts, ',')) != 0) {
*op++ = 0;
/* recurse */
debug_fields(op);
}
if (strlen(opts) > BUFSZ / 2)
return;
/* strip leading and trailing white space */
while (isspace((uchar) *opts))
opts++;
op = eos((char *) opts);
while (--op >= opts && isspace((uchar) *op))
*op = '\0';
if (!*opts) {
/* empty */
return;
}
while ((*opts == '!') || !strncmpi(opts, "no", 2)) {
if (*opts == '!')
opts++;
else
opts += 2;
negated = !negated;
}
if (match_optname(opts, "test", 4, FALSE))
iflags.debug.test = negated ? FALSE : TRUE;
#ifdef TTY_GRAPHICS
if (match_optname(opts, "ttystatus", 9, FALSE))
iflags.debug.ttystatus = negated ? FALSE : TRUE;
#endif
#ifdef WIN32
if (match_optname(opts, "immediateflips", 14, FALSE))
iflags.debug.immediateflips = negated ? FALSE : TRUE;
#endif
return;
}
/*allmain.c*/

View File

@@ -331,9 +331,14 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
Strcpy(hackdir, HACKDIR);
#endif
if (argc > 1) {
if (argcheck(argc, argv, ARG_VERSION))
if (argcheck(argc, argv, ARG_VERSION) == 2)
nethack_exit(EXIT_SUCCESS);
if (argcheck(argc, argv, ARG_DEBUG) == 1) {
argc--;
argv++;
}
if (!strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') {
/* avoid matching "-dec" for DECgraphics; since the man page
* says -d directory, hope nobody's using -desomething_else

View File

@@ -111,9 +111,14 @@ char *argv[];
dir = nh_getenv("HACKDIR");
if (argc > 1) {
if (argcheck(argc, argv, ARG_VERSION))
if (argcheck(argc, argv, ARG_VERSION) == 2)
exit(EXIT_SUCCESS);
if (argcheck(argc, argv, ARG_DEBUG) == 1) {
argc--;
argv++;
}
if (!strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') {
/* avoid matching "-dec" for DECgraphics; since the man page
* says -d directory, hope nobody's using -desomething_else

View File

@@ -252,8 +252,6 @@ cell_t undefined_cell;
static boolean buffer_flipping_initialized = FALSE;
boolean do_immediate_flips = FALSE;
static void check_buffer_size(int width, int height);
static cell_t * buffer_get_cell(console_buffer_t * buffer, int x, int y);
@@ -370,7 +368,7 @@ static void buffer_fill_to_end(console_buffer_t * buffer, cell_t * src,
while (dst != sentinel)
*dst++ = clear_cell;
if (do_immediate_flips && buffer == &back_buffer)
if (iflags.debug.immediateflips && buffer == &back_buffer)
back_buffer_flip();
}
@@ -379,7 +377,7 @@ static void back_buffer_write(cell_t * cell, int x, int y)
cell_t * dst = buffer_get_cell(&back_buffer, x, y);
*dst = *cell;
if (do_immediate_flips)
if (iflags.debug.immediateflips)
back_buffer_flip();
}
@@ -393,7 +391,7 @@ static void back_buffer_clear_to_end_of_line(int x, int y)
while (cell != sentinel)
*cell++ = clear_cell;
if (do_immediate_flips)
if (iflags.debug.immediateflips)
back_buffer_flip();
}