shithub: choc

Download patch

ref: 45e57dd270a4045b709e8baacd02aff7428f35b8
parent: 76dd7ccbc3fe1d1d129bfe132ecf1c88ab23609c
author: Simon Howard <[email protected]>
date: Thu Nov 24 16:33:03 EST 2016

Add API for handling non-vanilla demo extensions.

As per the recent change to PHILOSOPHY, we now support non-vanilla
demo format extensions provided that warnings are given and there is
an option to disable them (#817). Add an API for handling such
extensions in a consistent way across games.

--- a/src/d_loop.c
+++ b/src/d_loop.c
@@ -816,3 +816,85 @@
 {
     loop_interface = i;
 }
+
+// TODO: Move nonvanilla demo functions into a dedicated file.
+#include "m_misc.h"
+#include "w_wad.h"
+
+static boolean StrictDemos(void)
+{
+    //!
+    // @category demo
+    //
+    // When recording or playing back demos, disable any extensions
+    // of the vanilla demo format - record demos as vanilla would do,
+    // and play back demos as vanilla would do.
+    //
+    return M_ParmExists("-strictdemos");
+}
+
+// If the provided conditional value is true, we're trying to record
+// a demo file that will include a non-vanilla extension. The function
+// will return true if the conditional is true and it's allowed to use
+// this extension (no extensions are allowed if -strictdemos is given
+// on the command line). A warning is shown on the console using the
+// provided string describing the non-vanilla expansion.
+boolean D_NonVanillaRecord(boolean conditional, char *feature)
+{
+    if (!conditional || StrictDemos())
+    {
+        return false;
+    }
+
+    printf("Warning: Recording a demo file with a non-vanilla extension "
+           "(%s). Use -strictdemos to disable this extension.\n",
+           feature);
+
+    return true;
+}
+
+// Returns true if the given lump number corresponds to data from a .lmp
+// file, as opposed to a WAD.
+static boolean IsDemoFile(int lumpnum)
+{
+    char *lower;
+    boolean result;
+
+    lower = M_StringDuplicate(lumpinfo[lumpnum]->wad_file->path);
+    M_ForceLowercase(lower);
+    result = M_StringEndsWith(lower, ".lmp");
+    free(lower);
+
+    return result;
+}
+
+// If the provided conditional value is true, we're trying to play back
+// a demo that includes a non-vanilla extension. We return true if the
+// conditional is true and it's allowed to use this extension, checking
+// that:
+//  - The -strictdemos command line argument is not provided.
+//  - The given lumpnum identifying the demo to play back identifies a
+//    demo that comes from a .lmp file, not a .wad file.
+//  - Before proceeding, a warning is shown to the user on the console.
+boolean D_NonVanillaPlayback(boolean conditional, int lumpnum,
+                             char *feature)
+{
+    if (!conditional || StrictDemos())
+    {
+        return false;
+    }
+
+    if (!IsDemoFile(lumpnum))
+    {
+        printf("Warning: WAD contains demo with a non-vanilla extension "
+               "(%s)\n", feature);
+        return false;
+    }
+
+    printf("Warning: Playing back a demo file with a non-vanilla extension "
+           "(%s). Use -strictdemos to disable this extension.\n",
+           feature);
+
+    return true;
+}
+
--- a/src/d_loop.h
+++ b/src/d_loop.h
@@ -77,5 +77,12 @@
 extern boolean singletics;
 extern int gametic, ticdup;
 
+// Check if it is permitted to record a demo with a non-vanilla feature.
+boolean D_NonVanillaRecord(boolean conditional, char *feature);
+
+// Check if it is permitted to play back a demo with a non-vanilla feature.
+boolean D_NonVanillaPlayback(boolean conditional, int lumpnum,
+                             char *feature);
+
 #endif
 
--- a/src/doom/g_game.c
+++ b/src/doom/g_game.c
@@ -2056,6 +2056,8 @@
 { 
     int             i; 
 
+    demo_p = demobuffer;
+
     //!
     // @category demo
     //
@@ -2062,16 +2064,12 @@
     // Record a high resolution "Doom 1.91" demo.
     //
 
-    longtics = M_CheckParm("-longtics") != 0;
+    longtics = D_NonVanillaRecord(M_ParmExists("-longtics"),
+                                  "Doom 1.91 demo format");
 
     // If not recording a longtics demo, record in low res
-
     lowres_turn = !longtics;
-    
-    demo_p = demobuffer;
-	
-    // Save the right version code for this demo
- 
+
     if (longtics)
     {
         *demo_p++ = DOOM_191_VERSION;
@@ -2148,21 +2146,6 @@
     }
 }
 
-// Returns true if the given lump number corresponds to data from a .lmp
-// file, as opposed to a WAD.
-static boolean IsDemoFile(int lumpnum)
-{
-    char *lower;
-    boolean result;
-
-    lower = M_StringDuplicate(lumpinfo[lumpnum]->wad_file->path);
-    M_ForceLowercase(lower);
-    result = M_StringEndsWith(lower, ".lmp");
-    free(lower);
-
-    return result;
-}
-
 void G_DoPlayDemo (void)
 {
     skill_t skill;
@@ -2179,10 +2162,9 @@
     longtics = false;
 
     // Longtics demos use the modified format that is generated by cph's
-    // hacked "v1.91" doom exe. We support this format, but only if the
-    // demo is being played "manually" on the command line; such demos
-    // are forbidden inside WAD files.
-    if (IsDemoFile(lumpnum) && demoversion == DOOM_191_VERSION)
+    // hacked "v1.91" doom exe. This is a non-vanilla extension.
+    if (D_NonVanillaPlayback(demoversion == DOOM_191_VERSION, lumpnum,
+                             "Doom 1.91 demo format"))
     {
         longtics = true;
     }
@@ -2200,7 +2182,7 @@
         I_Error(message, demoversion, G_VanillaVersionCode(),
                          DemoVersionDescription(demoversion));
     }
-    
+
     skill = *demo_p++; 
     episode = *demo_p++; 
     map = *demo_p++;