fix: Sync cumulative game clock with period clock display#17
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Details
Clock sync fix: Both clocks internally track tenths but display whole seconds. Previously, each truncated
tenths / 10independently, sofloor(a/10) + floor(b/10)could differ fromfloor((a+b)/10)— creating a 1-second gap. The fix derives cumulative elapsed asperiod_length - displayed_period_seconds, guaranteeingdisplayed_period + cumulative == period_lengthat every tick.Persistence fix:
cumulative_clock.txtwas written but never read back on startup. Nowscoreboard_read_all_files()parses it (both M:SS and H:MM:SS formats) and restoresgame_clock_accumulated_tenthsby subtracting the current-period elapsed time from the total.Test plan
test_game_clock_subsecond_sync— verifies invariant with sub-second tickstest_game_clock_subsecond_sync_across_periods— verifies across period boundariestest_game_clock_read_all_files— write/reset/read round-triptest_game_clock_read_all_files_across_periods— multi-period round-triptest_game_clock_read_disabled_no_restore— ignored when feature is offtest_game_clock_read_hmmss_format— H:MM:SS parsingtest_game_clock_read_invalid_format— garbage file silently ignoredtest_game_clock_read_clamps_negative— negative accumulated clamped to 0Closes #16
🤖 Generated with Claude Code