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

@@ -66,7 +66,7 @@ hooked_tty_getlin(const char *query, register char *bufp, getlin_hook_proc hook)
for (;;) {
(void) fflush(stdout);
Strcat(strcat(strcpy(g.toplines, query), " "), obufp);
Strcat(strcat(strcpy(gt.toplines, query), " "), obufp);
c = pgetchar();
if (c == '\033' || c == EOF) {
if (c == '\033' && obufp[0] != '\0') {
@@ -194,11 +194,11 @@ hooked_tty_getlin(const char *query, register char *bufp, getlin_hook_proc hook)
if (suppress_history) {
/* prevent next message from pushing current query+answer into
tty message history */
*g.toplines = '\0';
*gt.toplines = '\0';
#ifdef DUMPLOG
} else {
/* needed because we've bypassed pline() */
dumplogmsg(g.toplines);
dumplogmsg(gt.toplines);
#endif
}
}
@@ -211,7 +211,7 @@ xwaitforspace(register const char *s) /* chars allowed besides return */
morc = 0;
while (
#ifdef HANGUPHANDLING
!g.program_state.done_hup &&
!gp.program_state.done_hup &&
#endif
(c = tty_nhgetch()) != EOF) {
if (c == '\n' || c == '\r')
@@ -280,14 +280,14 @@ tty_get_ext_cmd(void)
suppress_history = TRUE;
/* maybe a runtime option?
* hooked_tty_getlin("#", buf,
* (flags.cmd_comp && !g.in_doagain)
* (flags.cmd_comp && !gi.in_doagain)
* ? ext_cmd_getlin_hook
* : (getlin_hook_proc) 0);
*/
extcmd_char[0] = extcmd_initiator(), extcmd_char[1] = '\0';
buf[0] = '\0';
hooked_tty_getlin(extcmd_char, buf,
!g.in_doagain ? ext_cmd_getlin_hook : no_hook);
!gi.in_doagain ? ext_cmd_getlin_hook : no_hook);
(void) mungspaces(buf);
nmatches = (buf[0] == '\0' || buf[0] == '\033') ? -1

View File

@@ -489,7 +489,7 @@ tty_start_screen(void)
utf8graphics_mode_callback = tty_utf8graphics_fixup;
#endif
if (g.Cmd.num_pad)
if (gc.Cmd.num_pad)
tty_number_pad(1); /* make keypad send digits */
}

View File

@@ -36,7 +36,7 @@ tty_doprev_message(void)
putstr(prevmsg_win, 0, cw->data[i]);
i = (i + 1) % cw->rows;
} while (i != cw->maxcol);
putstr(prevmsg_win, 0, g.toplines);
putstr(prevmsg_win, 0, gt.toplines);
display_nhwindow(prevmsg_win, TRUE);
destroy_nhwindow(prevmsg_win);
} else if (iflags.prevmsg_window == 'c') { /* combination */
@@ -44,7 +44,7 @@ tty_doprev_message(void)
morc = 0;
if (cw->maxcol == cw->maxrow) {
ttyDisplay->dismiss_more = C('p'); /* ^P ok at --More-- */
redotoplin(g.toplines);
redotoplin(gt.toplines);
cw->maxcol--;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
@@ -69,7 +69,7 @@ tty_doprev_message(void)
putstr(prevmsg_win, 0, cw->data[i]);
i = (i + 1) % cw->rows;
} while (i != cw->maxcol);
putstr(prevmsg_win, 0, g.toplines);
putstr(prevmsg_win, 0, gt.toplines);
display_nhwindow(prevmsg_win, TRUE);
destroy_nhwindow(prevmsg_win);
}
@@ -81,7 +81,7 @@ tty_doprev_message(void)
prevmsg_win = create_nhwindow(NHW_MENU);
putstr(prevmsg_win, 0, "Message History");
putstr(prevmsg_win, 0, "");
putstr(prevmsg_win, 0, g.toplines);
putstr(prevmsg_win, 0, gt.toplines);
cw->maxcol = cw->maxrow - 1;
if (cw->maxcol < 0)
cw->maxcol = cw->rows - 1;
@@ -104,7 +104,7 @@ tty_doprev_message(void)
do {
morc = 0;
if (cw->maxcol == cw->maxrow)
redotoplin(g.toplines);
redotoplin(gt.toplines);
else if (cw->data[cw->maxcol])
redotoplin(cw->data[cw->maxcol]);
cw->maxcol--;
@@ -171,9 +171,9 @@ remember_topl(void)
{
register struct WinDesc *cw = wins[WIN_MESSAGE];
int idx = cw->maxrow;
unsigned len = strlen(g.toplines) + 1;
unsigned len = strlen(gt.toplines) + 1;
if ((cw->flags & WIN_LOCKHISTORY) || !*g.toplines)
if ((cw->flags & WIN_LOCKHISTORY) || !*gt.toplines)
return;
if (len > (unsigned) cw->datlen[idx]) {
@@ -183,9 +183,9 @@ remember_topl(void)
cw->data[idx] = (char *) alloc(len);
cw->datlen[idx] = (short) len;
}
Strcpy(cw->data[idx], g.toplines);
if (!g.program_state.in_checkpoint) {
*g.toplines = '\0';
Strcpy(cw->data[idx], gt.toplines);
if (!gp.program_state.in_checkpoint) {
*gt.toplines = '\0';
cw->maxcol = cw->maxrow = (idx + 1) % cw->rows;
}
}
@@ -261,10 +261,10 @@ update_topl(register const char *bp)
n0 = strlen(bp);
if ((ttyDisplay->toplin == TOPLINE_NEED_MORE || skip)
&& cw->cury == 0
&& n0 + (int) strlen(g.toplines) + 3 < CO - 8 /* room for --More-- */
&& n0 + (int) strlen(gt.toplines) + 3 < CO - 8 /* room for --More-- */
&& (notdied = strncmp(bp, "You die", 7)) != 0) {
Strcat(g.toplines, " ");
Strcat(g.toplines, bp);
Strcat(gt.toplines, " ");
Strcat(gt.toplines, bp);
cw->curx += 2;
if (!skip)
addtopl(bp);
@@ -278,10 +278,10 @@ update_topl(register const char *bp)
}
}
remember_topl();
(void) strncpy(g.toplines, bp, TBUFSZ);
g.toplines[TBUFSZ - 1] = 0;
(void) strncpy(gt.toplines, bp, TBUFSZ);
gt.toplines[TBUFSZ - 1] = 0;
for (tl = g.toplines; n0 >= CO; ) {
for (tl = gt.toplines; n0 >= CO; ) {
otl = tl;
for (tl += CO - 1; tl != otl; --tl)
if (*tl == ' ')
@@ -298,7 +298,7 @@ update_topl(register const char *bp)
if (!notdied) /* double negative => "You die"; avoid suppressing mesg */
cw->flags &= ~WIN_STOP, skip = FALSE;
if (!skip)
redotoplin(g.toplines);
redotoplin(gt.toplines);
}
static void
@@ -532,10 +532,10 @@ tty_yn_function(
Sprintf(rtmp, "#%ld", yn_number);
else
(void) key2txt(q, rtmp);
/* addtopl(rtmp); -- rewrite g.toplines instead */
Sprintf(g.toplines, "%s%s", prompt, rtmp);
/* addtopl(rtmp); -- rewrite gt.toplines instead */
Sprintf(gt.toplines, "%s%s", prompt, rtmp);
#ifdef DUMPLOG
dumplogmsg(g.toplines);
dumplogmsg(gt.toplines);
#endif
ttyDisplay->inread--;
ttyDisplay->toplin = TOPLINE_NON_EMPTY;
@@ -565,7 +565,7 @@ msghistory_snapshot(
return;
cw = wins[WIN_MESSAGE];
/* flush g.toplines[], moving most recent message to history */
/* flush gt.toplines[], moving most recent message to history */
remember_topl();
/* for a passive snapshot, we just copy pointers, so can't allow further
@@ -686,7 +686,7 @@ tty_putmsghistory(const char *msg, boolean restoring_msghist)
initd = TRUE;
#ifdef DUMPLOG
/* this suffices; there's no need to scrub saved_pline[] pointers */
g.saved_pline_index = 0;
gs.saved_pline_index = 0;
#endif
}
@@ -700,9 +700,9 @@ tty_putmsghistory(const char *msg, boolean restoring_msghist)
/* move most recent message to history, make this become most recent */
remember_topl();
Strcpy(g.toplines, msg);
Strcpy(gt.toplines, msg);
#ifdef DUMPLOG
dumplogmsg(g.toplines);
dumplogmsg(gt.toplines);
#endif
} else if (snapshot_mesgs) {
nhassert(ttyDisplay == NULL ||
@@ -711,9 +711,9 @@ tty_putmsghistory(const char *msg, boolean restoring_msghist)
/* done putting arbitrary messages in; put the snapshot ones back */
for (idx = 0; snapshot_mesgs[idx]; ++idx) {
remember_topl();
Strcpy(g.toplines, snapshot_mesgs[idx]);
Strcpy(gt.toplines, snapshot_mesgs[idx]);
#ifdef DUMPLOG
dumplogmsg(g.toplines);
dumplogmsg(gt.toplines);
#endif
}
/* now release the snapshot */

View File

@@ -80,7 +80,7 @@ extern void msmsg(const char *, ...);
*/
#define HUPSKIP() \
do { \
if (g.program_state.done_hup) { \
if (gp.program_state.done_hup) { \
morc = '\033'; \
return; \
} \
@@ -88,7 +88,7 @@ extern void msmsg(const char *, ...);
/* morc=ESC - in case we bypass xwaitforspace() which sets that */
#define HUPSKIP_RESULT(RES) \
do { \
if (g.program_state.done_hup) \
if (gp.program_state.done_hup) \
return (RES); \
} while (0)
#else /* !HANGUPHANDLING */
@@ -411,7 +411,7 @@ winch_handler(int sig_unused UNUSED)
ttyDisplay->toplin = i;
flush_screen(1);
if (i) {
addtopl(g.toplines);
addtopl(gt.toplines);
} else
for (i = WIN_INVEN; i < MAXWIN; i++)
if (wins[i] && wins[i]->active) {
@@ -1046,7 +1046,7 @@ tty_player_selection(void)
Sprintf(plbuf, " %s", genders[GEND].adj);
else
*plbuf = '\0'; /* omit redundant gender */
Snprintf(pbuf, sizeof(pbuf), "%s, %s%s %s %s", g.plname,
Snprintf(pbuf, sizeof(pbuf), "%s, %s%s %s %s", gp.plname,
aligns[ALGN].adj, plbuf, races[RACE].adj,
(GEND == 1 && roles[ROLE].name.f) ? roles[ROLE].name.f
: roles[ROLE].name.m);
@@ -1097,8 +1097,8 @@ tty_player_selection(void)
GEND, ALGN; we'll override that and honor only the name */
saveROLE = ROLE, saveRACE = RACE, saveGEND = GEND,
saveALGN = ALGN;
*g.plname = '\0';
plnamesuffix(); /* calls askname() when g.plname[] is empty */
*gp.plname = '\0';
plnamesuffix(); /* calls askname() when gp.plname[] is empty */
ROLE = saveROLE, RACE = saveRACE, GEND = saveGEND,
ALGN = saveALGN;
break; /* getconfirmation is still True */
@@ -1344,7 +1344,7 @@ setup_algnmenu(winid win, boolean filtering, int role, int race, int gend)
}
/*
* g.plname is filled either by an option (-u Player or -uPlayer) or
* gp.plname is filled either by an option (-u Player or -uPlayer) or
* explicitly (by being the wizard) or by askname.
* It may still contain a suffix denoting the role, etc.
* Always called after init_nhwindows() and before display_gamewindows().
@@ -1364,7 +1364,7 @@ tty_askname(void)
case 0:
break; /* no game chosen; start new game */
case 1:
return; /* g.plname[] has been set */
return; /* gp.plname[] has been set */
}
#endif /* SELECTSAVED */
@@ -1427,7 +1427,7 @@ tty_askname(void)
&& !(c >= '0' && c <= '9' && ct > 0))
c = '_';
#endif
if (ct < (int) (sizeof g.plname) - 1) {
if (ct < (int) (sizeof gp.plname) - 1) {
#if defined(MICRO)
#if defined(MSDOS)
if (iflags.grmode) {
@@ -1438,13 +1438,13 @@ tty_askname(void)
#else
(void) putchar(c);
#endif
g.plname[ct++] = c;
gp.plname[ct++] = c;
#ifdef WIN32CON
ttyDisplay->curx++;
#endif
}
}
g.plname[ct] = 0;
gp.plname[ct] = 0;
} while (ct == 0);
/* move to next line to simulate echo of user's <return> */
@@ -1757,11 +1757,11 @@ tty_clear_nhwindow(winid window)
cw->data[i][n - 1] = '\0';
/*finalx[i][NOW] = finalx[i][BEFORE] = 0;*/
}
g.context.botlx = 1;
gc.context.botlx = 1;
break;
case NHW_MAP:
/* cheap -- clear the whole thing and tell nethack to redraw botl */
g.context.botlx = 1;
gc.context.botlx = 1;
/*FALLTHRU*/
case NHW_BASE:
clear_screen();
@@ -2182,7 +2182,7 @@ process_menu_window(winid window, struct WinDesc *cw)
Strcat(resp, " "); /* next page or end */
Strcat(resp, "0123456789\033\n\r"); /* counts, quit */
Strcat(resp, gacc); /* group accelerators */
Strcat(resp, g.mapped_menu_cmds);
Strcat(resp, gm.mapped_menu_cmds);
if (cw->npages > 1)
Sprintf(cw->morestr, "(%d of %d)", curr_page + 1,
@@ -2919,7 +2919,7 @@ tty_putstr(winid window, int attr, const char *str)
#ifndef STATUS_HILITES
case NHW_STATUS:
ob = &cw->data[cw->cury][j = cw->curx];
if (g.context.botlx)
if (gc.context.botlx)
*ob = '\0';
if (!cw->cury && (int) strlen(str) >= CO) {
/* the characters before "St:" are unnecessary */
@@ -2930,7 +2930,7 @@ tty_putstr(winid window, int attr, const char *str)
nb = str;
for (i = cw->curx + 1, n0 = cw->cols; i < n0; i++, nb++) {
if (!*nb) {
if (*ob || g.context.botlx) {
if (*ob || gc.context.botlx) {
/* last char printed may be in middle of line */
tty_curs(WIN_STATUS, i, cw->cury);
cl_end();
@@ -3060,9 +3060,9 @@ tty_display_file(const char *fname, boolean complain)
if (complain)
raw_printf("Cannot open %s as stdin.", fname);
} else {
(void) execlp(g.catmore, "page", (char *) 0);
(void) execlp(gc.catmore, "page", (char *) 0);
if (complain)
raw_printf("Cannot exec %s.", g.catmore);
raw_printf("Cannot exec %s.", gc.catmore);
}
if (complain)
sleep(10); /* want to wait_synch() but stdin is gone */
@@ -3144,7 +3144,7 @@ tty_start_menu(winid window, unsigned long mbehavior)
}
if (mbehavior == MENU_BEHAVE_PERMINV
&& (iflags.perm_invent
|| g.perm_invent_toggling_direction == toggling_on)) {
|| gp.perm_invent_toggling_direction == toggling_on)) {
winid w = ttyinv_create_window(window, wins[window]);
if (w == WIN_ERR) {
/* something went wrong, so add clean up code here */
@@ -3274,9 +3274,9 @@ tty_end_menu(winid window, /* menu to use */
}
#ifdef TTY_PERM_INVENT
if (cw->mbehavior == MENU_BEHAVE_PERMINV
&& (iflags.perm_invent || g.perm_invent_toggling_direction == toggling_on)
&& (iflags.perm_invent || gp.perm_invent_toggling_direction == toggling_on)
&& window == WIN_INVEN) {
if (g.program_state.in_moveloop)
if (gp.program_state.in_moveloop)
ttyinv_render(window, cw);
return;
}
@@ -3610,7 +3610,7 @@ ttyinv_add_menu(winid window UNUSED, struct WinDesc *cw, char ch,
ignore = FALSE;
int row, side, slot = 0, rows_per_side = (!show_gold ? 26 : 27);
if (!g.program_state.in_moveloop)
if (!gp.program_state.in_moveloop)
return;
slot = selector_to_slot(ch, ttyinvmode, &ignore);
if (!ignore) {
@@ -3689,7 +3689,7 @@ ttyinv_render(winid window, struct WinDesc *cw)
int row, col, slot, side, filled_count = 0, slot_limit;
struct tty_perminvent_cell *cell;
char invbuf[BUFSZ], *text;
boolean force_redraw = g.program_state.in_docrt ? TRUE : FALSE,
boolean force_redraw = gp.program_state.in_docrt ? TRUE : FALSE,
show_gold = (ttyinvmode & InvShowGold) != 0,
inuse_only = (ttyinvmode & InvInUse) != 0;
int rows_per_side = (!show_gold ? 26 : 27);
@@ -3720,9 +3720,9 @@ ttyinv_render(winid window, struct WinDesc *cw)
ttyinv_populate_slot(cw, row, side, text, 0);
}
/* has there been a glyph reset since we last got here? */
if (g.glyph_reset_timestamp > last_glyph_reset_when) {
if (gg.glyph_reset_timestamp > last_glyph_reset_when) {
// tty_invent_box_glyph_init(wins[WIN_INVEN]);
last_glyph_reset_when = g.glyph_reset_timestamp;
last_glyph_reset_when = gg.glyph_reset_timestamp;
force_redraw = TRUE;
}
/* render to the display */
@@ -3984,7 +3984,7 @@ tty_wait_synch(void)
if (ttyDisplay->inmore) {
addtopl("--More--");
(void) fflush(stdout);
} else if (ttyDisplay->inread > g.program_state.gameover) {
} else if (ttyDisplay->inread > gp.program_state.gameover) {
/* this can only happen if we were reading and got interrupted */
ttyDisplay->toplin = TOPLINE_SPECIAL_PROMPT;
/* do this twice; 1st time gets the Quit? message again */
@@ -4062,7 +4062,7 @@ docorner(register int xmin, register int ymax, int ystart_between_menu_pages)
if (ymax >= (int) wins[WIN_STATUS]->offy
&& !ystart_between_menu_pages) {
/* we have wrecked the bottom line */
g.context.botlx = 1;
gc.context.botlx = 1;
bot();
}
}