Fix start index for component iterators

This commit is contained in:
Christian Treffs 2018-09-29 16:07:59 +02:00
parent c64495b4a9
commit f6f8f5e5a2
6 changed files with 11 additions and 10 deletions

View File

@ -12,12 +12,18 @@ public protocol TypedFamilyProtocol: AnyObject {
var nexus: Nexus? { get }
var memberIds: UniformEntityIdentifiers { get }
var members: Members { get set }
var count: Int { get }
}
public extension TypedFamilyProtocol {
var memberIds: UniformEntityIdentifiers {
return nexus?.members(withFamilyTraits: traits) ?? UniformEntityIdentifiers()
}
var count: Int {
return memberIds.count
}
}
public protocol FamilyMembersProtocol: LazySequenceProtocol {

View File

@ -40,12 +40,11 @@ public struct ComponentIterator1<A>: ComponentIteratorProtocol where A: Componen
public private(set) weak var nexus: Nexus?
public let memberIds: UniformEntityIdentifiers
public var index: Int
public var index: Int = -1
public init(_ nexus: Nexus?, _ family: TypedFamily1<A>) {
self.nexus = nexus
memberIds = family.memberIds
index = memberIds.index(before: memberIds.startIndex)
}
public mutating func next() -> A? {

View File

@ -40,12 +40,11 @@ public struct ComponentIterator2<A, B>: ComponentIteratorProtocol where A: Compo
public private(set) weak var nexus: Nexus?
public let memberIds: UniformEntityIdentifiers
public var index: Int
public var index: Int = -1
public init(_ nexus: Nexus?, _ family: TypedFamily2<A, B>) {
self.nexus = nexus
memberIds = family.memberIds
index = memberIds.index(before: memberIds.startIndex)
}
public mutating func next() -> (A, B)? {

View File

@ -41,12 +41,11 @@ public struct ComponentIterator3<A, B, C>: ComponentIteratorProtocol where A: Co
public private(set) weak var nexus: Nexus?
public let memberIds: UniformEntityIdentifiers
public var index: Int
public var index: Int = -1
public init(_ nexus: Nexus?, _ family: TypedFamily3<A, B, C>) {
self.nexus = nexus
memberIds = family.memberIds
index = memberIds.index(before: memberIds.startIndex)
}
public mutating func next() -> (A, B, C)? {

View File

@ -41,12 +41,11 @@ public struct ComponentIterator4<A, B, C, D>: ComponentIteratorProtocol where A:
public private(set) weak var nexus: Nexus?
public let memberIds: UniformEntityIdentifiers
public var index: Int
public var index: Int = -1
public init(_ nexus: Nexus?, _ family: TypedFamily4<A, B, C, D>) {
self.nexus = nexus
memberIds = family.memberIds
index = memberIds.index(before: memberIds.startIndex)
}
public mutating func next() -> (A, B, C, D)? {

View File

@ -41,12 +41,11 @@ public struct ComponentIterator5<A, B, C, D, E>: ComponentIteratorProtocol where
public private(set) weak var nexus: Nexus?
public let memberIds: UniformEntityIdentifiers
public var index: Int
public var index: Int = -1
public init(_ nexus: Nexus?, _ family: TypedFamily5<A, B, C, D, E>) {
self.nexus = nexus
memberIds = family.memberIds
index = memberIds.index(before: memberIds.startIndex)
}
public mutating func next() -> (A, B, C, D, E)? {