2 * Copyright (c) 2011 Rudolf Polzer
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 var float autocvar_cl_movement_errorcompensation = 0;
24 var float autocvar_cl_movement = 2; // testing purposes
27 #define REFDEFFLAG_TELEPORTED 1
28 #define REFDEFFLAG_JUMPING 2
29 float pmove_onground; // weird engine flag we shouldn't really use but have to for now
31 vector csqcplayer_origin, csqcplayer_velocity;
32 float csqcplayer_sequence, player_pmflags;
33 float csqcplayer_moveframe;
34 vector csqcplayer_predictionerroro;
35 vector csqcplayer_predictionerrorv;
36 float csqcplayer_predictionerrortime;
37 float csqcplayer_predictionerrorfactor;
39 vector CSQCPlayer_GetPredictionErrorO()
41 if(time >= csqcplayer_predictionerrortime)
43 return csqcplayer_predictionerroro * (csqcplayer_predictionerrortime - time) * csqcplayer_predictionerrorfactor;
46 vector CSQCPlayer_GetPredictionErrorV()
48 if(time >= csqcplayer_predictionerrortime)
50 return csqcplayer_predictionerrorv * (csqcplayer_predictionerrortime - time) * csqcplayer_predictionerrorfactor;
53 void CSQCPlayer_SetPredictionError(vector o, vector v, float onground_diff)
55 // error too big to compensate, we LIKELY hit a teleport or a
56 // jumppad, or it's a jump time disagreement that'll get fixed
59 // FIXME we sometimes have disagreement in order of jump velocity. Do not act on them!
61 // commented out as this one did not help
64 printf("ONGROUND MISMATCH: %d x=%v v=%v\n", onground_diff, o, v);
68 if(vlen(o) > 32 || vlen(v) > 192)
70 //printf("TOO BIG: x=%v v=%v\n", o, v);
74 if(!autocvar_cl_movement_errorcompensation)
76 csqcplayer_predictionerrorfactor = 0;
80 csqcplayer_predictionerroro = CSQCPlayer_GetPredictionErrorO() + o;
81 csqcplayer_predictionerrorv = CSQCPlayer_GetPredictionErrorV() + v;
82 csqcplayer_predictionerrorfactor = autocvar_cl_movement_errorcompensation / ticrate;
83 csqcplayer_predictionerrortime = time + 1.0 / csqcplayer_predictionerrorfactor;
86 void CSQCPlayer_Unpredict()
88 if(csqcplayer_status == CSQCPLAYERSTATUS_UNPREDICTED)
90 if(csqcplayer_status != CSQCPLAYERSTATUS_PREDICTED)
91 error("Cannot unpredict in current status");
92 self.origin = csqcplayer_origin;
93 self.velocity = csqcplayer_velocity;
94 csqcplayer_moveframe = csqcplayer_sequence+1; //+1 because the recieved frame has the move already done (server side)
95 self.pmove_flags = player_pmflags;
98 void CSQCPlayer_SetMinsMaxs()
100 if(self.pmove_flags & PMF_DUCKED)
102 self.mins = PL_CROUCH_MIN;
103 self.maxs = PL_CROUCH_MAX;
104 self.view_ofs = PL_CROUCH_VIEW_OFS;
110 self.view_ofs = PL_VIEW_OFS;
114 void CSQCPlayer_SavePrediction()
116 player_pmflags = self.pmove_flags;
117 csqcplayer_origin = self.origin;
118 csqcplayer_velocity = self.velocity;
119 csqcplayer_sequence = servercommandframe;
120 csqcplayer_status = CSQCPLAYERSTATUS_PREDICTED;
123 // TODO: water prediction
124 float pmove_waterjumptime; // weird engine flag we shouldn't really use but have to for now
125 // TODO: move to a common header
126 #define vlen2(v) dotproduct(v, v)
127 void AngleVectors (vector angles, vector forward, vector right, vector up)
129 float angle, sr, sp, sy, cr, cp, cy;
131 angle = angles_y * (M_PI*2 / 360);
134 angle = angles_x * (M_PI*2 / 360);
147 angle = angles_z * (M_PI*2 / 360);
152 right_x = -1*(sr*sp*cy+cr*-sy);
153 right_y = -1*(sr*sp*sy+cr*cy);
154 right_z = -1*(sr*cp);
158 up_x = (cr*sp*cy+-sr*-sy);
159 up_y = (cr*sp*sy+-sr*cy);
181 // TODO: move these elsewhere
182 vector cl_playerstandmins = '-16 -16 -24';
183 vector cl_playerstandmaxs = '16 16 45';
184 vector cl_playercrouchmins = '-16 -16 -24';
185 vector cl_playercrouchmaxs = '16 16 25';
187 const float unstick_count = 27;
188 vector unstick_offsets[unstick_count] =
190 // 1 no nudge (just return the original if this test passes)
193 ' 0.000 0.000 0.125', '0.000 0.000 -0.125',
194 '-0.125 0.000 0.000', '0.125 0.000 0.000',
195 ' 0.000 -0.125 0.000', '0.000 0.125 0.000',
196 // 4 diagonal flat nudges
197 '-0.125 -0.125 0.000', '0.125 -0.125 0.000',
198 '-0.125 0.125 0.000', '0.125 0.125 0.000',
199 // 8 diagonal upward nudges
200 '-0.125 0.000 0.125', '0.125 0.000 0.125',
201 ' 0.000 -0.125 0.125', '0.000 0.125 0.125',
202 '-0.125 -0.125 0.125', '0.125 -0.125 0.125',
203 '-0.125 0.125 0.125', '0.125 0.125 0.125',
204 // 8 diagonal downward nudges
205 '-0.125 0.000 -0.125', '0.125 0.000 -0.125',
206 ' 0.000 -0.125 -0.125', '0.000 0.125 -0.125',
207 '-0.125 -0.125 -0.125', '0.125 -0.125 -0.125',
208 '-0.125 0.125 -0.125', '0.125 0.125 -0.125',
211 float CSQC_ClientMovement_Unstick(entity s)
215 for (i = 0; i < unstick_count; i++)
217 neworigin = unstick_offsets[i] + s.origin;
218 tracebox(neworigin, cl_playercrouchmins, cl_playercrouchmaxs, neworigin, MOVE_NORMAL, s);
219 if (!trace_startsolid)
221 s.origin = neworigin;
225 // if all offsets failed, give up
229 void CSQC_ClientMovement_UpdateStatus(entity s)
232 vector origin1, origin2;
234 // make sure player is not stuck
235 CSQC_ClientMovement_Unstick(s);
238 if (input_buttons & 16)
240 // wants to crouch, this always works..
241 if (!s.pmove_flags & PMF_DUCKED)
242 s.pmove_flags |= PMF_DUCKED;
246 // wants to stand, if currently crouching we need to check for a
248 if (s.pmove_flags & PMF_DUCKED)
250 tracebox(s.origin, cl_playerstandmins, cl_playerstandmaxs, s.origin, MOVE_NORMAL, s);
251 if (!trace_startsolid)
252 s.pmove_flags &= ~PMF_DUCKED;
255 if (s.pmove_flags & PMF_DUCKED)
257 s.mins = cl_playercrouchmins;
258 s.maxs = cl_playercrouchmaxs;
262 s.mins = cl_playerstandmins;
263 s.maxs = cl_playerstandmaxs;
270 origin2_z -= 1; // -2 causes clientside doublejump bug at above 150fps, raising that to 300fps :)
272 tracebox(origin1, s.mins, s.maxs, origin2, MOVE_NORMAL, s);
273 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
275 s.pmove_flags |= PMF_ONGROUND;
277 // this code actually "predicts" an impact; so let's clip velocity first
278 f = dotproduct(s.velocity, trace_plane_normal);
279 if(f < 0) // only if moving downwards actually
280 s.velocity -= f * trace_plane_normal;
283 s.pmove_flags &= ~PMF_ONGROUND; // onground = false;
285 // set watertype/waterlevel
287 origin1_z += s.mins_z + 1;
288 s.waterlevel = WATERLEVEL_NONE;
290 // s.watertype = CL_TracePoint(origin1, MOVE_NOMONSTERS, s, 0, true, false, NULL, false).startsupercontents & SUPERCONTENTS_LIQUIDSMASK;
293 // s.waterlevel = WATERLEVEL_WETFEET;
294 // origin1[2] = s.origin[2] + (s.mins[2] + s.maxs[2]) * 0.5f;
295 // if (CL_TracePoint(origin1, MOVE_NOMONSTERS, s, 0, true, false, NULL, false).startsupercontents & SUPERCONTENTS_LIQUIDSMASK)
297 // s.waterlevel = WATERLEVEL_SWIMMING;
298 // origin1[2] = s.origin[2] + 22;
299 // if (CL_TracePoint(origin1, MOVE_NOMONSTERS, s, 0, true, false, NULL, false).startsupercontents & SUPERCONTENTS_LIQUIDSMASK)
300 // s.waterlevel = WATERLEVEL_SUBMERGED;
304 // // water jump prediction
305 // if ((s.pmove_flags & PMF_ONGROUND) || s.velocity_z <= 0 || pmove_waterjumptime <= 0)
306 // pmove_waterjumptime = 0;
309 void CSQC_ClientMovement_Move(entity s)
315 vector currentorigin2;
317 vector primalvelocity;
318 float old_trace1_fraction;
319 vector old_trace1_endpos;
320 vector old_trace1_plane_normal;
321 float old_trace2_fraction;
322 vector old_trace2_plane_normal;
323 CSQC_ClientMovement_UpdateStatus(s);
324 primalvelocity = s.velocity;
325 for (bump = 0, t = input_timelength; bump < 8 && vlen2(s.velocity) > 0; bump++)
327 neworigin = s.origin + t * s.velocity;
328 tracebox(s.origin, s.mins, s.maxs, neworigin, MOVE_NORMAL, s);
329 old_trace1_fraction = trace_fraction;
330 old_trace1_endpos = trace_endpos;
331 old_trace1_plane_normal = trace_plane_normal;
332 if (trace_fraction < 1 && trace_plane_normal_z == 0)
334 // may be a step or wall, try stepping up
335 // first move forward at a higher level
336 currentorigin2 = s.origin;
337 currentorigin2_z += getstatf(STAT_MOVEVARS_STEPHEIGHT);
338 neworigin2 = neworigin;
339 neworigin2_z = s.origin_z + getstatf(STAT_MOVEVARS_STEPHEIGHT);
340 tracebox(currentorigin2, s.mins, s.maxs, neworigin2, MOVE_NORMAL, s);
341 if (!trace_startsolid)
343 // then move down from there
344 currentorigin2 = trace_endpos;
345 neworigin2 = trace_endpos;
346 neworigin2_z = s.origin_z;
347 old_trace2_fraction = trace_fraction;
348 old_trace2_plane_normal = trace_plane_normal;
349 tracebox(currentorigin2, s.mins, s.maxs, neworigin2, MOVE_NORMAL, s);
350 //Con_Printf("%f %f %f %f : %f %f %f %f : %f %f %f %f\n", trace.fraction, trace.endpos[0], trace.endpos[1], trace.endpos[2], trace2.fraction, trace2.endpos[0], trace2.endpos[1], trace2.endpos[2], trace3.fraction, trace3.endpos[0], trace3.endpos[1], trace3.endpos[2]);
351 // accept the new trace if it made some progress
352 if (fabs(trace_endpos_x - old_trace1_endpos_x) >= 0.03125 || fabs(trace_endpos_y - old_trace1_endpos_y) >= 0.03125)
354 trace_fraction = old_trace2_fraction;
355 trace_endpos = trace_endpos;
356 trace_plane_normal = old_trace2_plane_normal;
360 trace_fraction = old_trace1_fraction;
361 trace_endpos = old_trace1_endpos;
362 trace_plane_normal = old_trace1_plane_normal;
367 // check if it moved at all
368 if (trace_fraction >= 0.001)
369 s.origin = trace_endpos;
371 // check if it moved all the way
372 if (trace_fraction == 1)
375 // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
376 // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
377 // this got commented out in a change that supposedly makes the code match QW better
378 // so if this is broken, maybe put it in an if(cls.protocol != PROTOCOL_QUAKEWORLD) block
379 if (trace_plane_normal_z > 0.7)
380 s.pmove_flags |= PMF_ONGROUND;
382 t -= t * trace_fraction;
384 f = dotproduct(s.velocity, trace_plane_normal);
385 s.velocity -= f * trace_plane_normal;
387 if (pmove_waterjumptime > 0)
388 s.velocity = primalvelocity;
391 float CSQC_IsMoveInDirection(float forward, float side, float angle)
393 // TODO: move to a common header
394 #define RAD2DEG(a) ((a) * (180.0f / M_PI))
395 #define ANGLEMOD(a) ((a) - 360.0 * floor((a) / 360.0))
396 if(forward == 0 && side == 0)
397 return 0; // avoid division by zero
398 angle -= RAD2DEG(atan2(side, forward));
399 angle = (ANGLEMOD(angle + 180) - 180) / 45;
404 return 1 - fabs(angle);
409 float CSQC_GeomLerp(float a, float lerp, float b)
425 return a * pow(fabs(b / a), lerp);
428 void CSQC_ClientMovement_Physics_CPM_PM_Aircontrol(entity s, vector wishdir, float wishspeed)
430 float zspeed, speed, dot, k;
432 k = 32 * (2 * CSQC_IsMoveInDirection(input_movevalues_x, input_movevalues_y, 0) - 1);
436 k *= bound(0, wishspeed / getstatf(STAT_MOVEVARS_MAXAIRSPEED), 1);
438 zspeed = s.velocity_z;
440 speed = vlen(s.velocity);
441 if (speed) s.velocity /= speed;
443 dot = dotproduct(s.velocity, wishdir);
445 if(dot > 0) { // we can't change direction while slowing down
446 k *= pow(dot, getstatf(STAT_MOVEVARS_AIRCONTROL_POWER))*input_timelength;
447 speed = max(0, speed - getstatf(STAT_MOVEVARS_AIRCONTROL_PENALTY) * sqrt(max(0, 1 - dot*dot)) * k/32);
448 k *= getstatf(STAT_MOVEVARS_AIRCONTROL);
449 s.velocity = speed * s.velocity + k * wishdir;
450 s.velocity = normalize(s.velocity);
454 s.velocity_z = zspeed;
457 float CSQC_ClientMovement_Physics_AdjustAirAccelQW(float accelqw, float factor)
460 (accelqw < 0 ? -1 : +1)
462 bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1);
465 void CSQC_ClientMovement_Physics_PM_Accelerate(entity s, vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
472 float vel_xy_current;
473 float vel_xy_backward, vel_xy_forward;
476 if(stretchfactor > 0)
477 speedclamp = stretchfactor;
481 speedclamp = -1; // no clamping
486 if(moveflags & MOVEFLAG_Q2AIRACCELERATE)
487 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
489 vel_straight = dotproduct(s.velocity, wishdir);
490 vel_z = s.velocity_z;
493 vel_perpend = vel_xy - vel_straight * wishdir;
495 step = accel * input_timelength * wishspeed0;
497 vel_xy_current = vlen(vel_xy);
499 accelqw = CSQC_ClientMovement_Physics_AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
500 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
501 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
502 if(vel_xy_backward < 0)
503 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
505 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
507 if(sidefric < 0 && vlen2(vel_perpend))
508 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
511 f = max(0, 1 + input_timelength * wishspeed * sidefric);
512 fmin = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / vlen2(vel_perpend);
514 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
515 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
516 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
517 // obviously, this cannot be
523 vel_perpend *= max(fmin, f);
527 vel_perpend *= max(0, 1 - input_timelength * wishspeed * sidefric);
529 s.velocity = vel_perpend + vel_straight * wishdir;
533 float vel_xy_preclamp;
534 vel_xy_preclamp = vlen(s.velocity);
535 if(vel_xy_preclamp > 0) // prevent division by zero
537 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
538 if(vel_xy_current < vel_xy_preclamp)
539 s.velocity *= (vel_xy_current / vel_xy_preclamp);
543 s.velocity_z += vel_z;
546 void CSQC_ClientMovement_Physics_Walk(entity s)
554 vector forward = '0 0 0';
555 vector right = '0 0 0';
561 // jump if on ground with jump button pressed but only if it has been
562 // released at least once since the last jump
563 if (input_buttons & 2)
565 if ((s.pmove_flags & PMF_ONGROUND) && ((s.pmove_flags & PMF_JUMP_HELD) == 0 || !cvar("cl_movement_track_canjump")))
567 s.velocity_z += getstatf(STAT_MOVEVARS_JUMPVELOCITY);
568 s.pmove_flags &= ~PMF_ONGROUND;
569 s.pmove_flags |= PMF_JUMP_HELD; // canjump = false
573 s.pmove_flags &= ~PMF_JUMP_HELD; // canjump = true
575 // calculate movement vector
577 yawangles_y = input_angles_y;
578 AngleVectors(yawangles, forward, right, up);
579 wishvel = input_movevalues_x * forward + input_movevalues_y * right;
581 // split wishvel into wishspeed and wishdir
582 wishspeed = vlen(wishvel);
584 wishdir = wishvel / wishspeed;
588 if ((s.pmove_flags & PMF_ONGROUND))
590 wishspeed = min(wishspeed, getstatf(STAT_MOVEVARS_MAXSPEED));
591 if (s.pmove_flags & PMF_DUCKED)
594 // apply edge friction
595 f = sqrt(s.velocity_x * s.velocity_x + s.velocity_y * s.velocity_y);
598 friction = getstatf(STAT_MOVEVARS_FRICTION);
599 if (getstatf(STAT_MOVEVARS_EDGEFRICTION) != 1)
603 // note: QW uses the full player box for the trace, and yet still
604 // uses s.origin_z + s.mins_z, which is clearly an bug, but
605 // this mimics it for compatibility
606 neworigin2 = s.origin;
607 neworigin2_x += s.velocity_x*(16/f);
608 neworigin2_y += s.velocity_y*(16/f);
609 neworigin2_z += s.mins_z;
610 neworigin3 = neworigin2;
612 traceline(neworigin2, neworigin3, MOVE_NORMAL, s);
613 if (trace_fraction == 1 && !trace_startsolid)
614 friction *= getstatf(STAT_MOVEVARS_EDGEFRICTION);
616 // apply ground friction
617 f = 1 - input_timelength * friction * ((f < getstatf(STAT_MOVEVARS_STOPSPEED)) ? (getstatf(STAT_MOVEVARS_STOPSPEED) / f) : 1);
621 addspeed = wishspeed - dotproduct(s.velocity, wishdir);
624 accelspeed = min(getstatf(STAT_MOVEVARS_ACCELERATE) * input_timelength * wishspeed, addspeed);
625 s.velocity += accelspeed * wishdir;
627 gravity = getstatf(STAT_MOVEVARS_GRAVITY) * getstatf(STAT_MOVEVARS_ENTGRAVITY) * input_timelength;
628 if(!(moveflags & MOVEFLAG_NOGRAVITYONGROUND))
630 if(moveflags & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE)
631 s.velocity_z -= gravity * 0.5;
633 s.velocity_z -= gravity;
635 if (vlen2(s.velocity))
636 CSQC_ClientMovement_Move(s);
637 if(!(moveflags & MOVEFLAG_NOGRAVITYONGROUND) || !(s.pmove_flags & PMF_ONGROUND))
639 if(moveflags & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE)
640 s.velocity_z -= gravity * 0.5;
645 if (pmove_waterjumptime <= 0)
647 // apply air speed limit
648 float accel, wishspeed0, wishspeed2, accelqw, strafity;
651 accelqw = getstatf(STAT_MOVEVARS_AIRACCEL_QW);
652 wishspeed0 = wishspeed;
653 wishspeed = min(wishspeed, getstatf(STAT_MOVEVARS_MAXAIRSPEED));
654 if (s.pmove_flags & PMF_DUCKED)
656 accel = getstatf(STAT_MOVEVARS_AIRACCELERATE);
658 accelerating = (dotproduct(s.velocity, wishdir) > 0);
659 wishspeed2 = wishspeed;
662 if(getstatf(STAT_MOVEVARS_AIRSTOPACCELERATE) != 0)
665 curdir_x = s.velocity_x;
666 curdir_y = s.velocity_y;
668 curdir = normalize(curdir);
669 accel = accel + (getstatf(STAT_MOVEVARS_AIRSTOPACCELERATE) - accel) * max(0, -dotproduct(curdir, wishdir));
671 strafity = CSQC_IsMoveInDirection(input_movevalues_x, input_movevalues_y, -90) + CSQC_IsMoveInDirection(input_movevalues_x, input_movevalues_y, +90); // if one is nonzero, other is always zero
672 if(getstatf(STAT_MOVEVARS_MAXAIRSTRAFESPEED))
673 wishspeed = min(wishspeed, CSQC_GeomLerp(getstatf(STAT_MOVEVARS_MAXAIRSPEED), strafity, getstatf(STAT_MOVEVARS_MAXAIRSTRAFESPEED)));
674 if(getstatf(STAT_MOVEVARS_AIRSTRAFEACCELERATE))
675 accel = CSQC_GeomLerp(getstatf(STAT_MOVEVARS_AIRACCELERATE), strafity, getstatf(STAT_MOVEVARS_AIRSTRAFEACCELERATE));
676 if(getstatf(STAT_MOVEVARS_AIRSTRAFEACCEL_QW))
678 (((strafity > 0.5 ? getstatf(STAT_MOVEVARS_AIRSTRAFEACCEL_QW) : getstatf(STAT_MOVEVARS_AIRACCEL_QW)) >= 0) ? +1 : -1)
680 (1 - CSQC_GeomLerp(1 - fabs(getstatf(STAT_MOVEVARS_AIRACCEL_QW)), strafity, 1 - fabs(getstatf(STAT_MOVEVARS_AIRSTRAFEACCEL_QW))));
683 // if(getstatf(STAT_MOVEVARS_WARSOWBUNNY_TURNACCEL) && accelerating && input_movevalues_y == 0 && input_movevalues_x != 0)
684 // CSQC_ClientMovement_Physics_PM_AirAccelerate(s, wishdir, wishspeed2);
686 CSQC_ClientMovement_Physics_PM_Accelerate(s, wishdir, wishspeed, wishspeed0, accel, accelqw, getstatf(STAT_MOVEVARS_AIRACCEL_QW_STRETCHFACTOR), getstatf(STAT_MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION) / getstatf(STAT_MOVEVARS_MAXAIRSPEED), getstatf(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW));
688 if(getstatf(STAT_MOVEVARS_AIRCONTROL))
689 CSQC_ClientMovement_Physics_CPM_PM_Aircontrol(s, wishdir, wishspeed2);
691 gravity = getstatf(STAT_MOVEVARS_GRAVITY) * getstatf(STAT_MOVEVARS_ENTGRAVITY) * input_timelength;
692 if(moveflags & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE)
693 s.velocity_z -= gravity * 0.5;
695 s.velocity_z -= gravity;
696 CSQC_ClientMovement_Move(s);
697 if(!(moveflags & MOVEFLAG_NOGRAVITYONGROUND) || !(s.pmove_flags & PMF_ONGROUND))
699 if(moveflags & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE)
700 s.velocity_z -= gravity * 0.5;
705 void CSQC_ClientMovement_PlayerMove(entity s)
707 //Con_Printf(" %f", frametime);
708 if (!(input_buttons & 2)) // !jump
709 s.pmove_flags &= ~PMF_JUMP_HELD; // canjump = true
710 pmove_waterjumptime -= input_timelength;
711 CSQC_ClientMovement_UpdateStatus(s);
713 // if (s.waterlevel >= WATERLEVEL_SWIMMING)
714 // CL_ClientMovement_Physics_Swim(s);
716 CSQC_ClientMovement_Physics_Walk(s);
719 void CSQC_ClientMovement_PlayerMove_Frame(entity s)
721 // if a move is more than 50ms, do it as two moves (matching qwsv)
722 //Con_Printf("%i ", s.cmd.msec);
723 if(input_timelength > 0.0005)
725 if (input_timelength > 0.05)
727 input_timelength /= 2;
728 CSQC_ClientMovement_PlayerMove(s);
730 CSQC_ClientMovement_PlayerMove(s);
734 // we REALLY need this handling to happen, even if the move is not executed
735 if (!(input_buttons & 2)) // !jump
736 s.pmove_flags &= ~PMF_JUMP_HELD; // canjump = true
740 void CSQCPlayer_Physics(void)
742 switch(autocvar_cl_movement)
744 case 1: runstandardplayerphysics(self); break;
745 case 2: CSQC_ClientMovement_PlayerMove_Frame(self); break;
750 void CSQCPlayer_PredictTo(float endframe, float apply_error)
752 CSQCPlayer_Unpredict();
755 self.origin += CSQCPlayer_GetPredictionErrorO();
756 self.velocity += CSQCPlayer_GetPredictionErrorV();
758 CSQCPlayer_SetMinsMaxs();
760 csqcplayer_status = CSQCPLAYERSTATUS_PREDICTED;
763 // we don't need this
764 // darkplaces makes servercommandframe == 0 in these cases anyway
765 if (getstatf(STAT_HEALTH) <= 0)
767 csqcplayer_moveframe = clientcommandframe;
768 getinputstate(csqcplayer_moveframe-1);
769 print("the Weird code path got hit\n");
774 if(csqcplayer_moveframe >= endframe)
776 getinputstate(csqcplayer_moveframe - 1);
782 if (!getinputstate(csqcplayer_moveframe))
784 CSQCPlayer_Physics();
785 CSQCPlayer_SetMinsMaxs();
786 csqcplayer_moveframe++;
788 while(csqcplayer_moveframe < endframe);
791 //add in anything that was applied after (for low packet rate protocols)
792 input_angles = view_angles;
795 float CSQCPlayer_IsLocalPlayer()
797 return (self == csqcplayer);
800 void(entity e, float fl) V_CalcRefdef = #640; // DP_CSQC_V_CALCREFDEF
802 void CSQCPlayer_SetCamera()
805 v0 = pmove_vel; // TRICK: pmove_vel is set by the engine when we get here. No need to network velocity
813 #ifdef COMPAT_XON050_ENGINE
814 if(servercommandframe == 0 || clientcommandframe == 0 || !(checkextension("DP_CSQC_V_CALCREFDEF") || checkextension("DP_CSQC_V_CALCREFDEF_WIP1")))
816 if(servercommandframe == 0 || clientcommandframe == 0)
819 InterpolateOrigin_Do();
820 self.view_ofs = '0 0 1' * getstati(STAT_VIEWHEIGHT);
822 // get crouch state from the server
823 if(getstati(STAT_VIEWHEIGHT) == PL_VIEW_OFS_z)
824 self.pmove_flags &= ~PMF_DUCKED;
825 else if(getstati(STAT_VIEWHEIGHT) == PL_CROUCH_VIEW_OFS_z)
826 self.pmove_flags |= PMF_DUCKED;
828 // get onground state from the server
830 self.pmove_flags |= PMF_ONGROUND;
832 self.pmove_flags &= ~PMF_ONGROUND;
834 CSQCPlayer_SetMinsMaxs();
836 // override it back just in case
837 self.view_ofs = '0 0 1' * getstati(STAT_VIEWHEIGHT);
844 float flg = self.iflags;
845 self.iflags &= ~(IFLAG_ORIGIN | IFLAG_ANGLES);
846 InterpolateOrigin_Do();
849 if(csqcplayer_status == CSQCPLAYERSTATUS_FROMSERVER)
854 csqcplayer_status = CSQCPLAYERSTATUS_PREDICTED;
855 CSQCPlayer_PredictTo(servercommandframe + 1, FALSE);
856 CSQCPlayer_SetPredictionError(self.origin - o, self.velocity - v, pmove_onground - !!(self.pmove_flags & PMF_ONGROUND));
860 // get crouch state from the server
861 if(getstati(STAT_VIEWHEIGHT) == PL_VIEW_OFS_z)
862 self.pmove_flags &= ~PMF_DUCKED;
863 else if(getstati(STAT_VIEWHEIGHT) == PL_CROUCH_VIEW_OFS_z)
864 self.pmove_flags |= PMF_DUCKED;
866 // get onground state from the server
868 self.pmove_flags |= PMF_ONGROUND;
870 self.pmove_flags &= ~PMF_ONGROUND;
872 CSQCPlayer_SavePrediction();
874 CSQCPlayer_PredictTo(clientcommandframe + 1, TRUE);
876 #ifdef CSQCMODEL_SERVERSIDE_CROUCH
877 // get crouch state from the server (LAG)
878 if(getstati(STAT_VIEWHEIGHT) == PL_VIEW_OFS_z)
879 self.pmove_flags &= ~PMF_DUCKED;
880 else if(getstati(STAT_VIEWHEIGHT) == PL_CROUCH_VIEW_OFS_z)
881 self.pmove_flags |= PMF_DUCKED;
884 CSQCPlayer_SetMinsMaxs();
886 self.angles_y = input_angles_y;
890 setorigin(self, self.origin);
896 #ifdef COMPAT_XON050_ENGINE
897 view = CSQCModel_server2csqc((spectatee_status > 0) ? spectatee_status : player_localentnum);
899 view = CSQCModel_server2csqc(player_localentnum);
902 if(view && view != csqcplayer)
904 entity oldself = self;
906 InterpolateOrigin_Do();
907 self.view_ofs = '0 0 1' * getstati(STAT_VIEWHEIGHT);
911 #ifdef COMPAT_XON050_ENGINE
912 if(view && !(checkextension("DP_CSQC_V_CALCREFDEF") || checkextension("DP_CSQC_V_CALCREFDEF_WIP1")))
914 // legacy code, not totally correct, but good enough for not having V_CalcRefdef
915 setproperty(VF_ORIGIN, view.origin + '0 0 1' * getstati(STAT_VIEWHEIGHT));
916 setproperty(VF_ANGLES, view_angles);
922 var float refdefflags = 0;
924 if(view.csqcmodel_teleported)
925 refdefflags |= REFDEFFLAG_TELEPORTED;
927 if(input_buttons & 4)
928 refdefflags |= REFDEFFLAG_JUMPING;
930 // note: these two only work in WIP2, but are harmless in WIP1
931 if(getstati(STAT_HEALTH) <= 0)
932 refdefflags |= REFDEFFLAG_DEAD;
935 refdefflags |= REFDEFFLAG_INTERMISSION;
937 V_CalcRefdef(view, refdefflags);
941 // FIXME by CSQC spec we have to do this:
942 // but it breaks chase cam
944 setproperty(VF_ORIGIN, pmove_org + '0 0 1' * getstati(STAT_VIEWHEIGHT));
945 setproperty(VF_ANGLES, view_angles);
949 { CSQCPLAYER_HOOK_POSTCAMERASETUP }
952 void CSQCPlayer_Remove()
955 cvar_settemp("cl_movement_replay", "1");
958 float CSQCPlayer_PreUpdate()
960 if(self != csqcplayer)
962 if(csqcplayer_status != CSQCPLAYERSTATUS_FROMSERVER)
963 CSQCPlayer_Unpredict();
967 float CSQCPlayer_PostUpdate()
969 if(self.entnum != player_localnum + 1)
972 csqcplayer_status = CSQCPLAYERSTATUS_FROMSERVER;
973 cvar_settemp("cl_movement_replay", "0");
974 self.entremove = CSQCPlayer_Remove;