Xonotic
cl_player.qh File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

vector CSQCModel_ApplyStairSmoothing (entity this, bool isonground, vector v)
 
float CSQCPlayer_IsLocalPlayer (entity this)
 
float CSQCPlayer_PostUpdate (entity this)
 
float CSQCPlayer_PreUpdate (entity this)
 
void CSQCPlayer_SetCamera ()
 Called once per CSQC_UpdateView() More...
 

Variables

bool autocvar_cl_movement = true
 
entity csqcplayer
 
float csqcplayer_status
 
const int CSQCPLAYERSTATUS_FROMSERVER = 1
 
const int CSQCPLAYERSTATUS_PREDICTED = 2
 
const int CSQCPLAYERSTATUS_UNPREDICTED = 0
 
const int PMF_JUMP_HELD = 1
 
int pmove_flags
 

Function Documentation

◆ CSQCModel_ApplyStairSmoothing()

vector CSQCModel_ApplyStairSmoothing ( entity  this,
bool  isonground,
vector  v 
)

Definition at line 245 of file cl_player.qc.

References autocvar_cl_stairsmoothspeed, bound(), csqcmodel_teleported, drawtime, max(), PHYS_STEPHEIGHT, stairsmooth_drawtime, stairsmooth_offset, stairsmooth_prevtime, time, and v.

Referenced by CSQCModel_Hook_PreDraw(), and CSQCPlayer_SetCamera().

246 {
247  float smoothtime = bound(0, time - this.stairsmooth_prevtime, 0.1);
248  this.stairsmooth_prevtime = max(this.stairsmooth_prevtime, this.stairsmooth_drawtime); // stairsmooth_drawtime is the previous frame's time at this point
249 
250  if(this.csqcmodel_teleported || !isonground || autocvar_cl_stairsmoothspeed <= 0 || this.ground_networkentity)
251  this.stairsmooth_offset = v.z;
252  else
253  {
254  if(this.stairsmooth_offset < v.z)
255  v.z = this.stairsmooth_offset = bound(v.z - PHYS_STEPHEIGHT(this), this.stairsmooth_offset + smoothtime * autocvar_cl_stairsmoothspeed, v.z);
256  else if(this.stairsmooth_offset > v.z)
257  v.z = this.stairsmooth_offset = bound(v.z, this.stairsmooth_offset - smoothtime * autocvar_cl_stairsmoothspeed, v.z + PHYS_STEPHEIGHT(this));
258  }
259 
260  this.stairsmooth_prevtime = time;
262 
263  return v;
264 }
float stairsmooth_offset
Definition: cl_player.qc:242
float stairsmooth_drawtime
Definition: cl_player.qc:244
float drawtime
Definition: view.qh:115
float autocvar_cl_stairsmoothspeed
Definition: cl_player.qc:213
vector v
Definition: ent_cs.qc:116
float stairsmooth_prevtime
Definition: cl_player.qc:243
#define PHYS_STEPHEIGHT(s)
Definition: movetypes.qh:38
float time
Definition: csprogsdefs.qc:16
float csqcmodel_teleported
Definition: cl_model.qh:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CSQCPlayer_IsLocalPlayer()

float CSQCPlayer_IsLocalPlayer ( entity  this)

Definition at line 207 of file cl_player.qc.

References csqcplayer.

Referenced by CSQCModel_Draw().

208 {
209  return (this == csqcplayer);
210 }
entity csqcplayer
Definition: cl_player.qh:26
+ Here is the caller graph for this function:

◆ CSQCPlayer_PostUpdate()

float CSQCPlayer_PostUpdate ( entity  this)

Definition at line 674 of file cl_player.qc.

References csqcplayer, CSQCPlayer_Remove(), csqcplayer_status, CSQCPLAYERSTATUS_FROMSERVER, cvar(), cvar_settemp(), entnum, and player_localnum.

Referenced by NET_HANDLE().

675 {
676  if (this.entnum != player_localnum + 1) return false;
677  csqcplayer = this;
679  if (cvar("cl_movement_replay"))
680  cvar_settemp("cl_movement_replay", "0");
681  this.entremove = CSQCPlayer_Remove;
682  return true;
683 }
float cvar_settemp(string tmp_cvar, string tmp_value)
Definition: util.qc:696
void CSQCPlayer_Remove(entity this)
Definition: cl_player.qc:661
float csqcplayer_status
Definition: cl_player.qh:27
entity csqcplayer
Definition: cl_player.qh:26
const int CSQCPLAYERSTATUS_FROMSERVER
Definition: cl_player.qh:29
float entnum
Definition: csprogsdefs.qc:94
float player_localnum
Definition: csprogsdefs.qc:20
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CSQCPlayer_PreUpdate()

float CSQCPlayer_PreUpdate ( entity  this)

Definition at line 667 of file cl_player.qc.

References csqcplayer, csqcplayer_status, CSQCPlayer_Unpredict(), and CSQCPLAYERSTATUS_FROMSERVER.

Referenced by NET_HANDLE().

