summaryrefslogtreecommitdiff
path: root/composeApp/src/commonTest/kotlin/coffee
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/commonTest/kotlin/coffee
parent395aa7d1c312e495517701be11c21425d9a5838e (diff)
downloadabstraction-engine-kt-a8e5e723b7e1891c9b352261a3ee4c3d3563e8cf.tar.gz
abstraction-engine-kt-a8e5e723b7e1891c9b352261a3ee4c3d3563e8cf.zip
Checkpoint twoHEADmain
Diffstat (limited to 'composeApp/src/commonTest/kotlin/coffee')
-rw-r--r--composeApp/src/commonTest/kotlin/coffee/liz/abstractionengine/ComposeAppCommonTest.kt3
-rw-r--r--composeApp/src/commonTest/kotlin/coffee/liz/ecs/DAGWorldTest.kt187
-rw-r--r--composeApp/src/commonTest/kotlin/coffee/liz/ecs/EntityTest.kt24
-rw-r--r--composeApp/src/commonTest/kotlin/coffee/liz/ecs/animation/AnimationSystemTest.kt115
4 files changed, 205 insertions, 124 deletions
diff --git a/composeApp/src/commonTest/kotlin/coffee/liz/abstractionengine/ComposeAppCommonTest.kt b/composeApp/src/commonTest/kotlin/coffee/liz/abstractionengine/ComposeAppCommonTest.kt
index 78e642f..98b7be0 100644
--- a/composeApp/src/commonTest/kotlin/coffee/liz/abstractionengine/ComposeAppCommonTest.kt
+++ b/composeApp/src/commonTest/kotlin/coffee/liz/abstractionengine/ComposeAppCommonTest.kt
@@ -4,9 +4,8 @@ import kotlin.test.Test
import kotlin.test.assertEquals
class ComposeAppCommonTest {
-
@Test
fun example() {
assertEquals(3, 1 + 2)
}
-} \ No newline at end of file
+}
diff --git a/composeApp/src/commonTest/kotlin/coffee/liz/ecs/DAGWorldTest.kt b/composeApp/src/commonTest/kotlin/coffee/liz/ecs/DAGWorldTest.kt
index bdf7e99..a9f6249 100644
--- a/composeApp/src/commonTest/kotlin/coffee/liz/ecs/DAGWorldTest.kt
+++ b/composeApp/src/commonTest/kotlin/coffee/liz/ecs/DAGWorldTest.kt
@@ -4,20 +4,28 @@ import kotlin.reflect.KClass
import kotlin.test.*
// Test systems for circular dependency test
-class CircularSystemA : System {
- override val dependencies: Set<KClass<out System>>
- get() = setOf(CircularSystemB::class)
- override fun update(world: World, deltaTime: Float) {}
+class Outside
+
+class CircularSystemA : System<Outside> {
+ override val dependencies get() = setOf(CircularSystemB::class)
+
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {}
}
class CircularSystemB : System {
override val dependencies: Set<KClass<out System>>
get() = setOf(CircularSystemA::class)
- override fun update(world: World, deltaTime: Float) {}
+
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {}
}
class DAGWorldTest {
-
@Test
fun `can create entities with unique ids`() {
val world = DAGWorld(emptyList())
@@ -60,13 +68,19 @@ class DAGWorldTest {
@Test
fun `query with multiple components returns intersection`() {
val world = DAGWorld(emptyList())
- val entity1 = world.createEntity()
- .add(Position(10f, 20f))
- .add(Velocity(1f, 2f))
- val entity2 = world.createEntity()
- .add(Position(30f, 40f))
- val entity3 = world.createEntity()
- .add(Velocity(3f, 4f))
+ val entity1 =
+ world
+ .createEntity()
+ .add(Position(10f, 20f))
+ .add(Velocity(1f, 2f))
+ val entity2 =
+ world
+ .createEntity()
+ .add(Position(30f, 40f))
+ val entity3 =
+ world
+ .createEntity()
+ .add(Velocity(3f, 4f))
world.update(0f) // Trigger cache update
@@ -80,25 +94,39 @@ class DAGWorldTest {
fun `systems execute in dependency order`() {
val executionOrder = mutableListOf<String>()
- val systemA = object : System {
- override fun update(world: World, deltaTime: Float) {
- executionOrder.add("A")
+ val systemA =
+ object : System {
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {
+ executionOrder.add("A")
+ }
}
- }
- val systemB = object : System {
- override val dependencies = setOf(systemA::class)
- override fun update(world: World, deltaTime: Float) {
- executionOrder.add("B")
+ val systemB =
+ object : System {
+ override val dependencies = setOf(systemA::class)
+
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {
+ executionOrder.add("B")
+ }
}
- }
- val systemC = object : System {
- override val dependencies = setOf(systemB::class)
- override fun update(world: World, deltaTime: Float) {
- executionOrder.add("C")
+ val systemC =
+ object : System {
+ override val dependencies = setOf(systemB::class)
+
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {
+ executionOrder.add("C")
+ }
}
- }
val world = DAGWorld(listOf(systemC, systemA, systemB))
world.update(0f)
@@ -110,17 +138,25 @@ class DAGWorldTest {
fun `systems with no dependencies can execute in any order`() {
val executionOrder = mutableListOf<String>()
- val systemA = object : System {
- override fun update(world: World, deltaTime: Float) {
- executionOrder.add("A")
+ val systemA =
+ object : System {
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {
+ executionOrder.add("A")
+ }
}
- }
- val systemB = object : System {
- override fun update(world: World, deltaTime: Float) {
- executionOrder.add("B")
+ val systemB =
+ object : System {
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {
+ executionOrder.add("B")
+ }
}
- }
val world = DAGWorld(listOf(systemA, systemB))
world.update(0f)
@@ -144,11 +180,15 @@ class DAGWorldTest {
fun `system receives correct deltaTime`() {
var receivedDelta = 0f
- val system = object : System {
- override fun update(world: World, deltaTime: Float) {
- receivedDelta = deltaTime
+ val system =
+ object : System {
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {
+ receivedDelta = deltaTime
+ }
}
- }
val world = DAGWorld(listOf(system))
world.update(0.016f)
@@ -160,11 +200,15 @@ class DAGWorldTest {
fun `systems can query entities during update`() {
var queriedEntities: Set<Entity>? = null
- val system = object : System {
- override fun update(world: World, deltaTime: Float) {
- queriedEntities = world.query<Position>()
+ val system =
+ object : System {
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {
+ queriedEntities = world.query<Position>()
+ }
}
- }
val world = DAGWorld(listOf(system))
val entity = world.createEntity().add(Position(10f, 20f))
@@ -203,32 +247,51 @@ class DAGWorldTest {
// \ /
// D
- val systemA = object : System {
- override fun update(world: World, deltaTime: Float) {
- executionOrder.add("A")
+ val systemA =
+ object : System {
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {
+ executionOrder.add("A")
+ }
}
- }
- val systemB = object : System {
- override val dependencies = setOf(systemA::class)
- override fun update(world: World, deltaTime: Float) {
- executionOrder.add("B")
+ val systemB =
+ object : System {
+ override val dependencies = setOf(systemA::class)
+
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {
+ executionOrder.add("B")
+ }
}
- }
- val systemC = object : System {
- override val dependencies = setOf(systemA::class)
- override fun update(world: World, deltaTime: Float) {
- executionOrder.add("C")
+ val systemC =
+ object : System {
+ override val dependencies = setOf(systemA::class)
+
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {
+ executionOrder.add("C")
+ }
}
- }
- val systemD = object : System {
- override val dependencies = setOf(systemB::class, systemC::class)
- override fun update(world: World, deltaTime: Float) {
- executionOrder.add("D")
+ val systemD =
+ object : System {
+ override val dependencies = setOf(systemB::class, systemC::class)
+
+ override fun update(
+ world: World,
+ deltaTime: Float,
+ ) {
+ executionOrder.add("D")
+ }
}
- }
val world = DAGWorld(listOf(systemD, systemC, systemB, systemA))
world.update(0f)
diff --git a/composeApp/src/commonTest/kotlin/coffee/liz/ecs/EntityTest.kt b/composeApp/src/commonTest/kotlin/coffee/liz/ecs/EntityTest.kt
index e807bd2..9f7a88f 100644
--- a/composeApp/src/commonTest/kotlin/coffee/liz/ecs/EntityTest.kt
+++ b/composeApp/src/commonTest/kotlin/coffee/liz/ecs/EntityTest.kt
@@ -3,12 +3,21 @@ package coffee.liz.ecs
import kotlin.test.*
// Test components
-data class Position(val x: Float, val y: Float) : Component
-data class Velocity(val dx: Float, val dy: Float) : Component
-data class Health(val value: Int) : Component
+data class Position(
+ val x: Float,
+ val y: Float,
+) : Component
-class EntityTest {
+data class Velocity(
+ val dx: Float,
+ val dy: Float,
+) : Component
+
+data class Health(
+ val value: Int,
+) : Component
+class EntityTest {
@Test
fun `entity has unique id`() {
val entity1 = Entity(1)
@@ -43,9 +52,10 @@ class EntityTest {
fun `add returns entity for chaining`() {
val entity = Entity(0)
- val result = entity
- .add(Position(10f, 20f))
- .add(Velocity(1f, 2f))
+ val result =
+ entity
+ .add(Position(10f, 20f))
+ .add(Velocity(1f, 2f))
assertSame(entity, result)
assertTrue(entity.has<Position>())
diff --git a/composeApp/src/commonTest/kotlin/coffee/liz/ecs/animation/AnimationSystemTest.kt b/composeApp/src/commonTest/kotlin/coffee/liz/ecs/animation/AnimationSystemTest.kt
index 588e245..ceaef33 100644
--- a/composeApp/src/commonTest/kotlin/coffee/liz/ecs/animation/AnimationSystemTest.kt
+++ b/composeApp/src/commonTest/kotlin/coffee/liz/ecs/animation/AnimationSystemTest.kt
@@ -4,41 +4,43 @@ import coffee.liz.ecs.DAGWorld
import kotlin.test.*
class AnimationSystemTest {
-
- private fun createTestSpriteSheet(): SpriteSheet {
- return SpriteSheet(
+ private fun createTestSpriteSheet(): SpriteSheet =
+ SpriteSheet(
imagePath = "test.png",
- frames = mapOf(
- FrameName("idle_0") to Rect(0, 0, 32, 32),
- FrameName("idle_1") to Rect(32, 0, 32, 32),
- FrameName("walk_0") to Rect(0, 32, 32, 32),
- FrameName("walk_1") to Rect(32, 32, 32, 32),
- FrameName("walk_2") to Rect(64, 32, 32, 32)
- )
+ frames =
+ mapOf(
+ FrameName("idle_0") to Rect(0, 0, 32, 32),
+ FrameName("idle_1") to Rect(32, 0, 32, 32),
+ FrameName("walk_0") to Rect(0, 32, 32, 32),
+ FrameName("walk_1") to Rect(32, 32, 32, 32),
+ FrameName("walk_2") to Rect(64, 32, 32, 32),
+ ),
)
- }
- private fun createTestAnimator(): Animator {
- return Animator(
- clips = mapOf(
- AnimationName("idle") to AnimationClip(
- frameNames = listOf(FrameName("idle_0"), FrameName("idle_1")),
- frameTicks = 0.1f,
- loopMode = LoopMode.LOOP
+ private fun createTestAnimator(): Animator =
+ Animator(
+ clips =
+ mapOf(
+ AnimationName("idle") to
+ AnimationClip(
+ frameNames = listOf(FrameName("idle_0"), FrameName("idle_1")),
+ frameTicks = 0.1f,
+ loopMode = LoopMode.LOOP,
+ ),
+ AnimationName("walk") to
+ AnimationClip(
+ frameNames =
+ listOf(
+ FrameName("walk_0"),
+ FrameName("walk_1"),
+ FrameName("walk_2"),
+ ),
+ frameTicks = 0.15f,
+ loopMode = LoopMode.LOOP,
+ ),
),
- AnimationName("walk") to AnimationClip(
- frameNames = listOf(
- FrameName("walk_0"),
- FrameName("walk_1"),
- FrameName("walk_2")
- ),
- frameTicks = 0.15f,
- loopMode = LoopMode.LOOP
- )
- ),
- currentClip = AnimationName("idle")
+ currentClip = AnimationName("idle"),
)
- }
@Test
fun `animation advances frame after frame duration`() {
@@ -83,16 +85,19 @@ class AnimationSystemTest {
fun `ONCE mode stops at last frame`() {
val world = DAGWorld(listOf(AnimationSystem()))
val entity = world.createEntity()
- val animator = Animator(
- clips = mapOf(
- AnimationName("once") to AnimationClip(
- frameNames = listOf(FrameName("idle_0"), FrameName("idle_1")),
- frameTicks = 0.1f,
- loopMode = LoopMode.ONCE
- )
- ),
- currentClip = AnimationName("once")
- )
+ val animator =
+ Animator(
+ clips =
+ mapOf(
+ AnimationName("once") to
+ AnimationClip(
+ frameNames = listOf(FrameName("idle_0"), FrameName("idle_1")),
+ frameTicks = 0.1f,
+ loopMode = LoopMode.ONCE,
+ ),
+ ),
+ currentClip = AnimationName("once"),
+ )
entity.add(createTestSpriteSheet())
entity.add(animator)
@@ -114,20 +119,24 @@ class AnimationSystemTest {
fun `PING_PONG mode bounces back and forth`() {
val world = DAGWorld(listOf(AnimationSystem()))
val entity = world.createEntity()
- val animator = Animator(
- clips = mapOf(
- AnimationName("pingpong") to AnimationClip(
- frameNames = listOf(
- FrameName("walk_0"),
- FrameName("walk_1"),
- FrameName("walk_2")
+ val animator =
+ Animator(
+ clips =
+ mapOf(
+ AnimationName("pingpong") to
+ AnimationClip(
+ frameNames =
+ listOf(
+ FrameName("walk_0"),
+ FrameName("walk_1"),
+ FrameName("walk_2"),
+ ),
+ frameTicks = 0.1f,
+ loopMode = LoopMode.PING_PONG,
+ ),
),
- frameTicks = 0.1f,
- loopMode = LoopMode.PING_PONG
- )
- ),
- currentClip = AnimationName("pingpong")
- )
+ currentClip = AnimationName("pingpong"),
+ )
entity.add(createTestSpriteSheet())
entity.add(animator)