]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
attempt prediction error compensation (off by default, broken)
authorRudolf Polzer <divverent@alientrap.org>
Mon, 16 Jan 2012 13:04:35 +0000 (14:04 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Mon, 16 Jan 2012 13:04:35 +0000 (14:04 +0100)
qcsrc/csqcmodellib/cl_player.qc

index dc9627d9e8173fcc86a9c3a45408d71e101f0b6d..33e5f95d72fcc832c86c962b021d1dfe22638818 100644 (file)
@@ -35,23 +35,34 @@ entity csqcplayer;
 vector csqcplayer_origin, csqcplayer_velocity;
 float csqcplayer_sequence, player_pmflags;
 float csqcplayer_moveframe;
-vector csqcplayer_predictionerror;
+vector csqcplayer_predictionerroro;
+vector csqcplayer_predictionerrorv;
 float csqcplayer_predictionerrortime;
 
-vector CSQCPlayer_GetPredictionError()
+vector CSQCPlayer_GetPredictionErrorO()
 {
        if(!autocvar_cl_predictionerrorcompensation)
                return '0 0 0';
        if(time < csqcplayer_predictionerrortime)
-               return csqcplayer_predictionerror * (csqcplayer_predictionerrortime - time) * autocvar_cl_predictionerrorcompensation;
+               return csqcplayer_predictionerroro * (csqcplayer_predictionerrortime - time) * autocvar_cl_predictionerrorcompensation;
        return '0 0 0';
 }
 
-void CSQCPlayer_SetPredictionError(vector v)
+vector CSQCPlayer_GetPredictionErrorV()
+{
+       if(!autocvar_cl_predictionerrorcompensation)
+               return '0 0 0';
+       if(time < csqcplayer_predictionerrortime)
+               return csqcplayer_predictionerrorv * (csqcplayer_predictionerrortime - time) * autocvar_cl_predictionerrorcompensation;
+       return '0 0 0';
+}
+
+void CSQCPlayer_SetPredictionError(vector o, vector v)
 {
        if(!autocvar_cl_predictionerrorcompensation)
                return;
-       csqcplayer_predictionerror = (csqcplayer_predictionerrortime - time) * autocvar_cl_predictionerrorcompensation * csqcplayer_predictionerror + v;
+       csqcplayer_predictionerroro = (csqcplayer_predictionerrortime - time) * autocvar_cl_predictionerrorcompensation * csqcplayer_predictionerroro + o;
+       csqcplayer_predictionerrorv = (csqcplayer_predictionerrortime - time) * autocvar_cl_predictionerrorcompensation * csqcplayer_predictionerrorv + v;
        csqcplayer_predictionerrortime = time + 1.0 / autocvar_cl_predictionerrorcompensation;
 }
 
@@ -92,9 +103,14 @@ void CSQCPlayer_SavePrediction()
        csqcplayer_status = CSQCPLAYERSTATUS_PREDICTED;
 }
 
-void CSQCPlayer_PredictTo(float endframe)
+void CSQCPlayer_PredictTo(float endframe, float apply_error)
 {
        CSQCPlayer_Unpredict();
+       if(apply_error)
+       {
+               self.origin += CSQCPlayer_GetPredictionErrorO();
+               self.velocity += CSQCPlayer_GetPredictionErrorV();
+       }
        CSQCPlayer_SetMinsMaxs();
 
        csqcplayer_status = CSQCPLAYERSTATUS_PREDICTED;
@@ -183,11 +199,12 @@ void CSQCPlayer_SetCamera()
                        {
                                vector o, v;
                                o = self.origin;
+                               v = v0;
                                csqcplayer_status = CSQCPLAYERSTATUS_PREDICTED;
-                               CSQCPlayer_PredictTo(servercommandframe + 1);
-                               CSQCPlayer_SetPredictionError(o - self.origin);
+                               CSQCPlayer_PredictTo(servercommandframe + 1, FALSE);
+                               CSQCPlayer_SetPredictionError(o - self.origin, v0 - self.velocity);
                                self.origin = o;
-                               self.velocity = v0;
+                               self.velocity = v;
 
                                // get crouch state from the server
                                if(getstati(STAT_VIEWHEIGHT) == PL_VIEW_OFS_z)
@@ -203,7 +220,7 @@ void CSQCPlayer_SetCamera()
 
                                CSQCPlayer_SavePrediction();
                        }
-                       CSQCPlayer_PredictTo(clientcommandframe + 1);
+                       CSQCPlayer_PredictTo(clientcommandframe + 1, TRUE);
 
                        CSQCPlayer_SetMinsMaxs();