Skip to content

Add cl_localTime: PLL-based local rendering clock for smooth gameplay#65

Merged
neyoneit merged 1 commit intoDefrag-racing:mainfrom
neyoneit:pll-pr
Apr 3, 2026
Merged

Add cl_localTime: PLL-based local rendering clock for smooth gameplay#65
neyoneit merged 1 commit intoDefrag-racing:mainfrom
neyoneit:pll-pr

Conversation

@neyoneit
Copy link
Copy Markdown
Member

@neyoneit neyoneit commented Apr 3, 2026

Summary

  • New cvar cl_localTime (0/1, default 0, archived) - opt-in smooth local rendering clock
  • When enabled, cl.serverTime advances at a constant local rate instead of jumping to network-derived values each frame
  • Eliminates rendering jitter caused by snapshot arrival variance (network timing)
  • Soft rate adjustment: speeds up/slows down by max 2% to track server time
  • Hard clamp: never diverges more than 100ms from server
  • Disabled during demo playback (clc.demoplaying)
  • No effect when disabled (0) - standard network-synced behavior unchanged

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.

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>
@neyoneit neyoneit merged commit 8f2c9e3 into Defrag-racing:main Apr 3, 2026
28 checks passed
Comment thread code/client/cl_cgame.c
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

Comment thread code/client/cl_cgame.c
error = targetTime - cl.serverTime;

// 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

Comment thread code/client/cl_cgame.c

// soft rate adjustment: speed up/slow down max 2% to track server
if ( error > 2 )
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

Comment thread code/client/cl_cgame.c
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants