From 35273b8a8cf12bd5394a4606f659acf6407e09c6 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sun, 12 Mar 2023 18:39:13 +0200 Subject: [PATCH] Curses: prevent spurious cursor updates While watching a ttyrec, I noticed strange behaviour in the cursor updates; it was moved to approximately middle of the map window every so often, usually when doing ranged attacks. This wasn't really noticeable in normal gameplay, as it was moving the cursor there, and then almost immediately to where it was supposed to be. I managed to trace it down to the refresh() in curses_delay_output(). That call updates the terminal to match the ncurses stdscr window, but the stdscr window cursor position wasn't updated by NetHack. --- include/wincurs.h | 1 + win/curses/cursmain.c | 1 + win/curses/cursmisc.c | 11 +++++++++++ win/curses/cursmisc.h | 1 + 4 files changed, 14 insertions(+) diff --git a/include/wincurs.h b/include/wincurs.h index 03bc4d527..07e6083d2 100644 --- a/include/wincurs.h +++ b/include/wincurs.h @@ -164,6 +164,7 @@ extern boolean curses_is_menu(winid wid); extern boolean curses_is_text(winid wid); extern int curses_convert_glyph(int ch, int glyph); extern void curses_move_cursor(winid wid, int x, int y); +extern void curses_update_stdscr_cursor(void); extern void curses_prehousekeeping(void); extern void curses_posthousekeeping(void); extern void curses_view_file(const char *filename, boolean must_exist); diff --git a/win/curses/cursmain.c b/win/curses/cursmain.c index 2d29dacd6..9386bc5ab 100644 --- a/win/curses/cursmain.c +++ b/win/curses/cursmain.c @@ -1068,6 +1068,7 @@ curses_delay_output(void) if (flags.nap && !iflags.debug_fuzzer) { /* refreshing the whole display is a waste of time, * but that's why we're here */ + curses_update_stdscr_cursor(); refresh(); napms(50); } diff --git a/win/curses/cursmisc.c b/win/curses/cursmisc.c index ae3dfd7c8..adc8670d0 100644 --- a/win/curses/cursmisc.c +++ b/win/curses/cursmisc.c @@ -612,6 +612,17 @@ curses_move_cursor(winid wid, int x, int y) } } +/* update the ncurses stdscr cursor to where the cursor in our map is */ +void +curses_update_stdscr_cursor(void) +{ +#ifndef PDCURSES + int xadj = 0, yadj = 0; + + curses_get_window_xy(MAP_WIN, &xadj, &yadj); + move(curs_y + yadj, curs_x + xadj); +#endif +} /* Perform actions that should be done every turn before nhgetch() */ diff --git a/win/curses/cursmisc.h b/win/curses/cursmisc.h index e52d196ad..459decb4a 100644 --- a/win/curses/cursmisc.h +++ b/win/curses/cursmisc.h @@ -22,6 +22,7 @@ boolean curses_is_menu(winid wid); boolean curses_is_text(winid wid); int curses_convert_glyph(int ch, int glyph); void curses_move_cursor(winid wid, int x, int y); +void curses_update_stdscr_cursor(void); void curses_prehousekeeping(void); void curses_posthousekeeping(void); void curses_view_file(const char *filename, boolean must_exist);