Add TypedFamily5
This commit is contained in:
parent
f39e271d7e
commit
c64495b4a9
|
|
@ -47,4 +47,20 @@ public extension Nexus {
|
|||
excludesAll: excludedComponents)
|
||||
}
|
||||
|
||||
// swiftlint:disable function_parameter_count
|
||||
func family<A, B, C, D, E>(requiresAll componentA: A.Type,
|
||||
_ componentB: B.Type,
|
||||
_ componentC: C.Type,
|
||||
_ componentD: D.Type,
|
||||
_ componentE: E.Type,
|
||||
excludesAll excludedComponents: Component.Type...) -> TypedFamily5<A, B, C, D, E> where A: Component, B: Component, C: Component, D: Component, E: Component {
|
||||
return TypedFamily5(self,
|
||||
requiresAll: componentA,
|
||||
componentB,
|
||||
componentC,
|
||||
componentD,
|
||||
componentE,
|
||||
excludesAll: excludedComponents)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
//
|
||||
// TypedFamily5.swift
|
||||
// FirebladeECS
|
||||
//
|
||||
// Created by Christian Treffs on 29.09.18.
|
||||
//
|
||||
|
||||
// swiftlint:disable large_tuple
|
||||
|
||||
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
|
||||
traits = FamilyTraitSet(requiresAll: [compA, compB, compC, compD, compE], excludesAll: excludesAll)
|
||||
defer {
|
||||
nexus.onFamilyInit(traits: traits)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
public struct ComponentIterator5<A, B, C, D, E>: ComponentIteratorProtocol where A: Component, B: Component, C: Component, D: Component, E: Component {
|
||||
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public let memberIds: UniformEntityIdentifiers
|
||||
public var index: Int
|
||||
|
||||
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)? {
|
||||
guard let entityId: EntityIdentifier = nextEntityId() else {
|
||||
return nil
|
||||
}
|
||||
|
||||
guard
|
||||
let compA: A = nexus?.get(for: entityId),
|
||||
let compB: B = nexus?.get(for: entityId),
|
||||
let compC: C = nexus?.get(for: entityId),
|
||||
let compD: D = nexus?.get(for: entityId),
|
||||
let compE: E = nexus?.get(for: entityId)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return (compA, compB, compC, compD, compE)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue