diff --git a/engine/cl_main.cpp b/engine/cl_main.cpp index e11b78249f..8def103b06 100644 --- a/engine/cl_main.cpp +++ b/engine/cl_main.cpp @@ -2234,7 +2234,15 @@ void CL_Move(float accumulated_extra_samples, bool bFinalTick ) if ( cl.IsActive() ) { - NET_Tick mymsg( cl.m_nDeltaTick, cl.m_ClockDriftMgr.m_nCachedRealClientTick, host_frametime_unbounded, host_frametime_stddeviation ); + // TODO_ENHANCED: + // When fps is lower than tickrate, + // the server doesn't really know how many ticks were processed this frame client-side. + // + // When the client tick count is sent to server, sv_max_usercmd_future_ticks doesn't take into account when + // multiple commands are ran from client because it had low fps. + // We could probably store in CUserCmd structure the current tick number to account for that ? + // This works anyway. + NET_Tick mymsg( cl.m_nDeltaTick, cl.m_ClockDriftMgr.m_nCachedRealClientTick + cl.m_ClockDriftMgr.m_nCurrentTick, host_frametime_unbounded, host_frametime_stddeviation ); cl.m_NetChannel->SendNetMsg( mymsg ); } diff --git a/engine/clockdriftmgr.cpp b/engine/clockdriftmgr.cpp index de5430c93d..f7592f920a 100644 --- a/engine/clockdriftmgr.cpp +++ b/engine/clockdriftmgr.cpp @@ -99,9 +99,10 @@ void CClockDriftMgr::ApplyClockCorrection(bool bFinalTick) { if (bFinalTick) { - m_nCachedRealClientTick++; + cl.m_ClockDriftMgr.m_nCachedRealClientTick += cl.m_ClockDriftMgr.m_nNumberOfTicks; } - m_nClientTick = m_nCachedRealClientTick + m_nLagDiff + g_ClientGlobalVariables.simTicksThisFrame - 1; + + m_nClientTick = m_nCachedRealClientTick + m_nLagDiff; } void CClockDriftMgr::ShowDebugInfo() diff --git a/engine/clockdriftmgr.h b/engine/clockdriftmgr.h index 0d495f36d0..2d5d79ca37 100644 --- a/engine/clockdriftmgr.h +++ b/engine/clockdriftmgr.h @@ -39,6 +39,8 @@ public: int m_nOldServerTick; int m_nServerTick; // Last-received tick from the server. int m_nClientTick; + int m_nNumberOfTicks; + int m_nCurrentTick; int m_nCachedRealClientTick; // The client's own tick counter (specifically, for interpolation during rendering). // The server may be on a slightly different tick and the client will drift towards it. int m_nLaggedClientTick; diff --git a/engine/host.cpp b/engine/host.cpp index 3b714c8b62..7611c6fc29 100644 --- a/engine/host.cpp +++ b/engine/host.cpp @@ -3130,6 +3130,8 @@ void _Host_RunFrame (float time) host_remainder -= numticks * host_state.interval_per_tick; } + cl.m_ClockDriftMgr.m_nNumberOfTicks = numticks; + host_nexttick = host_state.interval_per_tick - host_remainder; g_pMDLCache->MarkFrame(); @@ -3246,7 +3248,7 @@ void _Host_RunFrame (float time) #endif cl.m_tickRemainder = host_remainder; g_ServerGlobalVariables.simTicksThisFrame = 1; - cl.SetFrameTime( host_frametime ); + cl.SetFrameTime(host_frametime); for ( int tick = 0; tick < numticks; tick++ ) { // Emit an ETW event every simulation frame. @@ -3315,8 +3317,9 @@ void _Host_RunFrame (float time) //------------------- #ifndef SWDS if ( !sv.IsDedicated() ) - { - _Host_RunFrame_Client( bFinalTick ); + { + cl.m_ClockDriftMgr.m_nCurrentTick = tick; + _Host_RunFrame_Client(bFinalTick); } toolframework->Think( bFinalTick ); @@ -3358,7 +3361,8 @@ void _Host_RunFrame (float time) // as quickly as we can. if ( numticks == 0 && ( demoplayer->IsPlayingTimeDemo() || demoplayer->IsSkipping() ) ) { - _Host_RunFrame_Client( true ); + cl.m_ClockDriftMgr.m_nCurrentTick = 0; + _Host_RunFrame_Client(true); } if ( !sv.IsDedicated() ) @@ -3455,7 +3459,8 @@ void _Host_RunFrame (float time) //------------------- if ( !sv.IsDedicated() ) { - _Host_RunFrame_Client( bFinalTick ); + cl.m_ClockDriftMgr.m_nCurrentTick = tick; + _Host_RunFrame_Client(bFinalTick); } toolframework->Think( bFinalTick ); }