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
include/rm.h
40
include/rm.h
@@ -89,7 +89,7 @@ enum levl_typ_types {
|
||||
#define IS_DOOR(typ) ((typ) == DOOR)
|
||||
#define IS_DOORJOIN(typ) (IS_ROCK(typ) || (typ) == IRONBARS)
|
||||
#define IS_TREE(typ) \
|
||||
((typ) == TREE || (g.level.flags.arboreal && (typ) == STONE))
|
||||
((typ) == TREE || (gl.level.flags.arboreal && (typ) == STONE))
|
||||
#define ACCESSIBLE(typ) ((typ) >= DOOR) /* good position */
|
||||
#define IS_ROOM(typ) ((typ) >= ROOM) /* ROOM, STAIRS, furniture.. */
|
||||
#define ZAP_POS(typ) ((typ) >= POOL)
|
||||
@@ -345,7 +345,7 @@ struct damage {
|
||||
an existing bones level; if so, most recent victim will be first in list */
|
||||
struct cemetery {
|
||||
struct cemetery *next; /* next struct is previous dead character... */
|
||||
/* "g.plname" + "-ROLe" + "-RACe" + "-GENder" + "-ALIgnment" + \0 */
|
||||
/* "gp.plname" + "-ROLe" + "-RACe" + "-GENder" + "-ALIgnment" + \0 */
|
||||
char who[PL_NSIZ + 4 * (1 + 3) + 1];
|
||||
/* death reason, same as in score/log file */
|
||||
char how[100 + 1]; /* [DTHSZ+1] */
|
||||
@@ -403,9 +403,9 @@ typedef struct {
|
||||
/*
|
||||
* Macros for compatibility with old code. Someday these will go away.
|
||||
*/
|
||||
#define levl g.level.locations
|
||||
#define fobj g.level.objlist
|
||||
#define fmon g.level.monlist
|
||||
#define levl gl.level.locations
|
||||
#define fobj gl.level.objlist
|
||||
#define fmon gl.level.monlist
|
||||
|
||||
/*
|
||||
* Covert a trap number into the defsym graphics array.
|
||||
@@ -415,43 +415,43 @@ typedef struct {
|
||||
#define trap_to_defsym(t) (S_arrow_trap + (t) - 1)
|
||||
#define defsym_to_trap(d) ((d) - S_arrow_trap + 1)
|
||||
|
||||
#define OBJ_AT(x, y) (g.level.objects[x][y] != (struct obj *) 0)
|
||||
#define OBJ_AT(x, y) (gl.level.objects[x][y] != (struct obj *) 0)
|
||||
/*
|
||||
* Macros for encapsulation of level.monsters references.
|
||||
*/
|
||||
#if 0
|
||||
#define MON_AT(x, y) \
|
||||
(g.level.monsters[x][y] != (struct monst *) 0 \
|
||||
&& !(g.level.monsters[x][y])->mburied)
|
||||
(gl.level.monsters[x][y] != (struct monst *) 0 \
|
||||
&& !(gl.level.monsters[x][y])->mburied)
|
||||
#define MON_BURIED_AT(x, y) \
|
||||
(g.level.monsters[x][y] != (struct monst *) 0 \
|
||||
&& (g.level.monsters[x][y])->mburied)
|
||||
(gl.level.monsters[x][y] != (struct monst *) 0 \
|
||||
&& (gl.level.monsters[x][y])->mburied)
|
||||
#else /* without 'mburied' */
|
||||
#define MON_AT(x, y) (g.level.monsters[x][y] != (struct monst *) 0)
|
||||
#define MON_AT(x, y) (gl.level.monsters[x][y] != (struct monst *) 0)
|
||||
#endif
|
||||
#ifdef EXTRA_SANITY_CHECKS
|
||||
#define place_worm_seg(m, x, y) \
|
||||
do { \
|
||||
if (g.level.monsters[x][y] && g.level.monsters[x][y] != m) \
|
||||
if (gl.level.monsters[x][y] && gl.level.monsters[x][y] != m) \
|
||||
impossible("place_worm_seg over mon"); \
|
||||
g.level.monsters[x][y] = m; \
|
||||
gl.level.monsters[x][y] = m; \
|
||||
} while(0)
|
||||
#define remove_monster(x, y) \
|
||||
do { \
|
||||
if (!g.level.monsters[x][y]) \
|
||||
if (!gl.level.monsters[x][y]) \
|
||||
impossible("no monster to remove"); \
|
||||
g.level.monsters[x][y] = (struct monst *) 0; \
|
||||
gl.level.monsters[x][y] = (struct monst *) 0; \
|
||||
} while(0)
|
||||
#else
|
||||
#define place_worm_seg(m, x, y) g.level.monsters[x][y] = m
|
||||
#define remove_monster(x, y) g.level.monsters[x][y] = (struct monst *) 0
|
||||
#define place_worm_seg(m, x, y) gl.level.monsters[x][y] = m
|
||||
#define remove_monster(x, y) gl.level.monsters[x][y] = (struct monst *) 0
|
||||
#endif
|
||||
#define m_at(x, y) (MON_AT(x, y) ? g.level.monsters[x][y] : (struct monst *) 0)
|
||||
#define m_at(x, y) (MON_AT(x, y) ? gl.level.monsters[x][y] : (struct monst *) 0)
|
||||
#define m_buried_at(x, y) \
|
||||
(MON_BURIED_AT(x, y) ? g.level.monsters[x][y] : (struct monst *) 0)
|
||||
(MON_BURIED_AT(x, y) ? gl.level.monsters[x][y] : (struct monst *) 0)
|
||||
|
||||
/* restricted movement, potential luck penalties */
|
||||
#define Sokoban g.level.flags.sokoban_rules
|
||||
#define Sokoban gl.level.flags.sokoban_rules
|
||||
|
||||
/*
|
||||
* These prototypes are in extern.h but some of the code which uses them
|
||||
|
||||
Reference in New Issue
Block a user