From 861fcdf9c462648695a17d24563e3e90cd7f6d11 Mon Sep 17 00:00:00 2001 From: PatR Date: Fri, 21 Apr 2023 14:32:43 -0700 Subject: [PATCH] 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.] --- src/display.c | 26 ++++++++++++++++++++++++-- src/insight.c | 10 ++++++++++ src/light.c | 6 ++++++ src/monst.c | 38 +++++++++++++++++++++++++++++--------- src/nhlobj.c | 5 +++++ 5 files changed, 74 insertions(+), 11 deletions(-) diff --git a/src/display.c b/src/display.c index b98fc88c8..31c92d14c 100644 --- a/src/display.c +++ b/src/display.c @@ -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 back into stone; 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*/ diff --git a/src/insight.c b/src/insight.c index cb35b8c6e..ef00fca02 100644 --- a/src/insight.c +++ b/src/insight.c @@ -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*/ diff --git a/src/light.c b/src/light.c index b37a2cd40..e09073516 100644 --- a/src/light.c +++ b/src/light.c @@ -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*/ diff --git a/src/monst.c b/src/monst.c index 2ac7f0781..04c80bd8b 100644 --- a/src/monst.c +++ b/src/monst.c @@ -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*/ diff --git a/src/nhlobj.c b/src/nhlobj.c index 584a8f4a1..ef8303528 100644 --- a/src/nhlobj.c +++ b/src/nhlobj.c @@ -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*/