Add EntitiesIterator

This commit is contained in:
Christian Treffs 2020-10-15 22:10:21 +02:00
parent d8ce40b9c3
commit 6779af105e
No known key found for this signature in database
GPG Key ID: 49A4B4B460BE3ED4
1 changed files with 23 additions and 0 deletions

View File

@ -67,3 +67,26 @@ extension Nexus {
return true
}
}
// MARK: - entities iterator
extension Nexus {
public struct EntitiesIterator: IteratorProtocol {
private var iterator: AnyIterator<Entity>
@usableFromInline
init(nexus: Nexus) {
var iter = nexus.componentIdsByEntity.keys.makeIterator()
iterator = AnyIterator {
guard let entityId = iter.next() else {
return nil
}
return Entity(nexus: nexus, id: entityId)
}
}
public func next() -> Entity? {
iterator.next()
}
}
}
extension Nexus.EntitiesIterator: Sequence { }