ref: d0d3b5a6945ece4bd6c8bb1102e8fe55f25852e8
parent: fd40e07993f83ecb222246d3137949b067c30fce
author: Simon Howard <[email protected]>
date: Fri Feb 3 13:41:26 EST 2006
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
--- 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 @@
// location of IWAD and WAD files
char * iwadfile;
-char * wadfiles[MAXWADFILES];
boolean devparm; // started game with -devparm
@@ -720,24 +724,13 @@
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 @@
};
// 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 @@
{
iwadfile = filename;
gamemission = iwads[i].mission;
- D_AddFile(filename);
- result = 1;
- break;
+ return filename;
}
- else
- {
- free(filename);
- }
+
+ free(filename);
}
- return result;
+ return NULL;
}
// When given an IWAD with the '-iwad' parameter,
@@ -840,12 +826,13 @@
// 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,9 +842,8 @@
if (iwadparm)
{
iwadfile = myargv[iwadparm + 1];
- D_AddFile(iwadfile);
+ result = iwadfile;
IdentifyIWADByName(iwadfile);
- result = 1;
}
else if (doomwaddir != NULL)
{
@@ -864,14 +850,14 @@
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 @@
}
}
-
//
// D_DoomMain
//
@@ -1404,6 +1389,86 @@
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 @@
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 @@
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();
--- 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.
@@ -47,13 +52,6 @@
#include "d_event.h"
-
-
-
-#define MAXWADFILES 20
-extern char* wadfiles[MAXWADFILES];
-
-void D_AddFile (char *file);
--- 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 @@
old_numlumps = numlumps;
- W_AddFile(filename);
+ // Load PWAD
- // failed to load?
-
- 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 @@
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;
+}
--- 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 */
--- 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 @@
// Location of each lump on disk.
lumpinfo_t* lumpinfo;
-int numlumps;
+int numlumps = 0;
#define strcmpi strcasecmp
@@ -171,7 +176,7 @@
char* reloadname;
-void W_AddFile (char *filename)
+boolean W_AddFile (char *filename)
{
wadinfo_t header;
lumpinfo_t* lump_p;
@@ -196,10 +201,9 @@
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 @@
fclose (handle);
Z_Free(fileinfo);
+
+ return true;
}
@@ -310,52 +316,6 @@
fclose(handle);
Z_Free(fileinfo);
-}
-
-
-
-//
-// 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);
}
--- 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 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 @@
//-----------------------------------------------------------------------------
//
// $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.