Make TypedFamilies structs and nexus reference non weak
This commit is contained in:
parent
cb248d87cf
commit
32bf1c3caf
|
|
@ -10,11 +10,11 @@
|
|||
// * define read/write access
|
||||
// * set size and storage constraints
|
||||
|
||||
public protocol TypedFamilyProtocol: class, Equatable, Sequence {
|
||||
public protocol TypedFamilyProtocol: Equatable, Sequence {
|
||||
associatedtype EntityComponentsSequence: EntityComponentsSequenceProtocol
|
||||
|
||||
var traits: FamilyTraitSet { get }
|
||||
var nexus: Nexus? { get }
|
||||
var nexus: Nexus { get }
|
||||
|
||||
var count: Int { get }
|
||||
|
||||
|
|
@ -28,15 +28,15 @@ public protocol TypedFamilyProtocol: class, Equatable, Sequence {
|
|||
|
||||
public extension TypedFamilyProtocol {
|
||||
func canBecomeMember(_ entity: Entity) -> Bool {
|
||||
return nexus?.canBecomeMember(entity, in: traits) ?? false
|
||||
return nexus.canBecomeMember(entity, in: traits)
|
||||
}
|
||||
|
||||
func isMember(_ entity: Entity) -> Bool {
|
||||
return nexus?.isMember(entity, in: traits) ?? false
|
||||
return nexus.isMember(entity, in: traits)
|
||||
}
|
||||
|
||||
var memberIds: UniformEntityIdentifiers {
|
||||
return nexus?.members(withFamilyTraits: traits) ?? UniformEntityIdentifiers()
|
||||
return nexus.members(withFamilyTraits: traits) ?? UniformEntityIdentifiers()
|
||||
}
|
||||
|
||||
var count: Int {
|
||||
|
|
@ -56,25 +56,24 @@ public protocol ComponentIteratorProtocol: IteratorProtocol {
|
|||
associatedtype TypedFamily: TypedFamilyProtocol
|
||||
|
||||
var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier> { get }
|
||||
var nexus: Nexus? { get }
|
||||
var nexus: Nexus { get }
|
||||
|
||||
init(_ nexus: Nexus?, _ family: TypedFamily)
|
||||
init(_ nexus: Nexus, _ family: TypedFamily)
|
||||
}
|
||||
|
||||
public protocol EntityComponentsSequenceProtocol: LazySequenceProtocol, IteratorProtocol {
|
||||
associatedtype TypedFamily: TypedFamilyProtocol
|
||||
|
||||
var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier> { get }
|
||||
var nexus: Nexus? { get }
|
||||
|
||||
init(_ nexus: Nexus?, _ family: TypedFamily)
|
||||
init(_ nexus: Nexus, _ family: TypedFamily)
|
||||
}
|
||||
|
||||
public struct FamilyEntities: LazySequenceProtocol, IteratorProtocol {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public let nexus: Nexus
|
||||
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
|
||||
|
||||
public init(_ nexus: Nexus?, _ memberIds: UniformEntityIdentifiers) {
|
||||
public init(_ nexus: Nexus, _ memberIds: UniformEntityIdentifiers) {
|
||||
self.nexus = nexus
|
||||
memberIdsIterator = memberIds.makeIterator()
|
||||
}
|
||||
|
|
@ -84,6 +83,6 @@ public struct FamilyEntities: LazySequenceProtocol, IteratorProtocol {
|
|||
return nil
|
||||
}
|
||||
|
||||
return nexus?.get(entity: entityId)
|
||||
return nexus.get(entity: entityId)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
// Created by Christian Treffs on 29.09.18.
|
||||
//
|
||||
|
||||
public final class TypedFamily1<A>: TypedFamilyProtocol where A: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public struct TypedFamily1<A>: TypedFamilyProtocol where A: Component {
|
||||
public let nexus: Nexus
|
||||
public let traits: FamilyTraitSet
|
||||
|
||||
public init(_ nexus: Nexus, requiresAll compA: A.Type, excludesAll: [Component.Type]) {
|
||||
|
|
@ -25,10 +25,10 @@ public final class TypedFamily1<A>: TypedFamilyProtocol where A: Component {
|
|||
}
|
||||
|
||||
public struct ComponentIterator1<A>: ComponentIteratorProtocol where A: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public let nexus: Nexus
|
||||
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
|
||||
|
||||
public init(_ nexus: Nexus?, _ family: TypedFamily1<A>) {
|
||||
public init(_ nexus: Nexus, _ family: TypedFamily1<A>) {
|
||||
self.nexus = nexus
|
||||
memberIdsIterator = family.memberIds.makeIterator()
|
||||
}
|
||||
|
|
@ -38,15 +38,15 @@ public struct ComponentIterator1<A>: ComponentIteratorProtocol where A: Componen
|
|||
return nil
|
||||
}
|
||||
|
||||
return nexus?.get(for: entityId)
|
||||
return nexus.get(for: entityId)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FamilyEntitiesAndComponents1<A>: EntityComponentsSequenceProtocol where A: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public let nexus: Nexus
|
||||
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
|
||||
|
||||
public init(_ nexus: Nexus?, _ family: TypedFamily1<A>) {
|
||||
public init(_ nexus: Nexus, _ family: TypedFamily1<A>) {
|
||||
self.nexus = nexus
|
||||
memberIdsIterator = family.memberIds.makeIterator()
|
||||
}
|
||||
|
|
@ -57,8 +57,8 @@ public struct FamilyEntitiesAndComponents1<A>: EntityComponentsSequenceProtocol
|
|||
}
|
||||
|
||||
guard
|
||||
let entity = nexus?.get(entity: entityId),
|
||||
let compA: A = nexus?.get(for: entityId)
|
||||
let entity = nexus.get(entity: entityId),
|
||||
let compA: A = nexus.get(for: entityId)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
// swiftlint:disable large_tuple
|
||||
|
||||
public final class TypedFamily2<A, B>: TypedFamilyProtocol where A: Component, B: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public struct TypedFamily2<A, B>: TypedFamilyProtocol where A: Component, B: Component {
|
||||
public let nexus: Nexus
|
||||
public let traits: FamilyTraitSet
|
||||
|
||||
public init(_ nexus: Nexus, requiresAll compA: A.Type, _ compB: B.Type, excludesAll: [Component.Type]) {
|
||||
|
|
@ -27,10 +27,10 @@ public final class TypedFamily2<A, B>: TypedFamilyProtocol where A: Component, B
|
|||
}
|
||||
|
||||
public struct ComponentIterator2<A, B>: ComponentIteratorProtocol where A: Component, B: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public let nexus: Nexus
|
||||
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
|
||||
|
||||
public init(_ nexus: Nexus?, _ family: TypedFamily2<A, B>) {
|
||||
public init(_ nexus: Nexus, _ family: TypedFamily2<A, B>) {
|
||||
self.nexus = nexus
|
||||
memberIdsIterator = family.memberIds.makeIterator()
|
||||
}
|
||||
|
|
@ -41,8 +41,8 @@ public struct ComponentIterator2<A, B>: ComponentIteratorProtocol where A: Compo
|
|||
}
|
||||
|
||||
guard
|
||||
let compA: A = nexus?.get(for: entityId),
|
||||
let compB: B = nexus?.get(for: entityId)
|
||||
let compA: A = nexus.get(for: entityId),
|
||||
let compB: B = nexus.get(for: entityId)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -52,10 +52,10 @@ public struct ComponentIterator2<A, B>: ComponentIteratorProtocol where A: Compo
|
|||
}
|
||||
|
||||
public struct FamilyEntitiesAndComponents2<A, B>: EntityComponentsSequenceProtocol where A: Component, B: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public let nexus: Nexus
|
||||
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
|
||||
|
||||
public init(_ nexus: Nexus?, _ family: TypedFamily2<A, B>) {
|
||||
public init(_ nexus: Nexus, _ family: TypedFamily2<A, B>) {
|
||||
self.nexus = nexus
|
||||
memberIdsIterator = family.memberIds.makeIterator()
|
||||
}
|
||||
|
|
@ -66,9 +66,9 @@ public struct FamilyEntitiesAndComponents2<A, B>: EntityComponentsSequenceProtoc
|
|||
}
|
||||
|
||||
guard
|
||||
let entity = nexus?.get(entity: entityId),
|
||||
let compA: A = nexus?.get(for: entityId),
|
||||
let compB: B = nexus?.get(for: entityId)
|
||||
let entity = nexus.get(entity: entityId),
|
||||
let compA: A = nexus.get(for: entityId),
|
||||
let compB: B = nexus.get(for: entityId)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
// swiftlint:disable large_tuple
|
||||
|
||||
public final class TypedFamily3<A, B, C>: TypedFamilyProtocol where A: Component, B: Component, C: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public struct TypedFamily3<A, B, C>: TypedFamilyProtocol where A: Component, B: Component, C: Component {
|
||||
public let nexus: Nexus
|
||||
public let traits: FamilyTraitSet
|
||||
|
||||
public init(_ nexus: Nexus, requiresAll compA: A.Type, _ compB: B.Type, _ compC: C.Type, excludesAll: [Component.Type]) {
|
||||
|
|
@ -27,10 +27,10 @@ public final class TypedFamily3<A, B, C>: TypedFamilyProtocol where A: Component
|
|||
}
|
||||
|
||||
public struct ComponentIterator3<A, B, C>: ComponentIteratorProtocol where A: Component, B: Component, C: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public let nexus: Nexus
|
||||
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
|
||||
|
||||
public init(_ nexus: Nexus?, _ family: TypedFamily3<A, B, C>) {
|
||||
public init(_ nexus: Nexus, _ family: TypedFamily3<A, B, C>) {
|
||||
self.nexus = nexus
|
||||
memberIdsIterator = family.memberIds.makeIterator()
|
||||
}
|
||||
|
|
@ -41,9 +41,9 @@ public struct ComponentIterator3<A, B, C>: ComponentIteratorProtocol where A: Co
|
|||
}
|
||||
|
||||
guard
|
||||
let compA: A = nexus?.get(for: entityId),
|
||||
let compB: B = nexus?.get(for: entityId),
|
||||
let compC: C = nexus?.get(for: entityId)
|
||||
let compA: A = nexus.get(for: entityId),
|
||||
let compB: B = nexus.get(for: entityId),
|
||||
let compC: C = nexus.get(for: entityId)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -53,10 +53,10 @@ public struct ComponentIterator3<A, B, C>: ComponentIteratorProtocol where A: Co
|
|||
}
|
||||
|
||||
public struct FamilyEntitiesAndComponents3<A, B, C>: EntityComponentsSequenceProtocol where A: Component, B: Component, C: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public let nexus: Nexus
|
||||
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
|
||||
|
||||
public init(_ nexus: Nexus?, _ family: TypedFamily3<A, B, C>) {
|
||||
public init(_ nexus: Nexus, _ family: TypedFamily3<A, B, C>) {
|
||||
self.nexus = nexus
|
||||
memberIdsIterator = family.memberIds.makeIterator()
|
||||
}
|
||||
|
|
@ -67,10 +67,10 @@ public struct FamilyEntitiesAndComponents3<A, B, C>: EntityComponentsSequencePro
|
|||
}
|
||||
|
||||
guard
|
||||
let entity = nexus?.get(entity: entityId),
|
||||
let compA: A = nexus?.get(for: entityId),
|
||||
let compB: B = nexus?.get(for: entityId),
|
||||
let compC: C = nexus?.get(for: entityId)
|
||||
let entity = nexus.get(entity: entityId),
|
||||
let compA: A = nexus.get(for: entityId),
|
||||
let compB: B = nexus.get(for: entityId),
|
||||
let compC: C = nexus.get(for: entityId)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
// swiftlint:disable large_tuple
|
||||
|
||||
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 struct TypedFamily4<A, B, C, D>: TypedFamilyProtocol where A: Component, B: Component, C: Component, D: Component {
|
||||
public let nexus: Nexus
|
||||
public let traits: FamilyTraitSet
|
||||
|
||||
public init(_ nexus: Nexus, requiresAll compA: A.Type, _ compB: B.Type, _ compC: C.Type, _ compD: D.Type, excludesAll: [Component.Type]) {
|
||||
|
|
@ -27,10 +27,10 @@ public final class TypedFamily4<A, B, C, D>: TypedFamilyProtocol where A: Compon
|
|||
}
|
||||
|
||||
public struct ComponentIterator4<A, B, C, D>: ComponentIteratorProtocol where A: Component, B: Component, C: Component, D: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public let nexus: Nexus
|
||||
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
|
||||
|
||||
public init(_ nexus: Nexus?, _ family: TypedFamily4<A, B, C, D>) {
|
||||
public init(_ nexus: Nexus, _ family: TypedFamily4<A, B, C, D>) {
|
||||
self.nexus = nexus
|
||||
memberIdsIterator = family.memberIds.makeIterator()
|
||||
}
|
||||
|
|
@ -41,10 +41,10 @@ public struct ComponentIterator4<A, B, C, D>: ComponentIteratorProtocol where A:
|
|||
}
|
||||
|
||||
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 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)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -54,10 +54,10 @@ public struct ComponentIterator4<A, B, C, D>: ComponentIteratorProtocol where A:
|
|||
}
|
||||
|
||||
public struct FamilyEntitiesAndComponents4<A, B, C, D>: EntityComponentsSequenceProtocol where A: Component, B: Component, C: Component, D: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public let nexus: Nexus
|
||||
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
|
||||
|
||||
public init(_ nexus: Nexus?, _ family: TypedFamily4<A, B, C, D>) {
|
||||
public init(_ nexus: Nexus, _ family: TypedFamily4<A, B, C, D>) {
|
||||
self.nexus = nexus
|
||||
memberIdsIterator = family.memberIds.makeIterator()
|
||||
}
|
||||
|
|
@ -68,11 +68,11 @@ public struct FamilyEntitiesAndComponents4<A, B, C, D>: EntityComponentsSequence
|
|||
}
|
||||
|
||||
guard
|
||||
let entity = nexus?.get(entity: entityId),
|
||||
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 entity = nexus.get(entity: entityId),
|
||||
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)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
// 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 struct TypedFamily5<A, B, C, D, E>: TypedFamilyProtocol where A: Component, B: Component, C: Component, D: Component, E: Component {
|
||||
public let nexus: Nexus
|
||||
public let traits: FamilyTraitSet
|
||||
|
||||
public init(_ nexus: Nexus, requiresAll compA: A.Type, _ compB: B.Type, _ compC: C.Type, _ compD: D.Type, _ compE: E.Type, excludesAll: [Component.Type]) {
|
||||
|
|
@ -27,10 +27,10 @@ public final class TypedFamily5<A, B, C, D, E>: TypedFamilyProtocol where A: Com
|
|||
}
|
||||
|
||||
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 nexus: Nexus
|
||||
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
|
||||
|
||||
public init(_ nexus: Nexus?, _ family: TypedFamily5<A, B, C, D, E>) {
|
||||
public init(_ nexus: Nexus, _ family: TypedFamily5<A, B, C, D, E>) {
|
||||
self.nexus = nexus
|
||||
memberIdsIterator = family.memberIds.makeIterator()
|
||||
}
|
||||
|
|
@ -41,11 +41,11 @@ public struct ComponentIterator5<A, B, C, D, E>: ComponentIteratorProtocol where
|
|||
}
|
||||
|
||||
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)
|
||||
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
|
||||
}
|
||||
|
|
@ -55,10 +55,10 @@ public struct ComponentIterator5<A, B, C, D, E>: ComponentIteratorProtocol where
|
|||
}
|
||||
|
||||
public struct FamilyEntitiesAndComponents5<A, B, C, D, E>: EntityComponentsSequenceProtocol where A: Component, B: Component, C: Component, D: Component, E: Component {
|
||||
public private(set) weak var nexus: Nexus?
|
||||
public let nexus: Nexus
|
||||
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
|
||||
|
||||
public init(_ nexus: Nexus?, _ family: TypedFamily5<A, B, C, D, E>) {
|
||||
public init(_ nexus: Nexus, _ family: TypedFamily5<A, B, C, D, E>) {
|
||||
self.nexus = nexus
|
||||
memberIdsIterator = family.memberIds.makeIterator()
|
||||
}
|
||||
|
|
@ -69,12 +69,12 @@ public struct FamilyEntitiesAndComponents5<A, B, C, D, E>: EntityComponentsSeque
|
|||
}
|
||||
|
||||
guard
|
||||
let entity = nexus?.get(entity: entityId),
|
||||
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)
|
||||
let entity = nexus.get(entity: entityId),
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue