Merge branch 'feature/lint-config' into develop
This commit is contained in:
commit
742937f10e
|
|
@ -1,8 +1,8 @@
|
|||
included:
|
||||
- Sources
|
||||
excluded:
|
||||
- docs
|
||||
- build
|
||||
- .build
|
||||
- Tests
|
||||
identifier_name:
|
||||
excluded:
|
||||
- id
|
||||
|
|
@ -10,17 +10,22 @@ line_length: 220
|
|||
number_separator:
|
||||
minimum_length: 5
|
||||
opt_in_rules:
|
||||
#- anyobject_protocol
|
||||
#- explicit_acl
|
||||
#- explicit_enum_raw_value
|
||||
#- explicit_type_interface
|
||||
#- extension_access_modifier
|
||||
#- file_header
|
||||
#- file_name
|
||||
#- file_types_order
|
||||
#- indentation_width
|
||||
#- missing_docs
|
||||
#- multiline_arguments_brackets
|
||||
#- no_grouping_extension
|
||||
#- multiline_literal_brackets
|
||||
#- multiline_parameters_brackets
|
||||
#- no_grouping_extension
|
||||
#- required_deinit
|
||||
#- type_contents_order
|
||||
#- unowned_variable_capture
|
||||
- anyobject_protocol
|
||||
- array_init
|
||||
- attributes
|
||||
- closure_body_length
|
||||
|
|
@ -28,27 +33,37 @@ opt_in_rules:
|
|||
- closure_spacing
|
||||
- collection_alignment
|
||||
- conditional_returns_on_newline
|
||||
- contains_over_filter_count
|
||||
- contains_over_filter_is_empty
|
||||
- contains_over_first_not_nil
|
||||
- contains_over_range_nil_comparison
|
||||
- convenience_type
|
||||
- custom_rules
|
||||
- discouraged_object_literal
|
||||
- discouraged_optional_boolean
|
||||
- discouraged_optional_collection
|
||||
- empty_collection_literal
|
||||
- empty_count
|
||||
- empty_string
|
||||
- empty_xctest_method
|
||||
- enum_case_associated_values_count
|
||||
- expiring_todo
|
||||
- explicit_init
|
||||
- explicit_self
|
||||
- explicit_top_level_acl
|
||||
- fallthrough
|
||||
- fatal_error_message
|
||||
- file_header
|
||||
- file_name_no_space
|
||||
- first_where
|
||||
- flatmap_over_map_reduce
|
||||
- force_unwrapping
|
||||
- function_default_parameter_at_end
|
||||
- identical_operands
|
||||
- implicit_return
|
||||
- implicitly_unwrapped_optional
|
||||
- joined_default_parameter
|
||||
- last_where
|
||||
- legacy_multiple
|
||||
- legacy_random
|
||||
- let_var_whitespace
|
||||
- literal_expression_end_indentation
|
||||
|
|
@ -57,15 +72,18 @@ opt_in_rules:
|
|||
- multiline_arguments
|
||||
- multiline_function_chains
|
||||
- multiline_parameters
|
||||
#- multiline_parameters_brackets
|
||||
- nimble_operator
|
||||
- no_extension_access_modifier
|
||||
- nslocalizedstring_key
|
||||
- nslocalizedstring_require_bundle
|
||||
- number_separator
|
||||
- object_literal
|
||||
- operator_usage_whitespace
|
||||
- optional_enum_case_matching
|
||||
- overridden_super_call
|
||||
- override_in_extension
|
||||
- pattern_matching_keywords
|
||||
- prefer_self_type_over_type_of_self
|
||||
- prefixed_toplevel_constant
|
||||
- private_action
|
||||
- private_outlet
|
||||
|
|
@ -74,6 +92,8 @@ opt_in_rules:
|
|||
- quick_discouraged_call
|
||||
- quick_discouraged_focused_test
|
||||
- quick_discouraged_pending_test
|
||||
- raw_value_for_camel_cased_codable_enum
|
||||
- reduce_into
|
||||
- redundant_nil_coalescing
|
||||
- redundant_type_annotation
|
||||
- required_enum_case
|
||||
|
|
@ -82,15 +102,18 @@ opt_in_rules:
|
|||
- sorted_imports
|
||||
- static_operator
|
||||
- strict_fileprivate
|
||||
- strong_iboutlet
|
||||
- switch_case_on_newline
|
||||
- toggle_bool
|
||||
- trailing_closure
|
||||
- unavailable_function
|
||||
- unneeded_parentheses_in_closure_argument
|
||||
- unneeded_parentheses_in_closure_argument
|
||||
- untyped_error_in_catch
|
||||
- unused_declaration
|
||||
- unused_import
|
||||
- vertical_parameter_alignment_on_call
|
||||
- vertical_whitespace_between_cases
|
||||
- vertical_whitespace_closing_braces
|
||||
- vertical_whitespace_opening_braces
|
||||
- yoda_condition
|
||||
- xct_specific_matcher
|
||||
- yoda_condition
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
// CodingStrategy.swift
|
||||
//
|
||||
//
|
||||
// Created by Christian Treffs on 05.08.20.
|
||||
//
|
||||
|
||||
public protocol CodingStrategy {
|
||||
func codingKey<C>(for componentType: C.Type) -> DynamicCodingKey where C: Component
|
||||
}
|
||||
|
||||
public struct DynamicCodingKey: CodingKey {
|
||||
public var intValue: Int?
|
||||
public var stringValue: String
|
||||
|
||||
public init?(intValue: Int) { self.intValue = intValue; self.stringValue = "\(intValue)" }
|
||||
public init?(stringValue: String) { self.stringValue = stringValue }
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// FamilyDecoding.swift
|
||||
//
|
||||
//
|
||||
// Created by Christian Treffs on 05.08.20.
|
||||
//
|
||||
|
||||
public protocol FamilyDecoding: FamilyRequirementsManaging {
|
||||
static func decode(componentsIn unkeyedContainer: inout UnkeyedDecodingContainer, using strategy: CodingStrategy) throws -> [Components]
|
||||
static func decode(componentsIn container: KeyedDecodingContainer<DynamicCodingKey>, using strategy: CodingStrategy) throws -> Components
|
||||
}
|
||||
|
||||
extension FamilyDecoding {
|
||||
public static func decode(componentsIn unkeyedContainer: inout UnkeyedDecodingContainer, using strategy: CodingStrategy) throws -> [Components] {
|
||||
var components = [Components]()
|
||||
if let count = unkeyedContainer.count {
|
||||
components.reserveCapacity(count)
|
||||
}
|
||||
while !unkeyedContainer.isAtEnd {
|
||||
let container = try unkeyedContainer.nestedContainer(keyedBy: DynamicCodingKey.self)
|
||||
let comps = try Self.decode(componentsIn: container, using: strategy)
|
||||
components.append(comps)
|
||||
}
|
||||
return components
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// FamilyEncoding.swift
|
||||
//
|
||||
//
|
||||
// Created by Christian Treffs on 05.08.20.
|
||||
//
|
||||
|
||||
public protocol FamilyEncoding: FamilyRequirementsManaging {
|
||||
static func encode(components: [Components], into container: inout UnkeyedEncodingContainer, using strategy: CodingStrategy) throws
|
||||
static func encode(components: Components, into container: inout KeyedEncodingContainer<DynamicCodingKey>, using strategy: CodingStrategy) throws
|
||||
}
|
||||
|
||||
extension FamilyEncoding {
|
||||
public static func encode(components: [Components], into container: inout UnkeyedEncodingContainer, using strategy: CodingStrategy) throws {
|
||||
for comps in components {
|
||||
var container = container.nestedContainer(keyedBy: DynamicCodingKey.self)
|
||||
try Self.encode(components: comps, into: &container, using: strategy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
//
|
||||
// FamilyRequirementsManaging.swift
|
||||
//
|
||||
//
|
||||
// Created by Christian Treffs on 21.08.19.
|
||||
//
|
||||
|
||||
public protocol FamilyRequirementsManaging {
|
||||
associatedtype Components
|
||||
associatedtype ComponentTypes
|
||||
associatedtype EntityAndComponents
|
||||
associatedtype RelativesDescending
|
||||
|
||||
init(_ types: ComponentTypes)
|
||||
|
||||
var componentTypes: [Component.Type] { get }
|
||||
|
||||
static func components(nexus: Nexus, entityId: EntityIdentifier) -> Components
|
||||
static func entityAndComponents(nexus: Nexus, entityId: EntityIdentifier) -> EntityAndComponents
|
||||
static func relativesDescending(nexus: Nexus, parentId: EntityIdentifier, childId: EntityIdentifier) -> RelativesDescending
|
||||
|
||||
static func createMember(nexus: Nexus, components: Components) -> Entity
|
||||
}
|
||||
|
||||
public protocol FamilyEncoding: FamilyRequirementsManaging {
|
||||
static func encode(components: [Components], into container: inout UnkeyedEncodingContainer, using strategy: CodingStrategy) throws
|
||||
static func encode(components: Components, into container: inout KeyedEncodingContainer<DynamicCodingKey>, using strategy: CodingStrategy) throws
|
||||
}
|
||||
|
||||
extension FamilyEncoding {
|
||||
public static func encode(components: [Components], into container: inout UnkeyedEncodingContainer, using strategy: CodingStrategy) throws {
|
||||
for comps in components {
|
||||
var container = container.nestedContainer(keyedBy: DynamicCodingKey.self)
|
||||
try Self.encode(components: comps, into: &container, using: strategy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public protocol FamilyDecoding: FamilyRequirementsManaging {
|
||||
static func decode(componentsIn unkeyedContainer: inout UnkeyedDecodingContainer, using strategy: CodingStrategy) throws -> [Components]
|
||||
static func decode(componentsIn container: KeyedDecodingContainer<DynamicCodingKey>, using strategy: CodingStrategy) throws -> Components
|
||||
}
|
||||
|
||||
extension FamilyDecoding {
|
||||
public static func decode(componentsIn unkeyedContainer: inout UnkeyedDecodingContainer, using strategy: CodingStrategy) throws -> [Components] {
|
||||
var components = [Components]()
|
||||
if let count = unkeyedContainer.count {
|
||||
components.reserveCapacity(count)
|
||||
}
|
||||
while !unkeyedContainer.isAtEnd {
|
||||
let container = try unkeyedContainer.nestedContainer(keyedBy: DynamicCodingKey.self)
|
||||
let comps = try Self.decode(componentsIn: container, using: strategy)
|
||||
components.append(comps)
|
||||
}
|
||||
return components
|
||||
}
|
||||
}
|
||||
|
||||
public protocol CodingStrategy {
|
||||
func codingKey<C>(for componentType: C.Type) -> DynamicCodingKey where C: Component
|
||||
}
|
||||
|
||||
public struct DynamicCodingKey: CodingKey {
|
||||
public var intValue: Int?
|
||||
public var stringValue: String
|
||||
|
||||
public init?(intValue: Int) { self.intValue = intValue; self.stringValue = "\(intValue)" }
|
||||
public init?(stringValue: String) { self.stringValue = stringValue }
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// FamilyRequirementsManaging.swift
|
||||
//
|
||||
//
|
||||
// Created by Christian Treffs on 21.08.19.
|
||||
//
|
||||
|
||||
public protocol FamilyRequirementsManaging {
|
||||
associatedtype Components
|
||||
associatedtype ComponentTypes
|
||||
associatedtype EntityAndComponents
|
||||
associatedtype RelativesDescending
|
||||
|
||||
init(_ types: ComponentTypes)
|
||||
|
||||
var componentTypes: [Component.Type] { get }
|
||||
|
||||
static func components(nexus: Nexus, entityId: EntityIdentifier) -> Components
|
||||
static func entityAndComponents(nexus: Nexus, entityId: EntityIdentifier) -> EntityAndComponents
|
||||
static func relativesDescending(nexus: Nexus, parentId: EntityIdentifier, childId: EntityIdentifier) -> RelativesDescending
|
||||
|
||||
static func createMember(nexus: Nexus, components: Components) -> Entity
|
||||
}
|
||||
|
|
@ -15,8 +15,7 @@ public struct FamilyTraitSet {
|
|||
let requiresAll = Set<ComponentIdentifier>(requiresAll.map { $0.identifier })
|
||||
let excludesAll = Set<ComponentIdentifier>(excludesAll.map { $0.identifier })
|
||||
|
||||
precondition(FamilyTraitSet.isValid(requiresAll: requiresAll, excludesAll: excludesAll),
|
||||
"invalid family trait created - requiresAll: \(requiresAll), excludesAll: \(excludesAll)")
|
||||
assert(FamilyTraitSet.isValid(requiresAll: requiresAll, excludesAll: excludesAll), "invalid family trait created - requiresAll: \(requiresAll), excludesAll: \(excludesAll)")
|
||||
|
||||
self.requiresAll = requiresAll
|
||||
self.excludesAll = excludesAll
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
// Created by Christian Treffs on 20.08.19.
|
||||
//
|
||||
|
||||
public protocol NexusEventDelegate: class {
|
||||
public protocol NexusEventDelegate: AnyObject {
|
||||
func nexusEvent(_ event: NexusEvent)
|
||||
func nexusNonFatalError(_ message: String)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,20 +9,6 @@ public protocol SingleComponent: Component {
|
|||
init()
|
||||
}
|
||||
|
||||
extension Nexus {
|
||||
public func single<S>(_ component: S.Type) -> Single<S> where S: SingleComponent {
|
||||
let family = self.family(requires: S.self)
|
||||
precondition(family.count <= 1, "Singleton count of \(S.self) must be 0 or 1: \(family.count)")
|
||||
let entityId: EntityIdentifier
|
||||
if family.isEmpty {
|
||||
entityId = createEntity(with: S()).identifier
|
||||
} else {
|
||||
entityId = family.memberIds.first.unsafelyUnwrapped
|
||||
}
|
||||
return Single<S>(nexus: self, traits: family.traits, entityId: entityId)
|
||||
}
|
||||
}
|
||||
|
||||
public struct Single<A> where A: SingleComponent {
|
||||
public let nexus: Nexus
|
||||
public let traits: FamilyTraitSet
|
||||
|
|
@ -49,3 +35,17 @@ extension Single where A: SingleComponent {
|
|||
nexus.get(entity: entityId).unsafelyUnwrapped
|
||||
}
|
||||
}
|
||||
|
||||
extension Nexus {
|
||||
public func single<S>(_ component: S.Type) -> Single<S> where S: SingleComponent {
|
||||
let family = self.family(requires: S.self)
|
||||
precondition(family.count <= 1, "Singleton count of \(S.self) must be 0 or 1: \(family.count)")
|
||||
let entityId: EntityIdentifier
|
||||
if family.isEmpty {
|
||||
entityId = createEntity(with: S()).identifier
|
||||
} else {
|
||||
entityId = family.memberIds.first.unsafelyUnwrapped
|
||||
}
|
||||
return Single<S>(nexus: self, traits: family.traits, entityId: entityId)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,9 @@
|
|||
import FirebladeECS
|
||||
|
||||
class EmptyComponent: Component {
|
||||
|
||||
}
|
||||
|
||||
class Name: Component {
|
||||
|
||||
var name: String
|
||||
init(name: String) {
|
||||
self.name = name
|
||||
|
|
@ -20,7 +18,6 @@ class Name: Component {
|
|||
}
|
||||
|
||||
class Position: Component {
|
||||
|
||||
var x: Int
|
||||
var y: Int
|
||||
init(x: Int, y: Int) {
|
||||
|
|
@ -30,7 +27,6 @@ class Position: Component {
|
|||
}
|
||||
|
||||
class Velocity: Component {
|
||||
|
||||
var a: Float
|
||||
init(a: Float) {
|
||||
self.a = a
|
||||
|
|
@ -38,7 +34,6 @@ class Velocity: Component {
|
|||
}
|
||||
|
||||
class Party: Component {
|
||||
|
||||
var partying: Bool
|
||||
init(partying: Bool) {
|
||||
self.partying = partying
|
||||
|
|
@ -46,7 +41,6 @@ class Party: Component {
|
|||
}
|
||||
|
||||
class Color: Component {
|
||||
|
||||
var r: UInt8 = 0
|
||||
var g: UInt8 = 0
|
||||
var b: UInt8 = 0
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import FirebladeECS
|
|||
import XCTest
|
||||
|
||||
class ComponentIdentifierTests: XCTestCase {
|
||||
|
||||
/// release: 0.034 sec
|
||||
/// debug: 0.456 sec
|
||||
func testMeasureStaticComponentIdentifier() {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import FirebladeECS
|
|||
import XCTest
|
||||
|
||||
class HashingPerformanceTests: XCTestCase {
|
||||
|
||||
/// release: 0.726 sec
|
||||
/// debug: 3.179 sec
|
||||
func testMeasureCombineHash() {
|
||||
|
|
@ -97,5 +96,4 @@ class HashingPerformanceTests: XCTestCase {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,5 +90,4 @@ final class TypeIdentifierPerformanceTests: XCTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
import FirebladeECS
|
||||
|
||||
class EmptyComponent: Component {
|
||||
|
||||
}
|
||||
|
||||
class Name: Component {
|
||||
|
|
@ -136,7 +135,7 @@ class PositionSystem {
|
|||
}
|
||||
|
||||
func randNorm() -> Double {
|
||||
return 4.0
|
||||
4.0
|
||||
}
|
||||
|
||||
func update() {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
import XCTest
|
||||
|
||||
final class ComponentIdentifierTests: XCTestCase {
|
||||
|
||||
func testMirrorAsStableIdentifier() {
|
||||
let m = String(reflecting: Position.self)
|
||||
let identifier: String = m
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import FirebladeECS
|
|||
import XCTest
|
||||
|
||||
final class EntityCreationTests: XCTestCase {
|
||||
|
||||
func testCreateEntityOneComponent() throws {
|
||||
let nexus = Nexus()
|
||||
let entity = nexus.createEntity {
|
||||
|
|
@ -76,5 +75,4 @@ final class EntityCreationTests: XCTestCase {
|
|||
XCTAssertEqual(nexus.numComponents, 200)
|
||||
XCTAssertEqual(nexus.numFamilies, 0)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,6 @@ class EntityTests: XCTestCase {
|
|||
XCTAssertEqual(entity[Position.self]?.x, 1234)
|
||||
XCTAssertNil(entity[Velocity.self]?.a)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Sequence {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import FirebladeECS
|
|||
import XCTest
|
||||
|
||||
final class FamilyCodingTests: XCTestCase {
|
||||
|
||||
func testEncodingFamily1() throws {
|
||||
let nexus = Nexus()
|
||||
|
||||
|
|
@ -49,7 +48,6 @@ final class FamilyCodingTests: XCTestCase {
|
|||
let newEntities = try family.decodeMembers(from: jsonData, using: &jsonDecoder)
|
||||
XCTAssertEqual(newEntities.count, 2)
|
||||
XCTAssertEqual(family.count, 2)
|
||||
|
||||
}
|
||||
|
||||
func testEncodeFamily2() throws {
|
||||
|
|
@ -301,7 +299,6 @@ final class FamilyCodingTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testFailDecodingFamily() {
|
||||
|
||||
let jsonString = """
|
||||
[
|
||||
{
|
||||
|
|
|
|||
|
|
@ -54,13 +54,12 @@ class HashingTests: XCTestCase {
|
|||
func testStringHashes() throws {
|
||||
let string = "EiMersaufEn1"
|
||||
|
||||
XCTAssertEqual(StringHashing.bernstein_djb2(string), 13447802024599246090)
|
||||
XCTAssertEqual(StringHashing.singer_djb2(string), 5428736256651916664)
|
||||
XCTAssertEqual(StringHashing.sdbm(string), 15559770072020577201)
|
||||
|
||||
XCTAssertEqual(StringHashing.bernstein_djb2("gamedev"), 229466792000542)
|
||||
XCTAssertEqual(StringHashing.singer_djb2("gamedev"), 2867840411746895486)
|
||||
XCTAssertEqual(StringHashing.sdbm("gamedev"), 2761443862055442870)
|
||||
XCTAssertEqual(StringHashing.bernstein_djb2(string), 13_447_802_024_599_246_090)
|
||||
XCTAssertEqual(StringHashing.singer_djb2(string), 5_428_736_256_651_916_664)
|
||||
XCTAssertEqual(StringHashing.sdbm(string), 15_559_770_072_020_577_201)
|
||||
|
||||
XCTAssertEqual(StringHashing.bernstein_djb2("gamedev"), 229_466_792_000_542)
|
||||
XCTAssertEqual(StringHashing.singer_djb2("gamedev"), 2_867_840_411_746_895_486)
|
||||
XCTAssertEqual(StringHashing.sdbm("gamedev"), 2_761_443_862_055_442_870)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,11 @@
|
|||
// Created by Christian Treffs on 30.09.19.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import FirebladeECS
|
||||
import XCTest
|
||||
|
||||
@available(*, deprecated, message: "This will be removed in the next minor update.")
|
||||
class SceneGraphTests: XCTestCase {
|
||||
|
||||
var nexus: Nexus!
|
||||
|
||||
override func setUp() {
|
||||
|
|
@ -130,5 +129,4 @@ class SceneGraphTests: XCTestCase {
|
|||
XCTAssertEqual(parentSum, 36)
|
||||
XCTAssertEqual(childSum, 45)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -540,7 +540,6 @@ class SparseSetTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testAlternativeKey() {
|
||||
|
||||
let set = UnorderedSparseSet<Character, String>()
|
||||
|
||||
set.insert("A", at: "a")
|
||||
|
|
@ -554,11 +553,9 @@ class SparseSetTests: XCTestCase {
|
|||
XCTAssertEqual(a.0, b.0)
|
||||
XCTAssertEqual(a.1, b.1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testEquality() {
|
||||
|
||||
let setA = UnorderedSparseSet<Int, String>()
|
||||
let setB = UnorderedSparseSet<Int, String>()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue