Add EntitiesIterator
This commit is contained in:
parent
d8ce40b9c3
commit
6779af105e
|
|
@ -67,3 +67,26 @@ extension Nexus {
|
||||||
return true
|
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 { }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue