do some performance optimizations on highlighting of tty status

This commit is contained in:
nhmall
2018-05-05 19:43:10 -04:00
parent 4e5c41401f
commit 71bead4e39
2 changed files with 100 additions and 63 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 botl.c $NHDT-Date: 1506903619 2017/10/02 00:20:19 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.81 $ */ /* NetHack 3.6 botl.c $NHDT-Date: 1525563781 2018/05/05 23:43:01 $ $NHDT-Branch: tty-status $:$NHDT-Revision: 1.90 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2006. */ /*-Copyright (c) Michael Allison, 2006. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -858,7 +858,10 @@ boolean
: TRUE; : TRUE;
fieldname = initblstats[i].fldname; fieldname = initblstats[i].fldname;
fieldfmt = initblstats[i].fldfmt; if (fld == BL_TITLE && iflags.wc2_hitpointbar)
fieldfmt = "%-30s";
else
fieldfmt = initblstats[i].fldfmt;
status_enablefield(fld, fieldname, fieldfmt, fldenabled); status_enablefield(fld, fieldname, fieldfmt, fldenabled);
} }
update_all = TRUE; update_all = TRUE;

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 wintty.c $NHDT-Date: 1520825319 2018/03/12 03:28:39 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.142 $ */ /* NetHack 3.6 wintty.c $NHDT-Date: 1525563766 2018/05/05 23:42:46 $ $NHDT-Branch: tty-status $:$NHDT-Revision: 1.144 $ */
/* Copyright (c) David Cohrs, 1991 */ /* Copyright (c) David Cohrs, 1991 */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -66,7 +66,7 @@ struct window_procs tty_procs = {
| WC2_SELECTSAVED | WC2_SELECTSAVED
#endif #endif
#if defined(STATUS_HILITES) #if defined(STATUS_HILITES)
| WC2_HILITE_STATUS | WC2_HITPOINTBAR | WC2_FLUSH_STATUS | WC2_HILITE_STATUS | WC2_HITPOINTBAR
#endif #endif
| WC2_DARKGRAY), | WC2_DARKGRAY),
tty_init_nhwindows, tty_player_selection, tty_askname, tty_get_nh_event, tty_init_nhwindows, tty_player_selection, tty_askname, tty_get_nh_event,
@@ -177,6 +177,21 @@ STATIC_DCL void FDECL(setup_gendmenu, (winid, BOOLEAN_P, int, int, int));
STATIC_DCL void FDECL(setup_algnmenu, (winid, BOOLEAN_P, int, int, int)); STATIC_DCL void FDECL(setup_algnmenu, (winid, BOOLEAN_P, int, int, int));
STATIC_DCL boolean NDECL(reset_role_filtering); STATIC_DCL boolean NDECL(reset_role_filtering);
#ifdef STATUS_HILITES
static long tty_condition_bits;
static struct tty_status_fields {
int color;
int attr;
coord loc;
boolean valid;
} tty_status[MAXBLSTATS], prev_tty_status[MAXBLSTATS];
static int st_fld;
int hpbar_percent, hpbar_color;
static int FDECL(condcolor, (long, unsigned long *));
static int FDECL(condattr, (long, unsigned long *));
#endif /* STATUS_HILITES */
/* /*
* A string containing all the default commands -- to add to a list * A string containing all the default commands -- to add to a list
* of acceptable inputs. * of acceptable inputs.
@@ -2491,6 +2506,7 @@ const char *str;
register char *ob; register char *ob;
register const char *nb; register const char *nb;
register long i, j, n0; register long i, j, n0;
boolean attr_match = FALSE;
/* Assume there's a real problem if the window is missing -- /* Assume there's a real problem if the window is missing --
* probably a panic message * probably a panic message
@@ -2530,16 +2546,19 @@ const char *str;
str = nb - 2; str = nb - 2;
} }
nb = str; nb = str;
#ifdef STATUS_HILITES
if (prev_tty_status[st_fld].valid
&& tty_status[st_fld].loc.x == prev_tty_status[st_fld].loc.x
&& tty_status[st_fld].loc.y == prev_tty_status[st_fld].loc.y
&& tty_status[st_fld].color == prev_tty_status[st_fld].color
&& tty_status[st_fld].attr == prev_tty_status[st_fld].attr)
#endif
attr_match = TRUE;
for (i = cw->curx + 1, n0 = cw->cols; i < n0; i++, nb++) { for (i = cw->curx + 1, n0 = cw->cols; i < n0; i++, nb++) {
if (!*nb) { if (!*nb) {
#ifndef STATUS_HILITES #ifndef STATUS_HILITES
if (*ob || context.botlx) { if (*ob || context.botlx) {
#else #else
/* STATUS_HILITES will call cl_end() when finished
* its sequence of putstr's. We don't want to call
* cl_end() with each putstr() which may cause flashing
* in the Windows port
*/
if (context.botlx) { if (context.botlx) {
#endif #endif
/* last char printed may be in middle of line */ /* last char printed may be in middle of line */
@@ -2548,17 +2567,14 @@ const char *str;
} }
break; break;
} }
if (*ob != *nb || !attr_match) {
#ifdef STATUS_HILITES #ifdef STATUS_HILITES
/* Don't optimize the putsym away, in case it happens tty_curs(WIN_STATUS,
to be the same character but different color/attr. tty_status[st_fld].loc.x,
We don't optimize on iflags.use_status_hilites either, tty_status[st_fld].loc.y);
in case old chars were written with highlighting and
that option has just now been toggled off. [We could
do better by tracking color/attr more closely.] */
#else
if (*ob != *nb)
#endif #endif
tty_putsym(WIN_STATUS, i, cw->cury, *nb); tty_putsym(WIN_STATUS, i, cw->cury, *nb);
}
if (*ob) if (*ob)
ob++; ob++;
} }
@@ -3426,7 +3442,7 @@ char *posbar;
video_update_positionbar(posbar); video_update_positionbar(posbar);
#endif #endif
} }
#endif #endif /* POSITIONBAR */
/* /*
* The following data structures come from the genl_ routines in * The following data structures come from the genl_ routines in
@@ -3439,23 +3455,20 @@ extern char *status_vals[MAXBLSTATS];
extern boolean status_activefields[MAXBLSTATS]; extern boolean status_activefields[MAXBLSTATS];
extern winid WIN_STATUS; extern winid WIN_STATUS;
#ifdef STATUS_HILITES
static long tty_condition_bits;
static int tty_status_colors[MAXBLSTATS];
int hpbar_percent, hpbar_color;
static int FDECL(condcolor, (long, unsigned long *));
static int FDECL(condattr, (long, unsigned long *));
#endif /* STATUS_HILITES */
void void
tty_status_init() tty_status_init()
{ {
#ifdef STATUS_HILITES #ifdef STATUS_HILITES
int i; int i;
for (i = 0; i < MAXBLSTATS; ++i) for (i = 0; i < MAXBLSTATS; ++i) {
tty_status_colors[i] = NO_COLOR; /* no color */ tty_status[i].color = NO_COLOR; /* no color */
tty_status[i].attr = ATR_NONE;
tty_status[i].loc.x = 0;
tty_status[i].loc.y = 0;
tty_status[i].valid = FALSE;
prev_tty_status[i] = tty_status[i];
}
tty_condition_bits = 0L; tty_condition_bits = 0L;
hpbar_percent = 0, hpbar_color = NO_COLOR; hpbar_percent = 0, hpbar_color = NO_COLOR;
#endif /* STATUS_HILITES */ #endif /* STATUS_HILITES */
@@ -3552,14 +3565,14 @@ tty_status_init()
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
#define MaybeDisplayCond(bm,txt) \ #define MaybeDisplayCond(bm,txt) \
if (tty_condition_bits & (bm)) { \ if (tty_condition_bits & (bm)) { \
putstr(WIN_STATUS, 0, " "); \ tty_putstr(WIN_STATUS, 0, " "); \
if (iflags.hilite_delta) { \ if (iflags.hilite_delta) { \
attrmask = condattr(bm, colormasks); \ attrmask = condattr(bm, colormasks); \
Begin_Attr(attrmask); \ Begin_Attr(attrmask); \
if ((coloridx = condcolor(bm, colormasks)) != NO_COLOR) \ if ((coloridx = condcolor(bm, colormasks)) != NO_COLOR) \
term_start_color(coloridx); \ term_start_color(coloridx); \
} \ } \
putstr(WIN_STATUS, 0, txt); \ tty_putstr(WIN_STATUS, 0, txt); \
if (iflags.hilite_delta) { \ if (iflags.hilite_delta) { \
if (coloridx != NO_COLOR) \ if (coloridx != NO_COLOR) \
term_end_color(); \ term_end_color(); \
@@ -3569,17 +3582,23 @@ tty_status_init()
#else #else
#define MaybeDisplayCond(bm,txt) \ #define MaybeDisplayCond(bm,txt) \
if (tty_condition_bits & (bm)) { \ if (tty_condition_bits & (bm)) { \
putstr(WIN_STATUS, 0, " "); \ tty_putstr(WIN_STATUS, 0, " "); \
if (iflags.hilite_delta) { \ if (iflags.hilite_delta) { \
attrmask = condattr(bm, colormasks); \ attrmask = condattr(bm, colormasks); \
Begin_Attr(attrmask); \ Begin_Attr(attrmask); \
} \ } \
putstr(WIN_STATUS, 0, txt); \ tty_putstr(WIN_STATUS, 0, txt); \
if (iflags.hilite_delta) { \ if (iflags.hilite_delta) { \
End_Attr(attrmask); \ End_Attr(attrmask); \
} \ } \
} }
#endif #endif
#define status_putstr(s) \
tty_status[st_fld].loc.x = (xchar) cw->curx; \
tty_status[st_fld].loc.y = (xchar) cw->cury; \
tty_status[st_fld].valid = TRUE; \
tty_putstr(WIN_STATUS, 0, s);
void void
tty_status_update(fldidx, ptr, chg, percent, color, colormasks) tty_status_update(fldidx, ptr, chg, percent, color, colormasks)
@@ -3592,6 +3611,8 @@ unsigned long *colormasks;
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
int coloridx = NO_COLOR; int coloridx = NO_COLOR;
#endif #endif
struct WinDesc *cw = 0;
char *text = (char *) ptr; char *text = (char *) ptr;
static boolean oncearound = FALSE; /* prevent premature partial display */ static boolean oncearound = FALSE; /* prevent premature partial display */
enum statusfields fieldorder[2][15] = { enum statusfields fieldorder[2][15] = {
@@ -3602,53 +3623,62 @@ unsigned long *colormasks;
BL_AC, BL_XP, BL_EXP, BL_HD, BL_TIME, BL_HUNGER, BL_AC, BL_XP, BL_EXP, BL_HD, BL_TIME, BL_HUNGER,
BL_CAP, BL_CONDITION, BL_FLUSH } BL_CAP, BL_CONDITION, BL_FLUSH }
}; };
int attridx = 0; int attridx = 0;
st_fld = fldidx;
if (fldidx != BL_FLUSH) { if (fldidx != BL_FLUSH) {
if (!status_activefields[fldidx]) if (!status_activefields[fldidx])
return; return;
switch (fldidx) { switch (fldidx) {
case BL_CONDITION: case BL_CONDITION:
tty_condition_bits = *condptr; tty_condition_bits = *condptr;
oncearound = TRUE; oncearound = TRUE;
break; break;
default: default:
Sprintf(status_vals[fldidx], Sprintf(status_vals[fldidx],
(fldidx == BL_TITLE && iflags.wc2_hitpointbar) ? "%-30s" : status_fieldfmt[fldidx] ?
status_fieldfmt[fldidx] ? status_fieldfmt[fldidx] : "%s", status_fieldfmt[fldidx] : "%s",
text); text);
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
tty_status_colors[fldidx] = color; tty_status[fldidx].color = (color & 0x00FF);
#else #else
tty_status_colors[fldidx] = NO_COLOR; tty_status[fldidx].color = NO_COLOR;
#endif #endif
if (iflags.wc2_hitpointbar && fldidx == BL_HP) { tty_status[fldidx].attr = (color & 0xFF00) >> 8;
hpbar_percent = percent;
if (iflags.wc2_hitpointbar && fldidx == BL_HP) {
hpbar_percent = percent;
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
hpbar_color = color; hpbar_color = color;
#else #else
hpbar_color = NO_COLOR; hpbar_color = NO_COLOR;
#endif #endif
} }
break; break;
} }
} }
if (!oncearound) return; if (!oncearound) return;
if (WIN_STATUS == WIN_ERR
|| (cw = wins[WIN_STATUS]) == (struct WinDesc *) 0) {
paniclog("status", "WIN_ERR on status window.");
return;
}
curs(WIN_STATUS, 1, 0); curs(WIN_STATUS, 1, 0);
for (i = 0; fieldorder[0][i] != BL_FLUSH; ++i) { for (i = 0; fieldorder[0][i] != BL_FLUSH; ++i) {
int fldidx1 = fieldorder[0][i]; int fldidx1 = fieldorder[0][i];
if (status_activefields[fldidx1]) { if (status_activefields[fldidx1]) {
if (fldidx1 != BL_TITLE || !iflags.wc2_hitpointbar) { if (fldidx1 != BL_TITLE || !iflags.wc2_hitpointbar) {
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
coloridx = tty_status_colors[fldidx1] & 0x00FF; coloridx = tty_status[fldidx1].color;
#endif #endif
attridx = (tty_status_colors[fldidx1] & 0xFF00) >> 8; attridx = tty_status[fldidx1].attr;
text = status_vals[fldidx1]; text = status_vals[fldidx1];
if (iflags.hilite_delta) { if (iflags.hilite_delta) {
if (*text == ' ') { if (*text == ' ') {
putstr(WIN_STATUS, 0, " "); status_putstr(" ");
text++; text++;
} }
/* multiple attributes can be in effect concurrently */ /* multiple attributes can be in effect concurrently */
@@ -3659,7 +3689,7 @@ unsigned long *colormasks;
#endif #endif
} }
putstr(WIN_STATUS, 0, text); status_putstr(text);
if (iflags.hilite_delta) { if (iflags.hilite_delta) {
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
@@ -3692,7 +3722,7 @@ unsigned long *colormasks;
} }
} }
if (iflags.hilite_delta && iflags.wc2_hitpointbar) { if (iflags.hilite_delta && iflags.wc2_hitpointbar) {
putstr(WIN_STATUS, 0, "["); status_putstr("[");
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
coloridx = hpbar_color & 0x00FF; coloridx = hpbar_color & 0x00FF;
/* attridx = (hpbar_color & 0xFF00) >> 8; */ /* attridx = (hpbar_color & 0xFF00) >> 8; */
@@ -3700,7 +3730,7 @@ unsigned long *colormasks;
term_start_color(coloridx); term_start_color(coloridx);
#endif #endif
term_start_attr(ATR_INVERSE); term_start_attr(ATR_INVERSE);
putstr(WIN_STATUS, 0, bar); tty_putstr(WIN_STATUS, 0, bar);
term_end_attr(ATR_INVERSE); term_end_attr(ATR_INVERSE);
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
if (coloridx != NO_COLOR) if (coloridx != NO_COLOR)
@@ -3708,11 +3738,11 @@ unsigned long *colormasks;
#endif #endif
if (twoparts) { if (twoparts) {
*bar2 = savedch; *bar2 = savedch;
putstr(WIN_STATUS, 0, bar2); tty_putstr(WIN_STATUS, 0, bar2);
} }
putstr(WIN_STATUS, 0, "]"); tty_putstr(WIN_STATUS, 0, "]");
} else } else
putstr(WIN_STATUS, 0, text); tty_putstr(WIN_STATUS, 0, text);
} }
} }
} }
@@ -3724,13 +3754,13 @@ unsigned long *colormasks;
if (status_activefields[fldidx2]) { if (status_activefields[fldidx2]) {
if (fldidx2 != BL_CONDITION) { if (fldidx2 != BL_CONDITION) {
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
coloridx = tty_status_colors[fldidx2] & 0x00FF; coloridx = tty_status[fldidx2].color;
#endif #endif
attridx = (tty_status_colors[fldidx2] & 0xFF00) >> 8; attridx = tty_status[fldidx2].attr;
text = status_vals[fldidx2]; text = status_vals[fldidx2];
if (iflags.hilite_delta) { if (iflags.hilite_delta) {
if (*text == ' ') { if (*text == ' ') {
putstr(WIN_STATUS, 0, " "); tty_putstr(WIN_STATUS, 0, " ");
text++; text++;
} }
/* multiple attributes can be in effect concurrently */ /* multiple attributes can be in effect concurrently */
@@ -3742,10 +3772,13 @@ unsigned long *colormasks;
} }
if (fldidx2 == BL_GOLD) { if (fldidx2 == BL_GOLD) {
tty_status[st_fld].loc.x = (xchar) cw->curx;
tty_status[st_fld].loc.y = (xchar) cw->cury;
tty_status[st_fld].valid = TRUE; \
/* putmixed() due to GOLD glyph */ /* putmixed() due to GOLD glyph */
putmixed(WIN_STATUS, 0, text); putmixed(WIN_STATUS, 0, text);
} else { } else {
putstr(WIN_STATUS, 0, text); status_putstr(text);
} }
if (iflags.hilite_delta) { if (iflags.hilite_delta) {
@@ -3771,6 +3804,7 @@ unsigned long *colormasks;
MaybeDisplayCond(BL_MASK_RIDE, "Ride"); MaybeDisplayCond(BL_MASK_RIDE, "Ride");
} }
} }
prev_tty_status[st_fld] = tty_status[st_fld]; /* copy struct */
} }
cl_end(); cl_end();
return; return;