From 395aa7d1c312e495517701be11c21425d9a5838e Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 26 Oct 2025 17:25:13 -0700 Subject: Checkpoint --- .../commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt (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 new file mode 100644 index 0000000..f512ca7 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt @@ -0,0 +1,17 @@ +package coffee.liz.ecs + +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) + + 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 + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2