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.
This commit is contained in:
Pasi Kallinen
2023-03-12 18:39:13 +02:00
parent d86f966ee6
commit 35273b8a8c
4 changed files with 14 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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() */

View File

@@ -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);