shithub: choc

Download patch

ref: feae49cdcda458fe18ae2df5aa783c4e9091e1f1
parent: 1ecd11222f7da8e54cd7c37d754eecb3ad7f09be
author: Simon Howard <[email protected]>
date: Sat Sep 2 15:10:07 EDT 2006

Add -nwtmerge option, which behaves the same as NWT's -merge option. What this
does is load a PWAD, then search through the IWAD sprites list, removing lumps
where there are lumps of the same name in the PWAD. The PWAD must then be
loaded again with the normal -file option.
This is needed to run TiC's Obituary TC:
chocolate-doom -nwtmerge obtic2.wad -file obtic1.wad obtic2.wad -deh obtic1.deh
Also add W_PrintDirectory debug function, W_AddFile changed to return handle.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 596

--- a/src/d_main.c
+++ b/src/d_main.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: d_main.c 593 2006-09-01 20:45:45Z fraggle $
+// $Id: d_main.c 596 2006-09-02 19:10:07Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -184,7 +184,7 @@
 //-----------------------------------------------------------------------------
 
 
-static const char rcsid[] = "$Id: d_main.c 593 2006-09-01 20:45:45Z fraggle $";
+static const char rcsid[] = "$Id: d_main.c 596 2006-09-02 19:10:07Z fraggle $";
 
 #define	BGCOLOR		7
 #define	FGCOLOR		8
@@ -743,8 +743,12 @@
 
 static boolean D_AddFile(char *filename)
 {
+    FILE *handle;
+
     printf(" adding %s\n", filename);
-    return W_AddFile(filename);
+    handle = W_AddFile(filename);
+
+    return handle != NULL;
 }
 
 
@@ -1586,6 +1590,7 @@
     D_AddFile(iwadfile);
 
 #ifdef FEATURE_WAD_MERGE
+
     // Merged PWADs are loaded first, because they are supposed to be 
     // modified IWADs.
 
@@ -1602,6 +1607,19 @@
 
     // NWT-style merging:
 
+    // NWT's -merge option:
+
+    p = M_CheckParm("-nwtmerge");
+
+    if (p > 0)
+    {
+        for (p = p + 1; p<myargc && myargv[p][0] != '-'; ++p)
+        {
+            printf(" performing NWT-style merge of %s\n", myargv[p]);
+            W_NWTDashMerge(myargv[p]);
+        }
+    }
+    
     // Add flats
 
     p = M_CheckParm("-af");
@@ -1654,6 +1672,9 @@
 	while (++p != myargc && myargv[p][0] != '-')
 	    D_AddFile (myargv[p]);
     }
+
+    // Debug:
+//    W_PrintDirectory();
 
     // add any files specified on the command line with -file wadfile
     // to the wad list
--- a/src/w_merge.c
+++ b/src/w_merge.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: w_merge.c 362 2006-02-03 18:41:26Z fraggle $
+// $Id: w_merge.c 596 2006-09-02 19:10:07Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -539,7 +539,12 @@
     lumpinfo = newlumps;
     numlumps = num_newlumps;
 
-#if 0
+}
+
+void W_PrintDirectory(void)
+{
+    int i, n;
+
     // debug
     for (i=0; i<numlumps; ++i)
     {
@@ -547,7 +552,6 @@
             putchar(lumpinfo[i].name[n]);
         putchar('\n');
     }
-#endif
 }
 
 // Merge in a file by name
@@ -560,7 +564,7 @@
 
     // Load PWAD
 
-    if (!W_AddFile(filename))
+    if (W_AddFile(filename) == NULL)
         return;
 
     // iwad is at the start, pwad was appended to the end
@@ -619,7 +623,7 @@
 
     // Load PWAD
 
-    if (!W_AddFile(filename))
+    if (W_AddFile(filename) == NULL)
         return;
 
     // iwad is at the start, pwad was appended to the end
@@ -651,5 +655,56 @@
     // Discard the PWAD
 
     numlumps = old_numlumps;
+}
+
+// Simulates the NWT -merge command line parameter.  What this does is load
+// a PWAD, then search the IWAD sprites, removing any sprite lumps that also
+// exist in the PWAD.
+
+void W_NWTDashMerge(char *filename)
+{
+    FILE *handle;
+    int old_numlumps;
+    int i;
+
+    old_numlumps = numlumps;
+
+    // Load PWAD
+
+    handle = W_AddFile(filename);
+
+    if (handle == NULL)
+        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();
+
+    // Search through the IWAD sprites list.
+
+    for (i=0; i<iwad_sprites.numlumps; ++i)
+    {
+        if (FindInList(&pwad, iwad_sprites.lumps[i].name) >= 0)
+        {
+            // Replace this entry with an empty string.  This is what
+            // nwt -merge does.
+
+            strcpy(iwad_sprites.lumps[i].name, "");
+        }
+    }
+
+    // Discard PWAD
+    // The PWAD must now be added in again with -file.
+
+    numlumps = old_numlumps;
+    fclose(handle);
 }
 
--- a/src/w_merge.h
+++ b/src/w_merge.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: w_merge.h 362 2006-02-03 18:41:26Z fraggle $
+// $Id: w_merge.h 596 2006-09-02 19:10:07Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -51,6 +51,14 @@
 // NWT-style merging
 
 void W_NWTMergeFile(char *filename, int flags);
+
+// Acts the same as NWT's "-merge" option.
+
+void W_NWTDashMerge(char *filename);
+
+// Debug function that prints the WAD directory.
+
+void W_PrintDirectory(void);
 
 #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 558 2006-06-16 17:06:05Z fraggle $
+// $Id: w_wad.c 596 2006-09-02 19:10:07Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -66,7 +66,7 @@
 
 
 static const char
-rcsid[] = "$Id: w_wad.c 558 2006-06-16 17:06:05Z fraggle $";
+rcsid[] = "$Id: w_wad.c 596 2006-09-02 19:10:07Z fraggle $";
 
 
 #include <ctype.h>
@@ -184,7 +184,7 @@
 char*			reloadname;
 
 
-boolean W_AddFile (char *filename)
+FILE *W_AddFile (char *filename)
 {
     wadinfo_t		header;
     lumpinfo_t*		lump_p;
@@ -209,7 +209,7 @@
     if ( (handle = fopen(filename,"rb")) == NULL)
     {
 	printf (" couldn't open %s\n",filename);
-	return false;
+	return NULL;
     }
 
     startlump = numlumps;
@@ -278,7 +278,7 @@
         lumphash = NULL;
     }
 
-    return true;
+    return handle;
 }
 
 
--- a/src/w_wad.h
+++ b/src/w_wad.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: w_wad.h 558 2006-06-16 17:06:05Z fraggle $
+// $Id: w_wad.h 596 2006-09-02 19:10:07Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -78,7 +78,7 @@
 extern	lumpinfo_t*	lumpinfo;
 extern	int		numlumps;
 
-boolean W_AddFile (char *filename);
+FILE   *W_AddFile (char *filename);
 void    W_Reload (void);
 
 int	W_CheckNumForName (char* name);