]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/csqcmodel/cl_player.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / csqcmodel / cl_player.qc
index 225c7307ded6c60a192056eafde3078912c4ae52..159c74c14e83dd31013b767fdcd4dceb63b80e7a 100644 (file)
@@ -43,13 +43,13 @@ float csqcplayer_predictionerrorfactor;
 
 vector CSQCPlayer_GetPredictionErrorO()
 {
-       if (time >= csqcplayer_predictionerrortime) return '0 0 0';
+       if (time >= csqcplayer_predictionerrortime) { return '0 0 0'; }
        return csqcplayer_predictionerroro * (csqcplayer_predictionerrortime - time) * csqcplayer_predictionerrorfactor;
 }
 
 vector CSQCPlayer_GetPredictionErrorV()
 {
-       if (time >= csqcplayer_predictionerrortime) return '0 0 0';
+       if (time >= csqcplayer_predictionerrortime) { return '0 0 0'; }
        return csqcplayer_predictionerrorv * (csqcplayer_predictionerrortime - time) * csqcplayer_predictionerrorfactor;
 }
 
@@ -64,18 +64,16 @@ void CSQCPlayer_SetPredictionError(vector o, vector v, float onground_diff)
        // commented out as this one did not help
        if(onground_diff)
        {
-               printf("ONGROUND MISMATCH: %d x=%v v=%v\n", onground_diff, o, v);
-               return;
+           printf("ONGROUND MISMATCH: %d x=%v v=%v\n", onground_diff, o, v);
+           return;
        }
        */
