]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_demo.c
moved the code that applies slowmo to demo playback so that it reacts
[xonotic/darkplaces.git] / cl_demo.c
index f4a4cf4ce90104bbd3c34581922a0e8c221c03ce..27761778f689a7ca4d0cd0a6c2053ea99d5b4898 100644 (file)
--- a/cl_demo.c
+++ b/cl_demo.c
@@ -87,7 +87,7 @@ void CL_StopPlayback (void)
        if (cls.timedemo)
                CL_FinishTimeDemo ();
 
-       if (COM_CheckParm("-demo") || COM_CheckParm("-demolooponly"))
+       if (COM_CheckParm("-demo"))
                Host_Quit_f();
 
 }
@@ -99,7 +99,7 @@ CL_WriteDemoMessage
 Dumps the current net message, prefixed by the length and view angles
 ====================
 */
-void CL_WriteDemoMessage (void)
+void CL_WriteDemoMessage (sizebuf_t *message)
 {
        int             len;
        int             i;
@@ -108,14 +108,14 @@ void CL_WriteDemoMessage (void)
        if (cls.demopaused) // LordHavoc: pausedemo
                return;
 
-       len = LittleLong (net_message.cursize);
+       len = LittleLong (message->cursize);
        FS_Write (cls.demofile, &len, 4);
        for (i=0 ; i<3 ; i++)
        {
                f = LittleFloat (cl.viewangles[i]);
                FS_Write (cls.demofile, &f, 4);
        }
-       FS_Write (cls.demofile, net_message.data, net_message.cursize);
+       FS_Write (cls.demofile, message->data, message->cursize);
 }
 
 /*
@@ -152,12 +152,14 @@ void CL_ReadDemoMessage(void)
                                }
                                if (cls.td_lastframe == -1)
                                {
-                                       // we start counting on the second frame
-                                       // (after parsing connection stuff)
-                                       cls.td_startframe = host_framecount + 1;
+                                       // render a couple frames before we start counting
+                                       cls.td_startframe = host_framecount + 3;
                                }
                                cls.td_lastframe = host_framecount;
                                cls.td_onesecondframes++;
+                               // don't read any new messages during the warm-up period
+                               if (host_framecount < cls.td_startframe)
+                                       return;
                                // if this is the first official frame we can now grab the real
                                // td_starttime so the bogus time on the first frame doesn't
                                // count against the final report
@@ -232,6 +234,9 @@ stop recording a demo
 */
 void CL_Stop_f (void)
 {
+       sizebuf_t buf;
+       unsigned char bufdata[64];
+
        if (!cls.demorecording)
        {
                Con_Print("Not recording a demo.\n");
@@ -239,9 +244,12 @@ void CL_Stop_f (void)
        }
 
 // write a disconnect message to the demo file
-       SZ_Clear (&net_message);
-       MSG_WriteByte (&net_message, svc_disconnect);
-       CL_WriteDemoMessage ();
+       // LordHavoc: don't replace the net_message when doing this
+       buf.data = bufdata;
+       buf.maxsize = sizeof(bufdata);
+       SZ_Clear(&buf);
+       MSG_WriteByte(&buf, svc_disconnect);
+       CL_WriteDemoMessage(&buf);
 
 // finish up
        FS_Close (cls.demofile);
@@ -415,6 +423,8 @@ void CL_TimeDemo_f (void)
                return;
        }
 
+       srand(0); // predictable random sequence for benchmarking
+
        CL_PlayDemo_f ();
 
 // cls.td_starttime will be grabbed at the second frame of the demo, so