viz_array[][] type

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....
This commit is contained in:
PatR
2022-07-15 13:48:29 -07:00
parent 5aca2fc590
commit b37f922cf7
7 changed files with 92 additions and 67 deletions

View 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) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2007. */ /*-Copyright (c) Michael Allison, 2007. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -1247,10 +1247,10 @@ struct instance_globals {
short nocreate4; short nocreate4;
/* uhitm.c */ /* uhitm.c */
boolean override_confirmation; /* Used to flag attacks caused by boolean override_confirmation; /* Used to flag attacks caused by
Stormbringer's maliciousness. */ * Stormbringer's maliciousness. */
/* vision.c */ /* 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_rmin; /* min could see indices */
coordxy *viz_rmax; /* max could see indices */ coordxy *viz_rmax; /* max could see indices */
boolean vision_full_recalc; boolean vision_full_recalc;

View 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. */ /* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */ /* 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 new_light_source(coordxy, coordxy, int, int, union any *);
extern void del_light_source(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 show_transient_light(struct obj *, coordxy, coordxy);
extern void transient_light_cleanup(void); extern void transient_light_cleanup(void);
extern struct monst *find_mid(unsigned, unsigned); extern struct monst *find_mid(unsigned, unsigned);

View 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) 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. */
@@ -85,6 +85,11 @@ typedef schar boolean; /* 0 or 1 */
#endif #endif
#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) */ /* Type for third parameter of read(2) */
#if defined(BSD) || defined(ULTRIX) #if defined(BSD) || defined(ULTRIX)
typedef int readLenType; typedef int readLenType;

View 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) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Pasi Kallinen, 2017. */ /*-Copyright (c) Pasi Kallinen, 2017. */
/* NetHack may be freely redistributed. See license for details. */ /* 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 * 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. * it has been seen, then we can determine what it looks like to the hero.
*/ */
#define SV0 0x01 #define SV0 ((seenV) 0x01)
#define SV1 0x02 #define SV1 ((seenV) 0x02)
#define SV2 0x04 #define SV2 ((seenV) 0x04)
#define SV3 0x08 #define SV3 ((seenV) 0x08)
#define SV4 0x10 #define SV4 ((seenV) 0x10)
#define SV5 0x20 #define SV5 ((seenV) 0x20)
#define SV6 0x40 #define SV6 ((seenV) 0x40)
#define SV7 0x80 #define SV7 ((seenV) 0x80)
#define SVALL 0xFF #define SVALL ((seenV) 0xFF)
/* if these get changed or expanded, make sure wizard-mode wishing becomes /* if these get changed or expanded, make sure wizard-mode wishing becomes
aware of the new usage */ aware of the new usage */

