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*/

View File

@@ -3222,4 +3222,14 @@ ustatusline(void)
Upolyd ? u.mhmax : u.uhpmax, u.uac, info);
}
/* for 'onefile' processing where end of this file isn't necessarily the
end of the source code seen by the compiler */
#undef enl_msg
#undef you_are
#undef you_have
#undef you_can
#undef you_have_been
#undef you_have_never
#undef you_have_X
/*insight.c*/

View File

@@ -871,4 +871,10 @@ wiz_light_sources(void)
return ECMD_OK;
}
/* for 'onefile' processing where end of this file isn't necessarily the
end of the source code seen by the compiler */
#undef LSF_SHOW
#undef LSF_NEEDS_FIXUP
#undef mon_is_local
/*light.c*/

View File

@@ -28,16 +28,18 @@
#define WT_ELF 800
#define WT_DRAGON 4500
#define MON(nam, sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, d, col, bn) \
{ \
{(const char *) 0, (const char *) 0, nam}, \
sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, d, C(col) \
#define MON(nam, sym, lvl, gen, atk, siz, mr1, mr2, \
flg1, flg2, flg3, d, col, bn) \
{ \
{ (const char *) 0, (const char *) 0, nam }, \
sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, d, C(col) \
}
#define MON3(namm, namf, namn, sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, d, col, bn) \
{ \
{namm, namf, namn}, \
sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, d, C(col) \
#define MON3(namm, namf, namn, sym, lvl, gen, atk, siz, mr1, mr2, \
flg1, flg2, flg3, d, col, bn) \
{ \
{ namm, namf, namn }, \
sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, d, C(col) \
}
/* LVL() and SIZ() collect several fields to cut down on number of args
* for MON()
@@ -71,11 +73,29 @@ struct permonst mons[SIZE(mons_init)];
void
monst_globals_init(void)
{
memcpy(mons, mons_init, sizeof(mons));
memcpy(mons, mons_init, sizeof mons);
return;
}
const struct attack c_sa_yes[NATTK] = SEDUCTION_ATTACKS_YES;
const struct attack c_sa_no[NATTK] = SEDUCTION_ATTACKS_NO;
/* for 'onefile' processing where end of this file isn't necessarily the
end of the source code seen by the compiler */
#undef C
#define C(c) (0x1f & (c)) /* global.h */
#ifdef TEXTCOLOR
#undef HI_DOMESTIC
#undef HI_LORD
#endif
#undef NO_ATTK
#undef WT_ELF
#undef WT_DRAGON
#undef MON
#undef MON3
#undef LVL
#undef SIZ
#undef ATTK
#undef A
/*monst.c*/

View File

@@ -655,3 +655,8 @@ l_obj_register(lua_State *L)
return 0;
}
/* for 'onefile' processing where end of this file isn't necessarily the
end of the source code seen by the compiler */
#undef lobj_is_ok
/*nhlobj.c*/