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:
@@ -459,7 +459,7 @@ plselInitDialog(HWND hWnd)
|
||||
TCHAR wbuf[BUFSZ];
|
||||
|
||||
/* set player name */
|
||||
SetDlgItemText(hWnd, IDC_PLSEL_NAME, NH_A2W(g.plname, wbuf, sizeof(wbuf)));
|
||||
SetDlgItemText(hWnd, IDC_PLSEL_NAME, NH_A2W(gp.plname, wbuf, sizeof(wbuf)));
|
||||
|
||||
/* check flags for consistency */
|
||||
if (flags.initrole >= 0) {
|
||||
|
||||
@@ -39,7 +39,7 @@ mswin_have_input()
|
||||
return
|
||||
#ifdef SAFERHANGUP
|
||||
/* we always have input (ESC) if hangup was requested */
|
||||
g.program_state.done_hup ||
|
||||
gp.program_state.done_hup ||
|
||||
#endif
|
||||
(nhi_read_pos != nhi_write_pos);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ mswin_input_pop()
|
||||
|
||||
#ifdef SAFERHANGUP
|
||||
/* always return ESC when hangup was requested */
|
||||
if (g.program_state.done_hup) {
|
||||
if (gp.program_state.done_hup) {
|
||||
static MSNHEvent hangup_event;
|
||||
hangup_event.type = NHEVENT_CHAR;
|
||||
hangup_event.kbd.ch = '\033';
|
||||
@@ -98,7 +98,7 @@ mswin_input_peek()
|
||||
|
||||
#ifdef SAFERHANGUP
|
||||
/* always return ESC when hangup was requested */
|
||||
if (g.program_state.done_hup) {
|
||||
if (gp.program_state.done_hup) {
|
||||
static MSNHEvent hangup_event;
|
||||
hangup_event.type = NHEVENT_CHAR;
|
||||
hangup_event.kbd.ch = '\033';
|
||||
|
||||
@@ -826,7 +826,7 @@ mswin_layout_main_window(HWND changed_child)
|
||||
/* show command window only if it exists and
|
||||
the game is ready (plname is set) */
|
||||
if (GetNHApp()->bCmdPad && cmd_size.cx > 0 && cmd_size.cy > 0
|
||||
&& *g.plname) {
|
||||
&& *gp.plname) {
|
||||
MoveWindow(GetNHApp()->hCmdWnd, cmd_org.x, cmd_org.y, cmd_size.cx,
|
||||
cmd_size.cy, TRUE);
|
||||
ShowWindow(GetNHApp()->hCmdWnd, SW_SHOW);
|
||||
|
||||
@@ -533,7 +533,7 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
if (!data->text.text) {
|
||||
data->text.text = mswin_init_text_buffer(
|
||||
g.program_state.gameover ? FALSE : GetNHApp()->bWrapText);
|
||||
gp.program_state.gameover ? FALSE : GetNHApp()->bWrapText);
|
||||
if (!data->text.text)
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ FormatStatusString(char *text, int format)
|
||||
int hp, hpmax;
|
||||
int cap = near_capacity();
|
||||
|
||||
Strcpy(text, g.plname);
|
||||
Strcpy(text, gp.plname);
|
||||
if ('a' <= text[0] && text[0] <= 'z')
|
||||
text[0] += 'A' - 'a';
|
||||
text[10] = 0;
|
||||
@@ -237,7 +237,7 @@ FormatStatusString(char *text, int format)
|
||||
hp = 0;
|
||||
(void) describe_level(nb = eos(nb));
|
||||
Sprintf(nb = eos(nb), "%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d",
|
||||
showsyms[COIN_CLASS + SYM_OFF_O], money_cnt(g.invent), hp, hpmax,
|
||||
showsyms[COIN_CLASS + SYM_OFF_O], money_cnt(gi.invent), hp, hpmax,
|
||||
u.uen, u.uenmax, u.uac);
|
||||
|
||||
if (Upolyd)
|
||||
@@ -253,7 +253,7 @@ FormatStatusString(char *text, int format)
|
||||
|
||||
/* forth line */
|
||||
if (flags.time)
|
||||
Sprintf(nb = eos(nb), "T:%ld ", g.moves);
|
||||
Sprintf(nb = eos(nb), "T:%ld ", gm.moves);
|
||||
|
||||
if (strcmp(hu_stat[u.uhs], " ")) {
|
||||
Strcat(text, hu_stat[u.uhs]);
|
||||
|
||||
@@ -39,7 +39,7 @@ mswin_init_text_window()
|
||||
|
||||
ZeroMemory(data, sizeof(NHTextWindow));
|
||||
data->window_text = mswin_init_text_buffer(
|
||||
g.program_state.gameover ? FALSE : GetNHApp()->bWrapText);
|
||||
gp.program_state.gameover ? FALSE : GetNHApp()->bWrapText);
|
||||
SetWindowLong(ret, GWL_USERDATA, (LONG) data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -646,7 +646,7 @@ mswin_askname(void)
|
||||
{
|
||||
logDebug("mswin_askname()\n");
|
||||
|
||||
if (mswin_getlin_window("who are you?", g.plname, PL_NSIZ) == IDCANCEL) {
|
||||
if (mswin_getlin_window("who are you?", gp.plname, PL_NSIZ) == IDCANCEL) {
|
||||
bail("bye-bye");
|
||||
/* not reached */
|
||||
}
|
||||
@@ -1927,7 +1927,7 @@ NHSPhoneDialogSetup(HWND hDlg, UINT nToolBarId, BOOL is_edit,
|
||||
|
||||
rtDlg.bottom -= rtOK.bottom - rtOK.top;
|
||||
ShowWindow(hOK, SW_HIDE);
|
||||
SetWindowPos(hDlg, HWND_TOP, 0, 0, rtDlg.right - rtDlg.left,
|
||||
SetWindowPos(hDlg, HWND_TOP, 0, 0, rtDlgr.right - rtDlg.left,
|
||||
rtDlg.bottom - rtDlg.top,
|
||||
SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
@@ -167,11 +167,11 @@ eraseoldlocks()
|
||||
*/
|
||||
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
|
||||
/* try to remove all */
|
||||
set_levelfile_name(g.lock, i);
|
||||
(void) unlink(fqname(g.lock, LEVELPREFIX, 0));
|
||||
set_levelfile_name(gl.lock, i);
|
||||
(void) unlink(fqname(gl.lock, LEVELPREFIX, 0));
|
||||
}
|
||||
set_levelfile_name(g.lock, 0);
|
||||
if (unlink(fqname(g.lock, LEVELPREFIX, 0)))
|
||||
set_levelfile_name(gl.lock, 0);
|
||||
if (unlink(fqname(gl.lock, LEVELPREFIX, 0)))
|
||||
return 0; /* cannot remove it */
|
||||
return (1); /* success! */
|
||||
}
|
||||
@@ -187,9 +187,9 @@ getlock()
|
||||
int choice;
|
||||
|
||||
/* regularize(lock); */ /* already done in pcmain */
|
||||
Sprintf(tbuf, "%s", fqname(g.lock, LEVELPREFIX, 0));
|
||||
set_levelfile_name(g.lock, 0);
|
||||
fq_lock = fqname(g.lock, LEVELPREFIX, 1);
|
||||
Sprintf(tbuf, "%s", fqname(gl.lock, LEVELPREFIX, 0));
|
||||
set_levelfile_name(gl.lock, 0);
|
||||
fq_lock = fqname(gl.lock, LEVELPREFIX, 1);
|
||||
|
||||
f = CreateFile(NH_A2W(fq_lock, wbuf, BUFSZ), GENERIC_READ, 0, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
@@ -226,8 +226,8 @@ gotlock:
|
||||
if (fd == -1) {
|
||||
error("cannot creat lock file (%s.)", fq_lock);
|
||||
} else {
|
||||
if (write(fd, (char *) &g.hackpid, sizeof(g.hackpid))
|
||||
!= sizeof(g.hackpid)) {
|
||||
if (write(fd, (char *) &gh.hackpid, sizeof(gh.hackpid))
|
||||
!= sizeof(gh.hackpid)) {
|
||||
error("cannot write lock (%s)", fq_lock);
|
||||
}
|
||||
if (close(fd) == -1) {
|
||||
|
||||
Reference in New Issue
Block a user