Lazy evaluation of overview info

Callgrind showed recalc_mapseen was three times more expensive (in terms
of instructions read) than anything else in our codebase.  It was being
called in every vision change, re-evaluating the last seen map terrain
type for every map location in sight.

Remove updating the lastseen info in the vision code, and make a small
change so newsym() uses update_lastseentyp.

From my short tests, this seems to work correctly ...
This commit is contained in:
Pasi Kallinen
2023-12-18 10:09:35 +02:00
parent 0d1be5c50b
commit e4026d55fb
4 changed files with 7 additions and 10 deletions

View File

@@ -828,6 +828,7 @@ extern int dooverview(void);
extern void show_overview(int, int);
extern void rm_mapseen(int);
extern void init_mapseen(d_level *) NONNULLARG1;
extern void update_lastseentyp(coordxy, coordxy);
extern void recalc_mapseen(void);
extern void mapseen_temple(struct monst *);
extern void room_discovered(int);

View File

@@ -152,7 +152,6 @@ static void set_seenv(struct rm *, coordxy, coordxy, coordxy, coordxy);
static void t_warn(struct rm *);
static int wall_angle(struct rm *);
#define remember_topology(x, y) (gl.lastseentyp[x][y] = levl[x][y].typ)
#define _glyph_at(x, y) gg.gbuf[y][x].glyphinfo.glyph
/*
@@ -256,7 +255,7 @@ magic_map_background(coordxy x, coordxy y, int show)
if (show)
show_glyph(x, y, glyph);
remember_topology(x, y);
update_lastseentyp(x, y);
}
/*
@@ -461,7 +460,7 @@ unmap_object(register coordxy x, register coordxy y)
else \
map_background(x, y, show); \
\
remember_topology(x, y); \
update_lastseentyp(x, y); \
}
void
@@ -3670,7 +3669,6 @@ fn_cmap_to_glyph(int cmap)
/* for 'onefile' processing where end of this file isn't necessarily the
end of the source code seen by the compiler (there are lots of other
macros defined above...) */
#undef remember_topology
#undef _glyph_at
#undef DETECTED
#undef PHYSICALLY_SEEN

View File

@@ -64,7 +64,6 @@ static mapseen *find_mapseen(d_level *);
static mapseen *find_mapseen_by_str(const char *);
static void print_mapseen(winid, mapseen *, int, int, boolean);
static boolean interest_mapseen(mapseen *);
static void update_lastseentyp(coordxy, coordxy);
static void count_feat_lastseentyp(mapseen *, coordxy, coordxy);
static void traverse_mapseenchn(int, winid, int, int, int *);
static const char *seen_string(xint16, const char *);
@@ -3062,7 +3061,7 @@ interest_mapseen(mapseen *mptr)
}
/* update the lastseentyp at x,y */
static void
void
update_lastseentyp(coordxy x, coordxy y)
{
struct monst *mtmp;
@@ -3312,10 +3311,11 @@ recalc_mapseen(void)
* the ability to have non-dungeon glyphs float above the last known
* dungeon glyph (i.e. items on fountains).
*/
if (!Levitation)
update_lastseentyp(u.ux, u.uy);
for (x = 1; x < COLNO; x++) {
for (y = 0; y < ROWNO; y++) {
if (cansee(x, y) || (u_at(x, y) && !Levitation))
update_lastseentyp(x, y);
count_feat_lastseentyp(mptr, x, y);
}
}

View File

@@ -838,8 +838,6 @@ vision_recalc(int control)
/* Set the new min and max pointers. */
gv.viz_rmin = next_rmin;
gv.viz_rmax = next_rmax;
recalc_mapseen();
}
/*