2004-08-23 00:15:46 +00:00
/*
Copyright ( C ) 1996 - 1997 Id Software , Inc .
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation ; either version 2
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
2005-11-26 03:02:55 +00:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
2004-08-23 00:15:46 +00:00
See the GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
# include "quakedef.h"
# include "winquake.h"
2013-09-06 22:57:44 +00:00
cvar_t cl_predict_extrapolate = CVARD ( " cl_predict_extrapolate " , " " , " If 1, enables prediction based upon partial input frames which can change over time resulting in a swimmy feel but does not need to interpolate. If 0, prediction will stay in the past and thus use only completed frames. Interpolation will then be used to smooth movement. \n This cvar only applies when video and input frames are independant (ie: cl_netfps is set). " ) ;
cvar_t cl_predict_timenudge = CVARD ( " cl_predict_timenudge " , " 0 " , " A debug feature. You should normally leave this as 0. Nudges local player prediction into the future if positive (resulting in extrapolation), or into the past if negative (resulting in laggy interpolation). Value is in seconds, so small decimals are required. This cvar applies even if input frames are tied to video frames. " ) ;
cvar_t cl_predict_smooth = CVARD ( " cl_lerp_smooth " , " 2 " , " If 2, will act as 1 when playing demos and otherwise act as if set to 0. \n If 1, interpolation will run in the past, resulting in really smooth movement at the cost of latency (even on bunchy german ISDNs). \n If 0, interpolation will be based upon packet arrival times and may judder due to packet loss. " ) ;
2006-02-11 02:09:43 +00:00
cvar_t cl_nopred = SCVAR ( " cl_nopred " , " 0 " ) ;
cvar_t cl_pushlatency = SCVAR ( " pushlatency " , " -999 " ) ;
2004-08-23 00:15:46 +00:00
extern float pm_airaccelerate ;
extern usercmd_t independantphysics [ MAX_SPLITS ] ;
# ifdef Q2CLIENT
2012-02-12 05:18:31 +00:00
# define MAX_PARSE_ENTITIES 1024
2013-10-08 14:28:11 +00:00
extern entity_state_t clq2_parse_entities [ MAX_PARSE_ENTITIES ] ;
2012-02-12 05:18:31 +00:00
2004-08-23 00:15:46 +00:00
char * Get_Q2ConfigString ( int i ) ;
# ifdef Q2BSPS
2005-03-18 06:14:07 +00:00
void VARGS Q2_Pmove ( q2pmove_t * pmove ) ;
2004-08-23 00:15:46 +00:00
# define Q2PMF_DUCKED 1
# define Q2PMF_JUMP_HELD 2
# define Q2PMF_ON_GROUND 4
# define Q2PMF_TIME_WATERJUMP 8 // pm_time is waterjump
# define Q2PMF_TIME_LAND 16 // pm_time is time before rejump
# define Q2PMF_TIME_TELEPORT 32 // pm_time is non-moving time
# define Q2PMF_NO_PREDICTION 64 // temporarily disables prediction (used for grappling hook)
# endif
vec3_t cl_predicted_origins [ UPDATE_BACKUP ] ;
/*
= = = = = = = = = = = = = = = = = = =
CL_CheckPredictionError
= = = = = = = = = = = = = = = = = = =
*/
# ifdef Q2BSPS
void CLQ2_CheckPredictionError ( void )
{
int frame ;
int delta [ 3 ] ;
int i ;
int len ;
if ( cl_nopred . value | | ( cl . q2frame . playerstate . pmove . pm_flags & Q2PMF_NO_PREDICTION ) )
return ;
// calculate the last usercmd_t we sent that the server has processed
frame = cls . netchan . incoming_acknowledged ;
frame & = ( UPDATE_MASK ) ;
// compare what the server returned with what we had predicted it to be
VectorSubtract ( cl . q2frame . playerstate . pmove . origin , cl_predicted_origins [ frame ] , delta ) ;
// save the prediction error for interpolation
len = abs ( delta [ 0 ] ) + abs ( delta [ 1 ] ) + abs ( delta [ 2 ] ) ;
if ( len > 640 ) // 80 world units
{ // a teleport or something
VectorClear ( cl . prediction_error ) ;
}
else
{
2005-03-28 00:11:59 +00:00
// if (/*cl_showmiss->value && */(delta[0] || delta[1] || delta[2]) )
2005-11-26 03:02:55 +00:00
// Con_Printf ("prediction miss on %i: %i\n", cl.q2frame.serverframe,
2005-03-28 00:11:59 +00:00
// delta[0] + delta[1] + delta[2]);
2004-08-23 00:15:46 +00:00
VectorCopy ( cl . q2frame . playerstate . pmove . origin , cl_predicted_origins [ frame ] ) ;
// save for error itnerpolation
for ( i = 0 ; i < 3 ; i + + )
cl . prediction_error [ i ] = delta [ i ] * 0.125 ;
}
}
/*
= = = = = = = = = = = = = = = = = = = =
CL_ClipMoveToEntities
= = = = = = = = = = = = = = = = = = = =
*/
void CLQ2_ClipMoveToEntities ( vec3_t start , vec3_t mins , vec3_t maxs , vec3_t end , trace_t * tr )
{
int i , x , zd , zu ;
trace_t trace ;
float * angles ;
entity_state_t * ent ;
int num ;
model_t * cmodel ;
vec3_t bmins , bmaxs ;
for ( i = 0 ; i < cl . q2frame . num_entities ; i + + )
{
num = ( cl . q2frame . parse_entities + i ) & ( MAX_PARSE_ENTITIES - 1 ) ;
2013-10-08 14:28:11 +00:00
ent = & clq2_parse_entities [ num ] ;
2004-08-23 00:15:46 +00:00
if ( ! ent - > solid )
continue ;
2013-06-23 02:17:02 +00:00
if ( ent - > number = = cl . playerview [ 0 ] . playernum + 1 )
2004-08-23 00:15:46 +00:00
continue ;
2012-02-12 05:18:31 +00:00
if ( ent - > solid = = ES_SOLID_BSP )
2004-08-23 00:15:46 +00:00
{ // special value for bmodel
cmodel = cl . model_precache [ ent - > modelindex ] ;
if ( ! cmodel )
continue ;
angles = ent - > angles ;
}
else
{ // encoded bbox
x = 8 * ( ent - > solid & 31 ) ;
zd = 8 * ( ( ent - > solid > > 5 ) & 31 ) ;
zu = 8 * ( ( ent - > solid > > 10 ) & 63 ) - 32 ;
bmins [ 0 ] = bmins [ 1 ] = - x ;
bmaxs [ 0 ] = bmaxs [ 1 ] = x ;
bmins [ 2 ] = - zd ;
bmaxs [ 2 ] = zu ;
2005-08-26 22:56:51 +00:00
cmodel = CM_TempBoxModel ( bmins , bmaxs ) ;
2004-08-23 00:15:46 +00:00
angles = vec3_origin ; // boxes don't rotate
}
if ( tr - > allsolid )
return ;
2005-08-26 22:56:51 +00:00
trace = CM_TransformedBoxTrace ( cmodel , start , end ,
mins , maxs , MASK_PLAYERSOLID ,
2004-08-23 00:15:46 +00:00
ent - > origin , angles ) ;
2006-02-11 18:06:18 +00:00
if ( trace . allsolid | | trace . startsolid | | trace . fraction < tr - > fraction )
2004-08-23 00:15:46 +00:00
{
trace . ent = ( struct edict_s * ) ent ;
2006-02-11 18:06:18 +00:00
* tr = trace ;
2004-08-23 00:15:46 +00:00
}
}
}
/*
= = = = = = = = = = = = = = = =
CL_PMTrace
= = = = = = = = = = = = = = = =
*/
2005-03-18 06:14:07 +00:00
q2trace_t VARGS CLQ2_PMTrace ( vec3_t start , vec3_t mins , vec3_t maxs , vec3_t end )
2004-08-23 00:15:46 +00:00
{
q2trace_t q2t ;
trace_t t ;
// check against world
2005-08-26 22:56:51 +00:00
t = CM_BoxTrace ( cl . worldmodel , start , end , mins , maxs , MASK_PLAYERSOLID ) ;
2004-08-23 00:15:46 +00:00
if ( t . fraction < 1.0 )
t . ent = ( struct edict_s * ) 1 ;
// check all other solid models
CLQ2_ClipMoveToEntities ( start , mins , maxs , end , & t ) ;
q2t . allsolid = t . allsolid ;
q2t . contents = t . contents ;
VectorCopy ( t . endpos , q2t . endpos ) ;
q2t . ent = t . ent ;
q2t . fraction = t . fraction ;
q2t . plane = t . plane ;
q2t . startsolid = t . startsolid ;
q2t . surface = t . surface ;
return q2t ;
}
2005-03-18 06:14:07 +00:00
int VARGS CLQ2_PMpointcontents ( vec3_t point )
2004-08-23 00:15:46 +00:00
{
int i ;
entity_state_t * ent ;
int num ;
model_t * cmodel ;
int contents ;
2005-08-26 22:56:51 +00:00
contents = CM_PointContents ( cl . worldmodel , point ) ;
2004-08-23 00:15:46 +00:00
for ( i = 0 ; i < cl . q2frame . num_entities ; i + + )
{
num = ( cl . q2frame . parse_entities + i ) & ( MAX_PARSE_ENTITIES - 1 ) ;
2013-10-08 14:28:11 +00:00
ent = & clq2_parse_entities [ num ] ;
2004-08-23 00:15:46 +00:00
if ( ent - > solid ! = 31 ) // special value for bmodel
continue ;
cmodel = cl . model_precache [ ent - > modelindex ] ;
if ( ! cmodel )
continue ;
2005-08-26 22:56:51 +00:00
contents | = CM_TransformedPointContents ( cl . worldmodel , point , cmodel - > hulls [ 0 ] . firstclipnode , ent - > origin , ent - > angles ) ;
2004-08-23 00:15:46 +00:00
}
return contents ;
}
# endif
/*
= = = = = = = = = = = = = = = = =
CL_PredictMovement
Sets cl . predicted_origin and cl . predicted_angles
= = = = = = = = = = = = = = = = =
*/
void CLQ2_PredictMovement ( void ) //q2 doesn't support split clients.
{
# ifdef Q2BSPS
int ack , current ;
int frame ;
int oldframe ;
2005-01-07 02:38:41 +00:00
q2usercmd_t * cmd ;
2004-08-23 00:15:46 +00:00
q2pmove_t pm ;
int step ;
int oldz ;
# endif
int i ;
2012-07-05 19:42:36 +00:00
int pnum = 0 ;
2004-08-23 00:15:46 +00:00
if ( cls . state ! = ca_active )
return ;
// if (cl_paused->value)
// return;
# ifdef Q2BSPS
if ( cl_nopred . value | | ( cl . q2frame . playerstate . pmove . pm_flags & Q2PMF_NO_PREDICTION ) )
# endif
{ // just set angles
for ( i = 0 ; i < 3 ; i + + )
{
2012-07-05 19:42:36 +00:00
cl . predicted_angles [ i ] = cl . playerview [ pnum ] . viewangles [ i ] + SHORT2ANGLE ( cl . q2frame . playerstate . pmove . delta_angles [ i ] ) ;
2004-08-23 00:15:46 +00:00
}
return ;
}
# ifdef Q2BSPS
ack = cls . netchan . incoming_acknowledged ;
current = cls . netchan . outgoing_sequence ;
// if we are too far out of date, just freeze
if ( current - ack > = UPDATE_MASK )
{
// if (cl_showmiss->value)
2005-03-28 00:11:59 +00:00
// Con_Printf ("exceeded CMD_BACKUP\n");
2005-11-26 03:02:55 +00:00
return ;
2004-08-23 00:15:46 +00:00
}
// copy current state to pmove
memset ( & pm , 0 , sizeof ( pm ) ) ;
pm . trace = CLQ2_PMTrace ;
pm . pointcontents = CLQ2_PMpointcontents ;
pm_airaccelerate = atof ( Get_Q2ConfigString ( Q2CS_AIRACCEL ) ) ;
pm . s = cl . q2frame . playerstate . pmove ;
// SCR_DebugGraph (current - ack - 1, 0);
frame = 0 ;
// run frames
while ( + + ack < current )
{
frame = ack & ( UPDATE_MASK ) ;
2013-03-12 22:53:23 +00:00
cmd = ( q2usercmd_t * ) & cl . outframes [ frame ] . cmd [ 0 ] ;
2004-08-23 00:15:46 +00:00
pm . cmd = * cmd ;
Q2_Pmove ( & pm ) ;
// save for debug checking
VectorCopy ( pm . s . origin , cl_predicted_origins [ frame ] ) ;
}
if ( independantphysics [ 0 ] . msec )
{
2005-01-07 02:38:41 +00:00
cmd = ( q2usercmd_t * ) & independantphysics [ 0 ] ;
2004-08-23 00:15:46 +00:00
pm . cmd = * cmd ;
Q2_Pmove ( & pm ) ;
}
oldframe = ( ack - 2 ) & ( UPDATE_MASK ) ;
oldz = cl_predicted_origins [ oldframe ] [ 2 ] ;
step = pm . s . origin [ 2 ] - oldz ;
if ( step > 63 & & step < 160 & & ( pm . s . pm_flags & Q2PMF_ON_GROUND ) )
{
cl . predicted_step = step * 0.125 ;
2005-03-18 06:14:07 +00:00
cl . predicted_step_time = realtime - host_frametime * 0.5 ;
2004-08-23 00:15:46 +00:00
}
2013-06-23 02:17:02 +00:00
cl . playerview [ 0 ] . onground = ! ! ( pm . s . pm_flags & Q2PMF_ON_GROUND ) ;
2004-08-23 00:15:46 +00:00
// copy results out for rendering
cl . predicted_origin [ 0 ] = pm . s . origin [ 0 ] * 0.125 ;
cl . predicted_origin [ 1 ] = pm . s . origin [ 1 ] * 0.125 ;
cl . predicted_origin [ 2 ] = pm . s . origin [ 2 ] * 0.125 ;
VectorCopy ( pm . viewangles , cl . predicted_angles ) ;
# endif
}
/*
= = = = = = = = = = = = = = = = =
CL_NudgePosition
If pmove . origin is in a solid position ,
try nudging slightly on all axis to
allow for the cut precision of the net coordinates
= = = = = = = = = = = = = = = = =
*/
void CL_NudgePosition ( void )
{
vec3_t base ;
int x , y ;
2010-08-28 17:14:38 +00:00
if ( cl . worldmodel - > funcs . PointContents ( cl . worldmodel , NULL , pmove . origin ) = = FTECONTENTS_EMPTY )
2004-08-23 00:15:46 +00:00
return ;
VectorCopy ( pmove . origin , base ) ;
for ( x = - 1 ; x < = 1 ; x + + )
{
for ( y = - 1 ; y < = 1 ; y + + )
{
pmove . origin [ 0 ] = base [ 0 ] + x * 1.0 / 8 ;
pmove . origin [ 1 ] = base [ 1 ] + y * 1.0 / 8 ;
2010-08-28 17:14:38 +00:00
if ( cl . worldmodel - > funcs . PointContents ( cl . worldmodel , NULL , pmove . origin ) = = FTECONTENTS_EMPTY )
2004-08-23 00:15:46 +00:00
return ;
}
}
Con_DPrintf ( " CL_NudgePosition: stuck \n " ) ;
}
# endif
/*
= = = = = = = = = = = = = =
CL_PredictUsercmd
= = = = = = = = = = = = = =
*/
2012-04-24 07:59:11 +00:00
void CL_PredictUsercmd ( int pnum , int entnum , player_state_t * from , player_state_t * to , usercmd_t * u )
2004-08-23 00:15:46 +00:00
{
extern vec3_t player_mins ;
extern vec3_t player_maxs ;
// split up very long moves
Fixes, workarounds, and breakages. Hexen2 should work much better (-hexen2 says no mission pack, -portals says h2mp). Started working on splitting bigcoords per client, far too much work still to go on that. Removed gl_ztrick entirely. Enabled csprogs download by default. Added client support for fitzquake's 666 protocol, needs testing, some cleanup for dp protocols too, no server support, couldn't selectively enable it anyway. Now attempting to cache shadow meshes for explosions and stuff. Played with lightmaps a little, should potentially run a little faster on certain (intel?) cards. Tweeked npfte a little to try to avoid deadlocks and crashes. Fixed sky worldspawn parsing. Added h2mp's model format. Fixed baseline issue in q2 client, made servers generate q2 baselines. MOVETYPE_PUSH will not rotate extra if rotation is forced. Made status command show allowed client types. Changed lighting on weapons - should now be shaded.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3572 fc73d0e0-1445-4013-8a0c-d673dee63da5
2010-08-11 03:36:31 +00:00
if ( u - > msec > 50 )
{
2004-08-23 00:15:46 +00:00
player_state_t temp ;
usercmd_t split ;
split = * u ;
2013-09-06 22:57:44 +00:00
split . msec = u - > msec / 2 ; //special care to avoid forgetting an msec here and there
2012-04-24 07:59:11 +00:00
CL_PredictUsercmd ( pnum , entnum , from , & temp , & split ) ;
2013-09-06 22:57:44 +00:00
split . msec = u - > msec - split . msec ;
2012-04-24 07:59:11 +00:00
CL_PredictUsercmd ( pnum , entnum , & temp , to , & split ) ;
2004-08-23 00:15:46 +00:00
return ;
}
2013-06-29 16:01:07 +00:00
if ( ! cl . worldmodel | | cl . worldmodel - > needload )
return ;
2004-08-23 00:15:46 +00:00
VectorCopy ( from - > origin , pmove . origin ) ;
VectorCopy ( u - > angles , pmove . angles ) ;
VectorCopy ( from - > velocity , pmove . velocity ) ;
2012-07-05 19:42:36 +00:00
VectorCopy ( from - > gravitydir , pmove . gravitydir ) ;
2004-08-23 00:15:46 +00:00
2008-01-09 00:52:31 +00:00
if ( ! ( pmove . velocity [ 0 ] = = 0 ) & & ! ( pmove . velocity [ 0 ] ! = 0 ) )
{
Con_Printf ( " nan velocity! \n " ) ;
pmove . velocity [ 0 ] = 0 ;
pmove . velocity [ 1 ] = 0 ;
pmove . velocity [ 2 ] = 0 ;
}
2004-08-23 00:15:46 +00:00
pmove . jump_msec = ( cls . z_ext & Z_EXT_PM_TYPE ) ? 0 : from - > jump_msec ;
pmove . jump_held = from - > jump_held ;
pmove . waterjumptime = from - > waterjumptime ;
pmove . pm_type = from - > pm_type ;
pmove . cmd = * u ;
2012-04-24 07:59:11 +00:00
pmove . skipent = entnum ;
2004-08-23 00:15:46 +00:00
2013-06-23 02:17:02 +00:00
movevars . entgravity = cl . playerview [ pnum ] . entgravity ;
movevars . maxspeed = cl . playerview [ pnum ] . maxspeed ;
2004-08-23 00:15:46 +00:00
movevars . bunnyspeedcap = cl . bunnyspeedcap ;
pmove . onladder = false ;
2012-02-12 05:18:31 +00:00
VectorCopy ( from - > szmins , player_mins ) ;
VectorCopy ( from - > szmaxs , player_maxs ) ;
2004-08-23 00:15:46 +00:00
2005-03-20 02:57:11 +00:00
PM_PlayerMove ( cl . gamespeed ) ;
2004-08-23 00:15:46 +00:00
to - > waterjumptime = pmove . waterjumptime ;
to - > jump_held = pmove . jump_held ;
to - > jump_msec = pmove . jump_msec ;
pmove . jump_msec = 0 ;
VectorCopy ( pmove . origin , to - > origin ) ;
VectorCopy ( pmove . angles , to - > viewangles ) ;
VectorCopy ( pmove . velocity , to - > velocity ) ;
2012-07-05 19:42:36 +00:00
VectorCopy ( pmove . gravitydir , to - > gravitydir ) ;
2004-08-23 00:15:46 +00:00
to - > onground = pmove . onground ;
to - > weaponframe = from - > weaponframe ;
to - > pm_type = from - > pm_type ;
2012-02-12 05:18:31 +00:00
VectorCopy ( player_mins , to - > szmins ) ;
VectorCopy ( player_maxs , to - > szmaxs ) ;
2004-08-23 00:15:46 +00:00
}
//Used when cl_nopred is 1 to determine whether we are on ground, otherwise stepup smoothing code produces ugly jump physics
2013-06-23 02:17:02 +00:00
void CL_CatagorizePosition ( playerview_t * pv )
2004-08-23 00:15:46 +00:00
{
if ( cl . spectator )
{
2013-06-23 02:17:02 +00:00
pv - > onground = false ; // in air
2004-08-23 00:15:46 +00:00
return ;
}
VectorClear ( pmove . velocity ) ;
2013-06-23 02:17:02 +00:00
VectorCopy ( pv - > simorg , pmove . origin ) ;
2004-08-23 00:15:46 +00:00
pmove . numtouch = 0 ;
PM_CategorizePosition ( ) ;
2013-06-23 02:17:02 +00:00
pv - > onground = pmove . onground ;
2004-08-23 00:15:46 +00:00
}
//Smooth out stair step ups.
//Called before CL_EmitEntities so that the player's lightning model origin is updated properly
2013-09-06 22:57:44 +00:00
void CL_CalcCrouch ( playerview_t * pv )
2004-08-23 00:15:46 +00:00
{
qboolean teleported ;
vec3_t delta ;
2013-09-06 22:57:44 +00:00
float orgz = - DotProduct ( pv - > simorg , pv - > gravitydir ) ; //compensate for running on walls.
2004-08-23 00:15:46 +00:00
2013-06-23 02:17:02 +00:00
VectorSubtract ( pv - > simorg , pv - > oldorigin , delta ) ;
2004-08-23 00:15:46 +00:00
teleported = Length ( delta ) > 48 ;
2013-06-23 02:17:02 +00:00
VectorCopy ( pv - > simorg , pv - > oldorigin ) ;
2004-08-23 00:15:46 +00:00
if ( teleported )
{
// possibly teleported or respawned
2013-06-23 02:17:02 +00:00
pv - > oldz = orgz ;
pv - > extracrouch = 0 ;
pv - > crouchspeed = 100 ;
pv - > crouch = 0 ;
VectorCopy ( pv - > simorg , pv - > oldorigin ) ;
2004-08-23 00:15:46 +00:00
return ;
}
2013-06-23 02:17:02 +00:00
if ( pv - > onground & & orgz - pv - > oldz > 0 )
2004-08-23 00:15:46 +00:00
{
2013-06-23 02:17:02 +00:00
if ( orgz - pv - > oldz > movevars . stepheight + 2 )
2004-08-23 00:15:46 +00:00
{
// if on steep stairs, increase speed
2013-06-23 02:17:02 +00:00
if ( pv - > crouchspeed < 160 )
2004-08-23 00:15:46 +00:00
{
2013-06-23 02:17:02 +00:00
pv - > extracrouch = orgz - pv - > oldz - host_frametime * 200 - 15 ;
pv - > extracrouch = min ( pv - > extracrouch , 5 ) ;
2004-08-23 00:15:46 +00:00
}
2013-06-23 02:17:02 +00:00
pv - > crouchspeed = 160 ;
2004-08-23 00:15:46 +00:00
}
2013-06-23 02:17:02 +00:00
pv - > oldz + = host_frametime * pv - > crouchspeed ;
if ( pv - > oldz > orgz )
pv - > oldz = orgz ;
2004-08-23 00:15:46 +00:00
2013-06-23 02:17:02 +00:00
if ( orgz - pv - > oldz > 15 + pv - > extracrouch )
pv - > oldz = orgz - 15 - pv - > extracrouch ;
pv - > extracrouch - = host_frametime * 200 ;
pv - > extracrouch = max ( pv - > extracrouch , 0 ) ;
2004-08-23 00:15:46 +00:00
2013-06-23 02:17:02 +00:00
pv - > crouch = pv - > oldz - orgz ;
2004-08-23 00:15:46 +00:00
}
else
{
// in air or moving down
2013-06-23 02:17:02 +00:00
pv - > oldz = orgz ;
pv - > crouch + = host_frametime * 150 ;
2013-09-06 22:57:44 +00:00
if ( orgz - pv - > oldz < = 0 )
pv - > crouch - = orgz - pv - > oldz ; //if the view moved down, remove that amount from our crouching to avoid unneeded bobbing
2013-06-23 02:17:02 +00:00
if ( pv - > crouch > 0 )
pv - > crouch = 0 ;
pv - > crouchspeed = 100 ;
pv - > extracrouch = 0 ;
2004-08-23 00:15:46 +00:00
}
}
2005-10-01 03:09:17 +00:00
float LerpAngles360 ( float to , float from , float frac )
{
2013-07-26 17:19:06 +00:00
float delta ;
2005-10-01 03:09:17 +00:00
delta = ( from - to ) ;
if ( delta > 180 )
delta - = 360 ;
if ( delta < - 180 )
delta + = 360 ;
return to + frac * delta ;
}
short LerpAngles16 ( short to , short from , float frac )
{
int delta ;
delta = ( from - to ) ;
if ( delta > 32767 )
delta - = 65535 ;
if ( delta < - 32767 )
delta + = 65535 ;
return to + frac * delta ;
}
void CL_CalcClientTime ( void )
{
2013-07-26 17:19:06 +00:00
extern float demtime ;
2012-10-08 04:36:10 +00:00
if ( cls . protocol ! = CP_QUAKE3 )
2005-10-01 03:09:17 +00:00
{
2009-11-04 21:16:50 +00:00
float oldst = realtime ;
2008-05-31 10:31:47 +00:00
2013-03-12 22:44:00 +00:00
if ( cls . protocol = = CP_QUAKEWORLD & & cls . demoplayback = = DPB_MVD & & ! ( cls . fteprotocolextensions2 & PEXT2_REPLACEMENTDELTAS ) )
2010-03-14 14:35:56 +00:00
{
extern float nextdemotime , olddemotime , demtime ;
float f ;
f = ( demtime - olddemotime ) / ( nextdemotime - olddemotime ) ;
f = bound ( 0 , f , 1 ) ;
2012-04-24 07:59:11 +00:00
cl . servertime = cl . gametime * f + cl . oldgametime * ( 1 - f ) ;
}
2013-09-06 22:57:44 +00:00
else if ( ! cl_predict_smooth . ival | | ( cl_predict_smooth . ival = = 2 & & ! cls . demoplayback ) )
2012-04-24 07:59:11 +00:00
{
float f ;
f = cl . gametime - cl . oldgametime ;
if ( f > 0.1 )
f = 0.1 ;
f = ( realtime - cl . gametimemark ) / ( f ) ;
f = bound ( 0 , f , 1 ) ;
cl . servertime = cl . gametime * f + cl . oldgametime * ( 1 - f ) ;
2010-03-14 14:35:56 +00:00
}
2009-11-04 21:16:50 +00:00
else
{
2011-12-05 15:23:40 +00:00
float min , max ;
2011-10-27 15:46:36 +00:00
oldst = cl . servertime ;
2012-07-21 04:43:31 +00:00
max = cl . gametime ;
min = cl . oldgametime ;
2013-06-23 02:17:02 +00:00
if ( max < min )
max = min ;
2011-12-05 15:23:40 +00:00
2012-08-04 01:35:52 +00:00
if ( max )
2013-07-26 17:19:06 +00:00
{
extern cvar_t cl_demospeed ;
if ( cls . demoplayback & & cl_demospeed . value > = 0 & & cls . state = = ca_active )
cl . servertime + = host_frametime * cl_demospeed . value ;
else
cl . servertime + = host_frametime ;
}
2012-08-04 01:35:52 +00:00
else
cl . servertime = 0 ;
2009-11-04 21:16:50 +00:00
2011-12-05 15:23:40 +00:00
if ( cl . servertime > max )
2011-10-27 15:46:36 +00:00
{
2013-06-23 02:17:02 +00:00
if ( cl . servertime > max )
2011-12-05 15:23:40 +00:00
{
2013-06-23 02:17:02 +00:00
cl . servertime = max ;
2011-12-05 15:23:40 +00:00
// Con_Printf("clamped to new time\n");
}
else
{
2013-06-23 02:17:02 +00:00
cl . servertime - = 0.02 * ( max - cl . servertime ) ;
2011-12-05 15:23:40 +00:00
}
2011-10-27 15:46:36 +00:00
}
2011-12-05 15:23:40 +00:00
if ( cl . servertime < min )
2011-10-27 15:46:36 +00:00
{
2011-12-05 15:23:40 +00:00
if ( cl . servertime < min - 0.5 )
2011-10-27 15:46:36 +00:00
{
2011-12-05 15:23:40 +00:00
cl . servertime = min - 0.5 ;
2011-10-27 15:46:36 +00:00
// Con_Printf("clamped to old time\n");
}
2011-12-05 15:23:40 +00:00
else if ( cl . servertime < min - 0.3 )
2011-10-27 15:46:36 +00:00
{
2011-12-05 15:23:40 +00:00
cl . servertime + = 0.02 * ( min - cl . servertime ) ;
2011-10-27 15:46:36 +00:00
// Con_Printf("running really slow\n");
}
else
{
2011-12-05 15:23:40 +00:00
cl . servertime + = 0.01 * ( min - cl . servertime ) ;
2011-10-27 15:46:36 +00:00
// Con_Printf("running slow\n");
}
}
2009-11-04 21:16:50 +00:00
}
2011-10-27 15:46:36 +00:00
cl . time = cl . servertime ;
2008-05-31 10:31:47 +00:00
if ( oldst = = 0 )
{
int i ;
2013-10-29 17:38:22 +00:00
for ( i = 0 ; i < cl . allocated_client_slots ; i + + )
2008-05-31 10:31:47 +00:00
{
cl . players [ i ] . entertime + = cl . servertime ;
}
}
2011-10-27 15:46:36 +00:00
return ;
2005-10-01 03:09:17 +00:00
}
2008-01-09 00:52:31 +00:00
if ( cls . protocol = = CP_NETQUAKE | | ( cls . demoplayback & & cls . demoplayback ! = DPB_MVD & & cls . demoplayback ! = DPB_EZTV ) )
2005-10-01 03:09:17 +00:00
{
float want ;
// float off;
want = cl . oldgametime + realtime - cl . gametimemark ;
// off = (want - cl.time);
if ( want > cl . time ) //don't decrease
cl . time = want ;
// Con_Printf("Drifted to %f off by %f\n", cl.time, off);
2005-11-26 03:02:55 +00:00
2005-10-01 03:09:17 +00:00
// Con_Printf("\n");
if ( cl . time > cl . gametime )
{
cl . time = cl . gametime ;
// Con_Printf("max TimeClamp\n");
}
if ( cl . time < cl . oldgametime )
{
cl . time = cl . oldgametime ;
// Con_Printf("old TimeClamp\n");
}
2005-11-26 03:02:55 +00:00
2005-10-01 03:09:17 +00:00
}
else
{
2013-09-06 22:57:44 +00:00
if ( cl_pushlatency . value > 0 )
Cvar_Set ( & cl_pushlatency , " 0 " ) ;
2005-10-01 03:09:17 +00:00
cl . time = realtime - cls . latency - cl_pushlatency . value * 0.001 ;
if ( cl . time > realtime )
cl . time = realtime ;
}
}
2012-02-12 05:18:31 +00:00
static void CL_DecodeStateSize ( unsigned short solid , int modelindex , vec3_t mins , vec3_t maxs )
{
if ( solid = = ES_SOLID_BSP )
{
if ( modelindex < MAX_MODELS & & cl . model_precache [ modelindex ] & & ! cl . model_precache [ modelindex ] - > needload )
{
VectorCopy ( cl . model_precache [ modelindex ] - > mins , mins ) ;
VectorCopy ( cl . model_precache [ modelindex ] - > maxs , maxs ) ;
}
else
{
VectorClear ( mins ) ;
VectorClear ( maxs ) ;
}
}
else if ( solid )
{
mins [ 0 ] = - 8 * ( solid & 31 ) ;
mins [ 1 ] = - 8 * ( solid & 31 ) ;
mins [ 2 ] = - 8 * ( ( solid > > 5 ) & 31 ) ;
maxs [ 0 ] = 8 * ( solid & 31 ) ;
maxs [ 1 ] = 8 * ( solid & 31 ) ;
maxs [ 2 ] = 8 * ( ( solid > > 10 ) & 63 ) - 32 ;
}
else
{
VectorClear ( mins ) ;
VectorClear ( maxs ) ;
}
}
/*called on packet reception*/
2012-02-12 05:33:16 +00:00
# include "pr_common.h"
2013-09-06 22:57:44 +00:00
static void CL_EntStateToPlayerState ( player_state_t * plstate , entity_state_t * state )
2012-02-12 05:18:31 +00:00
{
2012-07-05 19:42:36 +00:00
vec3_t a ;
2013-09-06 22:57:44 +00:00
int pmtype ;
memset ( plstate , 0 , sizeof ( * plstate ) ) ;
2012-02-15 13:53:30 +00:00
switch ( state - > u . q1 . pmovetype )
2012-02-12 05:18:31 +00:00
{
2012-02-15 13:53:30 +00:00
case MOVETYPE_NOCLIP :
2012-02-12 05:18:31 +00:00
if ( cls . z_ext & Z_EXT_PM_TYPE_NEW )
pmtype = PM_SPECTATOR ;
else
pmtype = PM_OLD_SPECTATOR ;
2012-02-15 13:53:30 +00:00
break ;
case MOVETYPE_FLY :
2012-02-12 05:18:31 +00:00
pmtype = PM_FLY ;
2012-02-15 13:53:30 +00:00
break ;
case MOVETYPE_NONE :
2012-02-12 05:18:31 +00:00
pmtype = PM_NONE ;
2012-02-15 13:53:30 +00:00
break ;
case MOVETYPE_BOUNCE :
case MOVETYPE_TOSS :
2012-02-12 05:18:31 +00:00
pmtype = PM_DEAD ;
2012-02-15 13:53:30 +00:00
break ;
case MOVETYPE_WALLWALK :
pmtype = PM_WALLWALK ;
break ;
default :
2012-02-12 05:18:31 +00:00
pmtype = PM_NORMAL ;
2012-02-15 13:53:30 +00:00
break ;
}
2012-02-12 05:18:31 +00:00
plstate - > pm_type = pmtype ;
VectorCopy ( state - > origin , plstate - > origin ) ;
VectorScale ( state - > u . q1 . velocity , 1 / 8.0 , plstate - > velocity ) ;
2013-10-08 14:28:11 +00:00
VectorCopy ( state - > angles , plstate - > viewangles ) ;
plstate - > viewangles [ 0 ] * = - 3 ;
2012-02-12 05:18:31 +00:00
2012-07-05 19:42:36 +00:00
a [ 0 ] = ( ( - 192 - state - > u . q1 . gravitydir [ 0 ] ) / 256.0f ) * 360 ;
a [ 1 ] = ( state - > u . q1 . gravitydir [ 1 ] / 256.0f ) * 360 ;
a [ 2 ] = 0 ;
AngleVectors ( a , plstate - > gravitydir , NULL , NULL ) ;
2012-02-12 05:18:31 +00:00
CL_DecodeStateSize ( state - > solid , state - > modelindex , plstate - > szmins , plstate - > szmaxs ) ;
}
2013-09-06 22:57:44 +00:00
static void CL_EntStateToPlayerCommand ( usercmd_t * cmd , entity_state_t * state , float age )
{
int msec ;
float extra ;
memset ( cmd , 0 , sizeof ( * cmd ) ) ;
extra = /*-cls.latency + */ 0.02 ; //network latency
extra + = age ; //if the state is not exactly current
// extra += realtime - cl.inframes[cl.validsequence&UPDATE_MASK].receivedtime;
// extra += (cl.inframes[cl.validsequence&UPDATE_MASK].receivedtime - cl.inframes[cl.oldvalidsequence&UPDATE_MASK].receivedtime)*4;
msec = 1000 * extra ;
2013-11-21 23:02:28 +00:00
// Con_DPrintf("%i: age = %i, stale=%i\n", state->number, msec, state->u.q1.msec);
2013-09-06 22:57:44 +00:00
msec + = state - > u . q1 . msec ; //this is the age on the server
cmd - > msec = bound ( 0 , msec , 250 ) ;
cmd - > forwardmove = state - > u . q1 . movement [ 0 ] ;
cmd - > sidemove = state - > u . q1 . movement [ 1 ] ;
cmd - > upmove = state - > u . q1 . movement [ 2 ] ;
cmd - > angles [ 0 ] = state - > angles [ 0 ] * - 3 * 65536 / 360.0 ;
cmd - > angles [ 1 ] = state - > angles [ 1 ] * 65536 / 360.0 ;
cmd - > angles [ 2 ] = state - > angles [ 2 ] * 65536 / 360.0 ;
}
2012-02-12 05:18:31 +00:00
2013-09-06 22:57:44 +00:00
void CL_PredictEntityMovement ( entity_state_t * estate , float age )
2012-02-12 05:18:31 +00:00
{
2013-09-06 22:57:44 +00:00
player_state_t startstate , resultstate ;
2012-02-12 05:18:31 +00:00
usercmd_t cmd ;
2013-09-06 22:57:44 +00:00
int oldphysent ;
//build the entitystate state into a player state for prediction to use
2012-02-12 05:18:31 +00:00
2013-09-06 22:57:44 +00:00
if ( ! estate - > u . q1 . pmovetype )
VectorCopy ( estate - > origin , estate - > u . q1 . predorg ) ;
else
2012-02-12 05:18:31 +00:00
{
2013-09-06 22:57:44 +00:00
CL_EntStateToPlayerState ( & startstate , estate ) ;
CL_EntStateToPlayerCommand ( & cmd , estate , age ) ;
2012-02-12 05:18:31 +00:00
2013-09-06 22:57:44 +00:00
// cmd.forwardmove = 5000;
// cmd.msec = sin(realtime*6) * 128 + 128;
oldphysent = pmove . numphysent ;
pmove . onground = true ;
CL_PredictUsercmd ( 0 , estate - > number , & startstate , & resultstate , & cmd ) ; //uses player 0's maxspeed/grav...
pmove . numphysent = oldphysent ;
2012-02-12 05:18:31 +00:00
2013-09-06 22:57:44 +00:00
VectorCopy ( resultstate . origin , estate - > u . q1 . predorg ) ;
}
2012-02-12 05:18:31 +00:00
}
2004-08-23 00:15:46 +00:00
/*
= = = = = = = = = = = = = =
CL_PredictMove
= = = = = = = = = = = = = =
*/
2013-06-23 02:17:02 +00:00
void CL_PredictMovePNum ( int seat )
2004-08-23 00:15:46 +00:00
{
2013-09-06 22:57:44 +00:00
//when this is called, the entity states have been interpolated.
//interpolation state should be updated to match prediction state, so entities move correctly in mirrors/portals.
//this entire function is pure convolouted bollocks.
2013-06-23 02:17:02 +00:00
playerview_t * pv = & cl . playerview [ seat ] ;
2004-08-23 00:15:46 +00:00
int i ;
float f ;
2013-09-06 22:57:44 +00:00
int fromframe , toframe ;
outframe_t * backdate ;
player_state_t * fromstate , * tostate , framebuf [ 2 ] ; //need two framebufs so we can interpolate between two states.
usercmd_t * cmdfrom , * cmdto ;
double fromtime , totime ;
2004-08-23 00:15:46 +00:00
int oldphysent ;
2013-03-12 22:53:23 +00:00
double simtime ;
extern cvar_t cl_netfps ;
2013-09-06 22:57:44 +00:00
lerpents_t * le ;
qboolean nopred ;
2013-03-12 22:53:23 +00:00
2004-08-23 00:15:46 +00:00
//these are to make svc_viewentity work better
float * vel ;
float * org ;
Fixes, workarounds, and breakages. Hexen2 should work much better (-hexen2 says no mission pack, -portals says h2mp). Started working on splitting bigcoords per client, far too much work still to go on that. Removed gl_ztrick entirely. Enabled csprogs download by default. Added client support for fitzquake's 666 protocol, needs testing, some cleanup for dp protocols too, no server support, couldn't selectively enable it anyway. Now attempting to cache shadow meshes for explosions and stuff. Played with lightmaps a little, should potentially run a little faster on certain (intel?) cards. Tweeked npfte a little to try to avoid deadlocks and crashes. Fixed sky worldspawn parsing. Added h2mp's model format. Fixed baseline issue in q2 client, made servers generate q2 baselines. MOVETYPE_PUSH will not rotate extra if rotation is forced. Made status command show allowed client types. Changed lighting on weapons - should now be shaded.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3572 fc73d0e0-1445-4013-8a0c-d673dee63da5
2010-08-11 03:36:31 +00:00
float stepheight = 0 ;
2013-03-12 22:53:23 +00:00
float netfps = cl_netfps . value ;
2013-07-26 17:19:06 +00:00
2013-03-12 22:53:23 +00:00
if ( ! netfps )
{
//every video frame has its own input frame.
simtime = realtime ;
}
else
{
2013-09-06 22:57:44 +00:00
qboolean extrap = cl_predict_extrapolate . ival ;
// float fps = 1/host_frametime;
// fps = bound(6.7, fps, cls.maxfps);
2013-03-12 22:53:23 +00:00
netfps = bound ( 6.7 , netfps , cls . maxfps ) ;
2013-09-06 22:57:44 +00:00
// if (netfps > fps)
// netfps = fps;
if ( ! * cl_predict_extrapolate . string )
extrap = netfps < 30 ;
if ( ! extrap )
2013-03-12 22:53:23 +00:00
{
//interpolate. The input rate is completely smoothed out, at the cost of some latency.
//You can still get juddering if the video rate doesn't match the monitor refresh rate (and isn't so high that it doesn't matter).
//note that the code below will back-date input frames if the server acks too fast.
simtime = realtime - ( 1 / netfps ) ;
}
2013-09-06 22:57:44 +00:00
else
{
//extrapolate if we've a low net rate. This should reduce apparent lag, but will be jerky if the net rate is not an (inverse) multiple of the monitor rate.
//this is in addition to any monitor desync.
simtime = realtime ;
}
2013-03-12 22:53:23 +00:00
}
2009-04-01 22:03:56 +00:00
2013-09-06 22:57:44 +00:00
simtime + = bound ( - 0.5 , cl_predict_timenudge . value , 0.5 ) ;
2013-06-23 02:17:02 +00:00
pv - > nolocalplayer = ! ! ( cls . fteprotocolextensions2 & PEXT2_REPLACEMENTDELTAS ) | | ( cls . protocol ! = CP_QUAKEWORLD ) ;
2009-04-01 22:03:56 +00:00
2004-08-23 00:15:46 +00:00
# ifdef Q2CLIENT
2005-05-26 12:55:34 +00:00
if ( cls . protocol = = CP_QUAKE2 )
2004-08-23 00:15:46 +00:00
{
2006-09-17 00:59:22 +00:00
if ( ! cl . worldmodel | | cl . worldmodel - > needload )
return ;
2013-06-23 02:17:02 +00:00
pv - > crouch = 0 ;
2004-08-23 00:15:46 +00:00
CLQ2_PredictMovement ( ) ;
return ;
}
# endif
2013-06-23 02:17:02 +00:00
if ( cl . paused & & ! ( cls . demoplayback ! = DPB_MVD & & cls . demoplayback ! = DPB_EZTV ) & & ( ! cl . spectator | | ! pv - > cam_auto ) )
2004-08-23 00:15:46 +00:00
return ;
2005-05-26 12:55:34 +00:00
2013-07-26 17:19:06 +00:00
if ( ! cl . validsequence )
2004-08-23 00:15:46 +00:00
{
return ;
}
2013-07-26 17:19:06 +00:00
if ( cl . intermission = = 1 & & cls . protocol = = CP_QUAKEWORLD )
2004-08-23 00:15:46 +00:00
{
2013-09-06 22:57:44 +00:00
//quakeworld locks view position once you hit intermission.
2013-07-26 17:19:06 +00:00
VectorCopy ( pv - > intermissionangles , pv - > simangles ) ;
2004-08-23 00:15:46 +00:00
return ;
}
2013-07-26 17:19:06 +00:00
else
{
if ( cl . currentpackentities & & cl . currentpackentities - > fixangles [ seat ] )
{
if ( cl . previouspackentities & & cl . previouspackentities - > fixangles [ seat ] = = cl . currentpackentities - > fixangles [ seat ] )
{
for ( i = 0 ; i < 3 ; i + + )
pv - > simangles [ i ] = LerpAngles360 ( cl . currentpackentities - > fixedangles [ seat ] [ i ] , cl . previouspackentities - > fixedangles [ seat ] [ i ] , 1 - ( cl . previouspackentities - > fixangles [ seat ] ? cl . packfrac : 1 ) ) ;
}
else
VectorCopy ( cl . currentpackentities - > fixedangles [ seat ] , pv - > simangles ) ;
}
else
2013-06-23 02:17:02 +00:00
VectorCopy ( pv - > viewangles , pv - > simangles ) ;
2004-08-23 00:15:46 +00:00
}
2013-09-06 22:57:44 +00:00
nopred = cl_nopred . ival ;
2013-07-26 17:19:06 +00:00
//don't wrap
2013-09-06 22:57:44 +00:00
if ( ! cl . ackedmovesequence )
nopred = true ;
else if ( cl . movesequence - cl . ackedmovesequence > = UPDATE_BACKUP - 1 )
2013-07-26 17:19:06 +00:00
return ;
2004-08-23 00:15:46 +00:00
2013-09-06 22:57:44 +00:00
//these things also force-disable prediction
2013-10-21 05:20:13 +00:00
if ( ( cls . demoplayback = = DPB_MVD | | cls . demoplayback = = DPB_EZTV ) | |
cl . paused | | pv - > pmovetype = = PM_NONE | | pv - > pmovetype = = PM_FREEZE | | pv - > cam_locked )
2013-09-06 22:57:44 +00:00
{
nopred = true ;
}
// figure out the first frame to lerp from.
// we generate one new input frame every 1/72th of a second, with a refresh rate of 60hz that's blatently obvious
// if we live in the present, we'll only have half a frame. in order to avoid extrapolation (which can give a swimmy feel), we live in the past by one frame time period
// if we're running somewhere with a low latency, we can get a reply from the server before our next input frame is even generated, so we need to go backwards beyond the current state
2004-08-23 00:15:46 +00:00
2013-09-06 22:57:44 +00:00
if ( nopred )
2004-08-23 00:15:46 +00:00
{
2013-09-06 22:57:44 +00:00
//match interpolation info
fromframe = ( ( char * ) cl . previouspackentities - ( char * ) & cl . inframes [ 0 ] . packet_entities ) / sizeof ( inframe_t ) ;
fromtime = cl . inframes [ fromframe & UPDATE_MASK ] . packet_entities . servertime ;
toframe = ( ( char * ) cl . currentpackentities - ( char * ) & cl . inframes [ 0 ] . packet_entities ) / sizeof ( inframe_t ) ;
totime = cl . inframes [ toframe & UPDATE_MASK ] . packet_entities . servertime ;
simtime = cl . currentpacktime ;
Fixes, workarounds, and breakages. Hexen2 should work much better (-hexen2 says no mission pack, -portals says h2mp). Started working on splitting bigcoords per client, far too much work still to go on that. Removed gl_ztrick entirely. Enabled csprogs download by default. Added client support for fitzquake's 666 protocol, needs testing, some cleanup for dp protocols too, no server support, couldn't selectively enable it anyway. Now attempting to cache shadow meshes for explosions and stuff. Played with lightmaps a little, should potentially run a little faster on certain (intel?) cards. Tweeked npfte a little to try to avoid deadlocks and crashes. Fixed sky worldspawn parsing. Added h2mp's model format. Fixed baseline issue in q2 client, made servers generate q2 baselines. MOVETYPE_PUSH will not rotate extra if rotation is forced. Made status command show allowed client types. Changed lighting on weapons - should now be shaded.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3572 fc73d0e0-1445-4013-8a0c-d673dee63da5
2010-08-11 03:36:31 +00:00
}
2013-09-06 22:57:44 +00:00
else
2009-03-03 01:52:30 +00:00
{
2013-09-06 22:57:44 +00:00
fromframe = 0 ;
toframe = 0 ;
totime = fromtime = 0 ;
//try to find the inbound frame that sandwiches the realtime that we're trying to simulate.
//if we're predicting, this will be some time in the future, and thus we'll be forced to pick the most recent frame.
//if we're interpolating, we'll need to grab the frame before that.
//we're only interested in inbound frames, not outbound, but its outbound frames that contain the prediction timing, so we need to look that up
//(note that in qw, inframe[i].ack==i holds true, but this code tries to be generic for unsyncronised protocols)
//(note that in nq, using outbound times means we'll skip over dupe states without noticing, and input packets with dupes should also be handled gracefully)
2013-10-21 05:20:13 +00:00
// Con_DPrintf("in:%i:%i out:%i:%i ack:%i\n", cls.netchan.incoming_sequence, cl.validsequence, cls.netchan.outgoing_sequence,cl.movesequence, cl.ackedmovesequence);
2013-09-06 22:57:44 +00:00
for ( i = cl . validsequence ; i > = cls . netchan . incoming_sequence - UPDATE_MASK ; i - - )
2009-03-03 01:52:30 +00:00
{
2013-09-06 22:57:44 +00:00
int out ;
//skip frames which were not received, or are otherwise invalid. yay packetloss
if ( cl . inframes [ i & UPDATE_MASK ] . frameid ! = i | | cl . inframes [ i & UPDATE_MASK ] . invalid )
{
2013-10-21 05:20:13 +00:00
// Con_DPrintf("stale incoming command %i\n", i);
2013-09-06 22:57:44 +00:00
continue ;
}
//each inbound frame tracks the outgoing frame that was last applied to it, and its outgoing frames that contain our timing info
out = cl . inframes [ i & UPDATE_MASK ] . ackframe ;
backdate = & cl . outframes [ out & UPDATE_MASK ] ;
if ( backdate - > cmd_sequence ! = out )
{
2013-10-21 05:20:13 +00:00
// Con_DPrintf("stale outgoing command %i (%i:%i:%i)\n", i, out, backdate->cmd_sequence, backdate->server_message_num);
2013-09-06 22:57:44 +00:00
continue ;
}
//okay, looks valid
//if this is the first one we found, make sure both from+to are set properly
if ( ! fromframe )
{
fromframe = i ;
fromtime = backdate - > senttime ;
}
toframe = fromframe ;
totime = fromtime ;
fromframe = i ;
fromtime = backdate - > senttime ;
if ( fromtime < simtime )
break ; //okay, we found the first frame that is older, no need to continue looking
2009-03-03 01:52:30 +00:00
}
}
2013-10-21 05:20:13 +00:00
// Con_DPrintf("sim%f, %i(%i-%i): old%f, cur%f\n", simtime, cl.ackedmovesequence, fromframe, toframe, fromtime, totime);
2009-03-03 01:52:30 +00:00
2013-10-21 05:20:13 +00:00
if ( pv - > cam_locked & & cl . spectator & & pv - > viewentity & & pv - > viewentity < = cl . allocated_client_slots )
{
fromstate = & cl . inframes [ fromframe & UPDATE_MASK ] . playerstate [ pv - > viewentity - 1 ] ;
tostate = & cl . inframes [ toframe & UPDATE_MASK ] . playerstate [ pv - > viewentity - 1 ] ;
}
else
{
if ( cls . demoplayback = = DPB_MVD | | cls . demoplayback = = DPB_EZTV )
{
fromstate = & cl . inframes [ cl . ackedmovesequence & UPDATE_MASK ] . playerstate [ pv - > playernum ] ;
tostate = & cl . inframes [ cl . movesequence & UPDATE_MASK ] . playerstate [ pv - > playernum ] ;
}
else
{
fromstate = & cl . inframes [ fromframe & UPDATE_MASK ] . playerstate [ pv - > playernum ] ;
tostate = & cl . inframes [ toframe & UPDATE_MASK ] . playerstate [ pv - > playernum ] ;
}
}
2013-10-07 15:27:55 +00:00
pv - > pmovetype = tostate - > pm_type ;
2013-09-06 22:57:44 +00:00
le = & cl . lerpplayers [ pv - > playernum ] ;
//if our network protocol doesn't have a concept of separate players, make sure our player states are updated from those entities
//fixme: use entity states instead of player states to avoid the extra work here
if ( pv - > nolocalplayer | | nopred )
2004-08-23 00:15:46 +00:00
{
2013-09-06 22:57:44 +00:00
packet_entities_t * pe ;
pe = & cl . inframes [ fromframe & UPDATE_MASK ] . packet_entities ;
for ( i = 0 ; i < pe - > num_entities ; i + + )
2011-12-23 03:12:29 +00:00
{
2013-09-06 22:57:44 +00:00
if ( pe - > entities [ i ] . number = = pv - > viewentity )
2013-07-26 17:19:06 +00:00
{
2013-09-06 22:57:44 +00:00
CL_EntStateToPlayerState ( fromstate , & pe - > entities [ i ] ) ;
break ;
2013-07-26 17:19:06 +00:00
}
2013-09-06 22:57:44 +00:00
}
pe = & cl . inframes [ toframe & UPDATE_MASK ] . packet_entities ;
for ( i = 0 ; i < pe - > num_entities ; i + + )
{
if ( pe - > entities [ i ] . number = = pv - > viewentity )
2013-07-26 17:19:06 +00:00
{
2013-09-06 22:57:44 +00:00
CL_EntStateToPlayerState ( tostate , & pe - > entities [ i ] ) ;
if ( cls . fteprotocolextensions2 & PEXT2_REPLACEMENTDELTAS )
{
cl . players [ pv - > playernum ] . stats [ STAT_WEAPONFRAME ] = pe - > entities [ i ] . u . q1 . weaponframe ;
cl . players [ pv - > playernum ] . statsf [ STAT_WEAPONFRAME ] = pe - > entities [ i ] . u . q1 . weaponframe ;
pv - > stats [ STAT_WEAPONFRAME ] = pe - > entities [ i ] . u . q1 . weaponframe ;
pv - > statsf [ STAT_WEAPONFRAME ] = pe - > entities [ i ] . u . q1 . weaponframe ;
pv - > pmovetype = tostate - > pm_type ;
}
break ;
2013-07-26 17:19:06 +00:00
}
2011-12-23 03:12:29 +00:00
}
2013-09-06 22:57:44 +00:00
if ( pv - > nolocalplayer & & pv - > viewentity < cl . maxlerpents )
le = & cl . lerpents [ pv - > viewentity ] ;
2004-08-23 00:15:46 +00:00
}
2013-09-06 22:57:44 +00:00
vel = fromstate - > velocity ;
org = fromstate - > origin ;
2004-08-23 00:15:46 +00:00
// predict forward until cl.time <= to->senttime
oldphysent = pmove . numphysent ;
2012-02-12 05:18:31 +00:00
CL_SetSolidPlayers ( ) ;
2013-09-06 22:57:44 +00:00
pmove . skipent = pv - > viewentity ;
2004-08-23 00:15:46 +00:00
2013-10-21 05:20:13 +00:00
//just in case we don't run any prediction
VectorCopy ( tostate - > gravitydir , pmove . gravitydir ) ;
2013-09-06 22:57:44 +00:00
cmdfrom = cmdto = & cl . outframes [ cl . ackedmovesequence & UPDATE_MASK ] . cmd [ seat ] ;
2013-03-12 22:53:23 +00:00
2013-09-06 22:57:44 +00:00
if ( ! nopred )
2004-08-23 00:15:46 +00:00
{
2013-09-06 22:57:44 +00:00
for ( i = 1 ; i < UPDATE_BACKUP - 1 & & cl . ackedmovesequence + i < cl . movesequence ; i + + )
2012-07-21 04:43:31 +00:00
{
2013-09-06 22:57:44 +00:00
outframe_t * of = & cl . outframes [ ( cl . ackedmovesequence + i ) & UPDATE_MASK ] ;
if ( totime > = simtime )
{
if ( i = = 1 )
{
//we must always predict a frame, just to ensure that the playerstate's jump status etc is valid for the next frame, even if we're not going to use it for interpolation.
//this assumes that we always have at least one video frame to each network frame, of course.
//note that q2 updates its values via networking rather than propagation.
2013-10-21 05:20:13 +00:00
// Con_DPrintf(" propagate %i: %f-%f\n", cl.ackedmovesequence+i, fromtime, totime);
2013-09-06 22:57:44 +00:00
CL_PredictUsercmd ( seat , pv - > viewentity , tostate , & cl . inframes [ ( toframe + i ) & UPDATE_MASK ] . playerstate [ pv - > playernum ] , & of - > cmd [ seat ] ) ;
}
break ;
}
if ( of - > cmd_sequence ! = cl . ackedmovesequence + i )
{
2013-10-21 05:20:13 +00:00
// Con_DPrintf("trying to predict a frame which is no longer valid\n");
2013-09-06 22:57:44 +00:00
break ;
}
fromtime = totime ;
fromstate = tostate ;
fromframe = toframe ; //qw debug
cmdfrom = cmdto ;
2005-10-01 03:09:17 +00:00
2013-09-06 22:57:44 +00:00
cmdto = & of - > cmd [ seat ] ;
totime = of - > senttime ;
toframe = cl . ackedmovesequence + i ; //qw debug
2005-10-01 03:09:17 +00:00
2013-09-06 22:57:44 +00:00
if ( i = = 1 ) //I've no idea how else to propogate event state from one frame to the next
tostate = & cl . inframes [ ( fromframe + i ) & UPDATE_MASK ] . playerstate [ pv - > playernum ] ;
else
tostate = & framebuf [ i & 1 ] ;
2012-01-24 04:24:14 +00:00
2013-10-21 05:20:13 +00:00
// Con_DPrintf(" pred %i: %f-%f\n", cl.ackedmovesequence+i, fromtime, totime);
2013-09-06 22:57:44 +00:00
CL_PredictUsercmd ( seat , pv - > viewentity , fromstate , tostate , cmdto ) ;
2005-10-01 03:09:17 +00:00
}
2013-09-06 22:57:44 +00:00
if ( simtime > totime )
2005-10-01 03:09:17 +00:00
{
2013-09-06 22:57:44 +00:00
//extrapolate X extra seconds
float msec ;
usercmd_t indcmd ;
2005-10-01 03:09:17 +00:00
2013-09-06 22:57:44 +00:00
msec = ( ( simtime - totime ) * 1000 ) ;
if ( msec > = 1 )
2012-01-24 04:24:14 +00:00
{
2013-03-12 22:53:23 +00:00
cmdfrom = cmdto ;
2013-09-06 22:57:44 +00:00
fromstate = tostate ;
fromtime = totime ;
fromframe = toframe ;
2005-11-26 03:02:55 +00:00
2013-09-06 22:57:44 +00:00
tostate = & framebuf [ i + + & 1 ] ;
if ( independantphysics [ seat ] . msec & & ! cls . demoplayback )
indcmd = independantphysics [ seat ] ;
else
indcmd = * cmdto ;
cmdto = & indcmd ;
totime = simtime ;
toframe + = 1 ;
2012-02-12 05:18:31 +00:00
2013-09-06 22:57:44 +00:00
cmdto - > msec = bound ( 0 , msec , 250 ) ;
2013-10-21 05:20:13 +00:00
// Con_DPrintf(" extrap %i: %f-%f\n", toframe, fromtime, simtime);
2013-09-06 22:57:44 +00:00
CL_PredictUsercmd ( seat , pv - > viewentity , fromstate , tostate , cmdto ) ;
}
2012-02-12 05:18:31 +00:00
}
2013-06-23 02:17:02 +00:00
pv - > onground = pmove . onground ;
2013-09-06 22:57:44 +00:00
pv - > pmovetype = tostate - > pm_type ;
2004-08-23 00:15:46 +00:00
}
pmove . numphysent = oldphysent ;
2013-09-06 22:57:44 +00:00
if ( totime = = fromtime )
2004-08-23 00:15:46 +00:00
{
2013-09-06 22:57:44 +00:00
VectorCopy ( tostate - > velocity , pv - > simvel ) ;
VectorCopy ( tostate - > origin , pv - > simorg ) ;
2013-10-21 05:20:13 +00:00
if ( pv - > viewentity & & pv - > viewentity ! = pv - > playernum + 1 )
VectorCopy ( tostate - > viewangles , pv - > simangles ) ;
//Con_DPrintf("%f %f %f\n", fromtime, simtime, totime);
2004-08-23 00:15:46 +00:00
}
else
{
2013-09-06 22:57:44 +00:00
vec3_t move ;
2004-08-23 00:15:46 +00:00
// now interpolate some fraction of the final frame
2013-09-06 22:57:44 +00:00
f = ( simtime - fromtime ) / ( totime - fromtime ) ;
2004-08-23 00:15:46 +00:00
2013-03-12 22:53:23 +00:00
if ( f < 0 )
f = 0 ;
if ( f > 1 )
f = 1 ;
2013-10-21 05:20:13 +00:00
//Con_DPrintf("%i:%f %f %i:%f (%f)\n", fromframe, fromtime, simtime, toframe, totime, f);
2013-09-06 22:57:44 +00:00
VectorSubtract ( tostate - > origin , fromstate - > origin , move ) ;
if ( DotProduct ( move , move ) > 128 * 128 )
2004-08-23 00:15:46 +00:00
{
2013-09-06 22:57:44 +00:00
// teleported, so don't lerp
VectorCopy ( tostate - > velocity , pv - > simvel ) ;
VectorCopy ( tostate - > origin , pv - > simorg ) ;
}
else
{
for ( i = 0 ; i < 3 ; i + + )
{
pv - > simorg [ i ] = ( 1 - f ) * fromstate - > origin [ i ] + f * tostate - > origin [ i ] ;
pv - > simvel [ i ] = ( 1 - f ) * fromstate - > velocity [ i ] + f * tostate - > velocity [ i ] ;
2013-10-08 14:28:11 +00:00
2013-10-21 05:20:13 +00:00
if ( pv - > viewentity & & pv - > viewentity ! = pv - > playernum + 1 )
2013-10-08 14:28:11 +00:00
{
pv - > simangles [ i ] = LerpAngles360 ( fromstate - > viewangles [ i ] , tostate - > viewangles [ i ] , f ) ; // * (360.0/65535);
// pv->viewangles[i] = LerpAngles16(fromstate->command.angles[i], tostate->command.angles[i], f) * (360.0/65535);
}
}
2013-09-06 22:57:44 +00:00
}
2013-06-23 02:17:02 +00:00
CL_CatagorizePosition ( pv ) ;
2004-08-23 00:15:46 +00:00
}
2005-10-01 03:09:17 +00:00
2013-09-06 22:57:44 +00:00
if ( le )
2013-03-12 22:53:23 +00:00
{
//keep the entity tracking the prediction position, so mirrors don't go all weird
2013-09-06 22:57:44 +00:00
VectorCopy ( tostate - > origin , le - > origin ) ;
2013-10-08 14:28:11 +00:00
if ( pv - > stats [ STAT_HEALTH ] > 0 )
{
VectorScale ( pv - > simangles , 1 , le - > angles ) ;
le - > angles [ 0 ] * = - 0.333 ;
}
2013-03-12 22:53:23 +00:00
}
2013-09-06 22:57:44 +00:00
// if (cls.demoplayback)
// CL_LerpMove (seat, totime);
2005-10-01 03:09:17 +00:00
2013-09-06 22:57:44 +00:00
CL_CalcCrouch ( pv ) ;
2013-06-23 02:17:02 +00:00
pv - > waterlevel = pmove . waterlevel ;
VectorCopy ( pmove . gravitydir , pv - > gravitydir ) ;
2004-08-23 00:15:46 +00:00
}
void CL_PredictMove ( void )
{
int i ;
2012-01-17 07:57:46 +00:00
//work out which packet entities are solid
CL_SetSolidEntities ( ) ;
// Set up prediction for other players
CL_SetUpPlayerPrediction ( false ) ;
// do client side motion prediction
2004-08-23 00:15:46 +00:00
for ( i = 0 ; i < cl . splitclients ; i + + )
CL_PredictMovePNum ( i ) ;
2012-01-17 07:57:46 +00:00
// Set up prediction for other players
CL_SetUpPlayerPrediction ( true ) ;
2004-08-23 00:15:46 +00:00
}
/*
= = = = = = = = = = = = = =
CL_InitPrediction
= = = = = = = = = = = = = =
*/
void CL_InitPrediction ( void )
{
extern char cl_predictiongroup [ ] ;
Cvar_Register ( & cl_pushlatency , cl_predictiongroup ) ;
Cvar_Register ( & cl_nopred , cl_predictiongroup ) ;
2013-09-06 22:57:44 +00:00
Cvar_Register ( & cl_predict_extrapolate , cl_predictiongroup ) ;
Cvar_Register ( & cl_predict_timenudge , cl_predictiongroup ) ;
Cvar_Register ( & cl_predict_smooth , cl_predictiongroup ) ;
2004-08-23 00:15:46 +00:00
}