SOURCE / PINNED RELEASE
Made of little things.
Faultline
- Release
- da1ffaa5624c…
- Author-recorded commit
- 60f5f03189db…
- License
- LICENSE
- Author’s source reference
- nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-6932b12c78c
Archive hash verified: 5a2e0492417ec4e7…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
import type { Input } from './simulation';
// Host ticks displayed by the guest. Advance steadily between snapshots, even
// when a late packet changes the estimate of the host clock.
export function nextViewTick(previous: number, latest: number, sinceSnapshot: number, elapsed: number) {
const target = Math.max(0, Math.min(latest, latest - 5 + sinceSnapshot * 0.06));
if (previous === 0 || target - previous > 18) return Math.max(previous, target);
const rate = Math.min(1.15, Math.max(0.85, 1 + (target - previous) / 24));
return Math.min(latest, previous + Math.max(0, elapsed) * 0.06 * rate);
}
// Consume one command per simulation tick. Under sustained delay prefer
// discarding superseded movement samples over a press or release transition.
export function queueCommand(queue: Input[], input: Input, ack: number, buttons: number) {
if (input[0] <= (queue.at(-1)?.[0] ?? ack)) return;
queue.push(input);
if (queue.length <= 9) return;
const redundant = queue.findIndex((v, i) => i < queue.length - 1 &&
v[5] === (i ? queue[i - 1][5] : buttons) && v[5] === queue[i + 1][5]);
queue.splice(redundant < 0 ? 0 : redundant, 1);
}
