]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/csqcmodel/cl_player.qc
simplify
[xonotic/xonotic-data.pk3dir.git] / qcsrc / csqcmodel / cl_player.qc
index 14c3b66c78833466b06ba20a83b0c141bad8b771..bcb0c08311c9e98f77121e46ef973e459996d517 100644 (file)
  */
 
 var float autocvar_cl_predictionerrorcompensation = 0;
-var float autocvar_chase_active;
-var float autocvar_chase_back;
 
+// engine stuff
 .float pmove_flags;
+float pmove_onground; // weird engine flag we shouldn't really use but have to for now
 #define PMF_DUCKED 4
+#define PMF_ONGROUND 8
+#define REFDEFFLAG_TELEPORTED 1
+#define REFDEFFLAG_JUMPING 2
 
 entity csqcplayer;
 vector csqcplayer_origin, csqcplayer_velocity;
@@ -122,19 +125,41 @@ float CSQCPlayer_IsLocalPlayer()
        return (self == csqcplayer);
 }
 
+void(entity e, float fl) V_CalcRefdef = #640; // DP_CSQC_V_CALCREFDEF
+
 void CSQCPlayer_SetCamera()
 {
        if(csqcplayer)
        {
-               vector org, ang;
                entity oldself;
                oldself = self;
                self = csqcplayer;
 
+#ifdef COMPAT_XON050_ENGINE
+               if(servercommandframe == 0 || !(checkextension("DP_CSQC_V_CALCREFDEF") || checkextension("DP_CSQC_V_CALCREFDEF_WIP1")))
+#else
                if(servercommandframe == 0)
+#endif
                {
                        InterpolateOrigin_Do();
                        self.view_ofs = '0 0 1' * getstati(STAT_VIEWHEIGHT);
+
+                       // get crouch state from the server
+                       if(getstati(STAT_VIEWHEIGHT) == PL_VIEW_OFS_z)
+                               self.pmove_flags &~= PMF_DUCKED;
+                       else if(getstati(STAT_VIEWHEIGHT) == PL_CROUCH_VIEW_OFS_z)
+                               self.pmove_flags |= PMF_DUCKED;
+
+                       // get onground state from the server
+                       if(pmove_onground)
+                               self.pmove_flags |= PMF_ONGROUND;
+                       else
+                               self.pmove_flags &~= PMF_ONGROUND;
+
+                       CSQCPlayer_SetMinsMaxs();
+
+                       // override it back just in case
+                       self.view_ofs = '0 0 1' * getstati(STAT_VIEWHEIGHT);
                }
                else
                {
@@ -155,41 +180,70 @@ void CSQCPlayer_SetCamera()
                                else if(getstati(STAT_VIEWHEIGHT) == PL_CROUCH_VIEW_OFS_z)
                                        self.pmove_flags |= PMF_DUCKED;
 
+                               // get onground state from the server
+                               if(pmove_onground)
+                                       self.pmove_flags |= PMF_ONGROUND;
+                               else
+                                       self.pmove_flags &~= PMF_ONGROUND;
+
                                CSQCPlayer_SavePrediction();
                        }
                        CSQCPlayer_PredictTo(clientcommandframe);
+
+                       CSQCPlayer_SetMinsMaxs();
                }
 
+               // relink
+               setorigin(self, self.origin);
+
+               self.angles_y = input_angles_y;
+
                self = oldself;
+       }
 
-               // relink
-               setorigin(csqcplayer, csqcplayer.origin);
+       entity view;
+#ifdef COMPAT_XON050_ENGINE
+       view = CSQCModel_server2csqc((spectatee_status > 0) ? spectatee_status : player_localentnum);
+#else
+       view = CSQCModel_server2csqc(player_localentnum);
+#endif
 
-               org = csqcplayer.origin + self.view_ofs + CSQCPlayer_GetPredictionError();
-               ang = R_SetView3fv(VF_ANGLES);
+#ifdef COMPAT_XON050_ENGINE
+       if(view && !(checkextension("DP_CSQC_V_CALCREFDEF") || checkextension("DP_CSQC_V_CALCREFDEF_WIP1")))
+       {
+               // legacy code, not totally correct, but good enough for not having V_CalcRefdef
+               setproperty(VF_ORIGIN, view.origin + '0 0 1' * getstati(STAT_VIEWHEIGHT));
+               setproperty(VF_ANGLES, view.angles);
+       }
+       else
+#endif
+       if(view)
+       {
+               var float refdefflags = 0;
 
-               // simulate missing engine features
-               if(autocvar_chase_active)
+               if(view.csqcmodel_teleported)
                {
-                       float dist;
-                       vector chase_dest;
-                       dist = -autocvar_chase_back - 8;
-                       makevectors(ang);
-                       chase_dest = org + v_forward * dist;
-                       traceline(org, chase_dest, MOVE_NOMONSTERS, csqcplayer);
-                       org = trace_endpos + 8 * v_forward + 4 * trace_plane_normal;
+                       refdefflags |= REFDEFFLAG_TELEPORTED;
+                       view.csqcmodel_teleported = 0;
                }
 
-               R_SetView3fv(VF_ORIGIN, org);
-               R_SetView3fv(VF_ANGLES, ang);
+               if(input_buttons & 4)
+                       refdefflags |= REFDEFFLAG_JUMPING;
 
-               { CSQCPLAYER_HOOK_POSTCAMERASETUP }
+               V_CalcRefdef(view, refdefflags);
        }
+       else
+       {
+               // no setup, keep engine provided values
+               // to support a legacy entity being the view
+       }
+
+       { CSQCPLAYER_HOOK_POSTCAMERASETUP }
 }
 
 void CSQCPlayer_Remove()
 {
-       if(self.entnum != player_localentnum)
+       if(self.entnum != player_localnum + 1)
                return;
        csqcplayer = world;
        cvar_clientsettemp("cl_movement_replay", "1");
@@ -197,7 +251,7 @@ void CSQCPlayer_Remove()
 
 float CSQCPlayer_PreUpdate()
 {
-       if(self.entnum != player_localentnum)
+       if(self.entnum != player_localnum + 1)
                return 0;
        cvar_clientsettemp("cl_movement_replay", "0");
        if(csqcplayer_status != CSQCPLAYERSTATUS_FROMSERVER)
@@ -207,10 +261,6 @@ float CSQCPlayer_PreUpdate()
 
 float CSQCPlayer_PostUpdate()
 {
-       if(self.entnum == player_localentnum)
-               self.renderflags |= RF_EXTERNALMODEL;
-       else
-               self.renderflags &~= RF_EXTERNALMODEL;
        if(self.entnum != player_localentnum)
                return 0;
        csqcplayer_status = CSQCPLAYERSTATUS_FROMSERVER;
@@ -218,8 +268,3 @@ float CSQCPlayer_PostUpdate()
        self.entremove = CSQCPlayer_Remove;
        return 1;
 }
-
-entity CSQCPlayer_GetPlayer(float pl)
-{
-       return findfloat(world, entnum, pl); // FIXME optimize this using an array
-}