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

@@ -95,7 +95,7 @@ pass_one(schar bg_typ, schar fg_typ)
}
}
#define new_loc(i, j) *(g.new_locations + ((j) * (WIDTH + 1)) + (i))
#define new_loc(i, j) *(gn.new_locations + ((j) * (WIDTH + 1)) + (i))
static void
pass_two(schar bg_typ, schar fg_typ)
@@ -169,10 +169,10 @@ flood_fill_rm(
sx++; /* compensate for extra decrement */
/* assume sx,sy is valid */
if (sx < g.min_rx)
g.min_rx = sx;
if (sy < g.min_ry)
g.min_ry = sy;
if (sx < gm.min_rx)
gm.min_rx = sx;
if (sy < gm.min_ry)
gm.min_ry = sy;
for (i = sx; i <= WIDTH && levl[i][sy].typ == fg_typ; i++) {
levl[i][sy].roomno = rmno;
@@ -195,7 +195,7 @@ flood_fill_rm(
levl[ii][jj].roomno = SHARED;
}
}
g.n_loc_filled++;
gn.n_loc_filled++;
}
nx = i;
@@ -236,10 +236,10 @@ flood_fill_rm(
}
}
if (nx > g.max_rx)
g.max_rx = nx - 1; /* nx is just past valid region */
if (sy > g.max_ry)
g.max_ry = sy;
if (nx > gm.max_rx)
gm.max_rx = nx - 1; /* nx is just past valid region */
if (sy > gm.max_ry)
gm.max_ry = sy;
}
/* join_map uses temporary rooms; clean up after it */
@@ -251,8 +251,8 @@ join_map_cleanup(void)
for (x = 1; x < COLNO; x++)
for (y = 0; y < ROWNO; y++)
levl[x][y].roomno = NO_ROOM;
g.nroom = g.nsubroom = 0;
g.rooms[g.nroom].hx = g.subrooms[g.nsubroom].hx = -1;
gn.nroom = gn.nsubroom = 0;
gr.rooms[gn.nroom].hx = gs.subrooms[gn.nsubroom].hx = -1;
}
static void
@@ -269,25 +269,25 @@ join_map(schar bg_typ, schar fg_typ)
for (i = 2; i <= WIDTH; i++)
for (j = 1; j < HEIGHT; j++) {
if (levl[i][j].typ == fg_typ && levl[i][j].roomno == NO_ROOM) {
g.min_rx = g.max_rx = i;
g.min_ry = g.max_ry = j;
g.n_loc_filled = 0;
flood_fill_rm(i, j, g.nroom + ROOMOFFSET, FALSE, FALSE);
if (g.n_loc_filled > 3) {
add_room(g.min_rx, g.min_ry, g.max_rx, g.max_ry,
gm.min_rx = gm.max_rx = i;
gm.min_ry = gm.max_ry = j;
gn.n_loc_filled = 0;
flood_fill_rm(i, j, gn.nroom + ROOMOFFSET, FALSE, FALSE);
if (gn.n_loc_filled > 3) {
add_room(gm.min_rx, gm.min_ry, gm.max_rx, gm.max_ry,
FALSE, OROOM, TRUE);
g.rooms[g.nroom - 1].irregular = TRUE;
if (g.nroom >= (MAXNROFROOMS * 2))
gr.rooms[gn.nroom - 1].irregular = TRUE;
if (gn.nroom >= (MAXNROFROOMS * 2))
goto joinm;
} else {
/*
* it's a tiny hole; erase it from the map to avoid
* having the player end up here with no way out.
*/
for (sx = g.min_rx; sx <= g.max_rx; sx++)
for (sy = g.min_ry; sy <= g.max_ry; sy++)
for (sx = gm.min_rx; sx <= gm.max_rx; sx++)
for (sy = gm.min_ry; sy <= gm.max_ry; sy++)
if ((int) levl[sx][sy].roomno
== g.nroom + ROOMOFFSET) {
== gn.nroom + ROOMOFFSET) {
levl[sx][sy].typ = bg_typ;
levl[sx][sy].roomno = NO_ROOM;
}
@@ -302,8 +302,8 @@ join_map(schar bg_typ, schar fg_typ)
* so don't call sort_rooms(), which can screw up the roomno's
* validity in the levl structure.
*/
for (croom = &g.rooms[0], croom2 = croom + 1;
croom2 < &g.rooms[g.nroom]; ) {
for (croom = &gr.rooms[0], croom2 = croom + 1;
croom2 < &gr.rooms[gn.nroom]; ) {
/* pick random starting and end locations for "corridor" */
if (!somexy(croom, &sm) || !somexy(croom2, &em)) {
/* ack! -- the level is going to be busted */
@@ -350,8 +350,8 @@ finish_map(
|| (bg_typ == TREE && levl[i][j].typ == bg_typ)
|| (walled && IS_WALL(levl[i][j].typ)))
levl[i][j].lit = TRUE;
for (i = 0; i < g.nroom; i++)
g.rooms[i].rlit = 1;
for (i = 0; i < gn.nroom; i++)
gr.rooms[i].rlit = 1;
}
/* light lava even if everything's otherwise unlit;
ice might be frozen pool rather than frozen moat */
@@ -383,8 +383,8 @@ remove_rooms(int lx, int ly, int hx, int hy)
int i;
struct mkroom *croom;
for (i = g.nroom - 1; i >= 0; --i) {
croom = &g.rooms[i];
for (i = gn.nroom - 1; i >= 0; --i) {
croom = &gr.rooms[i];
if (croom->hx < lx || croom->lx >= hx || croom->hy < ly
|| croom->ly >= hy)
continue; /* no overlap */
@@ -411,8 +411,8 @@ remove_rooms(int lx, int ly, int hx, int hy)
static void
remove_room(unsigned int roomno)
{
struct mkroom *croom = &g.rooms[roomno];
struct mkroom *maxroom = &g.rooms[--g.nroom];
struct mkroom *croom = &gr.rooms[roomno];
struct mkroom *maxroom = &gr.rooms[--gn.nroom];
int i, j;
unsigned oroomno;
@@ -424,7 +424,7 @@ remove_room(unsigned int roomno)
sizeof(struct mkroom));
/* since maxroom moved, update affected level roomno values */
oroomno = g.nroom + ROOMOFFSET;
oroomno = gn.nroom + ROOMOFFSET;
roomno += ROOMOFFSET;
for (i = croom->lx; i <= croom->hx; ++i)
for (j = croom->ly; j <= croom->hy; ++j) {
@@ -458,7 +458,7 @@ mkmap(lev_init* init_lev)
lit = litstate_rnd(lit);
g.new_locations = (char *) alloc((WIDTH + 1) * HEIGHT);
gn.new_locations = (char *) alloc((WIDTH + 1) * HEIGHT);
init_map(bg_typ);
init_fill(bg_typ, fg_typ);
@@ -480,10 +480,10 @@ mkmap(lev_init* init_lev)
init_lev->icedpools);
/* a walled, joined level is cavernous, not mazelike -dlc */
if (walled && join) {
g.level.flags.is_maze_lev = FALSE;
g.level.flags.is_cavernous_lev = TRUE;
gl.level.flags.is_maze_lev = FALSE;
gl.level.flags.is_cavernous_lev = TRUE;
}
free(g.new_locations);
free(gn.new_locations);
}
/*mkmap.c*/