code wiki / (root) / nx_lagcomp.nx

nx_lagcomp.nx source

↩ module page · 20 lines · 1206 B

1// nx_lagcomp.nx -- SERVER-SIDE LAG COMPENSATION. The authoritative server keeps a ring of recent entity positions (~1s 2// of history). When a client acts on what it SAW -- its view is (latency + interpolation-delay) in the PAST -- the server 3// rewinds to that exact moment and adjudicates the action (catch / hit / ability) against the HISTORICAL state, so it 4// "connects" fairly despite the 150ms ocean RTT. Without this, a correctly-aimed throw misses because the target has 5// already moved on the server. Cited: Valve (1s history, ExecTime = ServerTime - PacketLatency - InterpolationDelay), 6// favor-the-shooter asymmetry. Pure integer. license_tier: ORIGINAL 7 8// the position the acting client saw = the historical sample at (now - rewind_ticks), rewind = latency + interp delay. 9func lc_rewind(hist: *i64, now: i64, rewind_ticks: i64) -> i64 { 10 var t: i64 = now - rewind_ticks 11 if t < 0 { t = 0 } 12 return hist[t] 13} 14// hit/connect test: did the aimed action land within radius of the (rewound) target position? 15func lc_hit(aim_pos: i64, target_pos: i64, radius: i64) -> i64 { 16 var d: i64 = aim_pos - target_pos 17 if d < 0 { d = 0 - d } 18 if d <= radius { return 1 } 19 return 0 20}