Setup counts toward the household's hour; comfort settings stay with each TV
- Channel setup (one request a second) now keeps to the household's share of SETUP_HOURLY (600) in any 60 minutes, slowing rather than refusing, so a channel always finishes (12 Nov: 502 requests in the living room's first hour). - Joining a room no longer copies reduce motion or subtitles: comfort settings stay with each TV, like its sound and picture switches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -69,8 +69,10 @@ internal enum class RoomPart(val title: String, val line: String) {
|
||||
}
|
||||
|
||||
/** On screen and Arcade settings that may travel; the sound output and anything about this box stay where they are. */
|
||||
private val LookKeys = listOf("look", "subtitles_on", "channel_logo", "idents", "ident_sound", "special_idents", "block_ident_sound", "squeeze_back", "up_next",
|
||||
"cast_on", "drive_in_intro", "reduce_motion")
|
||||
// Comfort settings (reduce motion, subtitles) stay with each TV (1.0 RC3, Paul: joining mustn't overwrite a room's own
|
||||
// accessibility, sound or playback choices), as the box's sound and picture switches always have.
|
||||
private val LookKeys = listOf("look", "channel_logo", "idents", "ident_sound", "special_idents", "block_ident_sound", "squeeze_back", "up_next",
|
||||
"cast_on", "drive_in_intro")
|
||||
private val ArcadeKeys = listOf("snake_best", "block_drop_best", "brick_break_best", "pairs_best", "patience_wins", "orb_man_best", "blast_best", "skydoku_solved", "snake_music")
|
||||
private val DirectorFiles = listOf("director-decisions-0.json", "director-learning-0.json", "event-ideas-history-0.json")
|
||||
private const val BUNDLE_LIMIT = 12 * 1024 * 1024
|
||||
|
||||
@@ -176,15 +176,25 @@ internal object BackgroundPacing {
|
||||
}
|
||||
private var lastSetupMs = 0L
|
||||
private val setupLock = Any()
|
||||
private val setupSent = ArrayDeque<Long>()
|
||||
/** Setup requests a household may make in any 60 minutes at full speed (see [beforeRequest]). */
|
||||
const val SETUP_HOURLY = 600
|
||||
|
||||
/** Called before each request; waits its turn for background work, or refuses once the hour's budget is spent. */
|
||||
fun beforeRequest() {
|
||||
if (!active) {
|
||||
// Its own lock: a background request waiting out its 1.5 s must never hold up setup (seen on the emulator, 0.129 audit).
|
||||
if (inSetup.get() == true) synchronized(setupLock) {
|
||||
val wait = lastSetupMs + SETUP_GAP_MS - clock()
|
||||
// Setup counts too (1.0 RC3, Paul: no path past every protection): one a second up to the household's share of
|
||||
// SETUP_HOURLY in any 60 minutes, then slower, so the hour never goes over it. Never refused, so a channel being
|
||||
// set up always finishes; it just takes longer.
|
||||
val now0 = clock()
|
||||
while (setupSent.isNotEmpty() && setupSent.first() <= now0 - 60 * 60_000L) setupSent.removeFirst()
|
||||
val cap = share(SETUP_HOURLY)
|
||||
val gap = if (setupSent.size >= cap) 60 * 60_000L / cap else SETUP_GAP_MS
|
||||
val wait = lastSetupMs + gap - now0
|
||||
if (wait > 0) sleep(wait)
|
||||
lastSetupMs = clock()
|
||||
lastSetupMs = clock(); setupSent.addLast(lastSetupMs)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -200,7 +210,7 @@ internal object BackgroundPacing {
|
||||
lastMs = now; sent.addLast(now)
|
||||
}
|
||||
}
|
||||
internal fun resetForTest() { lastMs = 0; lastSetupMs = 0; sent.clear(); ceilingHitMs = null; budget = HOURLY_BUDGET; tvs = 1; gapMs = GAP_MS; clock = System::currentTimeMillis; sleep = { Thread.sleep(it) } }
|
||||
internal fun resetForTest() { lastMs = 0; lastSetupMs = 0; sent.clear(); setupSent.clear(); ceilingHitMs = null; budget = HOURLY_BUDGET; tvs = 1; gapMs = GAP_MS; clock = System::currentTimeMillis; sleep = { Thread.sleep(it) } }
|
||||
@Synchronized internal fun usedThisHour(): Int { val now = clock(); return sent.count { it > now - 60 * 60_000L } }
|
||||
}
|
||||
|
||||
|
||||
@@ -20,3 +20,19 @@ class HouseholdBudgetTest {
|
||||
assertEquals(BackgroundPacing.MIN_CEILING, BackgroundPacing.ceiling)
|
||||
}
|
||||
}
|
||||
|
||||
class SetupBudgetTest {
|
||||
@org.junit.After fun reset() = BackgroundPacing.resetForTest()
|
||||
@Test fun setupSlowsOnceTheHouseholdsHourIsUsedButNeverStops() {
|
||||
var now = 0L
|
||||
val waits = mutableListOf<Long>()
|
||||
BackgroundPacing.resetForTest()
|
||||
BackgroundPacing.clock = { now }
|
||||
BackgroundPacing.sleep = { ms -> waits += ms; now += ms }
|
||||
BackgroundPacing.tvs = 2
|
||||
BackgroundPacing.setup { repeat(301) { BackgroundPacing.beforeRequest() } }
|
||||
// 300 at a second apart, then the 301st waits 12 s (300 an hour for each of two TVs).
|
||||
assertEquals(1_000L, waits[waits.size - 2])
|
||||
assertEquals(12_000L, waits.last())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user