Skip to content

Commit

Permalink
Count identical messages for dumping
Browse files Browse the repository at this point in the history
Last messages shown in the dumplog now compress repeated messages, like
this: "This door is locked. (12x)", so now it shows the last 30
different messages.

Original implementation to go with NitroHack's original dumplog
implementation.

This also fixes a bug in upstream NitroHack with Norep() not detecting
repeated messages properly; it was checking one-ahead of where it was
supposed to in the circular buffer of recent messages.

NitroHack doesn't seem to save or restore this recent messages buffer
either, which I'm sure is a bug, but I haven't done anything about that
here.

(cherry picked from commit 5dc44480b48c59bc65424e6393e28ba189cc37db)

Inspired by UnNetHack CS678.

Conflicts:
	libnitrohack/src/pline.c
  • Loading branch information
tung authored and Alex Smith committed Oct 4, 2013
1 parent e37ffa7 commit 33707a5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions libnitrohack/include/decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ extern struct nh_option_desc *options;
#define MSGCOUNT 30

extern char toplines[MSGCOUNT][BUFSZ];
extern int toplines_count[MSGCOUNT];
extern int curline;

# define add_menuitem(m, i, cap, acc, sel)\
Expand Down
1 change: 1 addition & 0 deletions libnitrohack/src/decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ struct nh_option_desc *birth_options;
struct nh_option_desc *options;

char toplines[MSGCOUNT][BUFSZ];
int toplines_count[MSGCOUNT];
int curline;


Expand Down
8 changes: 7 additions & 1 deletion libnitrohack/src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ end_dump(int how, char *killbuf, char *pbuf, long umoney)
fprintf(dumpfp, "Latest messages:\n");
for (i = 0; i < MSGCOUNT; i++) {
line = (curline + i) % MSGCOUNT;
if (toplines[line][0])
if (toplines[line][0]) {
if (toplines_count[line] == 1) {
fprintf(dumpfp, " %s\n", toplines[line]);
} else {
fprintf(dumpfp, " %s (%dx)\n", toplines[line],
toplines_count[line]);
}
}
}
fprintf(dumpfp, "\n");

Expand Down
19 changes: 16 additions & 3 deletions libnitrohack/src/pline.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,35 @@ static void
vpline(const char *line, va_list the_args)
{
char pbuf[BUFSZ];
boolean repeated;
int lastline;

lastline = curline - 1;
if (lastline < 0)
lastline += MSGCOUNT;

if (!line || !*line)
return;
if (strchr(line, '%')) {
vsprintf(pbuf, line, the_args);
line = pbuf;
}
if (no_repeat && !strcmp(line, toplines[curline]))
repeated = !strcmp(line, toplines[lastline]);
if (no_repeat && repeated)
return;
if (vision_full_recalc)
vision_recalc(0);
if (u.ux)
flush_screen();

strcpy(toplines[curline++], line);
curline %= MSGCOUNT;
if (repeated) {
toplines_count[lastline]++;
} else {
strcpy(toplines[curline], line);
toplines_count[curline] = 1;
curline++;
curline %= MSGCOUNT;
}
if (iflags.next_msg_nonblocking)
(*windowprocs.win_print_message_nonblocking) (moves, line);
else
Expand Down

0 comments on commit 33707a5

Please sign in to comment.