]> granicus.if.org Git - nethack/commitdiff
viz_array[][] type
authorPatR <rankin@nethack.org>
Fri, 15 Jul 2022 20:48:29 +0000 (13:48 -0700)
committerPatR <rankin@nethack.org>
Fri, 15 Jul 2022 20:48:29 +0000 (13:48 -0700)
viz_array[][] is indexed by coordinates but the data it contains has
nothing to do with them so it shouldn't have been changed to coordxy.
'char' was sufficient; 'uchar' would have been better; this invents
'seenV' instead.  This led to a cascade of required changes.  The
result is warning free and seems to be working but my fingers are
crosssed....

include/decl.h
include/extern.h
include/global.h
include/rm.h
src/display.c
src/light.c
src/vision.c

index 5e6ee46e39f024cf54d247d3ab6339de60795d5e..3131ee65593639000ad3064b50e2a81b76b80388 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7  decl.h  $NHDT-Date: 1655161560 2022/06/13 23:06:00 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.298 $ */
+/* NetHack 3.7  decl.h  $NHDT-Date: 1657918080 2022/07/15 20:48:00 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.303 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Michael Allison, 2007. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -1247,10 +1247,10 @@ struct instance_globals {
     short nocreate4;
     /* uhitm.c */
     boolean override_confirmation; /* Used to flag attacks caused by
-                                      Stormbringer's maliciousness. */
+                                    * Stormbringer's maliciousness. */
 
     /* vision.c */
-    coordxy **viz_array; /* used in cansee() and couldsee() macros */
+    seenV **viz_array; /* used in cansee() and couldsee() macros */
     coordxy *viz_rmin;                 /* min could see indices */
     coordxy *viz_rmax;                 /* max could see indices */
     boolean vision_full_recalc;
index dcc64aa7197a3a7d148f5062d87f309c82a64af3..604ac1ca6fed07776daad8f86eed5c04a6e384ef 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 extern.h        $NHDT-Date: 1655065134 2022/06/12 20:18:54 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1121 $ */
+/* NetHack 3.7 extern.h        $NHDT-Date: 1657918089 2022/07/15 20:48:09 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1132 $ */
 /* Copyright (c) Steve Creps, 1988.                              */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -1193,7 +1193,7 @@ extern int dosuspend(void);
 
 extern void new_light_source(coordxy, coordxy, int, int, union any *);
 extern void del_light_source(int, union any *);
-extern void do_light_sources(coordxy **);
+extern void do_light_sources(seenV **);
 extern void show_transient_light(struct obj *, coordxy, coordxy);
 extern void transient_light_cleanup(void);
 extern struct monst *find_mid(unsigned, unsigned);
index a3abfadfe0e58ad533c75fb5c9c5776ad45d022d..12d6211e00c959d93a9035711e184ba2d54ebeee 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 global.h        $NHDT-Date: 1646322467 2022/03/03 15:47:47 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.135 $ */
+/* NetHack 3.7 global.h        $NHDT-Date: 1657918090 2022/07/15 20:48:10 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.144 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Michael Allison, 2006. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -85,6 +85,11 @@ typedef schar boolean; /* 0 or 1 */
 #endif
 #endif
 
+/* vision seen vectors: viz_array[][] and levl[][].seenv, which use different
+   values from each other but are close enough in size to share a type;
+   viz_array contains 8-bit bitmasks, lev->seenv is a 5-bit bitfield */
+typedef unsigned char seenV; /* no need for uint8_t */
+
 /* Type for third parameter of read(2) */
 #if defined(BSD) || defined(ULTRIX)
 typedef int readLenType;
index 2d674980fe324554fd595d0ce9e38596febf5972..71ea4da0b2da7e7ff994219a19de5a47725137ba 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 rm.h    $NHDT-Date: 1651099392 2022/04/27 22:43:12 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.94 $ */
+/* NetHack 3.7 rm.h    $NHDT-Date: 1657918091 2022/07/15 20:48:11 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.96 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Pasi Kallinen, 2017. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -309,15 +309,15 @@ struct rm {
  * directions.  If we know the type of wall and the directions from which
  * it has been seen, then we can determine what it looks like to the hero.
  */
-#define SV0   0x01
-#define SV1   0x02
-#define SV2   0x04
-#define SV3   0x08
-#define SV4   0x10
-#define SV5   0x20
-#define SV6   0x40
-#define SV7   0x80
-#define SVALL 0xFF
+#define SV0   ((seenV) 0x01)
+#define SV1   ((seenV) 0x02)
+#define SV2   ((seenV) 0x04)
+#define SV3   ((seenV) 0x08)
+#define SV4   ((seenV) 0x10)
+#define SV5   ((seenV) 0x20)
+#define SV6   ((seenV) 0x40)
+#define SV7   ((seenV) 0x80)
+#define SVALL ((seenV) 0xFF)
 
 /* if these get changed or expanded, make sure wizard-mode wishing becomes
    aware of the new usage */
