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:
@@ -40,17 +40,17 @@ extern "C" {
|
||||
/* check whether plname[] is among the list of generic user names */
|
||||
static bool generic_plname()
|
||||
{
|
||||
if (*g.plname) {
|
||||
if (*gp.plname) {
|
||||
const char *sptr, *p;
|
||||
const char *genericusers = sysopt.genericusers;
|
||||
int ln = (int) strlen(g.plname);
|
||||
int ln = (int) strlen(gp.plname);
|
||||
|
||||
if (!genericusers || !*genericusers)
|
||||
genericusers = "player games";
|
||||
else if (!strcmp(genericusers, "*")) /* "*" => always ask for name */
|
||||
return true;
|
||||
|
||||
while ((sptr = strstri(genericusers, g.plname)) != NULL) {
|
||||
while ((sptr = strstri(genericusers, gp.plname)) != NULL) {
|
||||
/* check for full word: start of list or following a space */
|
||||
if ((sptr == genericusers || sptr[-1] == ' ')
|
||||
/* and also preceding a space or at end of list */
|
||||
@@ -263,8 +263,8 @@ NetHackQtPlayerSelector::NetHackQtPlayerSelector(
|
||||
|
||||
// if plname[] contains a generic user name, clear it
|
||||
if (generic_plname())
|
||||
*g.plname = '\0';
|
||||
name->setText(g.plname);
|
||||
*gp.plname = '\0';
|
||||
name->setText(gp.plname);
|
||||
connect(name, SIGNAL(textChanged(const QString&)),
|
||||
this, SLOT(selectName(const QString&)));
|
||||
name->setFocus();
|
||||
@@ -545,7 +545,7 @@ void NetHackQtPlayerSelector::Randomize()
|
||||
// if plname[] is empty, disable [Play], otherwise [Play] is the default
|
||||
void NetHackQtPlayerSelector::plnamePlayVsQuit()
|
||||
{
|
||||
if (*g.plname) {
|
||||
if (*gp.plname) {
|
||||
play_btn->setEnabled(true);
|
||||
play_btn->setDefault(true);
|
||||
//quit_btn->setDefault(false);
|
||||
@@ -564,7 +564,7 @@ void NetHackQtPlayerSelector::selectName(const QString& n)
|
||||
// (it would be better to set up a validator that rejects leading spaces)
|
||||
while (*name_str == ' ')
|
||||
++name_str;
|
||||
str_copy(g.plname, name_str, PL_NSIZ);
|
||||
str_copy(gp.plname, name_str, PL_NSIZ);
|
||||
// possibly enable or disable the [Play] button
|
||||
plnamePlayVsQuit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user