summaryrefslogtreecommitdiff
path: root/composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-10-26 21:38:22 -0700
committerElizabeth Hunt <me@liz.coffee>2025-10-26 21:39:58 -0700
commita8e5e723b7e1891c9b352261a3ee4c3d3563e8cf (patch)
tree853df79c877d37d7e5d25f52b301aedcc3d5db55 /composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt
parent395aa7d1c312e495517701be11c21425d9a5838e (diff)
downloadabstraction-engine-kt-a8e5e723b7e1891c9b352261a3ee4c3d3563e8cf.tar.gz
abstraction-engine-kt-a8e5e723b7e1891c9b352261a3ee4c3d3563e8cf.zip
Checkpoint twoHEADmain
Diffstat (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt')
-rw-r--r--composeApp/src/commonMain/kotlin/coffee/liz/ecs/TickedSystem.kt29
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
+}