ref: 27f8ea9f5a210f055f443ef34017dd2412feb326
parent: 02f2b37c714aa44d82b7e311e03df39430706e69
author: Simon Howard <fraggle@gmail.com>
date: Wed Dec 3 13:54:36 EST 2008
Centralise the list of IWAD files and use bitmasks to select which mission types are valid. Subversion-branch: /branches/raven-branch Subversion-revision: 1405
--- a/src/d_iwad.c
+++ b/src/d_iwad.c
@@ -39,6 +39,19 @@
#include "w_wad.h"
#include "z_zone.h"
+static iwad_t iwads[] =
+{+ { "doom2.wad", doom2 },+ { "plutonia.wad", pack_plut },+ { "tnt.wad", pack_tnt },+ { "doom.wad", doom },+ { "doom1.wad", doom },+ { "chex.wad", doom },+ { "heretic.wad", heretic },+ { "heretic1.wad", heretic },+ { "hexen.wad", hexen },+};
+
// Array of locations to search for IWAD files
//
// "128 IWAD search directories should be enough for anybody".
@@ -320,16 +333,20 @@
// Search a directory to try to find an IWAD
// Returns the location of the IWAD if found, otherwise NULL.
-static char *SearchDirectoryForIWAD(char *dir, iwad_t *iwads,
- GameMission_t *mission)
+static char *SearchDirectoryForIWAD(char *dir, int mask, GameMission_t *mission)
{size_t i;
- for (i=0; iwads[i].name != NULL; ++i)
+ for (i=0; i<arrlen(iwads); ++i)
{char *filename;
char *iwadname;
+ if ((iwads[i].mission & mask) == 0)
+ {+ continue;
+ }
+
iwadname = DEH_String(iwads[i].name);
filename = malloc(strlen(dir) + strlen(iwadname) + 3);
@@ -359,17 +376,22 @@
// When given an IWAD with the '-iwad' parameter,
// attempt to identify it by its name.
-static GameMission_t IdentifyIWADByName(char *name, iwad_t *iwads)
+static GameMission_t IdentifyIWADByName(char *name, int mask)
{size_t i;
GameMission_t mission;
mission = none;
-
- for (i=0; iwads[i].name != NULL; ++i)
+
+ for (i=0; i<arrlen(iwads); ++i)
{char *iwadname;
+ // Only use supported missions:
+
+ if ((iwads[i].mission & mask) == 0)
+ continue;
+
iwadname = DEH_String(iwads[i].name);
if (strlen(name) < strlen(iwadname))
@@ -390,7 +412,7 @@
//
// Add directories from the list in the DOOMWADPATH environment variable.
-//
+//
static void AddDoomWadPath(void)
{@@ -564,7 +586,7 @@
// should be executed (notably loading PWADs).
//
-char *D_FindIWAD(iwad_t *iwads, GameMission_t *mission)
+char *D_FindIWAD(int mask, GameMission_t *mission)
{char *result;
char *iwadfile;
@@ -594,7 +616,7 @@
I_Error("IWAD file '%s' not found!", iwadfile);}
- *mission = IdentifyIWADByName(result, iwads);
+ *mission = IdentifyIWADByName(result, mask);
}
else
{@@ -606,34 +628,10 @@
for (i=0; result == NULL && i<num_iwad_dirs; ++i)
{- result = SearchDirectoryForIWAD(iwad_dirs[i], iwads, mission);
+ result = SearchDirectoryForIWAD(iwad_dirs[i], mask, mission);
}
}
return result;
-}
-
-// Clever hack: Setup can invoke Doom to determine which IWADs are installed.
-// Doom searches install paths and exits with the return code being a
-// bitmask of the installed IWAD files.
-
-void D_FindInstalledIWADs(iwad_t *iwads)
-{- unsigned int i;
- int result;
-
- BuildIWADDirList();
-
- result = 0;
-
- for (i=0; i<arrlen(iwads); ++i)
- {- if (D_FindWADByName(iwads[i].name) != NULL)
- {- result |= 1 << i;
- }
- }
-
- exit(result);
}
--- a/src/d_iwad.h
+++ b/src/d_iwad.h
@@ -29,6 +29,13 @@
#include "d_mode.h"
+#define IWAD_MASK_DOOM ((1 << doom) \
+ | (1 << doom2) \
+ | (1 << pack_tnt) \
+ | (1 << pack_plut))
+#define IWAD_MASK_HERETIC (1 << heretic)
+#define IWAD_MASK_HEXEN (1 << hexen)
+
typedef struct
{char *name;
@@ -37,8 +44,7 @@
char *D_FindWADByName(char *filename);
char *D_TryFindWADByName(char *filename);
-char *D_FindIWAD(iwad_t *iwads, GameMission_t *mission);
-void D_FindInstalledIWADs(iwad_t *iwads);
+char *D_FindIWAD(int mask, GameMission_t *mission);
#endif
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -591,17 +591,6 @@
D_AdvanceDemo ();
}
-static iwad_t iwads[] =
-{- {"doom2.wad", doom2},- {"plutonia.wad", pack_plut},- {"tnt.wad", pack_tnt},- {"doom.wad", doom},- {"doom1.wad", doom},- {"chex.wad", doom},- {NULL, none},-};
-
// Strings for dehacked replacements of the startup banner
//
// These are from the original source: some of them are perhaps
@@ -1061,14 +1050,6 @@
M_FindResponseFile ();
- // Undocumented "search for IWADs" parameter used by the setup
- // tool.
-
- if (M_CheckParm("-findiwads") > 0)- {- D_FindInstalledIWADs(iwads);
- }
-
// print banner
I_PrintBanner(PACKAGE_STRING);
@@ -1123,7 +1104,7 @@
DEH_Init();
#endif
- iwadfile = D_FindIWAD(iwads, &gamemission);
+ iwadfile = D_FindIWAD(IWAD_MASK_DOOM, &gamemission);
// None found?
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -455,12 +455,6 @@
#define SHAREWAREWADNAME "heretic1.wad"
-static iwad_t iwads[] = {- { "heretic.wad", heretic },- { "heretic1.wad", heretic },- { NULL, none },-};
-
char *iwadfile;
char *basedefault = "heretic.cfg";
@@ -880,7 +874,7 @@
printf("W_Init: Init WADfiles.\n");- iwadfile = D_FindIWAD(iwads, &gamemission);
+ iwadfile = D_FindIWAD(IWAD_MASK_HERETIC, &gamemission);
if (iwadfile == NULL)
{--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -136,11 +136,6 @@
static int pagetic;
static char *pagename;
-static iwad_t iwads[] = {- { "hexen.wad", hexen },- { NULL, none },-};
-
static execOpt_t ExecOptions[] = { {"-file", ExecOptionFILE, 1, 0}, {"-scripts", ExecOptionSCRIPTS, 1, 0},@@ -272,7 +267,7 @@
ST_Message("W_Init: Init WADfiles.\n");- iwadfile = D_FindIWAD(iwads, &gamemission);
+ iwadfile = D_FindIWAD(IWAD_MASK_HEXEN, &gamemission);
if (iwadfile == NULL)
{--
⑨