diff options
author | Simon Howard | 2006-02-03 18:41:26 +0000 |
---|---|---|
committer | Simon Howard | 2006-02-03 18:41:26 +0000 |
commit | d0d3b5a6945ece4bd6c8bb1102e8fe55f25852e8 (patch) | |
tree | 3aa0225ccfa6aec2391efa17e81da895b3b664f6 /src | |
parent | fd40e07993f83ecb222246d3137949b067c30fce (diff) | |
download | chocolate-doom-d0d3b5a6945ece4bd6c8bb1102e8fe55f25852e8.tar.gz chocolate-doom-d0d3b5a6945ece4bd6c8bb1102e8fe55f25852e8.tar.bz2 chocolate-doom-d0d3b5a6945ece4bd6c8bb1102e8fe55f25852e8.zip |
Support NWT-style WAD merging (-af and -as command line parameters).
Restructure WAD loading so that merged WADs are always loaded before
normal PWADs. Remove W_InitMultipleFiles().
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 362
Diffstat (limited to 'src')
-rw-r--r-- | src/d_main.c | 183 | ||||
-rw-r--r-- | src/d_main.h | 14 | ||||
-rw-r--r-- | src/w_merge.c | 84 | ||||
-rw-r--r-- | src/w_merge.h | 14 | ||||
-rw-r--r-- | src/w_wad.c | 64 | ||||
-rw-r--r-- | src/w_wad.h | 11 |
6 files changed, 224 insertions, 146 deletions
diff --git a/src/d_main.c b/src/d_main.c index 2921684e..ccadb70b 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: d_main.c 336 2006-01-23 00:47:16Z fraggle $ +// $Id: d_main.c 362 2006-02-03 18:41:26Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,11 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.42 2006/02/03 18:41:26 fraggle +// Support NWT-style WAD merging (-af and -as command line parameters). +// Restructure WAD loading so that merged WADs are always loaded before +// normal PWADs. Remove W_InitMultipleFiles(). +// // Revision 1.41 2006/01/23 00:47:16 fraggle // Rearrange the order of startup code to allow replacing the IWAD filename via dehacked // @@ -179,7 +184,7 @@ //----------------------------------------------------------------------------- -static const char rcsid[] = "$Id: d_main.c 336 2006-01-23 00:47:16Z fraggle $"; +static const char rcsid[] = "$Id: d_main.c 362 2006-02-03 18:41:26Z fraggle $"; #define BGCOLOR 7 #define FGCOLOR 8 @@ -259,7 +264,6 @@ char * configdir; // location of IWAD and WAD files char * iwadfile; -char * wadfiles[MAXWADFILES]; boolean devparm; // started game with -devparm @@ -720,24 +724,13 @@ void D_StartTitle (void) char title[128]; - -// -// D_AddFile -// -void D_AddFile (char *file) +static void D_AddFile(char *filename) { - int numwadfiles; - char *newfile; - - for (numwadfiles = 0 ; wadfiles[numwadfiles] ; numwadfiles++) - ; - - newfile = malloc (strlen(file)+1); - strcpy (newfile, file); - - wadfiles[numwadfiles] = newfile; + printf(" adding %s\n", filename); + W_AddFile(filename); } + // Check if a file exists static int FileExists(char *filename) @@ -770,14 +763,11 @@ struct }; // Search a directory to try to find an IWAD -// Returns non-zero if successful +// Returns the location of the IWAD if found, otherwise NULL. -static int SearchDirectoryForIWAD(char *dir) +static char *SearchDirectoryForIWAD(char *dir) { int i; - int result; - - result = 0; for (i=0; i<sizeof(iwads) / sizeof(*iwads); ++i) { @@ -794,17 +784,13 @@ static int SearchDirectoryForIWAD(char *dir) { iwadfile = filename; gamemission = iwads[i].mission; - D_AddFile(filename); - result = 1; - break; - } - else - { - free(filename); + return filename; } + + free(filename); } - return result; + return NULL; } // When given an IWAD with the '-iwad' parameter, @@ -840,12 +826,13 @@ static void IdentifyIWADByName(char *name) // FindIWAD // Checks availability of IWAD files by name, // to determine whether registered/commercial features -// should be executed (notably loading PWAD's). +// should be executed (notably loading PWADs). // + static void FindIWAD (void) { char *doomwaddir; - int result; + char *result; int iwadparm; result = 0; @@ -855,23 +842,22 @@ static void FindIWAD (void) if (iwadparm) { iwadfile = myargv[iwadparm + 1]; - D_AddFile(iwadfile); + result = iwadfile; IdentifyIWADByName(iwadfile); - result = 1; } else if (doomwaddir != NULL) { result = SearchDirectoryForIWAD(doomwaddir); } - if (result == 0) - { - result = SearchDirectoryForIWAD(".") - || SearchDirectoryForIWAD("/usr/share/games/doom") - || SearchDirectoryForIWAD("/usr/local/share/games/doom"); - } + if (result == NULL) + result = SearchDirectoryForIWAD("."); + if (result == NULL) + result = SearchDirectoryForIWAD("/usr/share/games/doom"); + if (result == NULL) + result = SearchDirectoryForIWAD("/usr/local/share/games/doom"); - if (result == 0) + if (result == NULL) { I_Error("Game mode indeterminate. No IWAD file was found. Try\n" "specifying one with the '-iwad' command line parameter.\n"); @@ -1340,7 +1326,6 @@ void PrintGameVersion(void) } } - // // D_DoomMain // @@ -1404,6 +1389,86 @@ void D_DoomMain (void) sidemove[1] = sidemove[1]*scale/100; } + // init subsystems + printf (DEH_String("V_Init: allocate screens.\n")); + V_Init (); + + printf (DEH_String("M_LoadDefaults: Load system defaults.\n")); + M_LoadDefaults (); // load before initing other systems + + printf (DEH_String("W_Init: Init WADfiles.\n")); + D_AddFile(iwadfile); + +#ifdef FEATURE_WAD_MERGE + // Merged PWADs are loaded first, because they are supposed to be + // modified IWADs. + + p = M_CheckParm("-merge"); + + if (p > 0) + { + for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p) + { + printf(" merging %s\n", myargv[p]); + W_MergeFile(myargv[p]); + } + } + + // NWT-style merging: + + // Add flats + + p = M_CheckParm("-af"); + + if (p > 0) + { + for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p) + { + printf(" merging flats from %s\n", myargv[p]); + W_NWTMergeFile(myargv[p], W_NWT_MERGE_FLATS); + } + } + + // Add sprites + + p = M_CheckParm("-as"); + + if (p > 0) + { + for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p) + { + printf(" merging sprites from %s\n", myargv[p]); + W_NWTMergeFile(myargv[p], W_NWT_MERGE_SPRITES); + } + } + + // Add sprites AND flats + + p = M_CheckParm("-aa"); + + if (p > 0) + { + for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p) + { + printf(" merging sprites and flats from %s\n", myargv[p]); + W_NWTMergeFile(myargv[p], W_NWT_MERGE_SPRITES | W_NWT_MERGE_FLATS); + } + } + +#endif + + // Load normal PWADs + + p = M_CheckParm ("-file"); + if (p) + { + // the parms after p are wadfile/lump names, + // until end of parms or another - preceded parm + modifiedgame = true; // homebrew levels + while (++p != myargc && myargv[p][0] != '-') + D_AddFile (myargv[p]); + } + // add any files specified on the command line with -file wadfile // to the wad list // @@ -1438,16 +1503,6 @@ void D_DoomMain (void) D_AddFile (file); } - p = M_CheckParm ("-file"); - if (p) - { - // the parms after p are wadfile/lump names, - // until end of parms or another - preceded parm - modifiedgame = true; // homebrew levels - while (++p != myargc && myargv[p][0] != '-') - D_AddFile (myargv[p]); - } - p = M_CheckParm ("-playdemo"); if (!p) @@ -1460,28 +1515,6 @@ void D_DoomMain (void) printf(DEH_String("Playing demo %s.lmp.\n"),myargv[p+1]); } - // init subsystems - printf (DEH_String("V_Init: allocate screens.\n")); - V_Init (); - - printf (DEH_String("M_LoadDefaults: Load system defaults.\n")); - M_LoadDefaults (); // load before initing other systems - - printf (DEH_String("W_Init: Init WADfiles.\n")); - W_InitMultipleFiles (wadfiles); - -#ifdef FEATURE_WAD_MERGE - p = M_CheckParm("-merge"); - - if (p > 0) - { - for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p) - { - W_MergeFile(myargv[p]); - } - } -#endif - IdentifyVersion(); InitGameVersion(); SetGameDescription(); diff --git a/src/d_main.h b/src/d_main.h index c227cddc..9f61ed74 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: d_main.h 241 2006-01-02 00:17:42Z fraggle $ +// $Id: d_main.h 362 2006-02-03 18:41:26Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,11 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.5 2006/02/03 18:41:26 fraggle +// Support NWT-style WAD merging (-af and -as command line parameters). +// Restructure WAD loading so that merged WADs are always loaded before +// normal PWADs. Remove W_InitMultipleFiles(). +// // Revision 1.4 2006/01/02 00:17:42 fraggle // Encapsulate the event queue code properly. Add a D_PopEvent function // to read a new event from the event queue. @@ -50,13 +55,6 @@ -#define MAXWADFILES 20 -extern char* wadfiles[MAXWADFILES]; - -void D_AddFile (char *file); - - - // // D_DoomMain() // Not a globally visible function, just included for source reference, diff --git a/src/w_merge.c b/src/w_merge.c index 1a099e24..5aff8674 100644 --- a/src/w_merge.c +++ b/src/w_merge.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: w_merge.c 222 2005-10-23 20:22:35Z fraggle $ +// $Id: w_merge.c 362 2006-02-03 18:41:26Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,11 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.4 2006/02/03 18:41:26 fraggle +// Support NWT-style WAD merging (-af and -as command line parameters). +// Restructure WAD loading so that merged WADs are always loaded before +// normal PWADs. Remove W_InitMultipleFiles(). +// // Revision 1.3 2005/10/23 20:22:35 fraggle // Drastically refactor the WAD merging code. Allow multiple replacements // of the same sprite in a PWAD (fixes Scientist 2) @@ -44,6 +49,7 @@ #include <string.h> #include "i_system.h" +#include "w_merge.h" #include "w_wad.h" #include "z_zone.h" @@ -552,15 +558,11 @@ void W_MergeFile(char *filename) old_numlumps = numlumps; - W_AddFile(filename); - - // failed to load? + // Load PWAD - if (numlumps == old_numlumps) + if (!W_AddFile(filename)) return; - printf(" merging %s\n", filename); - // iwad is at the start, pwad was appended to the end iwad.lumps = lumpinfo; @@ -582,4 +584,72 @@ void W_MergeFile(char *filename) DoMerge(); } +// Replace lumps in the given list with lumps from the PWAD + +static void W_NWTAddLumps(searchlist_t *list) +{ + int i; + + // Go through the IWAD list given, replacing lumps with lumps of + // the same name from the PWAD + + for (i=0; i<list->numlumps; ++i) + { + int index; + + index = FindInList(&pwad, list->lumps[i].name); + + if (index > 0) + { + memcpy(&list->lumps[i], &pwad.lumps[index], + sizeof(lumpinfo_t)); + } + } + +} + +// Merge sprites and flats in the way NWT does with its -af and -as +// command-line options. + +void W_NWTMergeFile(char *filename, int flags) +{ + int old_numlumps; + + old_numlumps = numlumps; + + // Load PWAD + + if (!W_AddFile(filename)) + return; + + // iwad is at the start, pwad was appended to the end + + iwad.lumps = lumpinfo; + iwad.numlumps = old_numlumps; + + pwad.lumps = lumpinfo + old_numlumps; + pwad.numlumps = numlumps - old_numlumps; + + // Setup sprite/flat lists + + SetupLists(); + + // Merge in flats? + + if (flags & W_NWT_MERGE_FLATS) + { + W_NWTAddLumps(&iwad_flats); + } + + // Sprites? + + if (flags & W_NWT_MERGE_SPRITES) + { + W_NWTAddLumps(&iwad_sprites); + } + + // Discard the PWAD + + numlumps = old_numlumps; +} diff --git a/src/w_merge.h b/src/w_merge.h index 1a7eac47..00f127c5 100644 --- a/src/w_merge.h +++ b/src/w_merge.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: w_merge.h 168 2005-10-08 18:23:18Z fraggle $ +// $Id: w_merge.h 362 2006-02-03 18:41:26Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,11 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.2 2006/02/03 18:41:26 fraggle +// Support NWT-style WAD merging (-af and -as command line parameters). +// Restructure WAD loading so that merged WADs are always loaded before +// normal PWADs. Remove W_InitMultipleFiles(). +// // Revision 1.1 2005/10/08 18:23:18 fraggle // WAD merging code // @@ -36,9 +41,16 @@ #ifndef W_MERGE_H #define W_MERGE_H +#define W_NWT_MERGE_SPRITES 0x1 +#define W_NWT_MERGE_FLATS 0x2 + // Add a new WAD and merge it into the main directory void W_MergeFile(char *filename); +// NWT-style merging + +void W_NWTMergeFile(char *filename, int flags); + #endif /* #ifndef W_MERGE_H */ diff --git a/src/w_wad.c b/src/w_wad.c index feb0c96f..a7478f8a 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: w_wad.c 342 2006-01-24 01:46:08Z fraggle $ +// $Id: w_wad.c 362 2006-02-03 18:41:26Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,11 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.11 2006/02/03 18:41:26 fraggle +// Support NWT-style WAD merging (-af and -as command line parameters). +// Restructure WAD loading so that merged WADs are always loaded before +// normal PWADs. Remove W_InitMultipleFiles(). +// // Revision 1.10 2006/01/24 01:46:08 fraggle // More endianness fixes // @@ -61,7 +66,7 @@ static const char -rcsid[] = "$Id: w_wad.c 342 2006-01-24 01:46:08Z fraggle $"; +rcsid[] = "$Id: w_wad.c 362 2006-02-03 18:41:26Z fraggle $"; #include <ctype.h> @@ -88,7 +93,7 @@ rcsid[] = "$Id: w_wad.c 342 2006-01-24 01:46:08Z fraggle $"; // Location of each lump on disk. lumpinfo_t* lumpinfo; -int numlumps; +int numlumps = 0; #define strcmpi strcasecmp @@ -171,7 +176,7 @@ int reloadlump; char* reloadname; -void W_AddFile (char *filename) +boolean W_AddFile (char *filename) { wadinfo_t header; lumpinfo_t* lump_p; @@ -196,10 +201,9 @@ void W_AddFile (char *filename) if ( (handle = fopen(filename,"rb")) == NULL) { printf (" couldn't open %s\n",filename); - return; + return false; } - printf (" adding %s\n",filename); startlump = numlumps; if (strcmpi (filename+strlen(filename)-3 , "wad" ) ) @@ -259,6 +263,8 @@ void W_AddFile (char *filename) fclose (handle); Z_Free(fileinfo); + + return true; } @@ -315,52 +321,6 @@ void W_Reload (void) // -// W_InitMultipleFiles -// Pass a null terminated list of files to use. -// All files are optional, but at least one file -// must be found. -// Files with a .wad extension are idlink files -// with multiple lumps. -// Other files are single lumps with the base filename -// for the lump name. -// Lump names can appear multiple times. -// The name searcher looks backwards, so a later file -// does override all earlier ones. -// -void W_InitMultipleFiles (char** filenames) -{ - // open all the files, load headers, and count lumps - numlumps = 0; - - // will be realloced as lumps are added - lumpinfo = malloc(1); - - for ( ; *filenames ; filenames++) - W_AddFile (*filenames); - - if (!numlumps) - I_Error ("W_InitFiles: no files found"); -} - - - - -// -// W_InitFile -// Just initialize from a single file. -// -void W_InitFile (char* filename) -{ - char* names[2]; - - names[0] = filename; - names[1] = NULL; - W_InitMultipleFiles (names); -} - - - -// // W_NumLumps // int W_NumLumps (void) diff --git a/src/w_wad.h b/src/w_wad.h index 2fa4117b..548c2a54 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: w_wad.h 167 2005-10-08 18:22:46Z fraggle $ +// $Id: w_wad.h 362 2006-02-03 18:41:26Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -32,6 +32,7 @@ #include <stdio.h> +#include "doomtype.h" // @@ -72,8 +73,7 @@ extern void** lumpcache; extern lumpinfo_t* lumpinfo; extern int numlumps; -void W_AddFile (char *filename); -void W_InitMultipleFiles (char** filenames); +boolean W_AddFile (char *filename); void W_Reload (void); int W_CheckNumForName (char* name); @@ -92,6 +92,11 @@ void* W_CacheLumpName (char* name, int tag); //----------------------------------------------------------------------------- // // $Log$ +// Revision 1.5 2006/02/03 18:41:26 fraggle +// Support NWT-style WAD merging (-af and -as command line parameters). +// Restructure WAD loading so that merged WADs are always loaded before +// normal PWADs. Remove W_InitMultipleFiles(). +// // Revision 1.4 2005/10/08 18:22:46 fraggle // Store the cache as part of the lumpinfo_t struct. Add W_AddFile prototype // to header. |