summaryrefslogtreecommitdiff
path: root/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game
diff options
context:
space:
mode:
Diffstat (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game')
-rw-r--r--composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/AbstractionEngine.kt5
-rw-r--r--composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Game.kt37
-rw-r--r--composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Renderer.kt (renamed from composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/RenderSystem.kt)11
3 files changed, 12 insertions, 41 deletions
diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/AbstractionEngine.kt b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/AbstractionEngine.kt
new file mode 100644
index 0000000..18349c3
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/AbstractionEngine.kt
@@ -0,0 +1,5 @@
+package coffee.liz.abstractionengine.game
+
+class AbstractionEngine {
+
+} \ No newline at end of file
diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Game.kt b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Game.kt
index 9490f83..0c3a007 100644
--- a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Game.kt
+++ b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Game.kt
@@ -6,64 +6,35 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import coffee.liz.ecs.World
import kotlinx.coroutines.isActive
+import kotlin.time.Duration.Companion.nanoseconds
/**
- * Manages the game loop for an ECS world.
- * Syncs with Compose's frame rate (like requestAnimationFrame) and provides
- * the world to child content for custom rendering/UI.
- *
- * @param world The ECS world containing entities and systems
- * @param content Composable content that can use the world for rendering
+ * Manages and paints the [World].
*/
@Composable
fun Game(
world: World,
content: @Composable () -> Unit
) {
- // Trigger recomposition when we need to redraw
var frameCount by remember { mutableStateOf(0) }
- // Game loop - syncs with Compose's frame rate like requestAnimationFrame
LaunchedEffect(world) {
- var lastFrameTimeNanos = 0L
+ var lastUpdate: Long? = null
while (isActive) {
- // Wait for next frame (like requestAnimationFrame)
withFrameNanos { frameTimeNanos ->
- val deltaTime = if (lastFrameTimeNanos != 0L) {
- (frameTimeNanos - lastFrameTimeNanos) / 1_000_000_000f
- } else {
- 0f
- }
- lastFrameTimeNanos = frameTimeNanos
-
- // Update ECS world (runs all systems)
- if (deltaTime > 0f) {
- world.update(deltaTime)
- }
-
- // Trigger recomposition to redraw
frameCount++
}
}
}
- // Render content
content()
}
-/**
- * A Canvas that renders sprites from an ECS world using a RenderSystem.
- *
- * @param world The ECS world containing entities to render
- * @param renderSystem The system responsible for rendering sprites
- * @param backgroundColor Background color for the canvas
- * @param modifier Modifier for the Canvas
- */
@Composable
fun GameCanvas(
world: World,
- renderSystem: RenderSystem,
+ renderSystem: Renderer,
backgroundColor: Color = Color.Transparent,
modifier: Modifier = Modifier
) {
diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/RenderSystem.kt b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Renderer.kt
index 1d22ae6..57511f3 100644
--- a/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/RenderSystem.kt
+++ b/composeApp/src/commonMain/kotlin/coffee/liz/abstractionengine/game/Renderer.kt
@@ -1,7 +1,5 @@
package coffee.liz.abstractionengine.game
-import androidx.compose.ui.geometry.Offset
-import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
@@ -12,6 +10,7 @@ import coffee.liz.ecs.animation.Animator
import coffee.liz.ecs.animation.Position
import coffee.liz.ecs.animation.SpriteSheet
import kotlin.reflect.KClass
+import kotlin.time.Duration
/**
* System that renders sprites to a DrawScope.
@@ -21,17 +20,13 @@ import kotlin.reflect.KClass
*
* Depends on AnimationSystem to ensure animations are updated before rendering.
*/
-class RenderSystem(
+class Renderer(
private val imageCache: ImageCache
) : System {
override val dependencies: Set<KClass<out System>> = setOf(AnimationSystem::class)
- /**
- * The update method is required by the System interface, but rendering
- * happens synchronously during Compose's draw phase via the render() method.
- */
- override fun update(world: World, deltaTime: Float) {
+ override fun update(world: World, duration: Duration) {
// Rendering happens in render() method, not here
}