diff options
Diffstat (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt')
| -rw-r--r-- | composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt | 29 |
1 files changed, 21 insertions, 8 deletions
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<Outside>( protected val tickRate: Duration, - private var lastTick: Duration = Duration.ZERO -): System<Outside> { - abstract fun update(world: World<Outside>, state: Outside, ticks: Int) + private var lastTick: Duration = Duration.ZERO, +) : System<Outside> { + abstract fun update( + world: World<Outside>, + state: Outside, + ticks: Int, + ) - override fun update(world: World<Outside>, state: Outside, deltaTime: Duration) { + override fun update( + world: World<Outside>, + 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 +} |
