From 8f774b39ef501f3529008eb7bb48ddeb7d2624aa Mon Sep 17 00:00:00 2001 From: terencehill Date: Tue, 26 Jul 2016 15:29:58 +0200 Subject: [PATCH] Rewrite demo camera playback algorithm as it wasn't independent from demo playback frame rate and allowed to playback the camera record file at any moment --- qcsrc/client/view.qc | 93 +++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 02a81a000..a37a883e7 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -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(); + } } } } -- 2.39.2