index 228028f2ccd13e4912cc0864082dd4bf80d5b60a..89a644656db73a4073f35d176978c4e48a65db82 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 display.c       $NHDT-Date: 1654931503 2022/06/11 07:11:43 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.184 $ */
+/* NetHack 3.7 display.c       $NHDT-Date: 1657918092 2022/07/15 20:48:12 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.190 $ */
 /* Copyright (c) Dean Luick, with acknowledgements to Kevin Darcy */
 /* and Dave Cohrs, 1990.                                          */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -141,9 +141,11 @@ static glyph_info *glyphinfo_at(coordxy, coordxy, int);
 static boolean more_than_one(coordxy, coordxy, coordxy, coordxy, coordxy);
 #endif
 
-static int set_twall(coordxy, coordxy, coordxy, coordxy, coordxy, coordxy, coordxy, coordxy);
+static int set_twall(coordxy, coordxy, coordxy, coordxy,
+                     coordxy, coordxy, coordxy, coordxy);
 static int set_wall(coordxy, coordxy, int);
-static int set_corn(coordxy, coordxy, coordxy, coordxy, coordxy, coordxy, coordxy, coordxy);
+static int set_corn(coordxy, coordxy, coordxy, coordxy,
+                    coordxy, coordxy, coordxy, coordxy);
 static int set_crosswall(coordxy, coordxy);
 static void set_seenv(struct rm *, coordxy, coordxy, coordxy, coordxy);
 static void t_warn(struct rm *);
@@ -3040,16 +3042,20 @@ set_wall_state(void)
 
 /* ------------------------------------------------------------------------ */
 /* This matrix is used here and in vision.c. */
-unsigned char seenv_matrix[3][3] = { { SV2, SV1, SV0 },
-                                     { SV3, SVALL, SV7 },
-                                     { SV4, SV5, SV6 } };
+const seenV seenv_matrix[3][3] = {
+    { SV2, SV1,   SV0 },
+    { SV3, SVALL, SV7 },
+    { SV4, SV5,   SV6 }
+};
 
 #define sign(z) ((z) < 0 ? -1 : ((z) > 0 ? 1 : 0))
 
 /* Set the seen vector of lev as if seen from (x0,y0) to (x,y). */
 static void
