diff --git a/Sources/FirebladeECS/TypedFamily.swift b/Sources/FirebladeECS/TypedFamily.swift index 5cdfe85..4943d1a 100644 --- a/Sources/FirebladeECS/TypedFamily.swift +++ b/Sources/FirebladeECS/TypedFamily.swift @@ -5,13 +5,10 @@ // Created by Christian Treffs on 29.09.18. // -public protocol TypedFamilyProtocol: AnyObject { - associatedtype Members: FamilyMembersProtocol +public protocol TypedFamilyProtocol: AnyObject, LazySequenceProtocol { var traits: FamilyTraitSet { get } var nexus: Nexus? { get } - var memberIds: UniformEntityIdentifiers { get } - var members: Members { get set } var count: Int { get } } @@ -26,15 +23,6 @@ public extension TypedFamilyProtocol { } } -public protocol FamilyMembersProtocol: LazySequenceProtocol { - associatedtype TypedFamily: TypedFamilyProtocol - - var nexus: Nexus? { get } - var family: TypedFamily { get } - - init(_ nexus: Nexus?, _ family: TypedFamily) -} - public protocol ComponentIteratorProtocol: IteratorProtocol { associatedtype TypedFamily: TypedFamilyProtocol diff --git a/Sources/FirebladeECS/TypedFamily1.swift b/Sources/FirebladeECS/TypedFamily1.swift index 2e43ca7..762e967 100644 --- a/Sources/FirebladeECS/TypedFamily1.swift +++ b/Sources/FirebladeECS/TypedFamily1.swift @@ -9,7 +9,6 @@ public final class TypedFamily1: TypedFamilyProtocol where A: Component { public private(set) weak var nexus: Nexus? public let traits: FamilyTraitSet - public lazy var members: FamilyMembers1 = FamilyMembers1(nexus, self) public init(_ nexus: Nexus, requiresAll compA: A.Type, excludesAll: [Component.Type]) { self.nexus = nexus @@ -19,21 +18,10 @@ public final class TypedFamily1: TypedFamilyProtocol where A: Component { } } -} - -public struct FamilyMembers1: FamilyMembersProtocol where A: Component { - - public private(set) weak var nexus: Nexus? - public let family: TypedFamily1 - - public init(_ nexus: Nexus?, _ family: TypedFamily1) { - self.nexus = nexus - self.family = family - } - public func makeIterator() -> ComponentIterator1 { - return ComponentIterator1(nexus, family) + return ComponentIterator1(nexus, self) } + } public struct ComponentIterator1: ComponentIteratorProtocol where A: Component { diff --git a/Sources/FirebladeECS/TypedFamily2.swift b/Sources/FirebladeECS/TypedFamily2.swift index f7c3bf4..3d41abf 100644 --- a/Sources/FirebladeECS/TypedFamily2.swift +++ b/Sources/FirebladeECS/TypedFamily2.swift @@ -9,7 +9,6 @@ public final class TypedFamily2: TypedFamilyProtocol where A: Component, B public private(set) weak var nexus: Nexus? public let traits: FamilyTraitSet - public lazy var members: FamilyMembers2 = FamilyMembers2(nexus, self) public init(_ nexus: Nexus, requiresAll compA: A.Type, _ compB: B.Type, excludesAll: [Component.Type]) { self.nexus = nexus @@ -19,21 +18,10 @@ public final class TypedFamily2: TypedFamilyProtocol where A: Component, B } } -} - -public struct FamilyMembers2: FamilyMembersProtocol where A: Component, B: Component { - - public private(set) weak var nexus: Nexus? - public let family: TypedFamily2 - - public init(_ nexus: Nexus?, _ family: TypedFamily2) { - self.nexus = nexus - self.family = family - } - public func makeIterator() -> ComponentIterator2 { - return ComponentIterator2(nexus, family) + return ComponentIterator2(nexus, self) } + } public struct ComponentIterator2: ComponentIteratorProtocol where A: Component, B: Component { diff --git a/Sources/FirebladeECS/TypedFamily3.swift b/Sources/FirebladeECS/TypedFamily3.swift index 7488b95..dd69203 100644 --- a/Sources/FirebladeECS/TypedFamily3.swift +++ b/Sources/FirebladeECS/TypedFamily3.swift @@ -10,7 +10,6 @@ public final class TypedFamily3: TypedFamilyProtocol where A: Component, B: Component, C: Component { public private(set) weak var nexus: Nexus? public let traits: FamilyTraitSet - public lazy var members: FamilyMembers3 = FamilyMembers3(nexus, self) public init(_ nexus: Nexus, requiresAll compA: A.Type, _ compB: B.Type, _ compC: C.Type, excludesAll: [Component.Type]) { self.nexus = nexus @@ -20,21 +19,10 @@ public final class TypedFamily3: TypedFamilyProtocol where A: Component } } -} - -public struct FamilyMembers3: FamilyMembersProtocol where A: Component, B: Component, C: Component { - - public private(set) weak var nexus: Nexus? - public let family: TypedFamily3 - - public init(_ nexus: Nexus?, _ family: TypedFamily3) { - self.nexus = nexus - self.family = family - } - public func makeIterator() -> ComponentIterator3 { - return ComponentIterator3(nexus, family) + return ComponentIterator3(nexus, self) } + } public struct ComponentIterator3: ComponentIteratorProtocol where A: Component, B: Component, C: Component { @@ -57,7 +45,7 @@ public struct ComponentIterator3: ComponentIteratorProtocol where A: Co let compB: B = nexus?.get(for: entityId), let compC: C = nexus?.get(for: entityId) else { - return nil + return nil } return (compA, compB, compC) diff --git a/Sources/FirebladeECS/TypedFamily4.swift b/Sources/FirebladeECS/TypedFamily4.swift index 613cb60..beabfb5 100644 --- a/Sources/FirebladeECS/TypedFamily4.swift +++ b/Sources/FirebladeECS/TypedFamily4.swift @@ -10,7 +10,6 @@ public final class TypedFamily4: TypedFamilyProtocol where A: Component, B: Component, C: Component, D: Component { public private(set) weak var nexus: Nexus? public let traits: FamilyTraitSet - public lazy var members: FamilyMembers4 = FamilyMembers4(nexus, self) public init(_ nexus: Nexus, requiresAll compA: A.Type, _ compB: B.Type, _ compC: C.Type, _ compD: D.Type, excludesAll: [Component.Type]) { self.nexus = nexus @@ -20,21 +19,10 @@ public final class TypedFamily4: TypedFamilyProtocol where A: Compon } } -} - -public struct FamilyMembers4: FamilyMembersProtocol where A: Component, B: Component, C: Component, D: Component { - - public private(set) weak var nexus: Nexus? - public let family: TypedFamily4 - - public init(_ nexus: Nexus?, _ family: TypedFamily4) { - self.nexus = nexus - self.family = family - } - public func makeIterator() -> ComponentIterator4 { - return ComponentIterator4(nexus, family) + return ComponentIterator4(nexus, self) } + } public struct ComponentIterator4: ComponentIteratorProtocol where A: Component, B: Component, C: Component, D: Component { diff --git a/Sources/FirebladeECS/TypedFamily5.swift b/Sources/FirebladeECS/TypedFamily5.swift index df077a0..0aaa191 100644 --- a/Sources/FirebladeECS/TypedFamily5.swift +++ b/Sources/FirebladeECS/TypedFamily5.swift @@ -10,7 +10,6 @@ public final class TypedFamily5: TypedFamilyProtocol where A: Component, B: Component, C: Component, D: Component, E: Component { public private(set) weak var nexus: Nexus? public let traits: FamilyTraitSet - public lazy var members: FamilyMembers5 = FamilyMembers5(nexus, self) public init(_ nexus: Nexus, requiresAll compA: A.Type, _ compB: B.Type, _ compC: C.Type, _ compD: D.Type, _ compE: E.Type, excludesAll: [Component.Type]) { self.nexus = nexus @@ -20,21 +19,10 @@ public final class TypedFamily5: TypedFamilyProtocol where A: Com } } -} - -public struct FamilyMembers5: FamilyMembersProtocol where A: Component, B: Component, C: Component, D: Component, E: Component { - - public private(set) weak var nexus: Nexus? - public let family: TypedFamily5 - - public init(_ nexus: Nexus?, _ family: TypedFamily5) { - self.nexus = nexus - self.family = family - } - public func makeIterator() -> ComponentIterator5 { - return ComponentIterator5(nexus, family) + return ComponentIterator5(nexus, self) } + } public struct ComponentIterator5: ComponentIteratorProtocol where A: Component, B: Component, C: Component, D: Component, E: Component { diff --git a/Tests/FirebladeECSTests/TypedFamilyPerformanceTests.swift b/Tests/FirebladeECSTests/TypedFamilyPerformanceTests.swift index bf42a57..d59c810 100644 --- a/Tests/FirebladeECSTests/TypedFamilyPerformanceTests.swift +++ b/Tests/FirebladeECSTests/TypedFamilyPerformanceTests.swift @@ -40,7 +40,7 @@ class TypedFamilyPerformanceTests: XCTestCase { var loopCount: Int = 0 measure { - family.members.forEach { (position: Position) in + family.forEach { (position: Position) in _ = position loopCount += 1 @@ -59,7 +59,7 @@ class TypedFamilyPerformanceTests: XCTestCase { var loopCount: Int = 0 measure { - family.members.forEach { (position: Position, velocity: Velocity) in + family.forEach { (position: Position, velocity: Velocity) in _ = position _ = velocity @@ -79,7 +79,7 @@ class TypedFamilyPerformanceTests: XCTestCase { var loopCount: Int = 0 measure { - family.members.forEach { (position: Position, velocity: Velocity, name: Name) in + family.forEach { (position: Position, velocity: Velocity, name: Name) in _ = position _ = velocity _ = name @@ -100,7 +100,7 @@ class TypedFamilyPerformanceTests: XCTestCase { var loopCount: Int = 0 measure { - family.members.forEach { (position: Position, velocity: Velocity, name: Name, color: Color) in + family.forEach { (position: Position, velocity: Velocity, name: Name, color: Color) in _ = position _ = velocity _ = name @@ -122,7 +122,7 @@ class TypedFamilyPerformanceTests: XCTestCase { var loopCount: Int = 0 measure { - family.members.forEach { (position: Position, velocity: Velocity, name: Name, color: Color, empty: EmptyComponent) in + family.forEach { (position: Position, velocity: Velocity, name: Name, color: Color, empty: EmptyComponent) in _ = position _ = velocity _ = name