From a8e5e723b7e1891c9b352261a3ee4c3d3563e8cf Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 26 Oct 2025 21:38:22 -0700 Subject: Checkpoint two --- .../kotlin/coffee/liz/ecs/TickedSystem.kt | 29 ++++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt') diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt index f512ca7..fa4566d 100644 --- a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt +++ b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt @@ -4,14 +4,27 @@ import kotlin.time.Duration abstract class TickedSystem( protected val tickRate: Duration, - private var lastTick: Duration = Duration.ZERO -): System { - abstract fun update(world: World, state: Outside, ticks: Int) + private var lastTick: Duration = Duration.ZERO, +) : System { + abstract fun update( + world: World, + state: Outside, + ticks: Int, + ) - override fun update(world: World, state: Outside, deltaTime: Duration) { + override fun update( + world: World, + state: Outside, + deltaTime: Duration, + ) { val ticks = ((deltaTime - lastTick) / tickRate).toInt() - lastTick = if (ticks == 0) (lastTick + deltaTime).also { - update(world, state, ticks) - } else Duration.ZERO + lastTick = + if (ticks == 0) { + (lastTick + deltaTime).also { + update(world, state, ticks) + } + } else { + Duration.ZERO + } } -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2