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

@@ -884,7 +884,7 @@ void buffer_fill_to_end(cell_t * buffer, cell_t * fill, int x, int y)
while (dst != sentinel)
*dst++ = *fill;
if ((iflags.debug.immediateflips || !g.program_state.in_moveloop)
if ((iflags.debug.immediateflips || !gp.program_state.in_moveloop)
&& buffer == console.back_buffer)
back_buffer_flip();
}
@@ -900,7 +900,7 @@ static void buffer_clear_to_end_of_line(cell_t * buffer, int x, int y)
while (dst != sentinel)
*dst++ = clear_cell;
if (iflags.debug.immediateflips || !g.program_state.in_moveloop)
if (iflags.debug.immediateflips || !gp.program_state.in_moveloop)
back_buffer_flip();
}
@@ -912,7 +912,7 @@ void buffer_write(cell_t * buffer, cell_t * cell, COORD pos)
cell_t * dst = buffer + (console.width * pos.Y) + pos.X;
*dst = *cell;
if ((iflags.debug.immediateflips || !g.program_state.in_moveloop)
if ((iflags.debug.immediateflips || !gp.program_state.in_moveloop)
&& buffer == console.back_buffer)
back_buffer_flip();
}
@@ -1071,7 +1071,7 @@ process_keystroke(
int ch;
#ifdef QWERTZ_SUPPORT
if (g.Cmd.swap_yz)
if (gc.Cmd.swap_yz)
numberpad |= 0x10;
#endif
ch = keyboard_handling.pProcessKeystroke(
@@ -1103,11 +1103,11 @@ tgetch(void)
if (iflags.debug_fuzzer)
return randomkey();
#ifdef QWERTZ_SUPPORT
if (g.Cmd.swap_yz)
if (gc.Cmd.swap_yz)
numpad |= 0x10;
#endif
return (g.program_state.done_hup)
return (gp.program_state.done_hup)
? '\033'
: keyboard_handling.pCheckInput(
console.hConIn, &ir, &count, numpad, 0, &mod, &cc);
@@ -1132,10 +1132,10 @@ console_poskey(coordxy *x, coordxy *y, int *mod)
return poskey;
}
#ifdef QWERTZ_SUPPORT
if (g.Cmd.swap_yz)
if (gc.Cmd.swap_yz)
numpad |= 0x10;
#endif
ch = (g.program_state.done_hup)
ch = (gp.program_state.done_hup)
? '\033'
: keyboard_handling.pCheckInput(
console.hConIn, &ir, &count, numpad, 1, mod, &cc);
@@ -2104,8 +2104,8 @@ check_font_widths(void)
boolean used[256];
memset(used, 0, sizeof(used));
for (int i = 0; i < SYM_MAX; i++) {
used[g.primary_syms[i]] = TRUE;
used[g.rogue_syms[i]] = TRUE;
used[gp.primary_syms[i]] = TRUE;
used[gr.rogue_syms[i]] = TRUE;
}
int wcUsedCount = 0;

View File

@@ -263,16 +263,16 @@ set_default_prefix_locations(const char *programPath)
if (test_portable_config(executable_path,
portable_device_path, sizeof portable_device_path)) {
g.fqn_prefix[SYSCONFPREFIX] = executable_path;
g.fqn_prefix[CONFIGPREFIX] = portable_device_path;
g.fqn_prefix[HACKPREFIX] = portable_device_path;
g.fqn_prefix[SAVEPREFIX] = portable_device_path;
g.fqn_prefix[LEVELPREFIX] = portable_device_path;
g.fqn_prefix[BONESPREFIX] = portable_device_path;
g.fqn_prefix[SCOREPREFIX] = portable_device_path;
g.fqn_prefix[LOCKPREFIX] = portable_device_path;
g.fqn_prefix[TROUBLEPREFIX] = portable_device_path;
g.fqn_prefix[DATAPREFIX] = executable_path;
gf.fqn_prefix[SYSCONFPREFIX] = executable_path;
gf.fqn_prefix[CONFIGPREFIX] = portable_device_path;
gf.fqn_prefix[HACKPREFIX] = portable_device_path;
gf.fqn_prefix[SAVEPREFIX] = portable_device_path;
gf.fqn_prefix[LEVELPREFIX] = portable_device_path;
gf.fqn_prefix[BONESPREFIX] = portable_device_path;
gf.fqn_prefix[SCOREPREFIX] = portable_device_path;
gf.fqn_prefix[LOCKPREFIX] = portable_device_path;
gf.fqn_prefix[TROUBLEPREFIX] = portable_device_path;
gf.fqn_prefix[DATAPREFIX] = executable_path;
} else {
if(!build_known_folder_path(&FOLDERID_Profile, profile_path,
sizeof(profile_path), FALSE))
@@ -290,16 +290,16 @@ set_default_prefix_locations(const char *programPath)
versioned_global_data_path, sizeof(versioned_global_data_path), TRUE))
strcpy(versioned_global_data_path, executable_path);
g.fqn_prefix[SYSCONFPREFIX] = versioned_global_data_path;
g.fqn_prefix[CONFIGPREFIX] = profile_path;
g.fqn_prefix[HACKPREFIX] = versioned_profile_path;
g.fqn_prefix[SAVEPREFIX] = versioned_user_data_path;
g.fqn_prefix[LEVELPREFIX] = versioned_user_data_path;
g.fqn_prefix[BONESPREFIX] = versioned_global_data_path;
g.fqn_prefix[SCOREPREFIX] = versioned_global_data_path;
g.fqn_prefix[LOCKPREFIX] = versioned_global_data_path;
g.fqn_prefix[TROUBLEPREFIX] = versioned_profile_path;
g.fqn_prefix[DATAPREFIX] = executable_path;
gf.fqn_prefix[SYSCONFPREFIX] = versioned_global_data_path;
gf.fqn_prefix[CONFIGPREFIX] = profile_path;
gf.fqn_prefix[HACKPREFIX] = versioned_profile_path;
gf.fqn_prefix[SAVEPREFIX] = versioned_user_data_path;
gf.fqn_prefix[LEVELPREFIX] = versioned_user_data_path;
gf.fqn_prefix[BONESPREFIX] = versioned_global_data_path;
gf.fqn_prefix[SCOREPREFIX] = versioned_global_data_path;
gf.fqn_prefix[LOCKPREFIX] = versioned_global_data_path;
gf.fqn_prefix[TROUBLEPREFIX] = versioned_profile_path;
gf.fqn_prefix[DATAPREFIX] = executable_path;
}
}
@@ -370,18 +370,18 @@ void copy_sysconf_content(void)
/* Using the SYSCONFPREFIX path, lock it so that it does not change */
fqn_prefix_locked[SYSCONFPREFIX] = TRUE;
update_file(g.fqn_prefix[SYSCONFPREFIX], SYSCF_TEMPLATE,
g.fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE, FALSE);
update_file(gf.fqn_prefix[SYSCONFPREFIX], SYSCF_TEMPLATE,
gf.fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE, FALSE);
// update_file(g.fqn_prefix[SYSCONFPREFIX], SYMBOLS_TEMPLATE,
// g.fqn_prefix[DATAPREFIX], SYMBOLS_TEMPLATE, FALSE);
// update_file(gf.fqn_prefix[SYSCONFPREFIX], SYMBOLS_TEMPLATE,
// gf.fqn_prefix[DATAPREFIX], SYMBOLS_TEMPLATE, FALSE);
/* If the required early game file does not exist, copy it */
copy_file(g.fqn_prefix[SYSCONFPREFIX], SYSCF_FILE,
g.fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE);
copy_file(gf.fqn_prefix[SYSCONFPREFIX], SYSCF_FILE,
gf.fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE);
update_file(g.fqn_prefix[SYSCONFPREFIX], SYMBOLS,
g.fqn_prefix[DATAPREFIX], SYMBOLS, TRUE);
update_file(gf.fqn_prefix[SYSCONFPREFIX], SYMBOLS,
gf.fqn_prefix[DATAPREFIX], SYMBOLS, TRUE);
}
@@ -391,13 +391,13 @@ void copy_config_content(void)
fqn_prefix_locked[CONFIGPREFIX] = TRUE;
/* Keep templates up to date */
update_file(g.fqn_prefix[CONFIGPREFIX], CONFIG_TEMPLATE,
g.fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE, FALSE);
update_file(gf.fqn_prefix[CONFIGPREFIX], CONFIG_TEMPLATE,
gf.fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE, FALSE);
/* If the required early game file does not exist, copy it */
/* NOTE: We never replace .nethackrc or sysconf */
copy_file(g.fqn_prefix[CONFIGPREFIX], CONFIG_FILE,
g.fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE);
copy_file(gf.fqn_prefix[CONFIGPREFIX], CONFIG_FILE,
gf.fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE);
}
void
@@ -406,10 +406,10 @@ copy_hack_content(void)
nhassert(fqn_prefix_locked[HACKPREFIX]);
/* Keep Guidebook and opthelp up to date */
update_file(g.fqn_prefix[HACKPREFIX], GUIDEBOOK_FILE,
g.fqn_prefix[DATAPREFIX], GUIDEBOOK_FILE, FALSE);
update_file(g.fqn_prefix[HACKPREFIX], OPTIONFILE,
g.fqn_prefix[DATAPREFIX], OPTIONFILE, FALSE);
update_file(gf.fqn_prefix[HACKPREFIX], GUIDEBOOK_FILE,
gf.fqn_prefix[DATAPREFIX], GUIDEBOOK_FILE, FALSE);
update_file(gf.fqn_prefix[HACKPREFIX], OPTIONFILE,
gf.fqn_prefix[DATAPREFIX], OPTIONFILE, FALSE);
}
extern const char *known_handling[]; /* symbols.c */
extern const char *known_restrictions[]; /* symbols.c */
@@ -466,7 +466,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
#endif
#endif
g.hname = "NetHack"; /* used for syntax messages */
gh.hname = "NetHack"; /* used for syntax messages */
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
/* Save current directory and make sure it gets restored when
@@ -479,7 +479,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
set_default_prefix_locations(argv[0]);
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdir(g.fqn_prefix[HACKPREFIX]);
chdir(gf.fqn_prefix[HACKPREFIX]);
#endif
if (GUILaunched || IsDebuggerPresent())
@@ -544,8 +544,8 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
Strcpy(default_window_sys, "curses");
#endif /* CURSES */
#endif /* TTY */
if (iflags.windowtype_deferred && g.chosen_windowtype[0])
windowtype = g.chosen_windowtype;
if (iflags.windowtype_deferred && gc.chosen_windowtype[0])
windowtype = gc.chosen_windowtype;
}
choose_windows(windowtype);
@@ -564,8 +564,8 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
if (WINDOWPORT(tty))
toggle_mouse_support();
if (g.symset[PRIMARYSET].handling
&& !symset_is_compatible(g.symset[PRIMARYSET].handling,
if (gs.symset[PRIMARYSET].handling
&& !symset_is_compatible(gs.symset[PRIMARYSET].handling,
windowprocs.wincap2)) {
/* current symset handling and windowtype are
not compatible, feature-wise. Use IBM defaults */
@@ -591,21 +591,21 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
(*utf8graphics_mode_callback)();
#endif
/* strip role,race,&c suffix; calls askname() if g.plname[] is empty
/* strip role,race,&c suffix; calls askname() if gp.plname[] is empty
or holds a generic user name like "player" or "games" */
plnamesuffix();
set_playmode(); /* sets g.plname to "wizard" for wizard mode */
set_playmode(); /* sets gp.plname to "wizard" for wizard mode */
/* until the getlock code is resolved, override askname()'s
setting of renameallowed; when False, player_selection()
won't resent renaming as an option */
iflags.renameallowed = FALSE;
/* Obtain the name of the logged on user and incorporate
* it into the name. */
Sprintf(fnamebuf, "%s", g.plname);
Sprintf(fnamebuf, "%s", gp.plname);
(void) fname_encode(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.", '%',
fnamebuf, encodedfnamebuf, BUFSZ);
Sprintf(g.lock, "%s", encodedfnamebuf);
Sprintf(gl.lock, "%s", encodedfnamebuf);
/* regularize(lock); */ /* we encode now, rather than substitute */
if ((getlock_result = getlock()) == 0)
nethack_exit(EXIT_SUCCESS);
@@ -619,8 +619,8 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
if (!nhfp) {
raw_print("Cannot create lock file");
} else {
g.hackpid = GetCurrentProcessId();
write(nhfp->fd, (genericptr_t) &g.hackpid, sizeof(g.hackpid));
gh.hackpid = GetCurrentProcessId();
write(nhfp->fd, (genericptr_t) &gh.hackpid, sizeof(gh.hackpid));
close_nhfile(nhfp);
}
/*
@@ -641,7 +641,7 @@ attempt_restore:
iflags.news = FALSE;
}
#endif
if (g.early_raw_messages)
if (ge.early_raw_messages)
raw_print("Restoring save file...");
else
pline("Restoring save file...");
@@ -654,12 +654,12 @@ attempt_restore:
if (yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile();
else {
nh_compress(fqname(g.SAVEF, SAVEPREFIX, 0));
nh_compress(fqname(gs.SAVEF, SAVEPREFIX, 0));
}
}
}
if (g.program_state.in_self_recover) {
g.program_state.in_self_recover = FALSE;
if (gp.program_state.in_self_recover) {
gp.program_state.in_self_recover = FALSE;
set_savefile_name(TRUE);
}
}
@@ -744,7 +744,7 @@ process_options(int argc, char * argv[])
}
if (!*dir)
error("Flag -d must be followed by a directory name.");
Strcpy(g.hackdir, dir);
Strcpy(gh.hackdir, dir);
}
if (argc > 1) {
@@ -801,11 +801,11 @@ process_options(int argc, char * argv[])
#endif
case 'u':
if (argv[0][2])
(void) strncpy(g.plname, argv[0] + 2, sizeof(g.plname) - 1);
(void) strncpy(gp.plname, argv[0] + 2, sizeof(gp.plname) - 1);
else if (argc > 1) {
argc--;
argv++;
(void) strncpy(g.plname, argv[0], sizeof(g.plname) - 1);
(void) strncpy(gp.plname, argv[0], sizeof(gp.plname) - 1);
} else
raw_print("Player name expected after -u");
break;
@@ -845,7 +845,7 @@ process_options(int argc, char * argv[])
case 'w': /* windowtype */
config_error_init(FALSE, "command line", FALSE);
if (strlen(&argv[0][2]) < (WINTYPELEN - 1))
Strcpy(g.chosen_windowtype, &argv[0][2]);
Strcpy(gc.chosen_windowtype, &argv[0][2]);
config_error_done();
break;
case '@':
@@ -882,18 +882,18 @@ nhusage(void)
*/
(void) Sprintf(buf2, "\nUsage:\n%s [-d dir] -s [-r race] [-p profession] "
"[maxrank] [name]...\n or",
g.hname);
gh.hname);
ADD_USAGE(buf2);
(void) Sprintf(
buf2, "\n%s [-d dir] [-u name] [-r race] [-p profession] [-[DX]]",
g.hname);
gh.hname);
ADD_USAGE(buf2);
#ifdef NEWS
ADD_USAGE(" [-n]");
#endif
(void) Sprintf(buf2, "\n or\n%s [--showpaths]",
g.hname);
gh.hname);
ADD_USAGE(buf2);
if (!iflags.window_inited)
raw_printf("%s\n", buf1);
@@ -928,7 +928,7 @@ port_help(void)
boolean
authorize_wizard_mode(void)
{
if (!strcmp(g.plname, WIZARD_NAME))
if (!strcmp(gp.plname, WIZARD_NAME))
return TRUE;
return FALSE;
}
@@ -1141,14 +1141,14 @@ eraseoldlocks(void)
*/
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);
set_levelfile_name(gl.lock, 0);
#ifdef HOLD_LOCKFILE_OPEN
really_close();
#endif
if (unlink(fqname(g.lock, LEVELPREFIX, 0)))
if (unlink(fqname(gl.lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */
return (1); /* success! */
}
@@ -1178,9 +1178,9 @@ getlock(void)
}
/* 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);
if ((fd = open(fq_lock, 0)) == -1) {
if (errno == ENOENT)
goto gotlock; /* no such file */
@@ -1261,11 +1261,11 @@ gotlock:
#endif
Sprintf(oops, "cannot creat file (%s.)\n%s\n%s\"%s\" exists?\n", fq_lock,
strerror(ern), " Are you sure that the directory",
g.fqn_prefix[LEVELPREFIX]);
gf.fqn_prefix[LEVELPREFIX]);
raw_print(oops);
} 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)) {
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif