Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion code/client/cl_cgame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,37 @@ void CL_SetCGameTime( void ) {
// cl_timeNudge is a user adjustable cvar that allows more
// or less latency to be added in the interest of better
// smoothness or better responsiveness.
cl.serverTime = cls.realtime + cl.serverTimeDelta - CL_TimeNudge();

if ( cl_localTime->integer && !clc.demoplaying ) {
// PLL: advance serverTime at constant local rate instead of
// jumping to network-derived value each frame. Eliminates
// rendering jitter from snapshot arrival variance.
static int lastRealtime = 0;
int frameDelta, targetTime, error;

if ( lastRealtime == 0 || lastRealtime > cls.realtime )
lastRealtime = cls.realtime;

frameDelta = cls.realtime - lastRealtime;
lastRealtime = cls.realtime;

targetTime = cls.realtime + cl.serverTimeDelta - CL_TimeNudge();
error = targetTime - cl.serverTime;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable name is error, while value is time difference with previous frame


// soft rate adjustment: speed up/slow down max 2% to track server
if ( error > 2 )
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is always true pratically

cl.serverTime += (int)( frameDelta * 1.02f );
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frameDelta is typically 8, (int)( 8 * 1.02f ) = 8
'soft rate adjustment' is missing
practically, if time drifts away, additional weapon knockback lag is experienced, and this is visible on lagometer, until time resets by >100ms lag

else if ( error < -2 )
cl.serverTime += (int)( frameDelta * 0.98f );
else
cl.serverTime += frameDelta;

// hard clamp: never diverge more than 100ms from server
if ( error > 100 || error < -100 )
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case if ping spike this will add two lags by forth and back adjustments

cl.serverTime = targetTime;
} else {
cl.serverTime = cls.realtime + cl.serverTimeDelta - CL_TimeNudge();
}

// guarantee that time will never flow backwards, even if
// serverTimeDelta made an adjustment or cl_timeNudge was changed
Expand Down
5 changes: 5 additions & 0 deletions code/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cvar_t *cl_timeout;
cvar_t *cl_autoNudge;
cvar_t *cl_timeNudge;
cvar_t *cl_showTimeDelta;
cvar_t *cl_localTime;

cvar_t *cl_shownet;
cvar_t *cl_autoRecordDemo;
Expand Down Expand Up @@ -3908,6 +3909,10 @@ void CL_Init( void ) {
Cvar_CheckRange( cl_timeNudge, "-250", "250", CV_INTEGER );
Cvar_SetDescription( cl_timeNudge, "Allows more or less latency to be added in the interest of better smoothness or better responsiveness." );

cl_localTime = Cvar_Get( "cl_localTime", "0", CVAR_ARCHIVE_ND );
Cvar_CheckRange( cl_localTime, "0", "1", CV_INTEGER );
Cvar_SetDescription( cl_localTime, "Local time mode: cl.serverTime advances at constant local rate instead of jumping to network-derived values.\n 0 - standard network-synced time (default)\n 1 - smooth local clock, eliminates rendering jitter from network\n" );

cl_shownet = Cvar_Get ("cl_shownet", "0", CVAR_TEMP );
Cvar_SetDescription( cl_shownet, "Toggle the display of current network status." );
cl_showTimeDelta = Cvar_Get ("cl_showTimeDelta", "0", CVAR_TEMP );
Expand Down
1 change: 1 addition & 0 deletions code/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ extern cvar_t *cl_shownet;
extern cvar_t *cl_autoNudge;
extern cvar_t *cl_timeNudge;
extern cvar_t *cl_showTimeDelta;
extern cvar_t *cl_localTime;

extern cvar_t *com_timedemo;
extern cvar_t *cl_aviFrameRate;
Expand Down
Loading