Swiftlint autocorrect

This commit is contained in:
Christian Treffs 2018-12-24 12:41:08 +01:00
parent 7b9542179b
commit a0b541f351
17 changed files with 2 additions and 46 deletions

View File

@ -6,7 +6,6 @@
//
public extension Entity {
final func get<C>() -> C? where C: Component {
return nexus.get(for: identifier)
}

View File

@ -31,7 +31,6 @@ public extension Entity {
// MARK: - has component(s)
public extension Entity {
final func has<C>(_ type: C.Type) -> Bool where C: Component {
return has(type.identifier)
}
@ -43,12 +42,10 @@ public extension Entity {
final var hasComponents: Bool {
return nexus.count(components: identifier) > 0
}
}
// MARK: - add component(s)
public extension Entity {
@discardableResult
final func assign(_ components: Component...) -> Entity {
for component: Component in components {
@ -82,7 +79,6 @@ public extension Entity {
// MARK: - remove component(s)
public extension Entity {
@discardableResult
final func remove<C>(_ component: C) -> Entity where C: Component {
return remove(component.identifier)

View File

@ -6,7 +6,6 @@
//
public struct FamilyTraitSet: CustomStringConvertible, CustomDebugStringConvertible {
public let requiresAll: ComponentSet
public let excludesAll: ComponentSet
public let needsAtLeastOne: ComponentSet
@ -15,7 +14,6 @@ public struct FamilyTraitSet: CustomStringConvertible, CustomDebugStringConverti
private let stringRespresentation: String
public init(requiresAll: [Component.Type], excludesAll: [Component.Type], needsAtLeastOne: [Component.Type] = []) {
let all = ComponentSet(requiresAll.map { $0.identifier })
let none = ComponentSet(excludesAll.map { $0.identifier })
let one = ComponentSet(needsAtLeastOne.map { $0.identifier })
@ -77,7 +75,6 @@ public struct FamilyTraitSet: CustomStringConvertible, CustomDebugStringConverti
public var debugDescription: String {
return stringRespresentation
}
}
// MARK: - Equatable

View File

@ -59,7 +59,6 @@ public func hash<H: Sequence>(combine hashables: H) -> Int where H.Element == Ha
// MARK: - entity component hash
extension EntityComponentHash {
internal static func compose(entityId: EntityIdentifier, componentTypeHash: ComponentTypeHash) -> EntityComponentHash {
let entityIdSwapped = UInt(entityId).byteSwapped // needs to be 64 bit
let componentTypeHashUInt = UInt(bitPattern: componentTypeHash)

View File

@ -99,5 +99,4 @@ extension ManagedContiguousArray: Equatable where ManagedContiguousArray.Element
public static func == (lhs: ManagedContiguousArray<Element>, rhs: ManagedContiguousArray<Element>) -> Bool {
return lhs.store == rhs.store
}
}

View File

@ -6,7 +6,6 @@
//
public extension Nexus {
final var numComponents: Int {
return componentsByType.reduce(0) { $0 + $1.value.count }
}
@ -76,7 +75,6 @@ public extension Nexus {
@discardableResult
final func remove(component componentId: ComponentIdentifier, from entityId: EntityIdentifier) -> Bool {
let entityIdx: EntityIndex = entityId.index
// delete component instance
@ -92,7 +90,6 @@ public extension Nexus {
@discardableResult
final func clear(componentes entityId: EntityIdentifier) -> Bool {
guard let allComponents: SparseComponentIdentifierSet = get(components: entityId) else {
report("clearing components form entity \(entityId) with no components")
return false

View File

@ -6,7 +6,6 @@
//
extension Nexus {
private func nextEntityIdx() -> EntityIndex {
guard let nextReused: EntityIdentifier = freeEntities.popLast() else {
return entityStorage.count
@ -56,5 +55,4 @@ extension Nexus {
notify(EntityDestroyed(entityId: entityId))
return true
}
}

View File

@ -6,7 +6,6 @@
//
public extension Nexus {
final var numFamilies: Int {
return familyMembersByTraits.keys.count
}
@ -39,16 +38,13 @@ public extension Nexus {
}
return members.contains(entityId.index)
}
}
// MARK: - internal extensions
extension Nexus {
internal func update(familyMembership entityId: EntityIdentifier) {
// FIXME: iterating all families is costly for many families
familyMembersByTraits.forEach { familyTraits, _ in update(membership: familyTraits, for: entityId) }
}
internal enum UpdateState {
@ -81,10 +77,12 @@ extension Nexus {
add(entityWithId: entityId, andIndex: entityIdx, toFamilyWithTraits: traits)
notify(FamilyMemberAdded(member: entityId, toFamily: traits))
return
case (false, true):
remove(entityWithId: entityId, andIndex: entityIdx, fromFamilyWithTraits: traits)
notify(FamilyMemberRemoved(member: entityId, from: traits))
return
default:
return
}
@ -92,7 +90,6 @@ extension Nexus {
/// will be called on family init defer
internal func onFamilyInit(traits: FamilyTraitSet) {
if familyMembersByTraits[traits] == nil {
familyMembersByTraits[traits] = UniformEntityIdentifiers()
}
@ -106,12 +103,10 @@ extension Nexus {
internal func onFamilyDeinit(traits: FamilyTraitSet) {
// nothing todo here
}
}
// MARK: - fileprivate extensions
private extension Nexus {
final func calculateTraitEntityIdHash(traitHash: FamilyTraitSetHash, entityIdx: EntityIndex) -> TraitEntityIdHash {
return hash(combine: traitHash, entityIdx)
}

View File

@ -6,7 +6,6 @@
//
public extension Nexus {
func family<A>(requires componentA: A.Type,
excludesAll excludedComponents: Component.Type...) -> TypedFamily1<A> where A: Component {
return TypedFamily1(self,
@ -62,5 +61,4 @@ public extension Nexus {
componentE,
excludesAll: excludedComponents)
}
}

View File

@ -27,7 +27,6 @@ public protocol NexusDelegate: AnyObject {
}
public class Nexus: Equatable {
public weak var delegate: NexusDelegate?
/// - Index: index value matching entity identifier shifted to Int
@ -92,7 +91,6 @@ public class Nexus: Equatable {
// MARK: - nexus delegate
extension Nexus {
internal func notify(_ event: ECSEvent) {
delegate?.nexusEventOccurred(event)
}

View File

@ -50,7 +50,6 @@ public extension TypedFamilyProtocol {
static func == <Other>(lhs: Self, rhs: Other) -> Bool where Other: TypedFamilyProtocol {
return lhs.traits == rhs.traits && lhs.nexus == rhs.nexus
}
}
public protocol ComponentIteratorProtocol: IteratorProtocol {
@ -87,5 +86,4 @@ public struct FamilyEntities: LazySequenceProtocol, IteratorProtocol {
return nexus?.get(entity: entityId)
}
}

View File

@ -6,7 +6,6 @@
//
public final class TypedFamily1<A>: TypedFamilyProtocol where A: Component {
public private(set) weak var nexus: Nexus?
public let traits: FamilyTraitSet
@ -26,7 +25,6 @@ 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 var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
@ -42,7 +40,6 @@ public struct ComponentIterator1<A>: ComponentIteratorProtocol where A: Componen
return nexus?.get(for: entityId)
}
}
public struct FamilyEntitiesAndComponents1<A>: EntityComponentsSequenceProtocol where A: Component {

View File

@ -8,7 +8,6 @@
// swiftlint:disable large_tuple
public final class TypedFamily2<A, B>: TypedFamilyProtocol where A: Component, B: Component {
public private(set) weak var nexus: Nexus?
public let traits: FamilyTraitSet
@ -25,11 +24,9 @@ public final class TypedFamily2<A, B>: TypedFamilyProtocol where A: Component, B
public var entityAndComponents: FamilyEntitiesAndComponents2<A, B> {
return FamilyEntitiesAndComponents2<A, B>(nexus, self)
}
}
public struct ComponentIterator2<A, B>: ComponentIteratorProtocol where A: Component, B: Component {
public private(set) weak var nexus: Nexus?
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
@ -52,7 +49,6 @@ public struct ComponentIterator2<A, B>: ComponentIteratorProtocol where A: Compo
return (compA, compB)
}
}
public struct FamilyEntitiesAndComponents2<A, B>: EntityComponentsSequenceProtocol where A: Component, B: Component {

View File

@ -26,11 +26,9 @@ public final class TypedFamily3<A, B, C>: TypedFamilyProtocol where A: Component
public var entityAndComponents: FamilyEntitiesAndComponents3<A, B, C> {
return FamilyEntitiesAndComponents3(nexus, self)
}
}
public struct ComponentIterator3<A, B, C>: ComponentIteratorProtocol where A: Component, B: Component, C: Component {
public private(set) weak var nexus: Nexus?
public var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
@ -54,7 +52,6 @@ public struct ComponentIterator3<A, B, C>: ComponentIteratorProtocol where A: Co
return (compA, compB, compC)
}
}
public struct FamilyEntitiesAndComponents3<A, B, C>: EntityComponentsSequenceProtocol where A: Component, B: Component, C: Component {

View File

@ -27,7 +27,6 @@ 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 var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
@ -52,7 +51,6 @@ public struct ComponentIterator4<A, B, C, D>: ComponentIteratorProtocol where A:
return (compA, compB, compC, compD)
}
}
public struct FamilyEntitiesAndComponents4<A, B, C, D>: EntityComponentsSequenceProtocol where A: Component, B: Component, C: Component, D: Component {

View File

@ -24,11 +24,9 @@ public final class TypedFamily5<A, B, C, D, E>: TypedFamilyProtocol where A: Com
public var entityAndComponents: FamilyEntitiesAndComponents5<A, B, C, D, E> {
return FamilyEntitiesAndComponents5(nexus, self)
}
}
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 var memberIdsIterator: UnorderedSparseSetIterator<EntityIdentifier>
@ -54,7 +52,6 @@ public struct ComponentIterator5<A, B, C, D, E>: ComponentIteratorProtocol where
return (compA, compB, compC, compD, compE)
}
}
public struct FamilyEntitiesAndComponents5<A, B, C, D, E>: EntityComponentsSequenceProtocol where A: Component, B: Component, C: Component, D: Component, E: Component {

View File

@ -115,12 +115,10 @@ public class UnorderedSparseSet<Element> {
return (denseIndex, entry.element)
}
}
// MARK: - UnorderedSparseSetIterator
public struct UnorderedSparseSetIterator<Element>: IteratorProtocol {
public private(set) var iterator: IndexingIterator<ContiguousArray<UnorderedSparseSet<Element>.Entry>>
public init(_ sparseSet: UnorderedSparseSet<Element>) {
@ -157,7 +155,6 @@ extension UnorderedSparseSet: MutableCollection, RandomAccessCollection {
public var endIndex: Index {
return dense.endIndex
}
}
extension UnorderedSparseSet.Entry: Equatable where UnorderedSparseSet.Element: Equatable {