split g into multiple structures

The consolidation of global variables from scattered source
files into decl.c and declared in decl.h was begun in 3.7.0.
Their placement in common files was done for centralized
initialization and potential re-initialization during a
"play again" scenario.

It wasn't really necessary for all of them to be housed in a
single huge structure to meet the "play again" requirement,
and the single huge structure has been a little unwieldy when
it comes to maintenance.

Following this commit, instead of one single extremely large structure
named 'g' to house all of the relocated global variables, they
are distributed into several ga through gz.

To make things easy for the developer, each variable is placed
into the struct corresponding to the starting letter of the variable.
That way, no lookup is required in order to know which struct houses
a particular variable, it is a simple match to the starting letter
for all the centralized global variables.

A global variable named 'amulets', would be found in ga.
    ga.amulets
     ^ ^
A global varable named 'move', would be found in gm.
    gm.moves
     ^ ^
A global variable named 'val_for_n_or_more' would be found in gv.
    gv.val_for_n_or_more
     ^ ^
A global variable named 'youmonst' would be found in gy.
    gy.youmonst
     ^ ^
This commit is contained in:
nhmall
2022-11-29 21:53:21 -05:00
parent e64ed2859d
commit 02a48aa8cf
193 changed files with 10764 additions and 10148 deletions

View File

