diff options
Diffstat (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/ecs/World.kt')
| -rw-r--r-- | composeApp/src/commonMain/kotlin/coffee/liz/ecs/World.kt | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/World.kt b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/World.kt new file mode 100644 index 0000000..fd3b6df --- /dev/null +++ b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/World.kt @@ -0,0 +1,42 @@ +package coffee.liz.ecs + +import kotlin.jvm.JvmName +import kotlin.reflect.KClass + +/** + * The World manages entities and systems. + */ +interface World { + /** + * Create a new entity with a unique ID. + */ + fun createEntity(): Entity + + /** + * Destroy an entity and remove it from all caches. + */ + fun destroyEntity(entity: Entity) + + /** + * Get all entities that have all the specified component types. + */ + fun query(vararg componentTypes: KClass<out Component>): Set<Entity> + + /** + * Update all systems in dependency order. + * @param deltaTime Time elapsed since last update in seconds + */ + fun update(deltaTime: Float) +} + +// Convenience extension for queries +@JvmName("query1") +inline fun <reified T : Component> World.query(): Set<Entity> = query(T::class) + +@JvmName("query2") +inline fun <reified T1 : Component, reified T2 : Component> World.query(): Set<Entity> = + query(T1::class, T2::class) + +@JvmName("query3") +inline fun <reified T1 : Component, reified T2 : Component, reified T3 : Component> World.query(): Set<Entity> = + query(T1::class, T2::class, T3::class) |
