Log inGet started
World

Match Flow Kit: Countdowns, Rounds and Results

README.md

timeline

What keeps every machine's screen on the same moment of the match, as pure Luau with no engine calls. MatchFlow uses it on every machine, the one in charge included, and the test suite drives it with simulated latency.

  • newClock() / ownClock(), addSample(clock, t0, theirs, t1), guess and slew match this machine's clock to the match clock of the machine in charge from ping round trips. The quickest recent trip sets the offset, and the first one replaces the initial guess outright. Later corrections run the shown clock at most 5% fast or slow (SLEW_RATE), so it never jumps. clock.rttMax, the slowest recent trip, is what a machine reports so that the delay can be sized.
  • delayFor(rtts, lates?) picks how far every screen trails the machine in charge: the worst snapshot lateness any player reports plus 0.05 s (LATE_MARGIN), or half the slowest round trip plus 0.1 s (MARGIN: one sync tick, a frame either side and a little clock error) if that is longer, from 0.15 to 0.6 s. graceFor(delay, rtts) gives how long a timed round stays open after 0:00, so late-arriving reports made before the end still count.
  • newLate(), noteLate(track, late, now) and lateOf(track, now) keep how late snapshots reach this machine, worst of the last LATE_WINDOW (20) seconds. A follower reports it with each ping.
  • delayAt(ramp, now) and retarget(ramp, to, now) handle a published delay { from, to, at }. A new delay starts RAMP_LEAD (0.5 s) after it is published and slides at RAMP_RATE (0.2 s per second), so every machine's delay moves at the same instant and rate. A plain number is read as a fixed delay.
  • new(), push(tl, snapshot) and pick(tl, t) hold the recent snapshots and pick the one standing at a shared time. A snapshot carries ev, how far into its phase the latest change was made, so one that arrives a sync tick late is still shown from the moment of its change.
  • show(view, snapshot, t) turns a snapshot into the state to draw at time t. The clocks run on from the snapshot, and the clock never runs backwards within a phase.
  • decode(snap) reads a snapshot off the synced property, keeping a published delay ramp as a ramp; nil for anything that is not a snapshot.
  • newRival(), noteRival(r, snap, me, now) and rivalOf(r, now, present) catch a machine whose engine wrongly says it owns the match (one coming back into play can): fresh snapshots from another machine that is still present mean that machine is really in charge, for RIVAL_HOLD (1.5 s) after the last one.