shithub: choc

Download patch

ref: aa3e8e11e588c35eec44ea58f1a9d06b02e3efe5
parent: 69a8ad95840704e1061dca31b2427599291a6add
author: Thomas A. Birkel <capnclever@gmail.com>
date: Thu Oct 20 14:50:56 EDT 2016

Add demo support to automatically playback parameters in Heretic/Hexen

-longtics, -respawn, and -nomonsters are stored in the demo via the
player one header byte.

Move longtics into single file: its usage is now limited to only
G_RecordDemo so it can stay local to g_game.c.

Additional implemention for #432

--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -1034,14 +1034,6 @@
     //!
     // @category demo
     //
-    // Record or playback a demo with high resolution turning.
-    //
-
-    longtics = M_ParmExists("-longtics");
-
-    //!
-    // @category demo
-    //
     // Record or playback a demo without automatically quitting
     // after either level exit or player respawn.
     //
--- a/src/heretic/doomdef.h
+++ b/src/heretic/doomdef.h
@@ -527,7 +527,6 @@
 extern int GetWeaponAmmo[NUMWEAPONS];
 
 extern boolean demorecording;
-extern boolean longtics;        // specify high resolution turning in demos
 extern boolean demoplayback;
 extern boolean demoextend;      // allow demos to persist through exit/respawn
 extern int skytexture;
--- a/src/heretic/g_game.c
+++ b/src/heretic/g_game.c
@@ -110,7 +110,7 @@
 
 char demoname[32];
 boolean demorecording;
-boolean longtics;
+boolean longtics;               // specify high resolution turning in demos
 boolean lowres_turn;
 boolean shortticfix;            // calculate lowres turning like doom
 boolean demoplayback;
@@ -1737,6 +1737,14 @@
     int i;
     int maxsize;
 
+    //!
+    // @category demo
+    //
+    // Record or playback a demo with high resolution turning.
+    //
+
+    longtics = M_ParmExists("-longtics");
+
     // If not recording a longtics demo, record in low res
 
     lowres_turn = !longtics;
@@ -1746,6 +1754,7 @@
     //
     // Smooth out low resolution turning when recording a demo.
     //
+
     shortticfix = M_ParmExists("-shortticfix");
 
     G_InitNew(skill, episode, map);
@@ -1773,7 +1782,28 @@
     *demo_p++ = episode;
     *demo_p++ = map;
 
-    for (i = 0; i < MAXPLAYERS; i++)
+    // Write special parameter bits onto player one byte.
+    // This aligns with vvHeretic demo usage:
+    //   0x20 = -respawn
+    //   0x10 = -longtics
+    //   0x02 = -nomonsters
+
+    *demo_p = 1; // assume player one exists
+    if (respawnparm)
+    {
+        *demo_p += 32;
+    }
+    if (longtics)
+    {
+        *demo_p += 16;
+    }
+    if (nomonsters)
+    {
+        *demo_p += 2;
+    }
+    demo_p++;
+
+    for (i = 1; i < MAXPLAYERS; i++)
         *demo_p++ = playeringame[i];
 
     demorecording = true;
@@ -1807,6 +1837,11 @@
     episode = *demo_p++;
     map = *demo_p++;
 
+    // Read special parameter bits: see G_RecordDemo() for details.
+    respawnparm = *demo_p & 32;
+    longtics    = *demo_p & 16;
+    nomonsters  = *demo_p & 2;
+
     for (i = 0; i < MAXPLAYERS; i++)
         playeringame[i] = *demo_p++;
 
@@ -1835,6 +1870,11 @@
     skill = *demo_p++;
     episode = *demo_p++;
     map = *demo_p++;
+
+    // Read special parameter bits: see G_RecordDemo() for details.
+    respawnparm = *demo_p & 32;
+    longtics    = *demo_p & 16;
+    nomonsters  = *demo_p & 2;
 
     for (i = 0; i < MAXPLAYERS; i++)
     {
--- a/src/hexen/g_game.c
+++ b/src/hexen/g_game.c
@@ -93,7 +93,7 @@
 
 char demoname[32];
 boolean demorecording;
-boolean longtics;
+boolean longtics;               // specify high resolution turning in demos
 boolean lowres_turn;
 boolean shortticfix;            // calculate lowres turning like doom
 boolean demoplayback;
@@ -1896,17 +1896,26 @@
     int i;
     int maxsize;
 
+    //!
+    // @category demo
+    //
+    // Record or playback a demo with high resolution turning.
+    //
+
+    longtics = M_ParmExists("-longtics");
+
     // If not recording a longtics demo, record in low res
 
+    lowres_turn = !longtics;
+
     //!
     // @category demo
     //
     // Smooth out low resolution turning when recording a demo.
     //
+
     shortticfix = M_ParmExists("-shortticfix");
 
-    lowres_turn = !longtics;
-
     G_InitNew(skill, episode, map);
     usergame = false;
     M_StringCopy(demoname, name, sizeof(demoname));
@@ -1932,8 +1941,31 @@
     *demo_p++ = episode;
     *demo_p++ = map;
 
-    for (i = 0; i < maxplayers; i++)
+    // Write special parameter bits onto player one byte.
+    // This aligns with vvHeretic demo usage. Hexen demo support has no
+    // precedent here so consistency with another game is chosen:
+    //   0x20 = -respawn
+    //   0x10 = -longtics
+    //   0x02 = -nomonsters
+
+    *demo_p = 1; // assume player one exists
+    if (respawnparm)
     {
+        *demo_p += 32;
+    }
+    if (longtics)
+    {
+        *demo_p += 16;
+    }
+    if (nomonsters)
+    {
+        *demo_p += 2;
+    }
+    demo_p++;
+    *demo_p++ = PlayerClass[0];
+
+    for (i = 1; i < maxplayers; i++)
+    {
         *demo_p++ = playeringame[i];
         *demo_p++ = PlayerClass[i];
     }
@@ -1969,6 +2001,11 @@
     episode = *demo_p++;
     map = *demo_p++;
 
+    // Read special parameter bits: see G_RecordDemo() for details.
+    respawnparm = *demo_p & 32;
+    longtics    = *demo_p & 16;
+    nomonsters  = *demo_p & 2;
+
     for (i = 0; i < maxplayers; i++)
     {
         playeringame[i] = *demo_p++;
@@ -2003,6 +2040,11 @@
     skill = *demo_p++;
     episode = *demo_p++;
     map = *demo_p++;
+
+    // Read special parameter bits: see G_RecordDemo() for details.
+    respawnparm = *demo_p & 32;
+    longtics    = *demo_p & 16;
+    nomonsters  = *demo_p & 2;
 
     for (i = 0; i < maxplayers; i++)
     {
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -679,14 +679,6 @@
     //!
     // @category demo
     //
-    // Record or playback a demo with high resolution turning.
-    //
-
-    longtics = M_ParmExists("-longtics");
-
-    //!
-    // @category demo
-    //
     // Record or playback a demo without automatically quitting
     // after either level exit or player respawn.
     //
--- a/src/hexen/h2def.h
+++ b/src/hexen/h2def.h
@@ -632,7 +632,6 @@
 
 extern boolean DebugSound;      // debug flag for displaying sound info
 
-extern boolean longtics;        // specify high resolution turning in demos
 extern boolean demoplayback;
 extern boolean demoextend;      // allow demos to persist through exit/respawn
 extern int maxzone;             // Maximum chunk allocated for zone heap