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:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user