]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_demo.c
note to myself: skipping over data works better if you actually do it
[xonotic/darkplaces.git] / cl_demo.c
index f4a4cf4ce90104bbd3c34581922a0e8c221c03ce..6d5087f4df0809958496079230651ca5ae9b92d9 100644 (file)
--- a/cl_demo.c
+++ b/cl_demo.c
@@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "quakedef.h"
 
+extern cvar_t cl_capturevideo;
 int old_vsync = 0;
 
 void CL_FinishTimeDemo (void);
@@ -87,7 +88,7 @@ void CL_StopPlayback (void)
        if (cls.timedemo)
                CL_FinishTimeDemo ();
 
-       if (COM_CheckParm("-demo") || COM_CheckParm("-demolooponly"))
+       if (COM_CheckParm("-demo") || COM_CheckParm("-capturedemo"))
                Host_Quit_f();
 
 }
@@ -99,7 +100,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 +109,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);
 }
 
 /*
@@ -137,7 +138,7 @@ void CL_ReadDemoMessage(void)
        if (cls.demopaused)
                return;
 
-       while (1)
+       for (;;)
        {
                // decide if it is time to grab the next message
                // always grab until fully connected
@@ -145,33 +146,22 @@ void CL_ReadDemoMessage(void)
                {
                        if (cls.timedemo)
                        {
-                               if (host_framecount == cls.td_lastframe)
-                               {
-                                       // already read this frame's message
-                                       return;
-                               }
-                               if (cls.td_lastframe == -1)
-                               {
-                                       // we start counting on the second frame
-                                       // (after parsing connection stuff)
-                                       cls.td_startframe = host_framecount + 1;
-                               }
-                               cls.td_lastframe = host_framecount;
+                               cls.td_frames++;
                                cls.td_onesecondframes++;
                                // 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
-                               if (host_framecount == cls.td_startframe)
+                               if (cls.td_frames == 0)
                                {
                                        cls.td_starttime = realtime;
-                                       cls.td_onesecondnexttime = realtime + 1;
+                                       cls.td_onesecondnexttime = cl.time + 1;
                                        cls.td_onesecondframes = 0;
                                        cls.td_onesecondminframes = 0;
                                        cls.td_onesecondmaxframes = 0;
                                        cls.td_onesecondavgframes = 0;
                                        cls.td_onesecondavgcount = 0;
                                }
-                               if (realtime >= cls.td_onesecondnexttime)
+                               if (cl.time >= cls.td_onesecondnexttime)
                                {
                                        if (cls.td_onesecondavgcount == 0)
                                        {
@@ -196,6 +186,12 @@ void CL_ReadDemoMessage(void)
                // get the next message
                FS_Read(cls.demofile, &net_message.cursize, 4);
                net_message.cursize = LittleLong(net_message.cursize);
+               if(net_message.cursize & DEMOMSG_CLIENT_TO_SERVER) // This is a client->server message! Ignore for now!
+               {
+                       // skip over demo packet
+                       FS_Seek(cls.demofile, 12 + (net_message.cursize & (~DEMOMSG_CLIENT_TO_SERVER)), SEEK_CUR);
+                       continue;
+               }
                if (net_message.cursize > net_message.maxsize)
                        Host_Error("Demo message (%i) > net_message.maxsize (%i)", net_message.cursize, net_message.maxsize);
                VectorCopy(cl.mviewangles[0], cl.mviewangles[1]);
@@ -213,6 +209,9 @@ void CL_ReadDemoMessage(void)
                        // In case the demo contains a "svc_disconnect" message
                        if (!cls.demoplayback)
                                return;
+
+                       if (cls.timedemo)
+                               return;
                }
                else
                {
@@ -232,6 +231,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 +241,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);
@@ -386,8 +391,7 @@ void CL_FinishTimeDemo (void)
 
        cls.timedemo = false;
 
-// the first frame didn't count
-       frames = (host_framecount - cls.td_startframe) - 1;
+       frames = cls.td_frames;
        time = realtime - cls.td_starttime;
        totalfpsavg = time > 0 ? frames / time : 0;
        fpsmin = cls.td_onesecondminframes;
@@ -415,6 +419,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
@@ -426,7 +432,8 @@ void CL_TimeDemo_f (void)
        scr_con_current = 0;
 
        cls.timedemo = true;
-       // get first message this frame
-       cls.td_lastframe = -1;
+       cls.td_frames = -2;             // skip the first frame
+       cls.demonum = -1;               // stop demo loop
+       cls.demonum = -1;               // stop demo loop
 }