Remove FamilyMembers sequence since its unnecessary overhead

This commit is contained in:
Christian Treffs 2018-09-29 16:45:01 +02:00
parent 7f9ab6dcac
commit f034cdd178
7 changed files with 17 additions and 89 deletions

View File

@ -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

View File

@ -9,7 +9,6 @@ public final class TypedFamily1<A>: TypedFamilyProtocol where A: Component {
public private(set) weak var nexus: Nexus?
public let traits: FamilyTraitSet
public lazy var members: FamilyMembers1<A> = 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<A>: TypedFamilyProtocol where A: Component {
}
}
}
public struct FamilyMembers1<A>: FamilyMembersProtocol where A: Component {
public private(set) weak var nexus: Nexus?
public let family: TypedFamily1<A>
public init(_ nexus: Nexus?, _ family: TypedFamily1<A>) {
self.nexus = nexus
self.family = family
}
public func makeIterator() -> ComponentIterator1<A> {
return ComponentIterator1(nexus, family)
return ComponentIterator1(nexus, self)
}
}
public struct ComponentIterator1<A>: ComponentIteratorProtocol where A: Component {

View File

@ -9,7 +9,6 @@ public final class TypedFamily2<A, B>: TypedFamilyProtocol where A: Component, B
public private(set) weak var nexus: Nexus?
public let traits: FamilyTraitSet
public lazy var members: FamilyMembers2<A, B> = 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<A, B>: TypedFamilyProtocol where A: Component, B
}
}
}
public struct FamilyMembers2<A, B>: FamilyMembersProtocol where A: Component, B: Component {
public private(set) weak var nexus: Nexus?
public let family: TypedFamily2<A, B>
public init(_ nexus: Nexus?, _ family: TypedFamily2<A, B>) {
self.nexus = nexus
self.family = family
}
public func makeIterator() -> ComponentIterator2<A, B> {
return ComponentIterator2(nexus, family)
return ComponentIterator2(nexus, self)
}
}
public struct ComponentIterator2<A, B>: ComponentIteratorProtocol where A: Component, B: Component {

View File

@ -10,7 +10,6 @@
public final class TypedFamily3<A, B, C>: TypedFamilyProtocol where A: Component, B: Component, C: Component {
public private(set) weak var nexus: Nexus?
public let traits: FamilyTraitSet
public lazy var members: FamilyMembers3<A, B, C> = 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<A, B, C>: TypedFamilyProtocol where A: Component
}
}
}
public struct FamilyMembers3<A, B, C>: FamilyMembersProtocol where A: Component, B: Component, C: Component {
public private(set) weak var nexus: Nexus?
public let family: TypedFamily3<A, B, C>
public init(_ nexus: Nexus?, _ family: TypedFamily3<A, B, C>) {
self.nexus = nexus
self.family = family
}
public func makeIterator() -> ComponentIterator3<A, B, C> {
return ComponentIterator3(nexus, family)
return ComponentIterator3(nexus, self)
}
}
public struct ComponentIterator3<A, B, C>: ComponentIteratorProtocol where A: Component, B: Component, C: Component {
@ -57,7 +45,7 @@ public struct ComponentIterator3<A, B, C>: 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)

View File

@ -10,7 +10,6 @@
public final class TypedFamily4<A, B, C, D>: 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<A, B, C, D> = 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<A, B, C, D>: TypedFamilyProtocol where A: Compon
}
}
}
public struct FamilyMembers4<A, B, C, D>: FamilyMembersProtocol where A: Component, B: Component, C: Component, D: Component {
public private(set) weak var nexus: Nexus?
public let family: TypedFamily4<A, B, C, D>
public init(_ nexus: Nexus?, _ family: TypedFamily4<A, B, C, D>) {
self.nexus = nexus
self.family = family
}
public func makeIterator() -> ComponentIterator4<A, B, C, D> {
return ComponentIterator4(nexus, family)
return ComponentIterator4(nexus, self)
}
}
public struct ComponentIterator4<A, B, C, D>: ComponentIteratorProtocol where A: Component, B: Component, C: Component, D: Component {

View File

@ -10,7 +10,6 @@
public final class TypedFamily5<A, B, C, D, E>: 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<A, B, C, D, E> = 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<A, B, C, D, E>: TypedFamilyProtocol where A: Com
}
}
}
public struct FamilyMembers5<A, B, C, D, E>: FamilyMembersProtocol where A: Component, B: Component, C: Component, D: Component, E: Component {
public private(set) weak var nexus: Nexus?
public let family: TypedFamily5<A, B, C, D, E>
public init(_ nexus: Nexus?, _ family: TypedFamily5<A, B, C, D, E>) {
self.nexus = nexus
self.family = family
}
public func makeIterator() -> ComponentIterator5<A, B, C, D, E> {
return ComponentIterator5(nexus, family)
return ComponentIterator5(nexus, self)
}
}
public struct ComponentIterator5<A, B, C, D, E>: ComponentIteratorProtocol where A: Component, B: Component, C: Component, D: Component, E: Component {

View File

@ -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