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

@@ -226,7 +226,7 @@ void NetHackQtBind::qt_askname()
int ch = -1; // -1 => new game
have_asked = true;
str_copy(default_plname, g.plname, PL_NSIZ);
str_copy(default_plname, gp.plname, PL_NSIZ);
// We do it all here (plus qt_plsel.cpp and qt_svsel.cpp),
// nothing in player_selection().
@@ -241,9 +241,9 @@ void NetHackQtBind::qt_askname()
NetHackQtSavedGameSelector sgsel((const char **) saved);
ch = sgsel.choose();
if (ch >= 0)
str_copy(g.plname, saved[ch], SIZE(g.plname));
str_copy(gp.plname, saved[ch], SIZE(gp.plname));
// caller needs new lock name even if plname[] hasn't changed
// because successful get_saved_games() clobbers g.SAVEF[]
// because successful get_saved_games() clobbers gs.SAVEF[]
::iflags.renameinprogress = TRUE;
}
free_saved_games(saved);
@@ -271,10 +271,10 @@ void NetHackQtBind::qt_askname()
break;
}
if (!*g.plname)
if (!*gp.plname)
// in case Choose() returns with plname[] empty
Strcpy(g.plname, default_plname);
else if (strcmp(g.plname, default_plname) != 0)
Strcpy(gp.plname, default_plname);
else if (strcmp(gp.plname, default_plname) != 0)
// caller needs to set new lock file name
::iflags.renameinprogress = TRUE;
return;
@@ -487,7 +487,7 @@ void NetHackQtBind::qt_update_inventory(int arg UNUSED)
main->updateInventory(); // update the paper doll inventory subset
/* doesn't work yet
if (g.program_state.something_worth_saving && iflags.perm_invent)
if (gp.program_state.something_worth_saving && iflags.perm_invent)
display_inventory(NULL, false);
*/
}
@@ -641,7 +641,7 @@ char NetHackQtBind::qt_more()
// ^C comment in that routine] when the core triggers --More-- via
// done2() -> really_done() -> display_nhwindow(WIN_MESSAGE, TRUE)
// (get rid of this if the exec() loop issue gets properly fixed)
if (::g.program_state.gameover)
if (::gp.program_state.gameover)
return ch; // bypass --More-- and just continue with program exit
NetHackQtMessageWindow *mesgwin = main ? main->GetMessageWindow() : NULL;