From 6bdaa705b3e363075b87f9a471c68515a92e19b7 Mon Sep 17 00:00:00 2001 From: terencehill Date: Tue, 26 Jul 2016 15:06:41 +0200 Subject: [PATCH] Patch by Spaceman that enables recording and playing back demo camera movements (camera_enable 1) --- defaultXonotic.cfg | 2 + qcsrc/client/autocvars.qh | 2 + qcsrc/client/view.qc | 312 ++++++++++++++++++++++++-------------- 3 files changed, 206 insertions(+), 110 deletions(-) diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index 11ba8e4ff..73ad5fe9e 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -1106,6 +1106,8 @@ set camera_chase_smoothly 0 "Attenuate player movements (only in chase mode)" set camera_look_player 0 "Always look to the player. Mouse input is ignored in this mode" set camera_look_attenuation 8 "Attenuation of \"looking\" movements, only if camera_look_player is set. Bigger is smoother" set camera_forward_follows 1 "0: Move the camera forwards without changing altitude. 1: Move towards what you are looking" +set camera_playback 0 "replay the cameras position file" +set camera_record 0 "save the cameras position to a file" // "Gentle mode": show no blood seta sv_gentle 0 "force gentle mode for everyone, also remove references to acts of killing from the messages" diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index d159cd317..c5e45884e 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -13,6 +13,8 @@ bool autocvar_camera_free; float autocvar_camera_look_attenuation; float autocvar_camera_look_player; float autocvar_camera_mouse_threshold; +float autocvar_camera_playback; +float autocvar_camera_record; bool autocvar_camera_reset; float autocvar_camera_speed_attenuation; float autocvar_camera_speed_chase; diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 200bcfde7..b02b2ab37 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -707,6 +707,36 @@ float TrueAimCheck() return SHOTTYPE_HITWORLD; } +float open_file_value; + +void open_file_read(void) +{ + if(open_file_value) + return; + else + open_file_value = fopen("test_write", FILE_READ); +} + +void open_file_write(void) +{ + if(open_file_value) + return; + else + open_file_value = fopen("test_write", FILE_WRITE); +} + +void close_file(void) +{ + if(open_file_value) + { + fclose(open_file_value); + open_file_value = 0; + } +} + +vector origin_next, angle_next; +float time_next; // float playback_finished; + void PostInit(); void CSQC_Demo_Camera(); float HUD_WouldDrawScoreboard(); @@ -2271,144 +2301,206 @@ void CSQC_UpdateView(entity this, float w, float h) vector camera_offset, current_camera_offset, mouse_angles, current_angles, current_origin, current_position; void CSQC_Demo_Camera() { - float speed, attenuation, dimensions; - vector tmp, delta; - - if( autocvar_camera_reset || !camera_mode ) + if(autocvar_camera_playback) { - camera_offset = '0 0 0'; - current_angles = '0 0 0'; - camera_direction = '0 0 0'; - camera_offset.z += 30; - camera_offset.x += 30 * -cos(current_angles.y * DEG2RAD); - camera_offset.y += 30 * -sin(current_angles.y * DEG2RAD); - current_origin = view_origin; - current_camera_offset = camera_offset; - cvar_set("camera_reset", "0"); - camera_mode = CAMERA_CHASE; - } - - // Camera angles - if( camera_roll ) - mouse_angles.z += camera_roll * autocvar_camera_speed_roll; + open_file_read(); + string s, s2; - if(autocvar_camera_look_player) - { - vector dir; float n; - dir = normalize(view_origin - current_position); - n = mouse_angles.z; - mouse_angles = vectoangles(dir); - mouse_angles.x = mouse_angles.x * -1; - mouse_angles.z = n; + if(time >= time_next) + { + setproperty(VF_ANGLES, angle_next); + setproperty(VF_ORIGIN, origin_next); + + s = fgets(open_file_value); + + if(s == "") + { + print("^1file closed\n"); + close_file(); + autocvar_camera_playback = 0; + return; + } + + s2 = substring(s, 0, 2); + + if(s2 == "//") + print("Comment\n"); + else if(s2 == "##") + print("Do stuff\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)); + } + } + else + { + setproperty(VF_ANGLES, angle_next); + setproperty(VF_ORIGIN, origin_next); + } } else { - tmp = getmousepos() * 0.1; - if(vdist(tmp, >, autocvar_camera_mouse_threshold)) + float speed, attenuation, dimensions; + vector tmp, delta; + + if( autocvar_camera_reset || !camera_mode ) { - mouse_angles.x += tmp.y * cos(mouse_angles.z * DEG2RAD) + (tmp.x * sin(mouse_angles.z * DEG2RAD)); - mouse_angles.y -= tmp.x * cos(mouse_angles.z * DEG2RAD) + (tmp.y * -sin(mouse_angles.z * DEG2RAD)); + camera_offset = '0 0 0'; + current_angles = '0 0 0'; + camera_direction = '0 0 0'; + camera_offset.z += 30; + camera_offset.x += 30 * -cos(current_angles.y * DEG2RAD); + camera_offset.y += 30 * -sin(current_angles.y * DEG2RAD); + current_origin = view_origin; + current_camera_offset = camera_offset; + cvar_set("camera_reset", "0"); + camera_mode = CAMERA_CHASE; } - } - while (mouse_angles.x < -180) mouse_angles.x = mouse_angles.x + 360; - while (mouse_angles.x > 180) mouse_angles.x = mouse_angles.x - 360; - while (mouse_angles.y < -180) mouse_angles.y = mouse_angles.y + 360; - while (mouse_angles.y > 180) mouse_angles.y = mouse_angles.y - 360; + // Camera angles + if( camera_roll ) + mouse_angles.z += camera_roll * autocvar_camera_speed_roll; - // Fix difference when angles don't have the same sign - delta = '0 0 0'; - if(mouse_angles.y < -60 && current_angles.y > 60) - delta = '0 360 0'; - if(mouse_angles.y > 60 && current_angles.y < -60) - delta = '0 -360 0'; + if(autocvar_camera_look_player) + { + vector dir; + float n; - if(autocvar_camera_look_player) - attenuation = autocvar_camera_look_attenuation; - else - attenuation = autocvar_camera_speed_attenuation; + dir = normalize(view_origin - current_position); + n = mouse_angles.z; + mouse_angles = vectoangles(dir); + mouse_angles.x = mouse_angles.x * -1; + mouse_angles.z = n; + } + else + { + tmp = getmousepos() * 0.1; + if(vdist(tmp, >, autocvar_camera_mouse_threshold)) + { + mouse_angles.x += tmp.y * cos(mouse_angles.z * DEG2RAD) + (tmp.x * sin(mouse_angles.z * DEG2RAD)); + mouse_angles.y -= tmp.x * cos(mouse_angles.z * DEG2RAD) + (tmp.y * -sin(mouse_angles.z * DEG2RAD)); + } + } + + while (mouse_angles.x < -180) mouse_angles.x = mouse_angles.x + 360; + while (mouse_angles.x > 180) mouse_angles.x = mouse_angles.x - 360; + while (mouse_angles.y < -180) mouse_angles.y = mouse_angles.y + 360; + while (mouse_angles.y > 180) mouse_angles.y = mouse_angles.y - 360; + + // Fix difference when angles don't have the same sign + delta = '0 0 0'; + if(mouse_angles.y < -60 && current_angles.y > 60) + delta = '0 360 0'; + if(mouse_angles.y > 60 && current_angles.y < -60) + delta = '0 -360 0'; + + if(autocvar_camera_look_player) + attenuation = autocvar_camera_look_attenuation; + else + attenuation = autocvar_camera_speed_attenuation; - attenuation = 1 / max(1, attenuation); - current_angles += (mouse_angles - current_angles + delta) * attenuation; + attenuation = 1 / max(1, attenuation); + current_angles += (mouse_angles - current_angles + delta) * attenuation; - while (current_angles.x < -180) current_angles.x = current_angles.x + 360; - while (current_angles.x > 180) current_angles.x = current_angles.x - 360; - while (current_angles.y < -180) current_angles.y = current_angles.y + 360; - while (current_angles.y > 180) current_angles.y = current_angles.y - 360; + while (current_angles.x < -180) current_angles.x = current_angles.x + 360; + while (current_angles.x > 180) current_angles.x = current_angles.x - 360; + while (current_angles.y < -180) current_angles.y = current_angles.y + 360; + while (current_angles.y > 180) current_angles.y = current_angles.y - 360; - // Camera position - tmp = '0 0 0'; - dimensions = 0; + // Camera position + tmp = '0 0 0'; + dimensions = 0; - if( camera_direction.x ) - { - tmp.x = camera_direction.x * cos(current_angles.y * DEG2RAD); - tmp.y = camera_direction.x * sin(current_angles.y * DEG2RAD); - if( autocvar_camera_forward_follows && !autocvar_camera_look_player ) - tmp.z = camera_direction.x * -sin(current_angles.x * DEG2RAD); - ++dimensions; - } + if( camera_direction.x ) + { + tmp.x = camera_direction.x * cos(current_angles.y * DEG2RAD); + tmp.y = camera_direction.x * sin(current_angles.y * DEG2RAD); + if( autocvar_camera_forward_follows && !autocvar_camera_look_player ) + tmp.z = camera_direction.x * -sin(current_angles.x * DEG2RAD); + ++dimensions; + } - if( camera_direction.y ) - { - tmp.x += camera_direction.y * -sin(current_angles.y * DEG2RAD); - tmp.y += camera_direction.y * cos(current_angles.y * DEG2RAD) * cos(current_angles.z * DEG2RAD); - tmp.z += camera_direction.y * sin(current_angles.z * DEG2RAD); - ++dimensions; - } + if( camera_direction.y ) + { + tmp.x += camera_direction.y * -sin(current_angles.y * DEG2RAD); + tmp.y += camera_direction.y * cos(current_angles.y * DEG2RAD) * cos(current_angles.z * DEG2RAD); + tmp.z += camera_direction.y * sin(current_angles.z * DEG2RAD); + ++dimensions; + } - if( camera_direction.z ) - { - tmp.z += camera_direction.z * cos(current_angles.z * DEG2RAD); - ++dimensions; - } + if( camera_direction.z ) + { + tmp.z += camera_direction.z * cos(current_angles.z * DEG2RAD); + ++dimensions; + } - if(autocvar_camera_free) - speed = autocvar_camera_speed_free; - else - speed = autocvar_camera_speed_chase; + if(autocvar_camera_free) + speed = autocvar_camera_speed_free; + else + speed = autocvar_camera_speed_chase; - if(dimensions) - { - speed = speed * sqrt(1 / dimensions); - camera_offset += tmp * speed; - } + if(dimensions) + { + speed = speed * sqrt(1 / dimensions); + camera_offset += tmp * speed; + } - current_camera_offset += (camera_offset - current_camera_offset) * attenuation; + current_camera_offset += (camera_offset - current_camera_offset) * attenuation; - // Camera modes - if( autocvar_camera_free ) - { - if ( camera_mode == CAMERA_CHASE ) + // Camera modes + if( autocvar_camera_free ) { - current_camera_offset = current_origin + current_camera_offset; - camera_offset = current_origin + camera_offset; - } + if ( camera_mode == CAMERA_CHASE ) + { + current_camera_offset = current_origin + current_camera_offset; + camera_offset = current_origin + camera_offset; + } - camera_mode = CAMERA_FREE; - current_position = current_camera_offset; - } - else - { - if ( camera_mode == CAMERA_FREE ) + camera_mode = CAMERA_FREE; + current_position = current_camera_offset; + } + else { - current_origin = view_origin; - camera_offset = camera_offset - current_origin; - current_camera_offset = current_camera_offset - current_origin; + if ( camera_mode == CAMERA_FREE ) + { + current_origin = view_origin; + camera_offset = camera_offset - current_origin; + current_camera_offset = current_camera_offset - current_origin; + } + + camera_mode = CAMERA_CHASE; + + if(autocvar_camera_chase_smoothly) + current_origin += (view_origin - current_origin) * attenuation; + else + current_origin = view_origin; + + current_position = current_origin + current_camera_offset; } - camera_mode = CAMERA_CHASE; + setproperty(VF_ANGLES, current_angles); + setproperty(VF_ORIGIN, current_position); - if(autocvar_camera_chase_smoothly) - current_origin += (view_origin - current_origin) * attenuation; + if(autocvar_camera_record) + { + open_file_write(); + fputs(open_file_value, strcat(ftos(time), ",", vtos(current_position), ",", vtos(current_angles), "\n")); + } else - current_origin = view_origin; - - current_position = current_origin + current_camera_offset; + { + close_file(); + } } - - setproperty(VF_ANGLES, current_angles); - setproperty(VF_ORIGIN, current_position); } -- 2.39.2