]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Rewrite demo camera playback algorithm as it wasn't independent from demo playback... terencehill/demo_camera_record_and_playback
authorterencehill <piuntn@gmail.com>
Tue, 26 Jul 2016 13:29:58 +0000 (15:29 +0200)
committerterencehill <piuntn@gmail.com>
Tue, 26 Jul 2016 13:29:58 +0000 (15:29 +0200)
qcsrc/client/view.qc

index 02a81a0004915c4fad879a41792b1a30b11e602e..a37a883e7295d1897634ed787c7d5a16835687b9 100644 (file)
@@ -719,7 +719,43 @@ void close_file(void)
 }
 
 vector origin_next, angle_next;
-float time_next; // float playback_finished;
+float time_next;
+float read_next_line()
+{
+       string s, s2;
+       float n;
+       s = fgets(camera_record_fh);
+
+       if(s == "")
+       {
+               print("Finished reading camera record file\n");
+               close_file();
+               return 0;
+       }
+
+       s2 = substring(s, 0, 2);
+
+       if(s2 == "//")
+               ;
+       else if(s2 == "##")
+               localcmd("\n", substring(s, 2, strlen(s) - 2), "\n");
+       else
+       {
+               n = tokenizebyseparator(s, ",");
+
+               if(n != 3)
+               {
+                       print("^1Error: line with wrong number of arguments:", s, "\n");
+                       close_file();
+                       return 0;
+               }
+
+               time_next = stof(argv(0));
+               origin_next = stov(argv(1));
+               angle_next = stov(argv(2));
+       }
+       return 1;
+}
 
 void PostInit();
 void CSQC_Demo_Camera();
@@ -2287,53 +2323,28 @@ void CSQC_Demo_Camera()
 {
        if(autocvar_camera_playback)
        {
-               string s, s2;
-               float n;
-
                if(camera_record_fh < 0)
-                       camera_record_fh = fopen("test_write", FILE_READ);
-
-               if(time >= time_next)
                {
-                       setproperty(VF_ANGLES, angle_next);
-                       setproperty(VF_ORIGIN, origin_next);
-
-                       s = fgets(camera_record_fh);
-
-                       if(s == "")
+                       camera_record_fh = fopen("test_write", FILE_READ);
+                       if(camera_record_fh < 0)
                        {
-                               print("Camera record file closed\n");
-                               close_file();
+                               print("^1Error: couldn't open test_write\n");
                                autocvar_camera_playback = 0;
                                return;
                        }
 
-                       s2 = substring(s, 0, 2);
-
-                       if(s2 == "//")
-                               ;
-                       else if(s2 == "##")
-                               localcmd("\n", substring(s, 2, strlen(s) - 2), "\n");
-                       else
-                       {
-                               n = tokenizebyseparator(s, ",");
-
-                               if(n != 3)
-                               {
-                                       print("^1Error: ", s, "\n");
-                                       return;
-                               }
-
-                               time_next = stof(argv(0));
-                               origin_next = stov(argv(1));
-                               angle_next = stov(argv(2));
-                       }
+                       time_next = 0;
                }
-               else
+               while(time >= time_next)
                {
-                       setproperty(VF_ANGLES, angle_next);
-                       setproperty(VF_ORIGIN, origin_next);
+                       if(!read_next_line())
+                       {
+                               autocvar_camera_playback = 0;
+                               return;
+                       }
                }
+               setproperty(VF_ANGLES, angle_next);
+               setproperty(VF_ORIGIN, origin_next);
        }
        else
        {
@@ -2487,7 +2498,11 @@ void CSQC_Demo_Camera()
                }
                else
                {
-                       close_file();
+                       if(camera_record_fh >= 0)
+                       {
+                               print("Camera record file saved\n");
+                               close_file();
+                       }
                }
        }
 }