Add cl_localTime: PLL-based local rendering clock for smooth gameplay#65
Merged
neyoneit merged 1 commit intoDefrag-racing:mainfrom Apr 3, 2026
Merged
Add cl_localTime: PLL-based local rendering clock for smooth gameplay#65neyoneit merged 1 commit intoDefrag-racing:mainfrom
neyoneit merged 1 commit intoDefrag-racing:mainfrom
Conversation
Phase-locked loop for cl.serverTime: instead of jumping to network-derived values each frame (causing micro-stutters from snapshot arrival jitter), serverTime advances at a constant local rate and softly tracks the server (max 2% rate adjustment). Hard clamp at 100ms prevents excessive drift. cl_localTime 0 = standard network-synced time (default) cl_localTime 1 = smooth local clock, eliminates rendering jitter Based on clean oDFe (origin/main) with no other modifications. Only client-side change — server needs no modification. Files: code/client/cl_cgame.c, cl_main.c, client.h Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Garux
reviewed
Apr 24, 2026
| lastRealtime = cls.realtime; | ||
|
|
||
| targetTime = cls.realtime + cl.serverTimeDelta - CL_TimeNudge(); | ||
| error = targetTime - cl.serverTime; |
There was a problem hiding this comment.
variable name is error, while value is time difference with previous frame
| error = targetTime - cl.serverTime; | ||
|
|
||
| // soft rate adjustment: speed up/slow down max 2% to track server | ||
| if ( error > 2 ) |
|
|
||
| // soft rate adjustment: speed up/slow down max 2% to track server | ||
| if ( error > 2 ) | ||
| cl.serverTime += (int)( frameDelta * 1.02f ); |
There was a problem hiding this comment.
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
| cl.serverTime += frameDelta; | ||
|
|
||
| // hard clamp: never diverge more than 100ms from server | ||
| if ( error > 100 || error < -100 ) |
There was a problem hiding this comment.
in case if ping spike this will add two lags by forth and back adjustments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cl_localTime(0/1, default 0, archived) - opt-in smooth local rendering clockcl.serverTimeadvances at a constant local rate instead of jumping to network-derived values each frameclc.demoplaying)Technical Details
PLL (Phase-Locked Loop) approach: each frame, the local clock advances by
frameDelta(wall time between frames). The error between local clock and network-derived target is measured. If error > 2ms, the clock runs slightly fast (1.02x). If error < -2ms, slightly slow (0.98x). If error exceeds 100ms (e.g. after a lag spike), it snaps directly to the target.This produces visually smooth rendering while maintaining network accuracy within a few milliseconds.