more 'onefile' tweaks

Undefine some macros when the file that uses them is done so that
they won't be seen by any other source files if combined into one
huge source file.  I only looked at the few files where an #undef was
needed, not all the files, but in those few files I used #undef for
[almost] all their local macros instead of just the troublesome one.
display.c is the exception; it still has lots of macros which persist
through end of file.  nhlobj.c is another exception; I misremembered
the fixup for lua's lobject.c at the time and decided to include the
one #undef for nhlobj.c anyway even though 'onefile' isn't affected.

monst.c includes some reformatting.  display.c's sign() macro was
redone; it's intended for efficiency compared to calling hacklib.c's
sgn() function so streamline it.

[Keni, most of the file-specific #undef fixups in genonefile.pl can
now be removed.  It'll still need one for lua source file lobject.c;
addstr() there conflicts with curses.h, not with nethack's own code.]
This commit is contained in:
PatR
2023-04-21 14:32:43 -07:00
parent 8ec274bf2b
commit 861fcdf9c4
5 changed files with 74 additions and 11 deletions

View File

@@ -2309,7 +2309,10 @@ glyphinfo_at(coordxy x, coordxy y, int glyph)
*/
static void
get_bkglyph_and_framecolor(coordxy x, coordxy y, int *bkglyph, uint32 *framecolor)
get_bkglyph_and_framecolor(
coordxy x, coordxy y,
int *bkglyph,
uint32 *framecolor)
{
int idx, tmp_bkglyph = GLYPH_UNEXPLORED;
struct rm *lev = &levl[x][y];
@@ -3179,7 +3182,8 @@ const seenV seenv_matrix[3][3] = {
{ SV4, SV5, SV6 }
};
#define sign(z) ((z) < 0 ? -1 : ((z) > 0 ? 1 : 0))
/* negative: -1, zero: 0, positive +1; same as sgn() function (hacklib.c) */
#define sign(z) ((z) < 0 ? -1 : ((z) != 0))
/* Set the seen vector of lev as if seen from (x0,y0) to (x,y). */
static void
@@ -3193,6 +3197,8 @@ set_seenv(
lev->seenv |= seenv_matrix[sign(dy) + 1][sign(dx) + 1];
}
#undef sign
/* Called by blackout(vault.c) when vault guard removes temporary corridor,
turning spot <x0,y0> back into stone; <x1,y1> is an adjacent spot. */
void
@@ -3640,4 +3646,20 @@ fn_cmap_to_glyph(int cmap)
{
return cmap_to_glyph(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 DETECTED
#undef PHYSICALLY_SEEN
#undef is_worm_tail
#undef TMP_AT_MAX_GLYPHS
#undef Glyphinfo_at
#undef reset_glyph_bbox
#undef HAS_ROGUE_IBM_GRAPHICS
#undef HI_DOMESTIC
#undef GMAP_SET
#undef GMAP_ROGUELEVEL
/*display.c*/