fix(net): interpolate between snapshots to absorb jitter (P1-6)
netfight eased to the newest snapshot with no buffer, so a jittery client's robot stalled then jumped. Render ~120 ms in the past between the two bracketing snapshots instead. Dev params ?netlag/?interp/ ?netprobe reproduce it; unit test for the interp math + a Playwright lag test (tests/e2e/netlag.spec.js).
This commit is contained in:
@@ -99,6 +99,7 @@
|
||||
if (Kit.store(ID).get('music', null) === null) audio.setVolume(0.1, 0.35);
|
||||
const DEV = new URLSearchParams(location.search);
|
||||
if (DEV.has('touch')) document.body.classList.add('forcetouch'); // dev: &touch shows the touch pad on desktop
|
||||
const netProbe = DEV.has('netprobe') ? (window.__probe = []) : null; // dev: records opponent robot pos for the lag test
|
||||
const net = RC.Net(NET_CFG);
|
||||
const rank = RC.Ranking(net); // online ranking, computed by the server
|
||||
const cloud = RC.CloudSave(net); // campaign copy for registered accounts (online saves live on the server)
|
||||
@@ -768,7 +769,12 @@
|
||||
const count = online ? Math.max(0, +online.countdown || 0) : 3.5;
|
||||
F = { s, opp, training, exhibition: !!exhibition, online, tour: !!tour, brain: online ? null : RC.AI.create({ style: opp.style, skill, seed: seed + 5 }), count, beat: Math.ceil(count) + 1,
|
||||
acc: [0, 0], accT: 0, banner: null, ended: false, oppAway: false };
|
||||
if (online) { netStats.reset(); F.nf = RC.NetFight({ net, seat: online.seat, stats: netStats }); } // the server runs the fight, we show it
|
||||
if (online) { // the server runs the fight, we show it (interpolated); dev: ?netlag=base,jit[,seed], ?interp=ms
|
||||
netStats.reset();
|
||||
let lag = null; const nl = DEV.get('netlag');
|
||||
if (nl) { const [b, j, sd] = nl.split(',').map(Number); lag = { base: b || 0, jit: j || 0, seed: sd || 1 }; }
|
||||
F.nf = RC.NetFight({ net, seat: online.seat, stats: netStats, interp: +DEV.get('interp') || 0, lag });
|
||||
}
|
||||
// dev: ?auto = AI drives the player too, ?ff=30 = fast-forward 30 s (screenshots, balancing)
|
||||
if (DEV.has('auto')) F.auto = RC.AI.create({ style: 'brawler', skill: 0.7, seed: seed + 11 });
|
||||
if (DEV.has('ff')) {
|
||||
@@ -916,6 +922,7 @@
|
||||
let events;
|
||||
if (F.online) {
|
||||
events = F.nf.frame(s, playerInput(), dt);
|
||||
if (netProbe) { netProbe.push({ t: performance.now(), x: s.robots[1].x, z: s.robots[1].z }); if (netProbe.length > 2000) netProbe.shift(); }
|
||||
if (F.nf.oppAway !== F.oppAway) { F.oppAway = F.nf.oppAway; banner(t(F.oppAway ? 'peer_lost' : 'peer_back'), F.oppAway ? '#ff4a3a' : '#6dff9e', 2.2); }
|
||||
// no word from the server for 20 s (and no result yet - a hidden tab may simply have slept through the end)
|
||||
if (!F.serverEnd && F.nf.silentFor > 20 && !F.ended) { F.ended = true; onlineFightLost(); return; }
|
||||
|
||||
Reference in New Issue
Block a user