-set_seenv(struct rm *lev,
-          coordxy x0, coordxy y0, coordxy x, coordxy y) /* from, to */
+set_seenv(
+    struct rm *lev,
+    coordxy x0, coordxy y0, /* from */
+    coordxy x, coordxy y)   /*  to  */
 {
     coordxy dx = x - x0, dy = y0 - y;
 
@@ -3059,10 +3065,11 @@ set_seenv(struct rm *lev,
 /* Called by blackout(vault.c) when vault guard removes temporary corridor,
    turning spot <x0,y0> back coordxyo stone; <x1,y1> is an adjacent spot. */
 void
-unset_seenv(struct rm *lev,                 /* &levl[x1][y1] */
-            coordxy x0, coordxy y0,
-            coordxy x1, coordxy y1)         /* from, to; abs(x1-x0)==1
-                                               && abs(y0-y1)==1 */
+unset_seenv(
+    struct rm *lev,         /* &levl[x1][y1] */
+    coordxy x0, coordxy y0, /* from */
+    coordxy x1, coordxy y1) /*  to; abs(x1-x0)==1 && abs(y0-y1)==1 */
+
 {
     coordxy dx = x1 - x0, dy = y0 - y1;
 
index 2431388a29f226d9b994da7a46cf2968bdea1f9e..0f727328235a85a802beb43fa2e15d1be5286913 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 light.c $NHDT-Date: 1604442297 2020/11/03 22:24:57 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.46 $ */
+/* NetHack 3.7 light.c $NHDT-Date: 1657918094 2022/07/15 20:48:14 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.57 $ */
 /* Copyright (c) Dean Luick, 1994                                       */
 /* NetHack may be freely redistributed.  See license for details.       */
 
@@ -134,14 +134,14 @@ del_light_source(int type, anything *id)
 
 /* Mark locations that are temporarily lit via mobile light sources. */
 void
-do_light_sources(coordxy **cs_rows)
+do_light_sources(seenV **cs_rows)
 {
     coordxy x, y, min_x, max_x, max_y;
     int offset;
     coordxy *limits;
     short at_hero_range = 0;
     light_source *ls;
-    coordxy *row;
+    seenV *row;
 
     for (ls = g.light_base; ls; ls = ls->next) {
         ls->flags &= ~LSF_SHOW;
index 76fed0d8dd3e5266ef13aefc44c6c381ba884958..b81398233dd8657911591fbebf8f5accc5cce154 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 vision.c        $NHDT-Date: 1596498225 2020/08/03 23:43:45 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.38 $ */
+/* NetHack 3.7 vision.c        $NHDT-Date: 1657918095 2022/07/15 20:48:15 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.49 $ */
 /* Copyright (c) Dean Luick, with acknowledgements to Dave Cohrs, 1990. */
 /* NetHack may be freely redistributed.  See license for details.       */
 
@@ -74,8 +74,8 @@ const coordxy circle_start[] = {
 
 /*------ local variables ------*/
 
-static coordxy could_see[2][ROWNO][COLNO]; /* vision work space */
-static coordxy *cs_rows0[ROWNO], *cs_rows1[ROWNO];
+static seenV could_see[2][ROWNO][COLNO]; /* vision work space */
+static seenV *cs_rows0[ROWNO], *cs_rows1[ROWNO];
 static coordxy cs_rmin0[ROWNO], cs_rmax0[ROWNO];
 static coordxy cs_rmin1[ROWNO], cs_rmax1[ROWNO];
 
@@ -89,11 +89,11 @@ static coordxy right_ptrs[ROWNO][COLNO];
 static void fill_point(int, int);
 static void dig_point(int, int);
 static void view_init(void);
-static void view_from(coordxy, coordxy, coordxy **, coordxy *, coordxy *, int,
+static void view_from(coordxy, coordxy, seenV **, coordxy *, coordxy *, int,
                       void (*)(coordxy, coordxy, genericptr_t),
                       genericptr_t);
-static void get_unused_cs(coordxy ***, coordxy **, coordxy **);
-static void rogue_vision(coordxy **, coordxy *, coordxy *);
+static void get_unused_cs(seenV ***, coordxy **, coordxy **);
+static void rogue_vision(seenV **, coordxy *, coordxy *);
 
 /* Macro definitions that I can't find anywhere. */
 #define sign(z) ((z) < 0 ? -1 : ((z) ? 1 : 0))
@@ -265,7 +265,7 @@ vision_reset(void)
  * to the unused vision work area.
  */
 static void
-get_unused_cs(coordxy ***rows, coordxy **rmin, coordxy **rmax)
+get_unused_cs(seenV ***rows, coordxy **rmin, coordxy **rmax)
 {
     register int row;
     register coordxy *nrmin, *nrmax;
@@ -284,7 +284,8 @@ get_unused_cs(coordxy ***rows, coordxy **rmin, coordxy **rmax)
     nrmin = *rmin;
     nrmax = *rmax;
 
-    (void) memset((genericptr_t) **rows, 0, sizeof(coordxy) * (ROWNO * COLNO)); /* see nothing */
+    (void) memset((genericptr_t) **rows, 0,
+                  ROWNO * COLNO * sizeof (seenV)); /* see nothing */
     for (row = 0; row < ROWNO; row++) { /* set row min & max */
         *nrmin++ = COLNO - 1;
         *nrmax++ = 1;
@@ -304,7 +305,7 @@ get_unused_cs(coordxy ***rows, coordxy **rmin, coordxy **rmax)
  * due to the one-sided lit wall hack.
  */
 static void
-rogue_vision(coordxy **next, coordxy *rmin, coordxy *rmax)
+rogue_vision(seenV **next, coordxy *rmin, coordxy *rmax)
 {
     int rnum = levl[u.ux][u.uy].roomno - ROOMOFFSET; /* no SHARED... */
     int start, stop, in_door, xhi, xlo, yhi, ylo;
@@ -504,14 +505,14 @@ new_angle(struct rm *lev, unsigned char *sv, int row, int col)
 void
 vision_recalc(int control)
 {
-    extern unsigned char seenv_matrix[3][3]; /* from display.c */
-    static unsigned char colbump[COLNO + 1]; /* cols to bump sv */
-    coordxy **temp_array; /* points to the old vision array */
-    coordxy **next_array; /* points to the new vision array */
-    coordxy *next_row;    /* row pointer for the new array */
-    coordxy *old_row;     /* row pointer for the old array */
-    coordxy *next_rmin;   /* min pointer for the new array */
-    coordxy *next_rmax;   /* max pointer for the new array */
+    extern const seenV seenv_matrix[3][3]; /* from display.c */
+    static coordxy colbump[COLNO + 1]; /* cols to bump sv */
+    seenV **temp_array; /* points to the old vision array */
+    seenV **next_array; /* points to the new vision array */
+    seenV *next_row;    /* row pointer for the new array */
+    seenV *old_row;     /* row pointer for the old array */
+    coordxy *next_rmin; /* min pointer for the new array */
+    coordxy *next_rmax; /* max pointer for the new array */
     const coordxy *ranges; /* circle ranges -- used for xray & night vision */
     int row = 0;       /* row counter (outer loop)  */
     int start, stop;   /* inner loop starting/stopping index */
@@ -519,7 +520,7 @@ vision_recalc(int control)
     register int col;  /* inner loop counter */
     register struct rm *lev; /* pointer to current pos */
     struct rm *flev;   /* pointer to position in "front" of current pos */
-    unsigned char *sv; /* ptr to seen angle bits */
+    const seenV *sv;   /* ptr to seen angle bits */
     int oldseenv;      /* previous seenv value */
 
     g.vision_full_recalc = 0; /* reset flag */
@@ -1109,7 +1110,7 @@ fill_point(int row, int col)
 static int start_row;
 static int start_col;
 static int step;
-static coordxy **cs_rows;
+static seenV **cs_rows;
 static coordxy *cs_left;
 static coordxy *cs_right;
 
@@ -1623,7 +1624,11 @@ view_init(void)
  *   limits      points at range limit for current row, or NULL
  */
 static void
-right_side(int row, int left, int right_mark, const coordxy *limits)
+right_side(
+    int row,
+    int left,
+    int right_mark,
+    const coordxy *limits)
 {
     int right;                  /* right limit of "could see" */
     int right_edge;             /* right edge of an opening */
@@ -1631,9 +1636,9 @@ right_side(int row, int left, int right_mark, const coordxy *limits)
     int deeper;                 /* if TRUE, call self as needed */
     int result;                 /* set by q?_path() */
     register int i;             /* loop counter */
-    register coordxy *rowp = NULL; /* row optimization */
-    coordxy *row_min = NULL;       /* left most  [used by macro set_min()] */
-    coordxy *row_max = NULL;       /* right most [used by macro set_max()] */
+    register seenV *rowp = NULL; /* row optimization */
+    coordxy *row_min = NULL;     /* left most  [used by macro set_min()] */
+    coordxy *row_max = NULL;     /* right most [used by macro set_max()] */
     int lim_max;                /* right most limit of circle */
 
     nrow = row + step;
@@ -1811,18 +1816,19 @@ right_side(int row, int left, int right_mark, const coordxy *limits)
  * extensive comments.
  */
 static void
-left_side(int row, int left_mark, int right, const coordxy *limits)
+left_side(
+    int row,
+    int left_mark,
+    int right,
+    const coordxy *limits)
 {
     int left, left_edge, nrow, deeper, result;
     register int i;
-    register coordxy *rowp = NULL;
+    register seenV *rowp = NULL;
     coordxy *row_min = NULL;
     coordxy *row_max = NULL;
     int lim_min;
 
-#ifdef GCC_WARN
-    rowp = row_min = row_max = 0;
-#endif
     nrow = row + step;
     deeper = good_row(nrow) && (!limits || (*limits >= *(limits + 1)));
     if (!vis_func) {
@@ -1954,12 +1960,16 @@ left_side(int row, int left_mark, int right, const coordxy *limits)
  *   arg            argument for func
  */
 static void
-view_from(coordxy srow, coordxy scol, coordxy **loc_cs_rows,
-          coordxy *left_most, coordxy *right_most, int range,
-          void (*func)(coordxy, coordxy, genericptr_t), genericptr_t arg)
+view_from(
+    coordxy srow, coordxy scol,
+    seenV **loc_cs_rows,
+    coordxy *left_most, coordxy *right_most,
+    int range,
+    void (*func)(coordxy, coordxy, genericptr_t),
+    genericptr_t arg)
 {
     register int i; /* loop counter */
-    coordxy *rowp;     /* optimization for setting could_see */
+    seenV *rowp;    /* optimization for setting could_see */
     int nrow;       /* the next row */
     int left;       /* the left-most visible column */
     int right;      /* the right-most visible column */
@@ -2055,13 +2065,16 @@ view_from(coordxy srow, coordxy scol, coordxy **loc_cs_rows,
  * vision matrix and reduce extra work.
  */
 void
-do_clear_area(coordxy scol, coordxy srow, int range,
-              void (*func)(coordxy, coordxy, genericptr_t), genericptr_t arg)
+do_clear_area(
+    coordxy scol, coordxy srow,
+    int range,
+    void (*func)(coordxy, coordxy, genericptr_t),
+    genericptr_t arg)
 {
     /* If not centered on hero, do the hard work of figuring the area */
     if (scol != u.ux || srow != u.uy) {
-        view_from(srow, scol, (coordxy **) 0, (coordxy *) 0, (coordxy *) 0, range,
-                  func, arg);
+        view_from(srow, scol, (seenV **) 0, (coordxy *) 0, (coordxy *) 0,
+                  range, func, arg);
     } else {
         register int x;
         int y, min_x, max_x, max_y, offset;