X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Flib%2Fcsqcmodel%2Fcl_player.qc;h=4362c587fda022bdc5eeaae0b718381c8414b06b;hp=66613b53229ad6ef53d34a9ad43bc0b0ed413abd;hb=f785b8a76c2336cb00e78fe9e738d55512a086f5;hpb=04338413d72286b6f5a6377bc43a1fac55976a59 diff --git a/qcsrc/lib/csqcmodel/cl_player.qc b/qcsrc/lib/csqcmodel/cl_player.qc index 66613b5322..4362c587fd 100644 --- a/qcsrc/lib/csqcmodel/cl_player.qc +++ b/qcsrc/lib/csqcmodel/cl_player.qc @@ -25,15 +25,6 @@ #include "cl_model.qh" #include "common.qh" #include "interpolate.qh" -#include -#include -#include -#include -#include -#include -#include -#include -#include float autocvar_cl_movement_errorcompensation = 0; bool autocvar_cl_movement_intermissionrunning = false; @@ -107,17 +98,17 @@ void CSQCPlayer_Unpredict(entity this) void CSQCPlayer_SetMinsMaxs(entity this) { - if (IS_DUCKED(this) || !this.isplayermodel) + if (IS_DUCKED(this) || !(this.isplayermodel & ISPLAYER_PLAYER)) { - this.mins = STAT(PL_CROUCH_MIN, NULL); - this.maxs = STAT(PL_CROUCH_MAX, NULL); - this.view_ofs = STAT(PL_CROUCH_VIEW_OFS, NULL); + this.mins = PHYS_PL_CROUCH_MIN(this); + this.maxs = PHYS_PL_CROUCH_MAX(this); + this.view_ofs = PHYS_PL_CROUCH_VIEWOFS(this); } else { - this.mins = STAT(PL_MIN, NULL); - this.maxs = STAT(PL_MAX, NULL); - this.view_ofs = STAT(PL_VIEW_OFS, NULL); + this.mins = PHYS_PL_MIN(this); + this.maxs = PHYS_PL_MAX(this); + this.view_ofs = PHYS_PL_VIEWOFS(this); } } @@ -177,7 +168,7 @@ void CSQCPlayer_PredictTo(entity this, float endframe, bool apply_error) { csqcplayer_moveframe = clientcommandframe; getinputstate(csqcplayer_moveframe-1); - LOG_INFO("the Weird code path got hit\n"); + LOG_INFO("the Weird code path got hit"); return; } #endif @@ -216,19 +207,101 @@ bool CSQCPlayer_IsLocalPlayer(entity this) return (this == csqcplayer); } -void CSQCPlayer_SetViewLocation() +float stairsmoothz; +float autocvar_cl_stairsmoothspeed; +float autocvar_cl_smoothviewheight; +float smooth_prevtime; +float viewheightavg; +float autocvar_cl_bobfall; +float autocvar_cl_bobfallcycle; +float autocvar_cl_bobfallminspeed; +float bobfall_swing; +float bobfall_speed; +vector CSQCPlayer_ApplySmoothing(entity this, vector v) { - viewloc_SetViewLocation(); + if(this.csqcmodel_teleported || !IS_ONGROUND(this) || autocvar_cl_stairsmoothspeed <= 0) + stairsmoothz = v.z; + else + { + if(v.z > stairsmoothz) + v.z = stairsmoothz = bound(v.z - PHYS_STEPHEIGHT(this), stairsmoothz + frametime * autocvar_cl_stairsmoothspeed, v.z); + else if(v.z < stairsmoothz) + v.z = stairsmoothz = bound(v.z, stairsmoothz - frametime * autocvar_cl_stairsmoothspeed, v.z + PHYS_STEPHEIGHT(this)); + } + + float viewheight = bound(0, (time - smooth_prevtime) / max(0.0001, autocvar_cl_smoothviewheight), 1); + viewheightavg = viewheightavg * (1 - viewheight) + this.view_ofs.z * viewheight; + v.z += viewheightavg; + + if(autocvar_cl_bobfall && autocvar_cl_bobfallcycle) + { + if(!IS_ONGROUND(this)) + { + bobfall_speed = bound(-400, this.velocity.z, 0) * bound(0, autocvar_cl_bobfall, 0.1); + if(this.velocity.z < -autocvar_cl_bobfallminspeed) + bobfall_swing = 1; + else + bobfall_swing = 0; // really? + } + else + { + bobfall_swing = max(0, bobfall_swing - autocvar_cl_bobfallcycle * frametime); + float bobfall = sin(M_PI * bobfall_swing) * bobfall_speed; + v.z += bobfall; + } + } + + smooth_prevtime = time; + + return v; +} + +bool autocvar_v_deathtilt; +float autocvar_v_deathtiltangle; +void CSQCPlayer_ApplyDeathTilt(entity this) +{ + if(!autocvar_v_deathtilt) + return; + view_angles.y = autocvar_v_deathtiltangle; +} + +float autocvar_v_idlescale; +float autocvar_v_ipitch_cycle; +float autocvar_v_iyaw_cycle; +float autocvar_v_iroll_cycle; +float autocvar_v_ipitch_level; +float autocvar_v_iyaw_level; +float autocvar_v_iroll_level; +void CSQCPlayer_ApplyIdleScaling(entity this) +{ + view_angles.x += autocvar_v_idlescale * sin(time * autocvar_v_ipitch_cycle) * autocvar_v_ipitch_level; + view_angles.y += autocvar_v_idlescale * sin(time * autocvar_v_iyaw_cycle) * autocvar_v_iyaw_level; + view_angles.z += autocvar_v_idlescale * sin(time * autocvar_v_iroll_cycle) * autocvar_v_iroll_level; + setproperty(VF_CL_VIEWANGLES, view_angles); // update view angles as well so we can aim +} + +float autocvar_chase_back; +float autocvar_chase_up; +vector CSQCPlayer_ApplyChase(entity this, vector v) +{ + // TODO: chase_overhead + v += this.view_ofs; + makevectors(view_angles); + tracebox(v, '-4 -4 -4', '4 4 4', v - v_forward * autocvar_chase_back, MOVE_NORMAL, this); + v = trace_endpos; + tracebox(v, '-4 -4 -4', '4 4 4', v + v_up * autocvar_chase_up, MOVE_NORMAL, this); + v = trace_endpos; + return v; } /** Called once per CSQC_UpdateView() */ void CSQCPlayer_SetCamera() { - const vector v0 = ((intermission && !autocvar_cl_movement_intermissionrunning) ? '0 0 0' : pmove_vel); // TRICK: pmove_vel is set by the engine when we get here. No need to network velocity - const float vh = STAT(VIEWHEIGHT); - const vector pl_viewofs = STAT(PL_VIEW_OFS, NULL); - const vector pl_viewofs_crouch = STAT(PL_CROUCH_VIEW_OFS, NULL); - const entity e = csqcplayer; + vector v0 = ((intermission && !autocvar_cl_movement_intermissionrunning) ? '0 0 0' : pmove_vel); // TRICK: pmove_vel is set by the engine when we get here. No need to network velocity + float vh = PHYS_VIEWHEIGHT(NULL); + vector pl_viewofs = PHYS_PL_VIEWOFS(NULL); + vector pl_viewofs_crouch = PHYS_PL_CROUCH_VIEWOFS(NULL); + entity e = csqcplayer; if (e) { if (servercommandframe == 0 || clientcommandframe == 0) @@ -253,13 +326,13 @@ void CSQCPlayer_SetCamera() } else { - const int flg = e.iflags; e.iflags &= ~(IFLAG_ORIGIN | IFLAG_ANGLES); + int flg = e.iflags; e.iflags &= ~(IFLAG_ORIGIN | IFLAG_ANGLES); InterpolateOrigin_Do(e); e.iflags = flg; if (csqcplayer_status == CSQCPLAYERSTATUS_FROMSERVER) { - const vector o = e.origin; + vector o = e.origin; csqcplayer_status = CSQCPLAYERSTATUS_PREDICTED; CSQCPlayer_PredictTo(e, servercommandframe + 1, false); CSQCPlayer_SetPredictionError(e.origin - o, e.velocity - v0, pmove_onground - IS_ONGROUND(e)); @@ -299,13 +372,26 @@ void CSQCPlayer_SetCamera() InterpolateOrigin_Do(view); view.view_ofs = '0 0 1' * vh; } - int refdefflags = 0; - if (view.csqcmodel_teleported) refdefflags |= REFDEFFLAG_TELEPORTED; - if (input_buttons & BIT(1)) refdefflags |= REFDEFFLAG_JUMPING; + //int refdefflags = 0; + //if (view.csqcmodel_teleported) refdefflags |= REFDEFFLAG_TELEPORTED; + //if (input_buttons & BIT(1)) refdefflags |= REFDEFFLAG_JUMPING; // note: these two only work in WIP2, but are harmless in WIP1 - if (STAT(HEALTH) <= 0 && STAT(HEALTH) != -666 && STAT(HEALTH) != -2342) refdefflags |= REFDEFFLAG_DEAD; - if (intermission) refdefflags |= REFDEFFLAG_INTERMISSION; - V_CalcRefdef(view, refdefflags); + //if (PHYS_HEALTH(NULL) <= 0 && PHYS_HEALTH(NULL) != -666 && PHYS_HEALTH(NULL) != -2342) refdefflags |= REFDEFFLAG_DEAD; + //if (intermission) refdefflags |= REFDEFFLAG_INTERMISSION; + vector vieworg = view.origin; + if(autocvar_chase_active) + vieworg = CSQCPlayer_ApplyChase(view, vieworg); + else + { + vieworg = CSQCPlayer_ApplySmoothing(view, vieworg); + if(IS_DEAD(view)) + CSQCPlayer_ApplyDeathTilt(view); + } + if(autocvar_v_idlescale) + CSQCPlayer_ApplyIdleScaling(view); + setproperty(VF_ORIGIN, vieworg); + setproperty(VF_ANGLES, view_angles); + //V_CalcRefdef(view, refdefflags); // TODO? uses .health stat in the engine when this isn't called here, may be broken! } else {