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:
88
src/pline.c
88
src/pline.c
@@ -30,8 +30,8 @@ dumplogmsg(const char *line)
|
||||
* The core should take responsibility for that and have
|
||||
* this share it.
|
||||
*/
|
||||
unsigned indx = g.saved_pline_index; /* next slot to use */
|
||||
char *oldest = g.saved_plines[indx]; /* current content of that slot */
|
||||
unsigned indx = gs.saved_pline_index; /* next slot to use */
|
||||
char *oldest = gs.saved_plines[indx]; /* current content of that slot */
|
||||
|
||||
if (!strncmp(line, "Unknown command", 15))
|
||||
return;
|
||||
@@ -42,9 +42,9 @@ dumplogmsg(const char *line)
|
||||
} else {
|
||||
if (oldest)
|
||||
free((genericptr_t) oldest);
|
||||
g.saved_plines[indx] = dupstr(line);
|
||||
gs.saved_plines[indx] = dupstr(line);
|
||||
}
|
||||
g.saved_pline_index = (indx + 1) % DUMPLOG_MSG_COUNT;
|
||||
gs.saved_pline_index = (indx + 1) % DUMPLOG_MSG_COUNT;
|
||||
}
|
||||
|
||||
/* called during save (unlike the interface-specific message history,
|
||||
@@ -56,9 +56,9 @@ dumplogfreemessages(void)
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < DUMPLOG_MSG_COUNT; ++i)
|
||||
if (g.saved_plines[i])
|
||||
free((genericptr_t) g.saved_plines[i]), g.saved_plines[i] = 0;
|
||||
g.saved_pline_index = 0;
|
||||
if (gs.saved_plines[i])
|
||||
free((genericptr_t) gs.saved_plines[i]), gs.saved_plines[i] = 0;
|
||||
gs.saved_pline_index = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -68,10 +68,10 @@ putmesg(const char *line)
|
||||
{
|
||||
int attr = ATR_NONE;
|
||||
|
||||
if ((g.pline_flags & URGENT_MESSAGE) != 0
|
||||
if ((gp.pline_flags & URGENT_MESSAGE) != 0
|
||||
&& (windowprocs.wincap2 & WC2_URGENT_MESG) != 0)
|
||||
attr |= ATR_URGENT;
|
||||
if ((g.pline_flags & SUPPRESS_HISTORY) != 0
|
||||
if ((gp.pline_flags & SUPPRESS_HISTORY) != 0
|
||||
&& (windowprocs.wincap2 & WC2_SUPPRESS_HIST) != 0)
|
||||
attr |= ATR_NOHISTORY;
|
||||
|
||||
@@ -107,10 +107,10 @@ vpline(const char *line, va_list the_args)
|
||||
if (!line || !*line)
|
||||
return;
|
||||
#ifdef HANGUPHANDLING
|
||||
if (g.program_state.done_hup)
|
||||
if (gp.program_state.done_hup)
|
||||
return;
|
||||
#endif
|
||||
if (g.program_state.wizkit_wishing)
|
||||
if (gp.program_state.wizkit_wishing)
|
||||
return;
|
||||
|
||||
if (strchr(line, '%')) {
|
||||
@@ -149,7 +149,7 @@ vpline(const char *line, va_list the_args)
|
||||
* Unfortunately, that means Norep() isn't honored (general issue) and
|
||||
* that short lines aren't combined into one longer one (tty behavior).
|
||||
*/
|
||||
if ((g.pline_flags & SUPPRESS_HISTORY) == 0)
|
||||
if ((gp.pline_flags & SUPPRESS_HISTORY) == 0)
|
||||
dumplogmsg(line);
|
||||
#endif
|
||||
/* use raw_print() if we're called too early (or perhaps too late
|
||||
@@ -162,16 +162,16 @@ vpline(const char *line, va_list the_args)
|
||||
goto pline_done;
|
||||
}
|
||||
|
||||
no_repeat = (g.pline_flags & PLINE_NOREPEAT) ? TRUE : FALSE;
|
||||
if ((g.pline_flags & OVERRIDE_MSGTYPE) == 0) {
|
||||
no_repeat = (gp.pline_flags & PLINE_NOREPEAT) ? TRUE : FALSE;
|
||||
if ((gp.pline_flags & OVERRIDE_MSGTYPE) == 0) {
|
||||
msgtyp = msgtype_type(line, no_repeat);
|
||||
#ifdef USER_SOUNDS
|
||||
if (msgtyp == MSGTYP_NORMAL || msgtyp == MSGTYP_NOSHOW)
|
||||
maybe_play_sound(line);
|
||||
#endif
|
||||
if ((g.pline_flags & URGENT_MESSAGE) == 0
|
||||
if ((gp.pline_flags & URGENT_MESSAGE) == 0
|
||||
&& (msgtyp == MSGTYP_NOSHOW
|
||||
|| (msgtyp == MSGTYP_NOREP && !strcmp(line, g.prevmsg))))
|
||||
|| (msgtyp == MSGTYP_NOREP && !strcmp(line, gp.prevmsg))))
|
||||
/* FIXME: we need a way to tell our caller that this message
|
||||
* was suppressed so that caller doesn't set iflags.last_msg
|
||||
* for something that hasn't been shown, otherwise a subsequent
|
||||
@@ -182,7 +182,7 @@ vpline(const char *line, va_list the_args)
|
||||
goto pline_done;
|
||||
}
|
||||
|
||||
if (g.vision_full_recalc)
|
||||
if (gv.vision_full_recalc)
|
||||
vision_recalc(0);
|
||||
if (u.ux)
|
||||
flush_screen(1); /* %% */
|
||||
@@ -195,7 +195,7 @@ vpline(const char *line, va_list the_args)
|
||||
|
||||
/* this gets cleared after every pline message */
|
||||
iflags.last_msg = PLNMSG_UNKNOWN;
|
||||
(void) strncpy(g.prevmsg, line, BUFSZ), g.prevmsg[BUFSZ - 1] = '\0';
|
||||
(void) strncpy(gp.prevmsg, line, BUFSZ), gp.prevmsg[BUFSZ - 1] = '\0';
|
||||
if (msgtyp == MSGTYP_STOP)
|
||||
display_nhwindow(WIN_MESSAGE, TRUE); /* --more-- */
|
||||
|
||||
@@ -214,9 +214,9 @@ custompline(unsigned pflags, const char *line, ...)
|
||||
va_list the_args;
|
||||
|
||||
va_start(the_args, line);
|
||||
g.pline_flags = pflags;
|
||||
gp.pline_flags = pflags;
|
||||
vpline(line, the_args);
|
||||
g.pline_flags = 0;
|
||||
gp.pline_flags = 0;
|
||||
va_end(the_args);
|
||||
}
|
||||
|
||||
@@ -230,9 +230,9 @@ urgent_pline(const char *line, ...)
|
||||
va_list the_args;
|
||||
|
||||
va_start(the_args, line);
|
||||
g.pline_flags = URGENT_MESSAGE;
|
||||
gp.pline_flags = URGENT_MESSAGE;
|
||||
vpline(line, the_args);
|
||||
g.pline_flags = 0;
|
||||
gp.pline_flags = 0;
|
||||
va_end(the_args);
|
||||
}
|
||||
|
||||
@@ -242,30 +242,30 @@ Norep(const char *line, ...)
|
||||
va_list the_args;
|
||||
|
||||
va_start(the_args, line);
|
||||
g.pline_flags = PLINE_NOREPEAT;
|
||||
gp.pline_flags = PLINE_NOREPEAT;
|
||||
vpline(line, the_args);
|
||||
g.pline_flags = 0;
|
||||
gp.pline_flags = 0;
|
||||
va_end(the_args);
|
||||
}
|
||||
|
||||
static char *
|
||||
You_buf(int siz)
|
||||
{
|
||||
if (siz > g.you_buf_siz) {
|
||||
if (g.you_buf)
|
||||
free((genericptr_t) g.you_buf);
|
||||
g.you_buf_siz = siz + 10;
|
||||
g.you_buf = (char *) alloc((unsigned) g.you_buf_siz);
|
||||
if (siz > gy.you_buf_siz) {
|
||||
if (gy.you_buf)
|
||||
free((genericptr_t) gy.you_buf);
|
||||
gy.you_buf_siz = siz + 10;
|
||||
gy.you_buf = (char *) alloc((unsigned) gy.you_buf_siz);
|
||||
}
|
||||
return g.you_buf;
|
||||
return gy.you_buf;
|
||||
}
|
||||
|
||||
void
|
||||
free_youbuf(void)
|
||||
{
|
||||
if (g.you_buf)
|
||||
free((genericptr_t) g.you_buf), g.you_buf = (char *) 0;
|
||||
g.you_buf_siz = 0;
|
||||
if (gy.you_buf)
|
||||
free((genericptr_t) gy.you_buf), gy.you_buf = (char *) 0;
|
||||
gy.you_buf_siz = 0;
|
||||
}
|
||||
|
||||
/* `prefix' must be a string literal, not a pointer */
|
||||
@@ -406,7 +406,7 @@ void
|
||||
gamelog_add(long glflags, long gltime, const char *str)
|
||||
{
|
||||
struct gamelog_line *tmp;
|
||||
struct gamelog_line *lst = g.gamelog;
|
||||
struct gamelog_line *lst = gg.gamelog;
|
||||
|
||||
tmp = (struct gamelog_line *) alloc(sizeof (struct gamelog_line));
|
||||
tmp->turn = gltime;
|
||||
@@ -416,7 +416,7 @@ gamelog_add(long glflags, long gltime, const char *str)
|
||||
while (lst && lst->next)
|
||||
lst = lst->next;
|
||||
if (!lst)
|
||||
g.gamelog = tmp;
|
||||
gg.gamelog = tmp;
|
||||
else
|
||||
lst->next = tmp;
|
||||
}
|
||||
@@ -431,7 +431,7 @@ livelog_printf(long ll_type, const char *line, ...)
|
||||
(void) vsnprintf(gamelogbuf, sizeof gamelogbuf, line, the_args);
|
||||
va_end(the_args);
|
||||
|
||||
gamelog_add(ll_type, g.moves, gamelogbuf);
|
||||
gamelog_add(ll_type, gm.moves, gamelogbuf);
|
||||
strNsubst(gamelogbuf, "\t", "_", 0);
|
||||
livelog_add(ll_type, gamelogbuf);
|
||||
}
|
||||
@@ -464,8 +464,8 @@ raw_printf(const char *line, ...)
|
||||
va_start(the_args, line);
|
||||
vraw_printf(line, the_args);
|
||||
va_end(the_args);
|
||||
if (!g.program_state.beyond_savefile_load)
|
||||
g.early_raw_messages++;
|
||||
if (!gp.program_state.beyond_savefile_load)
|
||||
ge.early_raw_messages++;
|
||||
}
|
||||
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL
|
||||
@@ -493,8 +493,8 @@ vraw_printf(const char *line, va_list the_args)
|
||||
#if defined(MSGHANDLER)
|
||||
execplinehandler(line);
|
||||
#endif
|
||||
if (!g.program_state.beyond_savefile_load)
|
||||
g.early_raw_messages++;
|
||||
if (!gp.program_state.beyond_savefile_load)
|
||||
ge.early_raw_messages++;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -504,10 +504,10 @@ impossible(const char *s, ...)
|
||||
char pbuf[BIGBUFSZ]; /* will be chopped down to BUFSZ-1 if longer */
|
||||
|
||||
va_start(the_args, s);
|
||||
if (g.program_state.in_impossible)
|
||||
if (gp.program_state.in_impossible)
|
||||
panic("impossible called impossible");
|
||||
|
||||
g.program_state.in_impossible = 1;
|
||||
gp.program_state.in_impossible = 1;
|
||||
#if !defined(NO_VSNPRINTF)
|
||||
(void) vsnprintf(pbuf, sizeof(pbuf), s, the_args);
|
||||
#else
|
||||
@@ -521,7 +521,7 @@ impossible(const char *s, ...)
|
||||
pline("%s", pbuf);
|
||||
/* reuse pbuf[] */
|
||||
Strcpy(pbuf, "Program in disorder!");
|
||||
if (g.program_state.something_worth_saving)
|
||||
if (gp.program_state.something_worth_saving)
|
||||
Strcat(pbuf, " (Saving and reloading may fix this problem.)");
|
||||
pline("%s", pbuf);
|
||||
pline("Please report these messages to %s.", DEVTEAM_EMAIL);
|
||||
@@ -529,7 +529,7 @@ impossible(const char *s, ...)
|
||||
pline("Alternatively, contact local support: %s", sysopt.support);
|
||||
}
|
||||
|
||||
g.program_state.in_impossible = 0;
|
||||
gp.program_state.in_impossible = 0;
|
||||
}
|
||||
|
||||
RESTORE_WARNING_FORMAT_NONLITERAL
|
||||
|
||||
Reference in New Issue
Block a user