668 {
669  if (this != csqcplayer) return false;
671  return true;
672 }
float csqcplayer_status
Definition: cl_player.qh:27
void CSQCPlayer_Unpredict(entity this)
Definition: cl_player.qc:89
entity csqcplayer
Definition: cl_player.qh:26
const int CSQCPLAYERSTATUS_FROMSERVER
Definition: cl_player.qh:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CSQCPlayer_SetCamera()

void CSQCPlayer_SetCamera ( )

Called once per CSQC_UpdateView()

Definition at line 554 of file cl_player.qc.

References autocvar_cl_movement_intermissionrunning, autocvar_cl_useenginerefdef, BIT, BITSET, clientcommandframe, CSQCModel_ApplyStairSmoothing(), CSQCModel_server2csqc(), csqcplayer, CSQCPlayer_CalcRefdef(), CSQCPLAYER_HOOK_POSTCAMERASETUP, CSQCPlayer_PredictTo(), CSQCPlayer_SavePrediction(), CSQCPlayer_SetMinsMaxs(), CSQCPlayer_SetPredictionError(), csqcplayer_status, CSQCPLAYERSTATUS_FROMSERVER, CSQCPLAYERSTATUS_PREDICTED, drawtime, entity(), FL_ONGROUND, IFLAG_ANGLES, IFLAG_ORIGIN, input_angles, input_buttons, intermission, InterpolateOrigin_Do(), IS_DEAD, IS_ONGROUND, NULL, PHYS_HEALTH, PHYS_PL_CROUCH_VIEWOFS, PHYS_PL_VIEWOFS, PHYS_VIEWHEIGHT, player_localentnum, PMF_ONGROUND, pmove_onground, pmove_vel, REFDEFFLAG_DEAD, REFDEFFLAG_INTERMISSION, REFDEFFLAG_JUMPING, REFDEFFLAG_TELEPORTED, servercommandframe, setorigin(), and vector().

Referenced by CSQC_UpdateView().

