From 0e425d645f56160e7049b1f109f5c785a30045d0 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 6 Apr 2019 15:53:51 -0700 Subject: [PATCH] curses vs !HILITE_STATUS The curses interface wouldn't build with HILITE_STATUS disabled. I started adapting it to handle genl_status_update() but that was taking too much effort with each niggling detail leading to another. This goes the opposite direction: forcing the old STATUS_VIA_WINDOWPORT behavior without having that #define available. That dragged along a bunch of unexpected changes too. --- include/botl.h | 7 ++--- src/allmain.c | 12 ++++----- src/botl.c | 43 ++++++++++++++----------------- src/end.c | 7 +++-- src/options.c | 16 ++++++------ src/save.c | 7 +++-- win/curses/cursmain.c | 3 ++- win/curses/cursstat.c | 59 +++++++++++++++++++++++++++++++------------ 8 files changed, 88 insertions(+), 66 deletions(-) diff --git a/include/botl.h b/include/botl.h index 91de104f0..5b88072f4 100644 --- a/include/botl.h +++ b/include/botl.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 botl.h $NHDT-Date: 1553387147 2019/03/24 00:25:47 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.23 $ */ +/* NetHack 3.6 botl.h $NHDT-Date: 1554591222 2019/04/06 22:53:42 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.24 $ */ /* Copyright (c) Michael Allison, 2003 */ /* NetHack may be freely redistributed. See license for details. */ @@ -27,12 +27,10 @@ Astral Plane \GXXXXNNNN:123456 HP:1234(1234) Pw:1234(1234) AC:-127 #define MAXCO (COLNO + 40) #endif -#ifdef STATUS_HILITES struct condmap { const char *id; unsigned long bitmask; }; -#endif enum statusfields { BL_CHARACTERISTICS = -3, /* alias for BL_STR..BL_CH */ @@ -72,6 +70,9 @@ enum relationships { NO_LTEQGT = -1, #define BL_MASK_BITS 13 /* number of mask bits that can be set */ /* clang-format on */ +#define VIA_WINDOWPORT() \ + ((windowprocs.wincap2 & (WC2_HILITE_STATUS | WC2_FLUSH_STATUS)) != 0) + #define REASSESS_ONLY TRUE /* #ifdef STATUS_HILITES */ diff --git a/src/allmain.c b/src/allmain.c index 1237d6b41..84f9dfd0c 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 allmain.c $NHDT-Date: 1554045808 2019/03/31 15:23:28 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.96 $ */ +/* NetHack 3.6 allmain.c $NHDT-Date: 1554591223 2019/04/06 22:53:43 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.97 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -537,11 +537,11 @@ void display_gamewindows() { WIN_MESSAGE = create_nhwindow(NHW_MESSAGE); -#ifdef STATUS_HILITES - status_initialize(0); -#else - WIN_STATUS = create_nhwindow(NHW_STATUS); -#endif + if (VIA_WINDOWPORT()) { + status_initialize(0); + } else { + WIN_STATUS = create_nhwindow(NHW_STATUS); + } WIN_MAP = create_nhwindow(NHW_MAP); WIN_INVEN = create_nhwindow(NHW_MENU); /* in case of early quit where WIN_INVEN could be destroyed before diff --git a/src/botl.c b/src/botl.c index f0a8d18c9..0ae87df03 100644 --- a/src/botl.c +++ b/src/botl.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 botl.c $NHDT-Date: 1554554180 2019/04/06 12:36:20 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.142 $ */ +/* NetHack 3.6 botl.c $NHDT-Date: 1554591223 2019/04/06 22:53:43 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.143 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2006. */ /* NetHack may be freely redistributed. See license for details. */ @@ -15,10 +15,8 @@ const char *const enc_stat[] = { "", "Burdened", "Stressed", STATIC_OVL NEARDATA int mrank_sz = 0; /* loaded by max_rank_sz (from u_init) */ STATIC_DCL const char *NDECL(rank); -#ifdef STATUS_HILITES STATIC_DCL void NDECL(bot_via_windowport); STATIC_DCL void NDECL(stat_update_time); -#endif static char * get_strength_str() @@ -236,14 +234,14 @@ bot() { /* dosave() flags completion by setting u.uhp to -1 */ if ((u.uhp != -1) && youmonst.data && iflags.status_updates) { -#ifdef STATUS_HILITES - bot_via_windowport(); -#else - curs(WIN_STATUS, 1, 0); - putstr(WIN_STATUS, 0, do_statusline1()); - curs(WIN_STATUS, 1, 1); - putmixed(WIN_STATUS, 0, do_statusline2()); -#endif + if (VIA_WINDOWPORT()) { + bot_via_windowport(); + } else { + curs(WIN_STATUS, 1, 0); + putstr(WIN_STATUS, 0, do_statusline1()); + curs(WIN_STATUS, 1, 1); + putmixed(WIN_STATUS, 0, do_statusline2()); + } } context.botl = context.botlx = iflags.time_botl = FALSE; } @@ -251,13 +249,13 @@ bot() void timebot() { - if (flags.time) { -#ifdef STATUS_HILITES - stat_update_time(); -#else - /* old status display updates everything */ - bot(); -#endif + if (flags.time && iflags.status_updates) { + if (VIA_WINDOWPORT()) { + stat_update_time(); + } else { + /* old status display updates everything */ + bot(); + } } iflags.time_botl = FALSE; } @@ -735,11 +733,6 @@ bot_via_windowport() evaluate_and_notify_windowport(valset, idx); } -#ifdef STATUS_HILITES - /* stat_update_time() isn't really a STATUS_HILITES routine - * but timebot() will only ever call it for that configuration. - */ - /* update just the status lines' 'time' field */ STATIC_OVL void stat_update_time() @@ -757,7 +750,6 @@ stat_update_time() NO_COLOR, (unsigned long *) 0); return; } -#endif STATIC_OVL boolean eval_notify_windowport_field(fld, valsetlist, idx) @@ -2202,6 +2194,7 @@ boolean from_configfile; return TRUE; } +#endif /* STATUS_HILITES */ const struct condmap valid_conditions[] = { { "stone", BL_MASK_STONE }, @@ -2219,6 +2212,8 @@ const struct condmap valid_conditions[] = { { "ride", BL_MASK_RIDE }, }; +#ifdef STATUS_HILITES + const struct condmap condition_aliases[] = { { "strangled", BL_MASK_STRNGL }, { "all", BL_MASK_STONE | BL_MASK_SLIME | BL_MASK_STRNGL diff --git a/src/end.c b/src/end.c index 4dcf3947c..080fb729c 100644 --- a/src/end.c +++ b/src/end.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 end.c $NHDT-Date: 1554045810 2019/03/31 15:23:30 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.167 $ */ +/* NetHack 3.6 end.c $NHDT-Date: 1554591224 2019/04/06 22:53:44 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.168 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1372,9 +1372,8 @@ int how; } display_nhwindow(WIN_MESSAGE, TRUE); destroy_nhwindow(WIN_MAP), WIN_MAP = WIN_ERR; -#ifndef STATUS_HILITES - destroy_nhwindow(WIN_STATUS), WIN_STATUS = WIN_ERR; -#endif + if (WIN_STATUS != WIN_ERR) + destroy_nhwindow(WIN_STATUS), WIN_STATUS = WIN_ERR; destroy_nhwindow(WIN_MESSAGE), WIN_MESSAGE = WIN_ERR; if (!done_stopprint || flags.tombstone) diff --git a/src/options.c b/src/options.c index a9701c23e..a0446bfbc 100644 --- a/src/options.c +++ b/src/options.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 options.c $NHDT-Date: 1554155747 2019/04/01 21:55:47 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.362 $ */ +/* NetHack 3.6 options.c $NHDT-Date: 1554591224 2019/04/06 22:53:44 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.363 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2008. */ /* NetHack may be freely redistributed. See license for details. */ @@ -4044,9 +4044,8 @@ boolean tinitial, tfrom_file; || boolopt[i].addr == &flags.showscore #endif || boolopt[i].addr == &flags.showexp) { -#ifdef STATUS_HILITES - status_initialize(REASSESS_ONLY); -#endif + if (VIA_WINDOWPORT()) + status_initialize(REASSESS_ONLY); context.botl = TRUE; } else if (boolopt[i].addr == &flags.invlet_constant) { if (flags.invlet_constant) { @@ -4088,11 +4087,12 @@ boolean tinitial, tfrom_file; } #endif need_redraw = TRUE; -#ifdef STATUS_HILITES } else if (boolopt[i].addr == &iflags.wc2_hitpointbar) { - status_initialize(REASSESS_ONLY); - need_redraw = TRUE; -#endif + if (VIA_WINDOWPORT()) { + /* [is reassessment really needed here?] */ + status_initialize(REASSESS_ONLY); + need_redraw = TRUE; + } #ifdef TEXTCOLOR } else if (boolopt[i].addr == &iflags.use_color) { need_redraw = TRUE; diff --git a/src/save.c b/src/save.c index 75c1b1fd8..c3ce6d06f 100644 --- a/src/save.c +++ b/src/save.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 save.c $NHDT-Date: 1543972194 2018/12/05 01:09:54 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.115 $ */ +/* NetHack 3.6 save.c $NHDT-Date: 1554591225 2019/04/06 22:53:45 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.117 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2009. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1405,9 +1405,8 @@ freedynamicdata() /* free_pickinv_cache(); -- now done from really_done()... */ free_symsets(); #endif /* FREE_ALL_MEMORY */ -#ifdef STATUS_HILITES - status_finish(); -#endif + if (VIA_WINDOWPORT()) + status_finish(); #ifdef DUMPLOG dumplogfreemessages(); #endif diff --git a/win/curses/cursmain.c b/win/curses/cursmain.c index 9757e111a..c179610b6 100644 --- a/win/curses/cursmain.c +++ b/win/curses/cursmain.c @@ -354,7 +354,8 @@ curses_destroy_nhwindow(winid wid) curses_teardown_messages(); /* discard ^P message history data */ break; case STATUS_WIN: - curses_status_finish(); /* discard cached status data */ + if (VIA_WINDOWPORT()) + curses_status_finish(); /* discard cached status data */ break; case INV_WIN: iflags.perm_invent = 0; /* avoid unexpected update_inventory() */ diff --git a/win/curses/cursstat.c b/win/curses/cursstat.c index ad33482b9..eac7c26c2 100644 --- a/win/curses/cursstat.c +++ b/win/curses/cursstat.c @@ -24,25 +24,25 @@ extern boolean status_activefields[MAXBLSTATS]; /* Long format fields for vertical window */ static char *status_vals_long[MAXBLSTATS]; -#ifdef STATUS_HILITES static unsigned long *curses_colormasks; static long curses_condition_bits; static int curses_status_colors[MAXBLSTATS]; static int hpbar_percent, hpbar_color; static int vert_status_dirty; -#ifdef TEXTCOLOR -static int FDECL(condcolor, (long, unsigned long *)); -#endif -static int FDECL(condattr, (long, unsigned long *)); -static int FDECL(nhattr2curses, (int)); -#endif /* STATUS_HILITES */ static void NDECL(draw_status); static void FDECL(draw_vertical, (BOOLEAN_P)); static void FDECL(draw_horizontal, (BOOLEAN_P)); static void curs_HPbar(char *, int); static void curs_stat_conds(int, int *, int *, char *, boolean *); static void curs_vert_status_vals(int); +#ifdef STATUS_HILITES +#ifdef TEXTCOLOR +static int FDECL(condcolor, (long, unsigned long *)); +#endif +static int FDECL(condattr, (long, unsigned long *)); +static int FDECL(nhattr2curses, (int)); +#endif /* STATUS_HILITES */ /* width of a single line in vertical status orientation (one field per line; everything but title fits within 30 even with prefix and longest value) */ @@ -51,7 +51,6 @@ static void curs_vert_status_vals(int); void curses_status_init() { -#ifdef STATUS_HILITES int i; for (i = 0; i < MAXBLSTATS; ++i) { @@ -62,7 +61,6 @@ curses_status_init() curses_condition_bits = 0L; hpbar_percent = 0, hpbar_color = NO_COLOR; vert_status_dirty = 1; -#endif /* STATUS_HILITES */ /* let genl_status_init do most of the initialization */ genl_status_init(); @@ -72,14 +70,12 @@ curses_status_init() void curses_status_finish() { -#ifdef STATUS_HILITES int i; for (i = 0; i < MAXBLSTATS; ++i) { if (status_vals_long[i]) free(status_vals_long[i]), status_vals_long[i] = (char *) 0; } -#endif /* STATUS_HILITES */ genl_status_finish(); return; @@ -138,7 +134,6 @@ curses_status_finish() * See doc/window.doc for more details. */ -#ifdef STATUS_HILITES static int changed_fields = 0; void @@ -304,7 +299,9 @@ boolean border; cap_and_hunger, exp_points, sho_score, height, width, w, xtra, clen, x, y, t, ex, ey, condstart = 0, conddummy = 0; +#ifdef STATUS_HILITES int coloridx = NO_COLOR, attrmask = 0; +#endif /* STATUS_HILITES */ boolean asis = FALSE; WINDOW *win = curses_get_nhwin(STATUS_WIN); @@ -562,6 +559,7 @@ boolean border; } else if (fld != BL_CONDITION) { /* regular field, including title if no hitpointbar */ +#ifdef STATUS_HILITES coloridx = curses_status_colors[fld]; /* includes attribute */ if (iflags.hilite_delta && coloridx != NO_COLOR) { /* expect 1 leading space; don't highlight it */ @@ -580,9 +578,11 @@ boolean border; curses_toggle_color_attr(win, coloridx, NONE, ON); #endif } +#endif /* STATUS_HILITES */ waddstr(win, text); +#ifdef STATUS_HILITES if (iflags.hilite_delta) { #ifdef TEXTCOLOR if (coloridx != NO_COLOR) @@ -591,6 +591,7 @@ boolean border; if (attrmask) wattroff(win, attrmask); } +#endif /* STATUS_HILITES */ } else { /* status conditions */ @@ -677,8 +678,11 @@ boolean border; }; xchar spacing[MAXBLSTATS]; int i, fld, cap_and_hunger, time_and_score, cond_count; - char *text, *p, savedch = '\0'; + char *text; +#ifdef STATUS_HILITES + char *p, savedch = '\0'; int coloridx = NO_COLOR, attrmask = 0; +#endif /* STATUS_HILITES */ int height_needed, height, width, x = 0, y = 0; WINDOW *win = curses_get_nhwin(STATUS_WIN); @@ -827,6 +831,7 @@ boolean border; && (fld == BL_HUNGER || (fld == BL_CAP && cap_and_hunger != 3))) ++text; +#ifdef STATUS_HILITES coloridx = curses_status_colors[fld]; /* includes attributes */ if (iflags.hilite_delta && coloridx != NO_COLOR) { /* most status_vals_long[] are "long-text : value" and @@ -864,9 +869,11 @@ boolean border; curses_toggle_color_attr(win, coloridx, NONE, ON); #endif } /* highlighting active */ +#endif /* STATUS_HILITES */ waddstr(win, text); +#ifdef STATUS_HILITES if (iflags.hilite_delta) { #ifdef TEXTCOLOR if (coloridx != NO_COLOR) @@ -879,6 +886,7 @@ boolean border; *p = savedch; waddstr(win, p); } +#endif /* STATUS_HILITES */ } else { /* status conditions */ @@ -897,9 +905,11 @@ static void curs_HPbar(char *text, /* pre-padded with trailing spaces if short */ int bar_len) /* width of space within the brackets */ { +#ifdef STATUS_HILITES #ifdef TEXTCOLOR int coloridx; #endif +#endif /* STATUS_HILITES */ int k, bar_pos; char bar[STATVAL_WIDTH], *bar2 = (char *) 0, savedch = '\0'; boolean twoparts = (hpbar_percent < 100); @@ -927,6 +937,7 @@ curs_HPbar(char *text, /* pre-padded with trailing spaces if short */ if (*bar) { /* True unless dead (0 HP => bar_pos == 0) */ /* fixed attribute, not nhattr2curses((hpbar_color >> 8) & 0x00FF) */ wattron(win, A_REVERSE); /* do this even if hilite_delta is 0 */ +#ifdef STATUS_HILITES #ifdef TEXTCOLOR if (iflags.hilite_delta) { coloridx = hpbar_color & 0x00FF; @@ -934,16 +945,19 @@ curs_HPbar(char *text, /* pre-padded with trailing spaces if short */ curses_toggle_color_attr(win, coloridx, NONE, ON); } #endif +#endif /* STATUS_HILITES */ /* portion of title corresponding to current hit points */ waddstr(win, bar); +#ifdef STATUS_HILITES #ifdef TEXTCOLOR if (iflags.hilite_delta) { if (coloridx != NO_COLOR) curses_toggle_color_attr(win, coloridx, NONE, OFF); } #endif +#endif /* STATUS_HILITES */ wattroff(win, A_REVERSE); /* do this even if hilite_delta is 0 */ } /* *bar (current HP > 0) */ @@ -983,16 +997,20 @@ curs_stat_conds(int vert_cond, /* 0 => horizontal, 1 => vertical */ if (curses_condition_bits & bitmsk) { Strcpy(condnam, valid_conditions[i].id); Strcat(strcat(condbuf, " "), upstart(condnam)); +#ifdef STATUS_HILITES if (nohilite && *nohilite && (condcolor(bitmsk, curses_colormasks) != NO_COLOR || condattr(bitmsk, curses_colormasks) != 0)) *nohilite = FALSE; +#endif /* STATUS_HILITES */ } } } else if (curses_condition_bits) { unsigned long cond_bits; - int height = 0, width, cx, cy, cy0, cndlen, - attrmask = 0, color = NO_COLOR; + int height = 0, width, cx, cy, cy0, cndlen; +#ifdef STATUS_HILITES + int attrmask = 0, color = NO_COLOR; +#endif /* STATUS_HILITES */ boolean border, do_vert = (vert_cond != 0); WINDOW *win = curses_get_nhwin(STATUS_WIN); @@ -1023,6 +1041,7 @@ curs_stat_conds(int vert_cond, /* 0 => horizontal, 1 => vertical */ /* output unhighlighted leading space unless at #1 of 3 */ if (!do_vert || (vert_cond % 3) != 1) waddch(win, ' '); +#ifdef STATUS_HILITES if (iflags.hilite_delta) { if ((attrmask = condattr(bitmsk, curses_colormasks)) != 0) { @@ -1035,10 +1054,12 @@ curs_stat_conds(int vert_cond, /* 0 => horizontal, 1 => vertical */ curses_toggle_color_attr(win, color, NONE, ON); #endif } +#endif /* STATUS_HILITES */ /* output the condition name */ waddstr(win, upstart(condnam)); +#ifdef STATUS_HILITES if (iflags.hilite_delta) { #ifdef TEXTCOLOR if (color != NO_COLOR) @@ -1047,6 +1068,7 @@ curs_stat_conds(int vert_cond, /* 0 => horizontal, 1 => vertical */ if (attrmask) wattroff(win, attrmask); } +#endif /* STATUS_HILITES */ /* if that was #3 of 3 advance to next line */ if (do_vert && (++vert_cond % 3) == 1) wmove(win, (*y)++, *x); @@ -1199,6 +1221,7 @@ curs_vert_status_vals(int win_width) vert_status_dirty = 0; } +#ifdef STATUS_HILITES #ifdef TEXTCOLOR /* * Return what color this condition should @@ -1277,6 +1300,8 @@ int attrmask; } #endif /* STATUS_HILITES */ +/* ======================================================================== */ + #if 0 /* old stuff; some may be re-incorporated, most should be discarded */ /* Private declarations */ @@ -2216,4 +2241,6 @@ curses_decrement_highlights(boolean zero) if (unhighlight) curses_update_stats(); } -#endif +#endif /*0*/ + +/*cursstat.c*/ -- 2.40.0