]> granicus.if.org Git - nethack/commitdiff
streamline the tty perm_invent bounder box set up
authorPatR <rankin@nethack.org>
Sat, 25 Jun 2022 06:35:26 +0000 (23:35 -0700)
committerPatR <rankin@nethack.org>
Sat, 25 Jun 2022 06:35:26 +0000 (23:35 -0700)
For the tty perm_invent boundary box initialiation, instead of doing
one of many assignments that do glyph lookup, do one of many symbol
assignments and one glyph lookup.  No change in observable behavior.

Also, use the main dungeon's walls for box rendering instead of
selecting ones for whatever branch the hero happens to be in at the
time perm_invent gets enabled.

include/display.h
win/tty/wintty.c

index 256ba1d3609d86e1ab11aa550899e99776d0f198..c17fadae4ddd3b0379ac0d0a93b85792c4b44172 100644 (file)
@@ -582,6 +582,8 @@ enum glyph_offsets {
              : ((expltyp) == EXPL_NOXIOUS) ? GLYPH_EXPLODE_NOXIOUS_OFF  \
                : GLYPH_EXPLODE_FIERY_OFF))
 
+/* cmap_walls_to_glyph(): return the glyph number for specified wall
+   symbol; result varies by dungeon branch */
 #define cmap_walls_to_glyph(cmap_idx) \
     ((cmap_idx) - S_vwall                               \
      + (In_mines(&u.uz) ? GLYPH_CMAP_MINES_OFF          \
@@ -590,6 +592,12 @@ enum glyph_offsets {
             : In_sokoban(&u.uz) ? GLYPH_CMAP_SOKO_OFF   \
               : GLYPH_CMAP_MAIN_OFF))
 
+/* cmap_D0walls_to_glyph(): simpler version of cmap_walls_to_glyph()
+   which returns the glyph that would be used in the main dungeon,
+   regardless of hero's current location */
+#define cmap_D0walls_to_glyph(cmap_idx) \
+    ((cmap_idx) - S_vwall + GLYPH_CMAP_MAIN_OFF)
+
 #define cmap_a_to_glyph(cmap_idx) \
     (((cmap_idx) - S_ndoor) + GLYPH_CMAP_A_OFF)
 
index 889d430f5974310491c16a0112d538c2bf07974d..e3532b7e0e144bd77f7b7034c8f685181fb390b3 100644 (file)
@@ -3842,7 +3842,8 @@ RESTORE_WARNING_FORMAT_NONLITERAL
 static void
 tty_invent_box_glyph_init(struct WinDesc *cw)
 {
-    int row, col, glyph;
+    int row, col;
+    uchar sym;
     struct tty_perminvent_cell *cell;
 
     for (row = 0; row < cw->maxrow; ++row)
@@ -3852,46 +3853,52 @@ tty_invent_box_glyph_init(struct WinDesc *cw)
                a glyph_info structure rather than just a char */
             if (!cell->glyph)
                 continue;
-            glyph = 0;
+            /* sym will always get another value; if for some reason it
+               doesn't, this default is valid for cmap_walls_to_glyph() */
+               sym = S_crwall;
             /* note: for top and bottom, check [border_right] before
                [border_middle] because they could be the same and if so
                we want corner rather than tee */
             if (row == 0) {
                 if (col == bordercol[border_left])
-                    glyph = cmap_to_glyph(S_tlcorn);
+                    sym = S_tlcorn;
                 else if (col == bordercol[border_right])
-                    glyph = cmap_to_glyph(S_trcorn);
+                    sym = S_trcorn;
                 else if (col == bordercol[border_middle])
-                    glyph = cmap_to_glyph(S_tdwall);
+                    sym = S_tdwall;
                 else /*if ((col > bordercol[border_left]
                             && col < bordercol[border_middle])
                            || (col > bordercol[border_middle]
                                && col < bordercol[border_right]))*/
-                    glyph = cmap_to_glyph(S_hwall);
+                    sym = S_hwall;
             } else if (row == (cw->maxrow - 1)) {
                 if (col == bordercol[border_left])
-                    glyph = cmap_to_glyph(S_blcorn);
+                    sym = S_blcorn;
                 else if (col == bordercol[border_right])
-                    glyph = cmap_to_glyph(S_brcorn);
+                    sym = S_brcorn;
                 else if (col == bordercol[border_middle])
-                    glyph = cmap_to_glyph(S_tuwall);
+                    sym = S_tuwall;
                 else /*if ((col > bordercol[border_left]
                             && col < bordercol[border_middle])
                            || (col > bordercol[border_middle]
                                && col < bordercol[border_right]))*/
-                    glyph = cmap_to_glyph(S_hwall);
+                    sym = S_hwall;
             } else {
                 if (col == bordercol[border_left]
                     || col == bordercol[border_middle]
                     || col == bordercol[border_right])
-                    glyph = cmap_to_glyph(S_vwall);
+                    sym = S_vwall;
             }
-            if (glyph) {
+
+            /* to get here, cell->glyph is 1 and cell->content union has gi */
+            {
                 int oldsymidx = cell->content.gi->gm.sym.symidx;
 #ifdef ENHANCED_SYMBOLS
-                struct unicode_representation *oldgmu =
-                    cell->content.gi->gm.u;
+                struct unicode_representation *
+                    oldgmu = cell->content.gi->gm.u;
 #endif
+                int glyph = cmap_D0walls_to_glyph(sym);
+
                 map_glyphinfo(0, 0, glyph, 0, cell->content.gi);
                 if (
 #ifdef ENHANCED_SYMBOLS
@@ -3901,10 +3908,6 @@ tty_invent_box_glyph_init(struct WinDesc *cw)
                     cell->refresh = 1;
                 cell->glyph = 1; /* (redundant) */
                 cell->text = 0;
-            } else {
-                /* we can only get here when cell->glyph is 1;
-                   not assigning anything in that situation is a bug */
-                impossible("tty invent: expected glyph");
             }
         }
     done_tty_perm_invent_init = TRUE;