diff options
Diffstat (limited to 'src/cl_pred.c')
-rw-r--r-- | src/cl_pred.c | 130 |
1 files changed, 68 insertions, 62 deletions
diff --git a/src/cl_pred.c b/src/cl_pred.c index 34547c2..1a92a09 100644 --- a/src/cl_pred.c +++ b/src/cl_pred.c @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -26,22 +26,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. CL_CheckPredictionError =================== */ -void CL_CheckPredictionError( void ) { +void CL_CheckPredictionError(void) +{ int frame; int delta[3]; unsigned cmd; int len; - if( !cls.netchan ) { + if (!cls.netchan) { return; } - if( sv_paused->integer ) { - VectorClear( cl.prediction_error ); + if (sv_paused->integer) { + VectorClear(cl.prediction_error); return; } - if( !cl_predict->integer || ( cl.frame.ps.pmove.pm_flags & PMF_NO_PREDICTION ) ) + if (!cl_predict->integer || (cl.frame.ps.pmove.pm_flags & PMF_NO_PREDICTION)) return; // calculate the last usercmd_t we sent that the server has processed @@ -49,30 +50,30 @@ void CL_CheckPredictionError( void ) { cmd = cl.history[frame].cmdNumber; // don't predict steps against server returned data - if( cl.predicted_step_frame < cmd + 1 ) { + if (cl.predicted_step_frame < cmd + 1) { cl.predicted_step_frame = cmd + 1; } cmd &= CMD_MASK; // compare what the server returned with what we had predicted it to be - VectorSubtract( cl.frame.ps.pmove.origin, cl.predicted_origins[cmd], delta ); + VectorSubtract(cl.frame.ps.pmove.origin, cl.predicted_origins[cmd], delta); // save the prediction error for interpolation - len = abs( delta[0] ) + abs( delta[1] ) + abs( delta[2] ); - if( len > 640 ) { // 80 world units + len = abs(delta[0]) + abs(delta[1]) + abs(delta[2]); + if (len > 640) { // 80 world units // a teleport or something - VectorClear( cl.prediction_error ); + VectorClear(cl.prediction_error); } else { - if( delta[0] || delta[1] || delta[2] ) { - SHOWMISS( "prediction miss on %i: %i (%d %d %d)\n", - cl.frame.number, len, delta[0], delta[1], delta[2]); + if (delta[0] || delta[1] || delta[2]) { + SHOWMISS("prediction miss on %i: %i (%d %d %d)\n", + cl.frame.number, len, delta[0], delta[1], delta[2]); } - VectorCopy( cl.frame.ps.pmove.origin, cl.predicted_origins[cmd] ); + VectorCopy(cl.frame.ps.pmove.origin, cl.predicted_origins[cmd]); // save for error interpolation - VectorScale( delta, 0.125f, cl.prediction_error ); + VectorScale(delta, 0.125f, cl.prediction_error); } } @@ -82,34 +83,35 @@ CL_ClipMoveToEntities ==================== */ -static void CL_ClipMoveToEntities( vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, trace_t *tr ) { +static void CL_ClipMoveToEntities(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, trace_t *tr) +{ int i; trace_t trace; mnode_t *headnode; centity_t *ent; mmodel_t *cmodel; - for( i = 0; i < cl.numSolidEntities; i++ ) { + for (i = 0; i < cl.numSolidEntities; i++) { ent = cl.solidEntities[i]; - if( ent->current.solid == PACKED_BSP ) { + if (ent->current.solid == PACKED_BSP) { // special value for bmodel cmodel = cl.model_clip[ent->current.modelindex]; - if( !cmodel ) + if (!cmodel) continue; headnode = cmodel->headnode; } else { - headnode = CM_HeadnodeForBox( ent->mins, ent->maxs ); + headnode = CM_HeadnodeForBox(ent->mins, ent->maxs); } - if( tr->allsolid ) + if (tr->allsolid) return; - CM_TransformedBoxTrace( &trace, start, end, - mins, maxs, headnode, MASK_PLAYERSOLID, - ent->current.origin, ent->current.angles ); + CM_TransformedBoxTrace(&trace, start, end, + mins, maxs, headnode, MASK_PLAYERSOLID, + ent->current.origin, ent->current.angles); - CM_ClipEntity( tr, &trace, ( struct edict_s * )ent ); + CM_ClipEntity(tr, &trace, (struct edict_s *)ent); } } @@ -119,29 +121,31 @@ static void CL_ClipMoveToEntities( vec3_t start, vec3_t mins, vec3_t maxs, vec3_ CL_PMTrace ================ */ -static trace_t CL_Trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end) { +static trace_t CL_Trace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end) +{ trace_t t; // check against world - CM_BoxTrace (&t, start, end, mins, maxs, cl.bsp->nodes, MASK_PLAYERSOLID); + CM_BoxTrace(&t, start, end, mins, maxs, cl.bsp->nodes, MASK_PLAYERSOLID); if (t.fraction < 1.0) t.ent = (struct edict_s *)1; // check all other solid models - CL_ClipMoveToEntities (start, mins, maxs, end, &t); + CL_ClipMoveToEntities(start, mins, maxs, end, &t); return t; } -static int CL_PointContents (vec3_t point) { +static int CL_PointContents(vec3_t point) +{ int i; centity_t *ent; mmodel_t *cmodel; int contents; - contents = CM_PointContents (point, cl.bsp->nodes); + contents = CM_PointContents(point, cl.bsp->nodes); - for (i=0 ; i<cl.numSolidEntities ; i++) { + for (i = 0; i < cl.numSolidEntities; i++) { ent = cl.solidEntities[i]; if (ent->current.solid != PACKED_BSP) // special value for bmodel @@ -152,9 +156,9 @@ static int CL_PointContents (vec3_t point) { continue; contents |= CM_TransformedPointContents( - point, cmodel->headnode, - ent->current.origin, - ent->current.angles ); + point, cmodel->headnode, + ent->current.origin, + ent->current.angles); } return contents; @@ -167,30 +171,32 @@ CL_PredictMovement Sets cl.predicted_origin and cl.predicted_angles ================= */ -void CL_PredictAngles( void ) { - cl.predicted_angles[0] = cl.viewangles[0] + SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[0] ); - cl.predicted_angles[1] = cl.viewangles[1] + SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[1] ); - cl.predicted_angles[2] = cl.viewangles[2] + SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[2] ); +void CL_PredictAngles(void) +{ + cl.predicted_angles[0] = cl.viewangles[0] + SHORT2ANGLE(cl.frame.ps.pmove.delta_angles[0]); + cl.predicted_angles[1] = cl.viewangles[1] + SHORT2ANGLE(cl.frame.ps.pmove.delta_angles[1]); + cl.predicted_angles[2] = cl.viewangles[2] + SHORT2ANGLE(cl.frame.ps.pmove.delta_angles[2]); } -void CL_PredictMovement( void ) { +void CL_PredictMovement(void) +{ unsigned ack, current, frame; pmove_t pm; int step, oldz; - if( cls.state != ca_active ) { + if (cls.state != ca_active) { return; } - if( cls.demo.playback ) { + if (cls.demo.playback) { return; } - if( sv_paused->integer ) { + if (sv_paused->integer) { return; } - if( !cl_predict->integer || ( cl.frame.ps.pmove.pm_flags & PMF_NO_PREDICTION ) ) { + if (!cl_predict->integer || (cl.frame.ps.pmove.pm_flags & PMF_NO_PREDICTION)) { // just set angles CL_PredictAngles(); return; @@ -200,13 +206,13 @@ void CL_PredictMovement( void ) { current = cl.cmdNumber; // if we are too far out of date, just freeze - if( current - ack > CMD_BACKUP - 1 ) { - SHOWMISS( "%i: exceeded CMD_BACKUP\n", cl.frame.number ); - return; + if (current - ack > CMD_BACKUP - 1) { + SHOWMISS("%i: exceeded CMD_BACKUP\n", cl.frame.number); + return; } - if( !cl.cmd.msec && current == ack ) { - SHOWMISS( "%i: not moved\n", cl.frame.number ); + if (!cl.cmd.msec && current == ack) { + SHOWMISS("%i: not moved\n", cl.frame.number); return; } @@ -214,52 +220,52 @@ void CL_PredictMovement( void ) { X86_SINGLE_FPCW; // copy current state to pmove - memset( &pm, 0, sizeof( pm ) ); + memset(&pm, 0, sizeof(pm)); pm.trace = CL_Trace; pm.pointcontents = CL_PointContents; pm.s = cl.frame.ps.pmove; #if USE_SMOOTH_DELTA_ANGLES - VectorCopy( cl.delta_angles, pm.s.delta_angles ); + VectorCopy(cl.delta_angles, pm.s.delta_angles); #endif // run frames - while( ++ack <= current ) { + while (++ack <= current) { pm.cmd = cl.cmds[ack & CMD_MASK]; - Pmove( &pm, &cl.pmp ); + Pmove(&pm, &cl.pmp); // save for debug checking - VectorCopy( pm.s.origin, cl.predicted_origins[ack & CMD_MASK] ); + VectorCopy(pm.s.origin, cl.predicted_origins[ack & CMD_MASK]); } // run pending cmd - if( cl.cmd.msec ) { + if (cl.cmd.msec) { pm.cmd = cl.cmd; pm.cmd.forwardmove = cl.localmove[0]; pm.cmd.sidemove = cl.localmove[1]; pm.cmd.upmove = cl.localmove[2]; - Pmove( &pm, &cl.pmp ); + Pmove(&pm, &cl.pmp); frame = current; // save for debug checking - VectorCopy( pm.s.origin, cl.predicted_origins[( current + 1 ) & CMD_MASK] ); + VectorCopy(pm.s.origin, cl.predicted_origins[(current + 1) & CMD_MASK]); } else { frame = current - 1; } X86_POP_FPCW; - + oldz = cl.predicted_origins[cl.predicted_step_frame & CMD_MASK][2]; step = pm.s.origin[2] - oldz; - if( step > 63 && step < 160 && ( pm.s.pm_flags & PMF_ON_GROUND ) ) { + if (step > 63 && step < 160 && (pm.s.pm_flags & PMF_ON_GROUND)) { cl.predicted_step = step * 0.125f; cl.predicted_step_time = cls.realtime;/// - cls.frametime * 500; } cl.predicted_step_frame = frame; // copy results out for rendering - VectorScale( pm.s.origin, 0.125f, cl.predicted_origin ); - VectorScale( pm.s.velocity, 0.125f, cl.predicted_velocity ); - VectorCopy( pm.viewangles, cl.predicted_angles ); + VectorScale(pm.s.origin, 0.125f, cl.predicted_origin); + VectorScale(pm.s.velocity, 0.125f, cl.predicted_velocity); + VectorCopy(pm.viewangles, cl.predicted_angles); } |