View 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 */ /* Copyright (c) Dean Luick, with acknowledgements to Kevin Darcy */
/* and Dave Cohrs, 1990. */ /* and Dave Cohrs, 1990. */
/* NetHack may be freely redistributed. See license for details. */ /* 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); static boolean more_than_one(coordxy, coordxy, coordxy, coordxy, coordxy);
#endif #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_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 int set_crosswall(coordxy, coordxy);
static void set_seenv(struct rm *, coordxy, coordxy, coordxy, coordxy); static void set_seenv(struct rm *, coordxy, coordxy, coordxy, coordxy);
static void t_warn(struct rm *); static void t_warn(struct rm *);
@@ -3040,16 +3042,20 @@ set_wall_state(void)
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/* This matrix is used here and in vision.c. */ /* This matrix is used here and in vision.c. */
unsigned char seenv_matrix[3][3] = { { SV2, SV1, SV0 }, const seenV seenv_matrix[3][3] = {
{ SV3, SVALL, SV7 }, { SV2, SV1, SV0 },
{ SV4, SV5, SV6 } }; { SV3, SVALL, SV7 },
{ SV4, SV5, SV6 }
};
#define sign(z) ((z) < 0 ? -1 : ((z) > 0 ? 1 : 0)) #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). */ /* Set the seen vector of lev as if seen from (x0,y0) to (x,y). */
static void static void
set_seenv(struct rm *lev, set_seenv(
coordxy x0, coordxy y0, coordxy x, coordxy y) /* from, to */ struct rm *lev,
coordxy x0, coordxy y0, /* from */
coordxy x, coordxy y) /* to */
{ {
coordxy dx = x - x0, dy = y0 - y; 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, /* Called by blackout(vault.c) when vault guard removes temporary corridor,
turning spot <x0,y0> back coordxyo stone; <x1,y1> is an adjacent spot. */ turning spot <x0,y0> back coordxyo stone; <x1,y1> is an adjacent spot. */
void void
unset_seenv(struct rm *lev, /* &levl[x1][y1] */ unset_seenv(
coordxy x0, coordxy y0, struct rm *lev, /* &levl[x1][y1] */
coordxy x1, coordxy y1) /* from, to; abs(x1-x0)==1 coordxy x0, coordxy y0, /* from */
&& abs(y0-y1)==1 */ coordxy x1, coordxy y1) /* to; abs(x1-x0)==1 && abs(y0-y1)==1 */
{ {
coordxy dx = x1 - x0, dy = y0 - y1; coordxy dx = x1 - x0, dy = y0 - y1;

View 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 */ /* Copyright (c) Dean Luick, 1994 */
/* NetHack may be freely redistributed. See license for details. */ /* 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. */ /* Mark locations that are temporarily lit via mobile light sources. */
void void
do_light_sources(coordxy **cs_rows) do_light_sources(seenV **cs_rows)
{ {
coordxy x, y, min_x, max_x, max_y; coordxy x, y, min_x, max_x, max_y;
int offset; int offset;
coordxy *limits; coordxy *limits;
short at_hero_range = 0; short at_hero_range = 0;
light_source *ls; light_source *ls;
coordxy *row; seenV *row;
for (ls = g.light_base; ls; ls = ls->next) { for (ls = g.light_base; ls; ls = ls->next) {
ls->flags &= ~LSF_SHOW; ls->flags &= ~LSF_SHOW;

View 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. */ /* Copyright (c) Dean Luick, with acknowledgements to Dave Cohrs, 1990. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -74,8 +74,8 @@ const coordxy circle_start[] = {
/*------ local variables ------*/ /*------ local variables ------*/
static coordxy could_see[2][ROWNO][COLNO]; /* vision work space */ static seenV could_see[2][ROWNO][COLNO]; /* vision work space */
static coordxy *cs_rows0[ROWNO], *cs_rows1[ROWNO]; static seenV *cs_rows0[ROWNO], *cs_rows1[ROWNO];
static coordxy cs_rmin0[ROWNO], cs_rmax0[ROWNO]; static coordxy cs_rmin0[ROWNO], cs_rmax0[ROWNO];
static coordxy cs_rmin1[ROWNO], cs_rmax1[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 fill_point(int, int);
static void dig_point(int, int); static void dig_point(int, int);
static void view_init(void); 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), void (*)(coordxy, coordxy, genericptr_t),
genericptr_t); genericptr_t);
static void get_unused_cs(coordxy ***, coordxy **, coordxy **); static void get_unused_cs(seenV ***, coordxy **, coordxy **);
static void rogue_vision(coordxy **, coordxy *, coordxy *); static void rogue_vision(seenV **, coordxy *, coordxy *);
/* Macro definitions that I can't find anywhere. */ /* Macro definitions that I can't find anywhere. */
#define sign(z) ((z) < 0 ? -1 : ((z) ? 1 : 0)) #define sign(z) ((z) < 0 ? -1 : ((z) ? 1 : 0))
@@ -265,7 +265,7 @@ vision_reset(void)
* to the unused vision work area. * to the unused vision work area.
*/ */
static void static void
get_unused_cs(coordxy ***rows, coordxy **rmin, coordxy **rmax) get_unused_cs(seenV ***rows, coordxy **rmin, coordxy **rmax)
{ {
register int row; register int row;
register coordxy *nrmin, *nrmax; register coordxy *nrmin, *nrmax;
@@ -284,7 +284,8 @@ get_unused_cs(coordxy ***rows, coordxy **rmin, coordxy **rmax)
nrmin = *rmin; nrmin = *rmin;
nrmax = *rmax; 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 */ for (row = 0; row < ROWNO; row++) { /* set row min & max */
*nrmin++ = COLNO - 1; *nrmin++ = COLNO - 1;
*nrmax++ = 1; *nrmax++ = 1;
@@ -304,7 +305,7 @@ get_unused_cs(coordxy ***rows, coordxy **rmin, coordxy **rmax)
* due to the one-sided lit wall hack. * due to the one-sided lit wall hack.
*/ */
static void 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 rnum = levl[u.ux][u.uy].roomno - ROOMOFFSET; /* no SHARED... */
int start, stop, in_door, xhi, xlo, yhi, ylo; 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 void
vision_recalc(int control) vision_recalc(int control)
{ {
extern unsigned char seenv_matrix[3][3]; /* from display.c */ extern const seenV seenv_matrix[3][3]; /* from display.c */
static unsigned char colbump[COLNO + 1]; /* cols to bump sv */ static coordxy colbump[COLNO + 1]; /* cols to bump sv */
coordxy **temp_array; /* points to the old vision array */ seenV **temp_array; /* points to the old vision array */
coordxy **next_array; /* points to the new vision array */ seenV **next_array; /* points to the new vision array */
coordxy *next_row; /* row pointer for the new array */ seenV *next_row; /* row pointer for the new array */
coordxy *old_row; /* row pointer for the old array */ seenV *old_row; /* row pointer for the old array */
coordxy *next_rmin; /* min pointer for the new array */ coordxy *next_rmin; /* min pointer for the new array */
coordxy *next_rmax; /* max pointer for the new array */ coordxy *next_rmax; /* max pointer for the new array */
const coordxy *ranges; /* circle ranges -- used for xray & night vision */ const coordxy *ranges; /* circle ranges -- used for xray & night vision */
int row = 0; /* row counter (outer loop) */ int row = 0; /* row counter (outer loop) */
int start, stop; /* inner loop starting/stopping index */ int start, stop; /* inner loop starting/stopping index */
@@ -519,7 +520,7 @@ vision_recalc(int control)
register int col; /* inner loop counter */ register int col; /* inner loop counter */
register struct rm *lev; /* pointer to current pos */ register struct rm *lev; /* pointer to current pos */
struct rm *flev; /* pointer to position in "front" of 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 */ int oldseenv; /* previous seenv value */
g.vision_full_recalc = 0; /* reset flag */ g.vision_full_recalc = 0; /* reset flag */
@@ -1109,7 +1110,7 @@ fill_point(int row, int col)
static int start_row; static int start_row;
static int start_col; static int start_col;
static int step; static int step;
static coordxy **cs_rows; static seenV **cs_rows;
static coordxy *cs_left; static coordxy *cs_left;
static coordxy *cs_right; static coordxy *cs_right;
@@ -1623,7 +1624,11 @@ view_init(void)
* limits points at range limit for current row, or NULL * limits points at range limit for current row, or NULL
*/ */
static void 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; /* right limit of "could see" */
int right_edge; /* right edge of an opening */ 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 deeper; /* if TRUE, call self as needed */
int result; /* set by q?_path() */ int result; /* set by q?_path() */
register int i; /* loop counter */ register int i; /* loop counter */
register coordxy *rowp = NULL; /* row optimization */ register seenV *rowp = NULL; /* row optimization */
coordxy *row_min = NULL; /* left most [used by macro set_min()] */ coordxy *row_min = NULL; /* left most [used by macro set_min()] */
coordxy *row_max = NULL; /* right most [used by macro set_max()] */ coordxy *row_max = NULL; /* right most [used by macro set_max()] */
int lim_max; /* right most limit of circle */ int lim_max; /* right most limit of circle */
nrow = row + step; nrow = row + step;
@@ -1811,18 +1816,19 @@ right_side(int row, int left, int right_mark, const coordxy *limits)
* extensive comments. * extensive comments.
*/ */
static void 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; int left, left_edge, nrow, deeper, result;
register int i; register int i;
register coordxy *rowp = NULL; register seenV *rowp = NULL;
coordxy *row_min = NULL; coordxy *row_min = NULL;
coordxy *row_max = NULL; coordxy *row_max = NULL;
int lim_min; int lim_min;
#ifdef GCC_WARN
rowp = row_min = row_max = 0;
#endif
nrow = row + step; nrow = row + step;
deeper = good_row(nrow) && (!limits || (*limits >= *(limits + 1))); deeper = good_row(nrow) && (!limits || (*limits >= *(limits + 1)));
if (!vis_func) { if (!vis_func) {
@@ -1954,12 +1960,16 @@ left_side(int row, int left_mark, int right, const coordxy *limits)
* arg argument for func * arg argument for func
*/ */
static void static void
view_from(coordxy srow, coordxy scol, coordxy **loc_cs_rows, view_from(
coordxy *left_most, coordxy *right_most, int range, coordxy srow, coordxy scol,
void (*func)(coordxy, coordxy, genericptr_t), genericptr_t arg) 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 */ 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 nrow; /* the next row */
int left; /* the left-most visible column */ int left; /* the left-most visible column */
int right; /* the right-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. * vision matrix and reduce extra work.
*/ */
void void
do_clear_area(coordxy scol, coordxy srow, int range, do_clear_area(
void (*func)(coordxy, coordxy, genericptr_t), genericptr_t arg) 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 not centered on hero, do the hard work of figuring the area */
if (scol != u.ux || srow != u.uy) { if (scol != u.ux || srow != u.uy) {
view_from(srow, scol, (coordxy **) 0, (coordxy *) 0, (coordxy *) 0, range, view_from(srow, scol, (seenV **) 0, (coordxy *) 0, (coordxy *) 0,
func, arg); range, func, arg);
} else { } else {
register int x; register int x;
int y, min_x, max_x, max_y, offset; int y, min_x, max_x, max_y, offset;