From: nhmall Date: Tue, 15 May 2018 01:13:37 +0000 (-0400) Subject: some tty per field rendering and optimization X-Git-Tag: NetHack-3.6.2_Released~280^2^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e8b69d5ff2d896c9768455c105ad428c566538e;p=nethack some tty per field rendering and optimization --- diff --git a/doc/fixes36.2 b/doc/fixes36.2 index ca45e5826..35d75d637 100644 --- a/doc/fixes36.2 +++ b/doc/fixes36.2 @@ -17,6 +17,7 @@ Fixes to Post-3.6.1 Problems that Were Exposed Via git Repository Platform- and/or Interface-Specific Fixes ----------------------------------------- windows-tty: Specify both width and height when creating font for width testing +tty: some optimizations for performance and per field rendering Code Cleanup and Reorganization diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 77835a5ec..b9ac757c0 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -3650,6 +3650,8 @@ unsigned long *colormasks; int i; long *condptr = (long *) ptr; char *text = (char *) ptr; + char *lastchar = (char *) 0; + char *fval = (char *) 0; boolean do_color = FALSE; boolean force_update = FALSE; @@ -3672,15 +3674,6 @@ unsigned long *colormasks; tty_status[NOW][fldidx].dirty = TRUE; truncation_expected = FALSE; break; - case BL_CAP: - for (i = 0; i < SIZE(encvals); ++i) { - if (!strcmp(encvals[enc_shrinklvl][i], - status_vals[BL_CAP])) { - enclev = i; - break; - } - } - /*FALLTHRU*/ default: tty_status[NOW][fldidx].idx = fldidx; Sprintf(status_vals[fldidx], @@ -3692,16 +3685,9 @@ unsigned long *colormasks; tty_status[NOW][fldidx].lth = strlen(status_vals[fldidx]); tty_status[NOW][fldidx].valid = TRUE; tty_status[NOW][fldidx].dirty = TRUE; - break; } - /* Special additional processing for hitpointbar */ - if (iflags.wc2_hitpointbar && fldidx == BL_HP) { - hpbar_percent = percent; - hpbar_color = do_color ? (color & 0x00FF) : NO_COLOR; - } - /* The core botl engine sends a single blank to the window port for carrying-capacity when its unused. Let's suppress that */ if (tty_status[NOW][fldidx].lth == 1 @@ -3710,24 +3696,49 @@ unsigned long *colormasks; tty_status[NOW][fldidx].lth = 0; } - /* The core botl engine sends trailing blanks for some fields - Let's suppress the trailing blanks */ - if (fldidx == BL_LEVELDESC || fldidx == BL_HUNGER) { - char *lastchar = eos(status_vals[fldidx]); - lastchar--; - while (lastchar && *lastchar == ' ' - && lastchar >= status_vals[fldidx]) { - *lastchar-- = '\0'; - tty_status[NOW][fldidx].lth--; - } + /* default processing above was required before these */ + switch (fldidx) { + case BL_HP: + if (iflags.wc2_hitpointbar) { + /* Special additional processing for hitpointbar */ + hpbar_percent = percent; + hpbar_color = do_color ? (color & 0x00FF) : NO_COLOR; + } + break; + case BL_LEVELDESC: + case BL_HUNGER: + /* The core sends trailing blanks for some fields + Let's suppress the trailing blanks */ + char *lastchar = eos(status_vals[fldidx]); + lastchar = eos(status_vals[fldidx]); + lastchar--; + while (lastchar && *lastchar == ' ' + && lastchar >= status_vals[fldidx]) { + *lastchar-- = '\0'; + tty_status[NOW][fldidx].lth--; + } + break; + case BL_TITLE: + if (iflags.wc2_hitpointbar) + tty_status[NOW][fldidx].lth += 2; /* '[' and ']' */ + break; + case BL_GOLD: + tty_status[NOW][fldidx].lth -= 9; /* \GXXXXNNNN counts as 1 */ + break; + case BL_CAP: + fval = status_vals[fldidx]; + if (fval) { + if (*fval == ' ') + fval++; + for (i = 0; i < SIZE(encvals); ++i) { + if (!strcmp(encvals[enc_shrinklvl][i], fval)) { + enclev = i; + break; /* for */ + } + } + } + break; } - - /* Some other special case fixups */ - if (iflags.wc2_hitpointbar && fldidx == BL_TITLE) - tty_status[NOW][fldidx].lth += 2; /* [ and ] */ - if (fldidx == BL_GOLD) - tty_status[NOW][fldidx].lth -= 9; /* \GXXXXNNNN counts as 1 */ - if (make_things_fit(force_update) || truncation_expected) render_status(); return;