perf(ui): the idle home screen draws 30 frames a second

This commit is contained in:
maxjivi05 committed 2026-11-27 10:49:55 -05:00
1 parent 89ef2f1e90
commit 8f698dd1dc
2 files changed
+19 -5

No files matched your search

@@ -15,7 +15,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.runtime.withFrameMillis
import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
@@ -99,7 +99,7 @@ private fun rememberMarkClock(avoid: Rect?): MarkClock {
var vx = speed * 0.8f
var vy = -speed * 0.6f
while (true) {
if (clock.page == Size.Zero) { withFrameMillis { }; continue }
if (clock.page == Size.Zero) { withFrameNanos { }; continue }
val f = MarkFrame(clock.page, Offset.Zero)
if (clock.at == Offset.Unspecified) clock.at = Offset(clock.page.width * 0.64f, clock.page.height * 0.42f)
if (Motion.scale == 0f) {
@@ -108,7 +108,10 @@ private fun rememberMarkClock(avoid: Rect?): MarkClock {
clock.wall = 0f
return@LaunchedEffect
}
withFrameMillis { now ->
withFrameNanos { nanos ->
val settled = clock.intro >= END && clock.ball >= IMPACT + REVEAL_MS && !clock.poked
if (settled && last >= 0 && !IdleFrames.due(nanos)) return@withFrameNanos
val now = nanos / 1_000_000L
val dt = if (last < 0) 0f else min(50f, (now - last) / Motion.scale)
last = now
clock.intro += dt
@@ -82,7 +82,18 @@ import kotlinx.coroutines.withContext
private const val WALL_MIN_GAMES = 4
private const val WALL_DISTINCT = 40
private const val DRIFT_STEP_NS = 15_000_000L
private const val IDLE_FRAME_NS = 30_000_000L
internal object IdleFrames {
private var shown = 0L
fun due(nanos: Long): Boolean {
if (nanos == shown) return true
if (nanos - shown < IDLE_FRAME_NS) return false
shown = nanos
return true
}
}
@Composable
internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier) {
@@ -281,7 +292,7 @@ internal fun TiltedWall(
var shown = 0L
while (true) withFrameNanos { now ->
if (shown == 0L) shown = now
else if (now - shown >= DRIFT_STEP_NS) {
else if (IdleFrames.due(now)) {
drift.floatValue = ((drift.floatValue + (now - shown) / (period.value * 1_000_000.0 * Motion.scale)) % 1.0).toFloat()
shown = now
}