-
Notifications
You must be signed in to change notification settings - Fork 6
Add cl_localTime: PLL-based local rendering clock for smooth gameplay #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
| // soft rate adjustment: speed up/slow down max 2% to track server | ||
| if ( error > 2 ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is always true pratically |
||
| cl.serverTime += (int)( frameDelta * 1.02f ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. frameDelta is typically 8, (int)( 8 * 1.02f ) = 8 |
||
| 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 ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
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