-       if(vdist(o, >, 32) || vdist(v, >, 192))
-       {
-               //printf("TOO BIG: x=%v v=%v\n", o, v);
+       if (vdist(o, >, 32) || vdist(v, >, 192)) {
+               // printf("TOO BIG: x=%v v=%v\n", o, v);
                return;
        }
 
-       if(!autocvar_cl_movement_errorcompensation)
-       {
+       if (!autocvar_cl_movement_errorcompensation) {
                csqcplayer_predictionerrorfactor = 0;
                return;
        }
@@ -88,8 +86,8 @@ void CSQCPlayer_SetPredictionError(vector o, vector v, float onground_diff)
 
 void CSQCPlayer_Unpredict(entity this)
 {
-       if (csqcplayer_status == CSQCPLAYERSTATUS_UNPREDICTED) return;
-       if (csqcplayer_status != CSQCPLAYERSTATUS_PREDICTED) LOG_FATALF("Cannot unpredict in current status (%d)", csqcplayer_status);
+       if (csqcplayer_status == CSQCPLAYERSTATUS_UNPREDICTED) { return; }
+       if (csqcplayer_status != CSQCPLAYERSTATUS_PREDICTED) { LOG_FATALF("Cannot unpredict in current status (%d)", csqcplayer_status); }
        this.origin = csqcplayer_origin;
        this.velocity = csqcplayer_velocity;
        csqcplayer_moveframe = csqcplayer_sequence + 1; // + 1 because the recieved frame has the move already done (server side)
@@ -98,14 +96,11 @@ void CSQCPlayer_Unpredict(entity this)
 
 void CSQCPlayer_SetMinsMaxs(entity this)
 {
-       if (IS_DUCKED(this) || !this.isplayermodel)
-       {
+       if (IS_DUCKED(this) || !this.isplayermodel) {
                this.mins = PHYS_PL_CROUCH_MIN(this);
                this.maxs = PHYS_PL_CROUCH_MAX(this);
                this.view_ofs = PHYS_PL_CROUCH_VIEWOFS(this);
-       }
-       else
-       {
+       } else {
                this.mins = PHYS_PL_MIN(this);
                this.maxs = PHYS_PL_MAX(this);
                this.view_ofs = PHYS_PL_VIEWOFS(this);
@@ -125,9 +120,9 @@ void CSQC_ClientMovement_PlayerMove_Frame(entity this);
 
 void CSQCPlayer_Physics(entity this)
 {
-       if(!autocvar_cl_movement) { return; }
+       if (!autocvar_cl_movement) { return; }
 
-       _Movetype_CheckWater(this); // we apparently need to check water *before* physics so it can use this for water jump
+       _Movetype_CheckWater(this);     // we apparently need to check water *before* physics so it can use this for water jump
 
        vector oldv_angle = this.v_angle;
        vector oldangles = this.angles; // we need to save these, as they're abused by other code
@@ -144,16 +139,15 @@ void CSQCPlayer_Physics(entity this)
        this.angles = oldangles;
 
        this.pmove_flags =
-                       ((IS_DUCKED(this)) ? PMF_DUCKED : 0) |
-                       ((IS_JUMP_HELD(this)) ? PMF_JUMP_HELD : 0) |
-                       ((IS_ONGROUND(this)) ? PMF_ONGROUND : 0);
+               ((IS_DUCKED(this)) ? PMF_DUCKED : 0)
+               | ((IS_JUMP_HELD(this)) ? PMF_JUMP_HELD : 0)
+               | ((IS_ONGROUND(this)) ? PMF_ONGROUND : 0);
 }
 
 void CSQCPlayer_PredictTo(entity this, float endframe, bool apply_error)
 {
        CSQCPlayer_Unpredict(this);
-       if (apply_error)
-       {
+       if (apply_error) {
                this.origin += CSQCPlayer_GetPredictionErrorO();
                this.velocity += CSQCPlayer_GetPredictionErrorV();
        }
@@ -164,38 +158,32 @@ void CSQCPlayer_PredictTo(entity this, float endframe, bool apply_error)
 #if 0
        // we don't need this
        // darkplaces makes servercommandframe == 0 in these cases anyway
-       if (STAT(HEALTH) <= 0)
-       {
+       if (STAT(HEALTH) <= 0) {
                csqcplayer_moveframe = clientcommandframe;
-               getinputstate(csqcplayer_moveframe-1);
+               getinputstate(csqcplayer_moveframe - 1);
                LOG_INFO("the Weird code path got hit");
                return;
        }
 #endif
 
-       if (csqcplayer_moveframe >= endframe)
-       {
+       if (csqcplayer_moveframe >= endframe) {
                getinputstate(csqcplayer_moveframe - 1);
-       }
-       else
-       {
-               do
-               {
-                       if (!getinputstate(csqcplayer_moveframe)) break;
+       } else {
+               do {
+                       if (!getinputstate(csqcplayer_moveframe)) { break; }
                        /*if (input_timelength > 0.0005)
                        {
-                               if (input_timelength > 0.05)
-                               {
-                                       input_timelength /= 2;
-                                       CSQCPlayer_Physics(this);
-                               }
-                               CSQCPlayer_Physics(this);
+                           if (input_timelength > 0.05)
+                           {
+                               input_timelength /= 2;
+                               CSQCPlayer_Physics(this);
+                           }
+                           CSQCPlayer_Physics(this);
                        }*/
                        CSQCPlayer_Physics(this);
                        CSQCPlayer_SetMinsMaxs(this);
                        ++csqcplayer_moveframe;
-               }
-               while (csqcplayer_moveframe < endframe);
+               } while (csqcplayer_moveframe < endframe);
        }
 
        // add in anything that was applied after (for low packet rate protocols)
@@ -204,7 +192,7 @@ void CSQCPlayer_PredictTo(entity this, float endframe, bool apply_error)
 
 bool CSQCPlayer_IsLocalPlayer(entity this)
 {
-       return (this == csqcplayer);
+       return this == csqcplayer;
 }
 
 /** Called once per CSQC_UpdateView() */
@@ -215,16 +203,15 @@ void CSQCPlayer_SetCamera()
        const vector pl_viewofs = PHYS_PL_VIEWOFS(NULL);
        const vector pl_viewofs_crouch = PHYS_PL_CROUCH_VIEWOFS(NULL);
        const entity e = csqcplayer;
-       if (e)
-       {
-               if (servercommandframe == 0 || clientcommandframe == 0)
-               {
+       if (e) {
+               if (servercommandframe == 0 || clientcommandframe == 0) {
                        InterpolateOrigin_Do(e);
                        e.view_ofs = '0 0 1' * vh;
 
                        // get crouch state from the server
-                       if (vh == pl_viewofs.z) e.flags &= ~FL_DUCKED;
-                       else if (vh == pl_viewofs_crouch.z) e.flags |= FL_DUCKED;
+                       if (vh == pl_viewofs.z) { e.flags &= ~FL_DUCKED; } else if (vh == pl_viewofs_crouch.z) {
+                               e.flags |= FL_DUCKED;
+                       }
 
                        // get onground state from the server
                        e.flags = BITSET(e.flags, FL_ONGROUND, pmove_onground);
@@ -236,15 +223,13 @@ void CSQCPlayer_SetCamera()
 
                        // set velocity
                        e.velocity = v0;
-               }
-               else
-               {
-                       const int flg = e.iflags; e.iflags &= ~(IFLAG_ORIGIN | IFLAG_ANGLES);
+               } else {
+                       const int flg = e.iflags;
+                       e.iflags &= ~(IFLAG_ORIGIN | IFLAG_ANGLES);
                        InterpolateOrigin_Do(e);
                        e.iflags = flg;
 
-                       if (csqcplayer_status == CSQCPLAYERSTATUS_FROMSERVER)
-                       {
+                       if (csqcplayer_status == CSQCPLAYERSTATUS_FROMSERVER) {
                                const vector o = e.origin;
                                csqcplayer_status = CSQCPLAYERSTATUS_PREDICTED;
                                CSQCPlayer_PredictTo(e, servercommandframe + 1, false);
@@ -253,8 +238,9 @@ void CSQCPlayer_SetCamera()
                                e.velocity = v0;
 
                                // get crouch state from the server
-                               if (vh == pl_viewofs.z) e.flags &= ~FL_DUCKED;
-                               else if(vh == pl_viewofs_crouch.z) e.flags |= FL_DUCKED;
+                               if (vh == pl_viewofs.z) { e.flags &= ~FL_DUCKED; } else if (vh == pl_viewofs_crouch.z) {
+                                       e.flags |= FL_DUCKED;
+                               }
 
                                // get onground state from the server
                                e.flags = BITSET(e.flags, FL_ONGROUND, pmove_onground);
@@ -265,8 +251,9 @@ void CSQCPlayer_SetCamera()
 
 #ifdef CSQCMODEL_SERVERSIDE_CROUCH
                        // get crouch state from the server (LAG)
-                       if (vh == pl_viewofs.z) e.flags &= ~FL_DUCKED;
-                       else if (vh == pl_viewofs_crouch.z) e.flags |= FL_DUCKED;
+                       if (vh == pl_viewofs.z) { e.flags &= ~FL_DUCKED; } else if (vh == pl_viewofs_crouch.z) {
+                               e.flags |= FL_DUCKED;
+                       }
 #endif
                        CSQCPlayer_SetMinsMaxs(e);
 
@@ -278,23 +265,19 @@ void CSQCPlayer_SetCamera()
        }
 
        const entity view = CSQCModel_server2csqc(player_localentnum - 1);
-       if (view)
-       {
-               if (view != csqcplayer)
-               {
+       if (view) {
+               if (view != csqcplayer) {
                        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;
+               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 (PHYS_HEALTH(NULL) <= 0 && PHYS_HEALTH(NULL) != -666 && PHYS_HEALTH(NULL) != -2342) refdefflags |= REFDEFFLAG_DEAD;
-               if (intermission) refdefflags |= REFDEFFLAG_INTERMISSION;
+               if (PHYS_HEALTH(NULL) <= 0 && PHYS_HEALTH(NULL) != -666 && PHYS_HEALTH(NULL) != -2342) { refdefflags |= REFDEFFLAG_DEAD; }
+               if (intermission) { refdefflags |= REFDEFFLAG_INTERMISSION; }
                V_CalcRefdef(view, refdefflags);
-       }
-       else
-       {
+       } else {
                // FIXME by CSQC spec we have to do this:
                // but it breaks chase cam
                /*
@@ -313,14 +296,14 @@ void CSQCPlayer_Remove(entity this)
 
 bool CSQCPlayer_PreUpdate(entity this)
 {
-       if (this != csqcplayer) return false;
-       if (csqcplayer_status != CSQCPLAYERSTATUS_FROMSERVER) CSQCPlayer_Unpredict(this);
+       if (this != csqcplayer) { return false; }
+       if (csqcplayer_status != CSQCPLAYERSTATUS_FROMSERVER) { CSQCPlayer_Unpredict(this); }
        return true;
 }
 
 bool CSQCPlayer_PostUpdate(entity this)
 {
-       if (this.entnum != player_localnum + 1) return false;
+       if (this.entnum != player_localnum + 1) { return false; }
        csqcplayer = this;
        csqcplayer_status = CSQCPLAYERSTATUS_FROMSERVER;
        cvar_settemp("cl_movement_replay", "0");