From af949cb1df6bd36bd0f2ac16936862358e18a57a Mon Sep 17 00:00:00 2001 From: Bart House Date: Sat, 24 Nov 2018 21:08:17 -0800 Subject: [PATCH] Moving globals to instance_globals part 10ish. --- include/decl.h | 3 +++ src/decl.c | 3 +++ src/o_init.c | 32 +++++++++++++++----------------- src/objnam.c | 2 +- src/options.c | 9 +++++++-- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/include/decl.h b/include/decl.h index 517abe793..1f49decbd 100644 --- a/include/decl.h +++ b/include/decl.h @@ -838,6 +838,9 @@ struct instance_globals { * remember who zapped the wand. */ struct musable m; + /* o_init.c */ + short disco[NUM_OBJECTS]; + /* objname.c */ /* distantname used by distant_name() to pass extra information to xname_flags(); it would be much cleaner if this were a parameter, diff --git a/src/decl.c b/src/decl.c index 267d038e7..3882fb8ae 100644 --- a/src/decl.c +++ b/src/decl.c @@ -499,6 +499,9 @@ const struct instance_globals g_init = { UNDEFINED_VALUE, /* zap_oseen */ UNDEFINED_VALUES, /* m */ + /* o_init.c */ + DUMMY, /* disco */ + /* objname.c */ 0, /* distantname */ diff --git a/src/o_init.c b/src/o_init.c index b4fc440ee..77cd02229 100644 --- a/src/o_init.c +++ b/src/o_init.c @@ -12,8 +12,6 @@ STATIC_DCL void NDECL(shuffle_all); STATIC_DCL boolean FDECL(interesting_to_discover, (int)); STATIC_DCL char *FDECL(oclass_to_name, (CHAR_P, char *)); -static NEARDATA short disco[NUM_OBJECTS] = DUMMY; - #ifdef USE_TILES STATIC_DCL void NDECL(shuffle_tiles); extern short glyph2tile[]; /* from tile.c */ @@ -296,7 +294,7 @@ int fd, mode; if (perform_bwrite(mode)) { bwrite(fd, (genericptr_t) bases, sizeof bases); - bwrite(fd, (genericptr_t) disco, sizeof disco); + bwrite(fd, (genericptr_t) g.disco, sizeof g.disco); bwrite(fd, (genericptr_t) objects, sizeof(struct objclass) * NUM_OBJECTS); } @@ -325,7 +323,7 @@ register int fd; unsigned int len; mread(fd, (genericptr_t) bases, sizeof bases); - mread(fd, (genericptr_t) disco, sizeof disco); + mread(fd, (genericptr_t) g.disco, sizeof g.disco); mread(fd, (genericptr_t) objects, sizeof(struct objclass) * NUM_OBJECTS); for (i = 0; i < NUM_OBJECTS; i++) if (objects[i].oc_uname) { @@ -351,10 +349,10 @@ boolean credit_hero; uname'd) or the next open slot; one or the other will be found before we reach the next class... */ - for (dindx = bases[acls]; disco[dindx] != 0; dindx++) - if (disco[dindx] == oindx) + for (dindx = bases[acls]; g.disco[dindx] != 0; dindx++) + if (g.disco[dindx] == oindx) break; - disco[dindx] = oindx; + g.disco[dindx] = oindx; if (mark_as_known) { objects[oindx].oc_name_known = 1; @@ -377,19 +375,19 @@ register int oindx; register boolean found = FALSE; /* find the object; shift those behind it forward one slot */ - for (dindx = bases[acls]; dindx < NUM_OBJECTS && disco[dindx] != 0 + for (dindx = bases[acls]; dindx < NUM_OBJECTS && g.disco[dindx] != 0 && objects[dindx].oc_class == acls; dindx++) if (found) - disco[dindx - 1] = disco[dindx]; - else if (disco[dindx] == oindx) + g.disco[dindx - 1] = g.disco[dindx]; + else if (g.disco[dindx] == oindx) found = TRUE; /* clear last slot */ if (found) - disco[dindx - 1] = 0; + g.disco[dindx - 1] = 0; else - impossible("named object not in disco"); + impossible("named object not in g.disco"); update_inventory(); } } @@ -405,7 +403,7 @@ register int i; } /* items that should stand out once they're known */ -static short uniq_objs[] = { +static const short uniq_objs[] = { AMULET_OF_YENDOR, SPE_BOOK_OF_THE_DEAD, CANDELABRUM_OF_INVOCATION, BELL_OF_OPENING, }; @@ -446,7 +444,7 @@ dodiscovered() /* free after Robert Viduya */ prev_class = oclass + 1; /* forced different from oclass */ for (i = bases[(int) oclass]; i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) { - if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { + if ((dis = g.disco[i]) != 0 && interesting_to_discover(dis)) { ct++; if (oclass != prev_class) { putstr(tmpwin, iflags.menu_headings, @@ -543,7 +541,7 @@ doclassdisco() c = def_oc_syms[(int) oclass].sym; for (i = bases[(int) oclass]; i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) - if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { + if ((dis = g.disco[i]) != 0 && interesting_to_discover(dis)) { if (!index(discosyms, c)) { Sprintf(eos(discosyms), "%c", c); if (!traditional) { @@ -634,7 +632,7 @@ doclassdisco() putstr(tmpwin, iflags.menu_headings, buf); for (i = bases[(int) oclass]; i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) { - if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { + if ((dis = g.disco[i]) != 0 && interesting_to_discover(dis)) { Sprintf(buf, "%s %s", objects[dis].oc_pre_discovered ? "*" : " ", obj_typename(dis)); @@ -680,7 +678,7 @@ rename_disco() prev_class = oclass + 1; /* forced different from oclass */ for (i = bases[(int) oclass]; i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) { - dis = disco[i]; + dis = g.disco[i]; if (!dis || !interesting_to_discover(dis)) continue; ct++; diff --git a/src/objnam.c b/src/objnam.c index 7d71725b7..3a40978a1 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -2055,7 +2055,7 @@ struct sing_plur { /* word pairs that don't fit into formula-based transformations; also some suffices which have very few--often one--matches or which aren't systematically reversible (knives, staves) */ -static struct sing_plur one_off[] = { +static const struct sing_plur one_off[] = { { "child", "children" }, /* (for wise guys who give their food funny names) */ { "cubus", "cubi" }, /* in-/suc-cubus */ diff --git a/src/options.c b/src/options.c index b21df6a81..334faa209 100644 --- a/src/options.c +++ b/src/options.c @@ -51,11 +51,11 @@ enum window_option_types { * option (e.g. time and timed_delay) the shorter one must come first. */ -static struct Bool_Opt { +static const struct Bool_Opt { const char *name; boolean *addr, initvalue; int optflags; -} boolopt[] = { +} boolopt_init[] = { { "acoustics", &flags.acoustics, TRUE, SET_IN_GAME }, #if defined(SYSFLAGS) && defined(AMIGA) /* Amiga altmeta causes Alt+key to be converted into Meta+key by @@ -449,6 +449,8 @@ static struct Comp_Opt { { (char *) 0, (char *) 0, 0, 0 } }; +static struct Bool_Opt boolopt[SIZE(boolopt_init)]; + #ifdef OPTION_LISTS_ONLY #undef static @@ -688,6 +690,8 @@ initoptions_init() #endif int i; + memcpy(boolopt, boolopt_init, sizeof(boolopt)); + /* set up the command parsing */ reset_commands(TRUE); /* init */ @@ -6720,4 +6724,5 @@ set_playmode() #endif /* OPTION_LISTS_ONLY */ + /*options.c*/