Skip to content

fix: Sync cumulative game clock with period clock display#17

Merged
JRemitz merged 4 commits intomainfrom
fix/cumulative-clock-sync
Apr 17, 2026
Merged

fix: Sync cumulative game clock with period clock display#17
JRemitz merged 4 commits intomainfrom
fix/cumulative-clock-sync

Conversation

@JRemitz
Copy link
Copy Markdown
Contributor

@JRemitz JRemitz commented Apr 17, 2026

Summary

  • Fixes the 1-second drift between the cumulative game clock and the period clock (Cumulative game clock #16)
  • Fixes cumulative game clock resetting to 0:00 on OBS restart
  • Bumps version to 0.7.1

Details

Clock sync fix: Both clocks internally track tenths but display whole seconds. Previously, each truncated tenths / 10 independently, so floor(a/10) + floor(b/10) could differ from floor((a+b)/10) — creating a 1-second gap. The fix derives cumulative elapsed as period_length - displayed_period_seconds, guaranteeing displayed_period + cumulative == period_length at every tick.

Persistence fix: cumulative_clock.txt was written but never read back on startup. Now scoreboard_read_all_files() parses it (both M:SS and H:MM:SS formats) and restores game_clock_accumulated_tenths by subtracting the current-period elapsed time from the total.

Test plan

  • test_game_clock_subsecond_sync — verifies invariant with sub-second ticks
  • test_game_clock_subsecond_sync_across_periods — verifies across period boundaries
  • test_game_clock_read_all_files — write/reset/read round-trip
  • test_game_clock_read_all_files_across_periods — multi-period round-trip
  • test_game_clock_read_disabled_no_restore — ignored when feature is off
  • test_game_clock_read_hmmss_format — H:MM:SS parsing
  • test_game_clock_read_invalid_format — garbage file silently ignored
  • test_game_clock_read_clamps_negative — negative accumulated clamped to 0
  • All 7 test suites pass, 100% line coverage
  • Manual: enable cumulative clock, run a period, close/reopen OBS, verify clock is restored

Closes #16

🤖 Generated with Claude Code

JRemitz and others added 4 commits April 17, 2026 07:03
Truncate current-period elapsed tenths to whole-second boundaries so
the cumulative clock uses the same rounding as the displayed period
clock, eliminating the 1-second drift caused by independent truncation.

Co-Authored-By: Claude <noreply@anthropic.com>
The first approach (truncating raw elapsed tenths) still allowed a
1-second discrepancy because the period clock and cumulative clock
truncated independently.  Now cumulative elapsed is computed as
(period_length - displayed_seconds), guaranteeing the invariant
displayed_period + displayed_cumulative == period_length at every tick.

Co-Authored-By: Claude <noreply@anthropic.com>
Read cumulative_clock.txt back during scoreboard_read_all_files() so
the cumulative game clock survives OBS close/reopen.  Parses both
M:SS and H:MM:SS formats, derives accumulated_tenths by subtracting
the current-period elapsed from the total.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@JRemitz JRemitz self-assigned this Apr 17, 2026
@JRemitz JRemitz merged commit dfa596f into main Apr 17, 2026
7 checks passed
@JRemitz JRemitz deleted the fix/cumulative-clock-sync branch April 17, 2026 12:34
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.

Cumulative game clock

1 participant