Skip to content

Commit

Permalink
Curses Port: Fix unacceptable delay on ESC keypress
Browse files Browse the repository at this point in the history
  • Loading branch information
poschengband committed Feb 25, 2015
1 parent cc3ffb7 commit ba4fb87
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Expand Up @@ -8,7 +8,7 @@ OBJECTS = $(ANGFILES) $(ZFILES)
SRCS = ${OBJECTS:.o=.c} ${MAINFILES:.o=.c}
PROG = poschengband$(PROG_SUFFIX)
# VERSION := $(shell ../scripts/version.sh)
CFLAGS += -DBUILD_ID=${VERSION} -I. -std=c99 -Wdeclaration-after-statement -fno-omit-frame-pointer
CFLAGS += -DBUILD_ID=${VERSION} -I. -std=c99 -Wdeclaration-after-statement -O0 -g -fno-omit-frame-pointer

CLEAN = poschengband.o $(OBJECTS) win/poschengband.res
DISTCLEAN = autoconf.h
Expand Down
1 change: 1 addition & 0 deletions src/externs.h
Expand Up @@ -1501,6 +1501,7 @@ extern bool get_check_strict(cptr prompt, int mode);
extern bool get_com(cptr prompt, char *command, bool z_escape);
extern s16b get_quantity(cptr prompt, int max);
extern void pause_line(int row);
extern void pause_line_aux(cptr prompt, int row, int col);
extern void request_command(int shopping);
extern bool is_a_vowel(int ch);
extern int get_keymap_dir(char ch);
Expand Down
6 changes: 4 additions & 2 deletions src/main-gcu.c
Expand Up @@ -1205,8 +1205,7 @@ errr init_gcu(int argc, char *argv[])
/* Unused */
(void)argc;
(void)argv;



#ifdef USE_SOUND

/* Build the "sound" path */
Expand All @@ -1220,6 +1219,9 @@ errr init_gcu(int argc, char *argv[])
/* Extract the normal keymap */
keymap_norm_prepare();

if (!getenv("ESCDELAY"))
putenv("ESCDELAY=20");

#if defined(USG)
/* Initialize for USG Unix */
if (initscr() == NULL) return (-1);
Expand Down
3 changes: 1 addition & 2 deletions src/main.c
Expand Up @@ -765,7 +765,6 @@ int main(int argc, char *argv[])
/* Hack -- If requested, display scores and quit */
if (show_score > 0) display_scores(0, show_score);


/* Catch nasty signals */
signals_init();

Expand All @@ -775,7 +774,7 @@ int main(int argc, char *argv[])
/* Wait for response */
pause_line(23);

/* Play the game */
/* Play the game */
play_game(new_game);

/* Quit */
Expand Down
25 changes: 20 additions & 5 deletions src/util.c
Expand Up @@ -1811,7 +1811,7 @@ void sound(int val)
*/
static char inkey_aux(void)
{
int k = 0, n, p = 0, w = 0;
int k = 0, n, p = 0, w = 0, max_delay = 100;

char ch;

Expand Down Expand Up @@ -1861,7 +1861,17 @@ static char inkey_aux(void)
/* No macro pending */
if (k < 0) return (ch);


#ifdef USE_GCU
/* curses sends many single keystrokes as escape sequences, and we
* use macros to handle these (see pref-gcu.prf). For example, pressing '2'
* on the number pad comes as the three character sequence \e[B. If we
* aren't careful, then the game will pause when the user really just types
* escape. For the longest time, I was convinced this had to do with ESCDELAY
* in ncurses. Alas, the culprit is our macro processing system! */
if (ch == 27)
max_delay = 10;
#endif

/* Wait for a macro, or a timeout */
while (TRUE)
{
Expand Down Expand Up @@ -1889,7 +1899,7 @@ static char inkey_aux(void)
w += 10;

/* Excessive delay */
if (w >= 100) break;
if (w >= max_delay) break;

/* Delay */
Term_xtra(TERM_XTRA_DELAY, w);
Expand Down Expand Up @@ -3694,15 +3704,20 @@ s16b get_quantity(cptr prompt, int max)
/*
* Pause for user response XXX XXX XXX
*/
void pause_line(int row)
void pause_line_aux(cptr prompt, int row, int col)
{
prt("", row, 0);
put_str("[Press any key to continue]", row, 23);
put_str(prompt, row, col);

(void)inkey();
prt("", row, 0);
}

void pause_line(int row)
{
pause_line_aux("[Press any key to continue]", row, 23);
}


/*
* Hack -- special buffer to hold the action of the current keymap
Expand Down
1 change: 0 additions & 1 deletion src/z-config.h
Expand Up @@ -96,7 +96,6 @@
# define USE_GETCH
#endif


/*
* OPTION: Use the "curs_set()" call in "main-gcu.c".
* Hack -- This option will not work on most BSD machines
Expand Down

0 comments on commit ba4fb87

Please sign in to comment.