From d0d3b5a6945ece4bd6c8bb1102e8fe55f25852e8 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 3 Feb 2006 18:41:26 +0000 Subject: 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 --- src/d_main.c | 183 ++++++++++++++++++++++++++++++++++------------------------ src/d_main.h | 14 ++--- src/w_merge.c | 84 ++++++++++++++++++++++++--- src/w_merge.h | 14 ++++- src/w_wad.c | 64 ++++---------------- src/w_wad.h | 11 +++- 6 files changed, 224 insertions(+), 146 deletions(-) (limited to 'src') 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 0) + { + for (p = p + 1; p 0) + { + for (p = p + 1; p 0) + { + for (p = p + 1; p 0) + { + for (p = p + 1; p 0) - { - for (p = p + 1; p #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; inumlumps; ++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 @@ -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; } @@ -314,52 +320,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 // 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 +#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. -- cgit v1.2.3