@@ -24,7 +24,7 @@
static long final_fpos; /* [note: do not move this to the 'g' struct] */
#endif
#define done_stopprint g.program_state.stopprint
#define done_stopprint gp.program_state.stopprint
#define newttentry() (struct toptenentry *) alloc(sizeof (struct toptenentry))
#define dealloc_ttentry(ttent) free((genericptr_t) (ttent))
@@ -84,7 +84,7 @@ static void nsb_mung_line(char *);
static void nsb_unmung_line(char *);
#endif
/* "killed by",&c ["an"] 'g.killer.name' */
/* "killed by",&c ["an"] 'gk.killer.name' */
void
formatkiller(
char *buf,
@@ -103,12 +103,12 @@ formatkiller(
"", "", "", "", ""
};
unsigned l;
char c, *kname = g.killer.name;
char c, *kname = gk.killer.name;
buf[0] = '\0'; /* lint suppression */
switch (g.killer.format) {
switch (gk.killer.format) {
default:
impossible("bad killer format? (%d)", g.killer.format);
impossible("bad killer format? (%d)", gk.killer.format);
/*FALLTHRU*/
case NO_KILLER_PREFIX:
break;
@@ -146,12 +146,12 @@ formatkiller(
}
*buf = '\0';
if (incl_helpless && g.multi) {
if (incl_helpless && gm.multi) {
/* X <= siz: 'sizeof "string"' includes 1 for '\0' terminator */
if (g.multi_reason
&& strlen(g.multi_reason) + sizeof ", while " <= siz)
Sprintf(buf, ", while %s", g.multi_reason);
/* either g.multi_reason wasn't specified or wouldn't fit */
if (gm.multi_reason
&& strlen(gm.multi_reason) + sizeof ", while " <= siz)
Sprintf(buf, ", while %s", gm.multi_reason);
/* either gm.multi_reason wasn't specified or wouldn't fit */
else if (sizeof ", while helpless" <= siz)
Strcpy(buf, ", while helpless");
/* else extra death info won't fit, so leave it out */
@@ -161,19 +161,19 @@ formatkiller(
static void
topten_print(const char *x)
{
if (g.toptenwin == WIN_ERR)
if (gt.toptenwin == WIN_ERR)
raw_print(x);
else
putstr(g.toptenwin, ATR_NONE, x);
putstr(gt.toptenwin, ATR_NONE, x);
}
static void
topten_print_bold(const char *x)
{
if (g.toptenwin == WIN_ERR)
if (gt.toptenwin == WIN_ERR)
raw_print_bold(x);
else
putstr(g.toptenwin, ATR_BOLD, x);
putstr(gt.toptenwin, ATR_BOLD, x);
}
int
@@ -332,7 +332,7 @@ RESTORE_WARNING_FORMAT_NONLITERAL
#ifdef XLOGFILE
/* as tab is never used in eg. g.plname or death, no need to mangle those. */
/* as tab is never used in eg. gp.plname or death, no need to mangle those. */
static void
writexlentry(FILE* rfile, struct toptenentry* tt, int how)
{
@@ -358,12 +358,12 @@ writexlentry(FILE* rfile, struct toptenentry* tt, int how)
formatkiller(tmpbuf, sizeof tmpbuf, how, FALSE);
Fprintf(rfile, "%s%cname=%s%cdeath=%s",
buf, /* (already includes separator) */
XLOG_SEP, g.plname, XLOG_SEP, tmpbuf);
if (g.multi)
XLOG_SEP, gp.plname, XLOG_SEP, tmpbuf);
if (gm.multi)
Fprintf(rfile, "%cwhile=%s", XLOG_SEP,
g.multi_reason ? g.multi_reason : "helpless");
gm.multi_reason ? gm.multi_reason : "helpless");
Fprintf(rfile, "%cconduct=0x%lx%cturns=%ld%cachieve=0x%lx", XLOG_SEP,
encodeconduct(), XLOG_SEP, g.moves, XLOG_SEP,
encodeconduct(), XLOG_SEP, gm.moves, XLOG_SEP,
encodeachieve(FALSE));
Fprintf(rfile, "%cachieveX=%s", XLOG_SEP,
encode_extended_achievements(achbuf));
@@ -378,7 +378,7 @@ writexlentry(FILE* rfile, struct toptenentry* tt, int how)
aligns[1 - u.ualignbase[A_ORIGINAL]].filecode);
Fprintf(rfile, "%cflags=0x%lx", XLOG_SEP, encodexlogflags());
Fprintf(rfile, "%cgold=%ld", XLOG_SEP,
money_cnt(g.invent) + hidden_gold(TRUE));
money_cnt(gi.invent) + hidden_gold(TRUE));
Fprintf(rfile, "%cwish_cnt=%ld", XLOG_SEP, u.uconduct.wishes);
Fprintf(rfile, "%carti_wish_cnt=%ld", XLOG_SEP, u.uconduct.wisharti);
Fprintf(rfile, "%cbones=%ld", XLOG_SEP, u.uroleplay.numbones);
@@ -637,15 +637,15 @@ topten(int how, time_t when)
* topten uses alloc() several times, which will lead to
* problems if the panic was the result of an alloc() failure.
*/
if (g.program_state.panicking)
if (gp.program_state.panicking)
return;
if (iflags.toptenwin) {
g.toptenwin = create_nhwindow(NHW_TEXT);
gt.toptenwin = create_nhwindow(NHW_TEXT);
}
#if defined(UNIX) || defined(VMS) || defined(__EMX__)
#define HUP if (!g.program_state.done_hup)
#define HUP if (!gp.program_state.done_hup)
#else
#define HUP
#endif
@@ -674,11 +674,11 @@ topten(int how, time_t when)
t0->maxhp = u.uhpmax;
t0->deaths = u.umortality;
t0->uid = uid;
copynchars(t0->plrole, g.urole.filecode, ROLESZ);
copynchars(t0->plrace, g.urace.filecode, ROLESZ);
copynchars(t0->plrole, gu.urole.filecode, ROLESZ);
copynchars(t0->plrace, gu.urace.filecode, ROLESZ);
copynchars(t0->plgend, genders[flags.female].filecode, ROLESZ);
copynchars(t0->plalign, aligns[1 - u.ualign.type].filecode, ROLESZ);
copynchars(t0->name, g.plname, NAMSZ);
copynchars(t0->name, gp.plname, NAMSZ);
formatkiller(t0->death, sizeof t0->death, how, TRUE);
t0->birthdate = yyyymmdd(ubirthday);
t0->deathdate = yyyymmdd(when);
@@ -896,7 +896,7 @@ topten(int how, time_t when)
showwin:
if (!done_stopprint) {
if (iflags.toptenwin) {
display_nhwindow(g.toptenwin, TRUE);
display_nhwindow(gt.toptenwin, TRUE);
} else {
/* when not a window, we need something comparable to more()
but can't use it directly because we aren't dealing with
@@ -908,8 +908,8 @@ topten(int how, time_t when)
if (!t0_used)
dealloc_ttentry(t0);
if (iflags.toptenwin) {
destroy_nhwindow(g.toptenwin);
g.toptenwin = WIN_ERR;
destroy_nhwindow(gt.toptenwin);
gt.toptenwin = WIN_ERR;
}
}
@@ -1015,7 +1015,7 @@ outentry(int rank, struct toptenentry* t1, boolean so)
}
Sprintf(eos(linebuf), fmt, arg);
} else {
Sprintf(eos(linebuf), " in %s", g.dungeons[t1->deathdnum].dname);
Sprintf(eos(linebuf), " in %s", gd.dungeons[t1->deathdnum].dname);
if (t1->deathdnum != knox_level.dnum)
Sprintf(eos(linebuf), " on level %d", t1->deathlev);
if (t1->deathlev != t1->maxlvl)
@@ -1207,7 +1207,7 @@ prscore(int argc, char **argv)
playerct = 0;
players = (const char **) 0;
} else {
player0 = g.plname;
player0 = gp.plname;
if (!*player0)
player0 = "all"; /* if no plname[], show all scores
* (possibly filtered by '-v') */
@@ -1286,7 +1286,7 @@ prscore(int argc, char **argv)
Strcat(pbuf, ".");
raw_print(pbuf);
raw_printf("Usage: %s -s [-v] <playertypes> [maxrank] [playernames]",
g.hname);
gh.hname);
raw_printf("Player types are: [-p role] [-r race]");
}
free_ttlist(tt_head);