555 {
556  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
557  float vh = PHYS_VIEWHEIGHT(NULL);
558  vector pl_viewofs = PHYS_PL_VIEWOFS(NULL);
559  vector pl_viewofs_crouch = PHYS_PL_CROUCH_VIEWOFS(NULL);
560  entity e = csqcplayer;
561  if (e)
562  {
563  if (servercommandframe == 0 || clientcommandframe == 0)
564  {
566  e.view_ofs = '0 0 1' * vh;
567 
568  // get crouch state from the server
569  if (vh == pl_viewofs.z) e.flags &= ~FL_DUCKED;
570  else if (vh == pl_viewofs_crouch.z) e.flags |= FL_DUCKED;
571 
572  // get onground state from the server
573  e.flags = BITSET(e.flags, FL_ONGROUND, pmove_onground);
574 
576 
577  // override it back just in case
578  e.view_ofs = '0 0 1' * vh;
579 
580  // set velocity
581  e.velocity = v0;
582  }
583  else
584  {
585  int flg = e.iflags; e.iflags &= ~(IFLAG_ORIGIN | IFLAG_ANGLES);
587  e.iflags = flg;
588 
590  {
591  vector o = e.origin;
594  CSQCPlayer_SetPredictionError(e.origin - o, e.velocity - v0, pmove_onground - IS_ONGROUND(e));
595  e.origin = o;
596  e.velocity = v0;
597 
598  // get crouch state from the server
599  if (vh == pl_viewofs.z) e.flags &= ~FL_DUCKED;
600  else if(vh == pl_viewofs_crouch.z) e.flags |= FL_DUCKED;
601 
602  // get onground state from the server
603  e.flags = BITSET(e.flags, FL_ONGROUND, pmove_onground);
604 
606  }
608 
609 #ifdef CSQCMODEL_SERVERSIDE_CROUCH
610  // get crouch state from the server (LAG)
611  if (vh == pl_viewofs.z) e.flags &= ~FL_DUCKED;
612  else if (vh == pl_viewofs_crouch.z) e.flags |= FL_DUCKED;
613 #endif
615 
616  if (!IS_DEAD(e))
617  e.angles.y = input_angles.y;
618  }
619 
620  // relink
621  e.stairsmooth_drawtime = drawtime; // since drawtime is a frame old at this point, copy it now to avoid using a drawtime 2 frames old!
622  e.origin = CSQCModel_ApplyStairSmoothing(e, (e.pmove_flags & PMF_ONGROUND), e.origin);
623  setorigin(e, e.origin);
624  }
625 
627  if (view)
628  {
629  if (view != csqcplayer)
630  {
631  InterpolateOrigin_Do(view);
632  view.view_ofs = '0 0 1' * vh;
633  }
635  {
636  int refdefflags = 0;
637  if (view.csqcmodel_teleported) refdefflags |= REFDEFFLAG_TELEPORTED;
638  if (input_buttons & BIT(1)) refdefflags |= REFDEFFLAG_JUMPING;
639  // note: these two only work in WIP2, but are harmless in WIP1
640  if (PHYS_HEALTH(NULL) <= 0 && PHYS_HEALTH(NULL) != -666 && PHYS_HEALTH(NULL) != -2342) refdefflags |= REFDEFFLAG_DEAD;
641  if (intermission) refdefflags |= REFDEFFLAG_INTERMISSION;
642  V_CalcRefdef(view, refdefflags); // TODO? uses .health stat in the engine when this isn't called here, may be broken!
643  }
644  else
645  {
646  CSQCPlayer_CalcRefdef(view);
647  }
648  }
649  else
650  {
651  // FIXME by CSQC spec we have to do this:
652  // but it breaks chase cam
653  /*
654  setproperty(VF_ORIGIN, pmove_org + '0 0 1' * vh);
655  setproperty(VF_ANGLES, view_angles);
656  */
657  }
659 }
#define CSQCPLAYER_HOOK_POSTCAMERASETUP()
entity CSQCModel_server2csqc(int i)
Definition: cl_model.qc:314
#define PHYS_PL_CROUCH_VIEWOFS(s)
Definition: player.qh:86
#define PHYS_PL_VIEWOFS(s)
Definition: player.qh:85
float servercommandframe
Definition: csprogsdefs.qc:24
float FL_ONGROUND
Definition: progsdefs.qc:240
entity() spawn
float input_buttons
Definition: csprogsdefs.qc:62
vector input_angles
Definition: csprogsdefs.qc:60
#define IS_ONGROUND(s)
Definition: movetypes.qh:16
float intermission
Definition: csprogsdefs.qc:148
void CSQCPlayer_SetMinsMaxs(entity this)
Definition: cl_player.qc:99
const int CSQCPLAYERSTATUS_PREDICTED
Definition: cl_player.qh:30
vector pmove_vel
Definition: csprogsdefs.qc:55
float csqcplayer_status
Definition: cl_player.qh:27
float drawtime
Definition: view.qh:115
float REFDEFFLAG_DEAD
Definition: csprogsdefs.qc:925
void CSQCPlayer_CalcRefdef(entity this)
Definition: cl_player.qc:521
float clientcommandframe
Definition: csprogsdefs.qc:23
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition: bits.qh:8
float REFDEFFLAG_TELEPORTED
Definition: csprogsdefs.qc:923
#define NULL
Definition: post.qh:17
float PMF_ONGROUND
Definition: csprogsdefs.qc:922
#define IS_DEAD(s)
Definition: utils.qh:26
bool autocvar_cl_movement_intermissionrunning
Definition: cl_player.qc:30
float player_localentnum
Definition: csprogsdefs.qc:19
#define BITSET(var, mask, flag)
Definition: bits.qh:11
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define PHYS_VIEWHEIGHT(s)
Definition: player.qh:88
const int IFLAG_ORIGIN
Definition: interpolate.qh:36
void CSQCPlayer_SetPredictionError(vector o, vector v, float onground_diff)
Definition: cl_player.qc:56
vector CSQCModel_ApplyStairSmoothing(entity this, bool isonground, vector v)
Definition: cl_player.qc:245
setorigin(ent, v)
float REFDEFFLAG_INTERMISSION
Definition: csprogsdefs.qc:926
void CSQCPlayer_PredictTo(entity this, float endframe, bool apply_error)
Definition: cl_player.qc:154
entity csqcplayer
Definition: cl_player.qh:26
bool autocvar_cl_useenginerefdef
Definition: cl_player.qc:551
float pmove_onground
Definition: cl_player.qc:33
float REFDEFFLAG_JUMPING
Definition: csprogsdefs.qc:924
#define PHYS_HEALTH(s)
Definition: player.qh:89
const int CSQCPLAYERSTATUS_FROMSERVER
Definition: cl_player.qh:29
void InterpolateOrigin_Do(entity this)
set origin based on iorigin1 (old pos), iorigin2 (desired pos), and time
Definition: interpolate.qc:129
const int IFLAG_ANGLES
Definition: interpolate.qh:28
void CSQCPlayer_SavePrediction(entity this)
Definition: cl_player.qc:117
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ autocvar_cl_movement

bool autocvar_cl_movement = true

Definition at line 24 of file cl_player.qh.

Referenced by CSQCPlayer_Physics().

◆ csqcplayer

◆ csqcplayer_status

◆ CSQCPLAYERSTATUS_FROMSERVER

const int CSQCPLAYERSTATUS_FROMSERVER = 1

Definition at line 29 of file cl_player.qh.

Referenced by CSQCPlayer_PostUpdate(), CSQCPlayer_PreUpdate(), and CSQCPlayer_SetCamera().

◆ CSQCPLAYERSTATUS_PREDICTED

const int CSQCPLAYERSTATUS_PREDICTED = 2

◆ CSQCPLAYERSTATUS_UNPREDICTED

const int CSQCPLAYERSTATUS_UNPREDICTED = 0

Definition at line 28 of file cl_player.qh.

Referenced by CSQCPlayer_Unpredict().

◆ PMF_JUMP_HELD

const int PMF_JUMP_HELD = 1

Definition at line 34 of file cl_player.qh.

Referenced by CSQCPlayer_Physics().

◆ pmove_flags

int pmove_flags

Definition at line 33 of file cl_player.qh.

Referenced by CSQCPlayer_ApplySmoothing(), and CSQCPlayer_Physics().