diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/EntityType.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/EntityType.kt index a908c3bb..c32773ad 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/EntityType.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/EntityType.kt @@ -86,8 +86,6 @@ class EntityType private constructor( return EntityType(arr) } - //TODO intersection and union - override fun toString(): String = inner.joinToString(", ", prefix = "[", postfix = "]") { it.readableString() } } diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/QueryManager.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/QueryManager.kt index d7d73108..6bc9b426 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/QueryManager.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/QueryManager.kt @@ -9,5 +9,13 @@ interface QueryManager { fun trackEventListener(listener: Listener) fun trackQuery(query: GearyQuery) + /** Returns a list of entities matching the given family. */ fun getEntitiesMatching(family: Family): List + + /** + * Returns a sequence of entities matching the given family. + * This should be faster than [getEntitiesMatching] but will depend on impl. + * In an archetypal engine, this gets all matching archetypes first, then maps them to entities as a sequence. + */ + fun getEntitiesMatchingAsSequence(family: Family): Sequence } diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/archetypes/ArchetypeQueryManager.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/archetypes/ArchetypeQueryManager.kt index 2a525a0c..a3df536c 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/archetypes/ArchetypeQueryManager.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/archetypes/ArchetypeQueryManager.kt @@ -89,10 +89,13 @@ class ArchetypeQueryManager : QueryManager { return archetypes.match(family) } - //TODO convert to Sequence override fun getEntitiesMatching(family: Family): List { - return getArchetypesMatching(family).flatMap { arc -> - arc.entities - } + return getArchetypesMatching(family).flatMap(Archetype::entities) + } + + override fun getEntitiesMatchingAsSequence(family: Family): Sequence { + return getArchetypesMatching(family) + .asSequence() + .flatMap(Archetype::entities) } }