Skip to content

Commit

Permalink
Chore: Some todos about matching entities as sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Feb 13, 2024
1 parent 2ebf97f commit 1b0f53e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity>

/**
* 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<Entity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ class ArchetypeQueryManager : QueryManager {
return archetypes.match(family)
}

//TODO convert to Sequence
override fun getEntitiesMatching(family: Family): List<Entity> {
return getArchetypesMatching(family).flatMap { arc ->
arc.entities
}
return getArchetypesMatching(family).flatMap(Archetype::entities)
}

override fun getEntitiesMatchingAsSequence(family: Family): Sequence<Entity> {
return getArchetypesMatching(family)
.asSequence()
.flatMap(Archetype::entities)
}
}

0 comments on commit 1b0f53e

Please sign in to comment.