Skip to content

feat(gamebanners): smooth 1Hz round_duration ticker between polls - #8

Merged
s950tx16wasr10 merged 1 commit into
masterfrom
feat/smooth-round-duration-ticker
May 18, 2026
Merged

feat(gamebanners): smooth 1Hz round_duration ticker between polls#8
s950tx16wasr10 merged 1 commit into
masterfrom
feat/smooth-round-duration-ticker

Conversation

@s950tx16wasr10

Copy link
Copy Markdown
Contributor

What

Adds a local 1Hz `setInterval` that recomputes only the `.status`
line on each game banner using `Math.floor((Date.now() - fetchedAt) / 1000)`
as an offset on the last server-reported `round_duration`. With server
polls every 4s, the clock reads as a live tick and re-syncs naturally
(no visible jump when the prediction matches; one-second snap when it
drifts).

Why

Previously `round_duration` only updated on each upstream fetch, so
the user saw the clock step 4s at a time. UX feels frozen between
polls for a value that's nominally a second-by-second timer.

Notes

  • Refactor: `buildStatusString(d, extraSec)` pulled out of
    `renderBanner`. Same code path on the initial render (`extraSec=0`)
    and on every ticker iteration.
  • `shuttle_timer` is intentionally NOT ticked locally — direction
    depends on `shuttle_mode` (`called` counts down, `recalled` counts
    up, etc.) and we don't carry that mapping client-side. It re-syncs
    every server poll, which is fine for the shuttle's <5min lifetime.
  • `setUnavailable` and `setNetworkError` clear `_statusData` so the
    ticker can't drift over stale data while disconnected.

Companion

`ReduxStation/infrastructure#3` — server polls drop from 30s to 4s
so the banner re-syncs at the same cadence the local ticker assumes.

Previously the round-duration display stepped 4s at a time on each
upstream fetch — at 4-second intervals the user saw the clock jump
00:01:24 -> 00:01:28 every poll. Now a local setInterval increments
the displayed time every second using (now - last_fetch_ms)/1000 as
an offset on the most recent server-reported round_duration, so the
clock reads as a live tick and re-syncs naturally on each poll
(if the prediction was right, there's no visible jump; if drift, a
1-second snap).

Implementation:
- Pull the .status string builder out of renderBanner into
  buildStatusString(d, extraSec).
- renderBanner stores the last server payload on banner._statusData
  and the wall-clock fetch time on banner._fetchedAt.
- New setInterval(1000) iterates banners and recomputes only the
  .status line; everything else (version, map, revision, state
  classes) is fetch-driven as before.
- setUnavailable and setNetworkError clear _statusData so the
  ticker can't drift over a stale payload while we're disconnected.

shuttle_timer is intentionally NOT ticked locally — the sign /
direction depends on shuttle_mode (called counts down, recalled
counts up, etc.) and we don't carry that semantics client-side.
It re-syncs every server poll, which is good enough.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
s950tx16wasr10 added a commit to ReduxStation/infrastructure that referenced this pull request May 18, 2026
Matches the landing-page poll cadence (data-poll-interval=4000ms in
_data/site.yaml). At 30s, every 7th browser fetch hit fresh upstream
data and the other 6 returned a stale cached JSON, so player counts
and round durations stepped 30s at a time on the page.

DD-side cost is negligible:
  - /world/Topic ?status is a sync proc, sub-millisecond per call
  - 7.5x more calls = ~0.025% of one core on DD main thread
  - One additional 700-byte atomic file write every 4s

The public-log-parser also polls this same file (every 60s per its
config) for ongoing-round protection; its semantics are unchanged.

Companion change: ReduxStation/website#8 adds a 1Hz client-side
ticker so the displayed round_duration increments smoothly between
the 4s server polls.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@s950tx16wasr10
s950tx16wasr10 merged commit c518272 into master May 18, 2026
1 check passed
@s950tx16wasr10
s950tx16wasr10 deleted the feat/smooth-round-duration-ticker branch May 18, 2026 16:41
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.

1 participant