Merge branch 'feature/cleanups' into develop
This commit is contained in:
commit
24d9b15b6e
|
|
@ -8,8 +8,8 @@ excluded:
|
||||||
line_length: 220
|
line_length: 220
|
||||||
number_separator:
|
number_separator:
|
||||||
minimum_length: 5
|
minimum_length: 5
|
||||||
disabled_rules:
|
#disabled_rules:
|
||||||
- identifier_name
|
#- identifier_name
|
||||||
opt_in_rules:
|
opt_in_rules:
|
||||||
- file_header
|
- file_header
|
||||||
- array_init
|
- array_init
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@
|
||||||
// Created by Christian Treffs on 08.10.17.
|
// Created by Christian Treffs on 08.10.17.
|
||||||
//
|
//
|
||||||
|
|
||||||
public final class Entity: UniqueEntityIdentifiable {
|
open class Entity: UniqueEntityIdentifiable {
|
||||||
internal(set) public var identifier: EntityIdentifier = EntityIdentifier.invalid
|
internal(set) public var identifier: EntityIdentifier = EntityIdentifier.invalid
|
||||||
public var name: String?
|
public var name: String?
|
||||||
unowned let nexus: Nexus
|
unowned let nexus: Nexus
|
||||||
|
|
||||||
init(nexus: Nexus, id: EntityIdentifier, name: String? = nil) {
|
internal init(nexus: Nexus, id: EntityIdentifier, name: String? = nil) {
|
||||||
self.nexus = nexus
|
self.nexus = nexus
|
||||||
self.identifier = id
|
self.identifier = id
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,11 @@ public final class Family: Equatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final var memberIds: UniformEntityIdentifiers {
|
public final var memberIds: UniformEntityIdentifiers {
|
||||||
return nexus?.members(of: traits) ?? UniformEntityIdentifiers()
|
return nexus?.members(withFamilyTraits: traits) ?? UniformEntityIdentifiers()
|
||||||
}
|
}
|
||||||
|
|
||||||
public final var count: Int {
|
public final var count: Int {
|
||||||
return nexus?.members(of: traits)?.count ?? 0
|
return nexus?.members(withFamilyTraits: traits)?.count ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
public final func canBecomeMember(_ entity: Entity) -> Bool {
|
public final func canBecomeMember(_ entity: Entity) -> Bool {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
public extension Nexus {
|
public extension Nexus {
|
||||||
|
|
||||||
final var numComponents: Int {
|
final var numComponents: Int {
|
||||||
return componentsByType.reduce(0) { return $0 + $1.value.count }
|
return componentsByType.reduce(0) { $0 + $1.value.count }
|
||||||
}
|
}
|
||||||
|
|
||||||
final func has(componentId: ComponentIdentifier, entityIdx: EntityIndex) -> Bool {
|
final func has(componentId: ComponentIdentifier, entityIdx: EntityIndex) -> Bool {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ extension Nexus {
|
||||||
return entityStorage.count
|
return entityStorage.count
|
||||||
}
|
}
|
||||||
|
|
||||||
public func has(entity entityId: EntityIdentifier) -> Bool {
|
public func exists(entity entityId: EntityIdentifier) -> Bool {
|
||||||
return entityStorage.contains(entityId.index)
|
return entityStorage.contains(entityId.index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ public extension Nexus {
|
||||||
return family.traits.isMatch(components: componentSet)
|
return family.traits.isMatch(components: componentSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
func members(of traits: FamilyTraitSet) -> UniformEntityIdentifiers? {
|
func members(withFamilyTraits traits: FamilyTraitSet) -> UniformEntityIdentifiers? {
|
||||||
return familyMembersByTraits[traits]
|
return familyMembersByTraits[traits]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,11 +46,11 @@ public extension Nexus {
|
||||||
}
|
}
|
||||||
|
|
||||||
func isMember(_ entityId: EntityIdentifier, in family: Family) -> Bool {
|
func isMember(_ entityId: EntityIdentifier, in family: Family) -> Bool {
|
||||||
return isMember(entityId, in: family.traits)
|
return isMember(entity: entityId, inFamilyWithTraits: family.traits)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isMember(_ entityId: EntityIdentifier, in traits: FamilyTraitSet) -> Bool {
|
func isMember(entity entityId: EntityIdentifier, inFamilyWithTraits traits: FamilyTraitSet) -> Bool {
|
||||||
guard let members: UniformEntityIdentifiers = members(of: traits) else {
|
guard let members: UniformEntityIdentifiers = members(withFamilyTraits: traits) else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return members.contains(entityId.index)
|
return members.contains(entityId.index)
|
||||||
|
|
@ -63,9 +63,8 @@ extension Nexus {
|
||||||
|
|
||||||
func update(familyMembership entityId: EntityIdentifier) {
|
func update(familyMembership entityId: EntityIdentifier) {
|
||||||
// FIXME: iterating all families is costly for many families
|
// FIXME: iterating all families is costly for many families
|
||||||
for (familyTraits, _) in familyMembersByTraits {
|
familyMembersByTraits.forEach { familyTraits, _ in update(membership: familyTraits, for: entityId) }
|
||||||
update(membership: familyTraits, for: entityId)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum UpdateState {
|
enum UpdateState {
|
||||||
|
|
@ -76,32 +75,34 @@ extension Nexus {
|
||||||
case unchanged(id: EntityIdentifier, traits: FamilyTraitSet)
|
case unchanged(id: EntityIdentifier, traits: FamilyTraitSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
func update(membership traits: FamilyTraitSet, for entityId: EntityIdentifier) {
|
||||||
func update(membership traits: FamilyTraitSet, for entityId: EntityIdentifier) -> UpdateState {
|
|
||||||
let entityIdx: EntityIndex = entityId.index
|
let entityIdx: EntityIndex = entityId.index
|
||||||
guard let componentIds: SparseComponentIdentifierSet = componentIdsByEntity[entityIdx] else {
|
guard let componentIds: SparseComponentIdentifierSet = componentIdsByEntity[entityIdx] else {
|
||||||
return .noComponents(id: entityId, traits: traits)
|
// no components - so skip
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let isMember: Bool = self.isMember(entityId, in: traits)
|
let isMember: Bool = self.isMember(entity: entityId, inFamilyWithTraits: traits)
|
||||||
if !has(entity: entityId) && isMember {
|
if !exists(entity: entityId) && isMember {
|
||||||
remove(from: traits, entityId: entityId, entityIdx: entityIdx)
|
remove(entityWithId: entityId, andIndex: entityIdx, fromFamilyWithTraits: traits)
|
||||||
return .removedDeleted(id: entityId, traits: traits)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: get rid of set creation for comparison
|
||||||
let componentsSet: ComponentSet = ComponentSet(componentIds)
|
let componentsSet: ComponentSet = ComponentSet(componentIds)
|
||||||
let isMatch: Bool = traits.isMatch(components: componentsSet)
|
let isMatch: Bool = traits.isMatch(components: componentsSet)
|
||||||
|
|
||||||
switch (isMatch, isMember) {
|
switch (isMatch, isMember) {
|
||||||
case (true, false):
|
case (true, false):
|
||||||
add(to: traits, entityId: entityId, entityIdx: entityIdx)
|
add(entityWithId: entityId, andIndex: entityIdx, toFamilyWithTraits: traits)
|
||||||
notify(FamilyMemberAdded(member: entityId, toFamily: traits))
|
notify(FamilyMemberAdded(member: entityId, toFamily: traits))
|
||||||
return .added(id: entityId, traits: traits)
|
return
|
||||||
case (false, true):
|
case (false, true):
|
||||||
remove(from: traits, entityId: entityId, entityIdx: entityIdx)
|
remove(entityWithId: entityId, andIndex: entityIdx, fromFamilyWithTraits: traits)
|
||||||
notify(FamilyMemberRemoved(member: entityId, from: traits))
|
notify(FamilyMemberRemoved(member: entityId, from: traits))
|
||||||
return .removed(id: entityId, traits: traits)
|
return
|
||||||
default:
|
default:
|
||||||
return .unchanged(id: entityId, traits: traits)
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,28 +128,27 @@ extension Nexus {
|
||||||
// MARK: - fileprivate extensions
|
// MARK: - fileprivate extensions
|
||||||
private extension Nexus {
|
private extension Nexus {
|
||||||
|
|
||||||
func get(family traits: FamilyTraitSet) -> Family? {
|
final func get(family traits: FamilyTraitSet) -> Family? {
|
||||||
return create(family: traits)
|
return create(family: traits)
|
||||||
}
|
}
|
||||||
|
|
||||||
func create(family traits: FamilyTraitSet) -> Family {
|
final func create(family traits: FamilyTraitSet) -> Family {
|
||||||
let family: Family = Family(self, traits: traits)
|
let family: Family = Family(self, traits: traits)
|
||||||
return family
|
return family
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateTraitEntityIdHash(traitHash: FamilyTraitSetHash, entityIdx: EntityIndex) -> TraitEntityIdHash {
|
final func calculateTraitEntityIdHash(traitHash: FamilyTraitSetHash, entityIdx: EntityIndex) -> TraitEntityIdHash {
|
||||||
return hash(combine: traitHash, entityIdx)
|
return hash(combine: traitHash, entityIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func add(to traits: FamilyTraitSet, entityId: EntityIdentifier, entityIdx: EntityIndex) {
|
final func add(entityWithId entityId: EntityIdentifier, andIndex entityIdx: EntityIndex, toFamilyWithTraits traits: FamilyTraitSet) {
|
||||||
if familyMembersByTraits[traits] == nil {
|
if familyMembersByTraits[traits] == nil {
|
||||||
familyMembersByTraits[traits] = UniformEntityIdentifiers()
|
familyMembersByTraits[traits] = UniformEntityIdentifiers()
|
||||||
}
|
}
|
||||||
|
|
||||||
familyMembersByTraits[traits]?.insert(entityId, at: entityIdx)
|
familyMembersByTraits[traits]?.insert(entityId, at: entityIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func remove(from traits: FamilyTraitSet, entityId: EntityIdentifier, entityIdx: EntityIndex) {
|
final func remove(entityWithId entityId: EntityIdentifier, andIndex entityIdx: EntityIndex, fromFamilyWithTraits traits: FamilyTraitSet) {
|
||||||
familyMembersByTraits[traits]?.remove(at: entityIdx)
|
familyMembersByTraits[traits]?.remove(at: entityIdx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
// Created by Christian Treffs on 30.10.17.
|
// Created by Christian Treffs on 30.10.17.
|
||||||
//
|
//
|
||||||
|
|
||||||
public class UnorderedSparseSet<Element>: Sequence {
|
public class UnorderedSparseSet<Element> {
|
||||||
public typealias Index = Int
|
public typealias Index = Int
|
||||||
public typealias Key = Int
|
public typealias Key = Int
|
||||||
|
|
||||||
|
|
@ -136,6 +136,33 @@ public class UnorderedSparseSet<Element>: Sequence {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension UnorderedSparseSet: MutableCollection, RandomAccessCollection {
|
||||||
|
public func index(after index: Index) -> Int {
|
||||||
|
return dense.index(after: index)
|
||||||
|
}
|
||||||
|
|
||||||
|
public subscript(position: Index) -> Element {
|
||||||
|
get {
|
||||||
|
guard let element: Element = get(at: position) else {
|
||||||
|
fatalError("no element at index \(position)")
|
||||||
|
}
|
||||||
|
return element
|
||||||
|
}
|
||||||
|
set(newValue) {
|
||||||
|
insert(newValue, at: position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public var startIndex: Index {
|
||||||
|
return dense.startIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
public var endIndex: Index {
|
||||||
|
return dense.endIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
extension UnorderedSparseSet.Entry: Equatable where UnorderedSparseSet.Element: Equatable {
|
extension UnorderedSparseSet.Entry: Equatable where UnorderedSparseSet.Element: Equatable {
|
||||||
public static func == (lhs: UnorderedSparseSet.Entry, rhs: UnorderedSparseSet.Entry) -> Bool {
|
public static func == (lhs: UnorderedSparseSet.Entry, rhs: UnorderedSparseSet.Entry) -> Bool {
|
||||||
return lhs.element == rhs.element && lhs.key == rhs.key
|
return lhs.element == rhs.element && lhs.key == rhs.key
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,6 @@ class ExampleSystem {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
// Created by Christian Treffs on 09.05.18.
|
// Created by Christian Treffs on 09.05.18.
|
||||||
//
|
//
|
||||||
|
|
||||||
import XCTest
|
|
||||||
import FirebladeECS
|
import FirebladeECS
|
||||||
|
import XCTest
|
||||||
|
|
||||||
class FamilyPerformanceTests: XCTestCase {
|
class FamilyPerformanceTests: XCTestCase {
|
||||||
|
|
||||||
|
|
@ -22,7 +22,6 @@ class FamilyPerformanceTests: XCTestCase {
|
||||||
super.tearDown()
|
super.tearDown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func testMeasureIterateMembers() {
|
func testMeasureIterateMembers() {
|
||||||
|
|
||||||
let number: Int = 10_000
|
let number: Int = 10_000
|
||||||
|
|
@ -88,6 +87,4 @@ class FamilyPerformanceTests: XCTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,6 @@ class FamilyTests: XCTestCase {
|
||||||
let familyB = nexus.family(requiresAll: [Velocity.self],
|
let familyB = nexus.family(requiresAll: [Velocity.self],
|
||||||
excludesAll: [Position.self])
|
excludesAll: [Position.self])
|
||||||
|
|
||||||
|
|
||||||
XCTAssertEqual(familyA.count, 10)
|
XCTAssertEqual(familyA.count, 10)
|
||||||
XCTAssertEqual(familyB.count, 0)
|
XCTAssertEqual(familyB.count, 0)
|
||||||
|
|
||||||
|
|
@ -132,7 +131,6 @@ class FamilyTests: XCTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func testFamilyMemberBasicIteration() {
|
func testFamilyMemberBasicIteration() {
|
||||||
|
|
||||||
for i in 0..<1000 {
|
for i in 0..<1000 {
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
// Created by Christian Treffs on 09.05.18.
|
// Created by Christian Treffs on 09.05.18.
|
||||||
//
|
//
|
||||||
|
|
||||||
import XCTest
|
|
||||||
@testable import FirebladeECS
|
@testable import FirebladeECS
|
||||||
|
import XCTest
|
||||||
|
|
||||||
class FamilyTraitsTests: XCTestCase {
|
class FamilyTraitsTests: XCTestCase {
|
||||||
|
|
||||||
|
|
@ -22,7 +22,6 @@ class FamilyTraitsTests: XCTestCase {
|
||||||
super.tearDown()
|
super.tearDown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func testTraitCommutativity() {
|
func testTraitCommutativity() {
|
||||||
|
|
||||||
let t1 = FamilyTraitSet(requiresAll: [Position.self, Velocity.self],
|
let t1 = FamilyTraitSet(requiresAll: [Position.self, Velocity.self],
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ class HashingTests: XCTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMeasureCombineHash() {
|
func testMeasureCombineHash() {
|
||||||
let a: Set<Int> = Set<Int>.init([14_561_291, 26_451_562, 34_562_182, 488_972_556, 5_128_426_962, 68_211_812])
|
let a: Set<Int> = Set<Int>([14_561_291, 26_451_562, 34_562_182, 488_972_556, 5_128_426_962, 68_211_812])
|
||||||
let b: Set<Int> = Set<Int>.init([1_083_838, 912_312, 83_333, 71_234_555, 4_343_234])
|
let b: Set<Int> = Set<Int>([1_083_838, 912_312, 83_333, 71_234_555, 4_343_234])
|
||||||
let c: Set<Int> = Set<Int>.init([3_410_346_899_765, 90_000_002, 12_212_321, 71, 6_123_345_676_543])
|
let c: Set<Int> = Set<Int>([3_410_346_899_765, 90_000_002, 12_212_321, 71, 6_123_345_676_543])
|
||||||
|
|
||||||
let input: ContiguousArray<Int> = ContiguousArray<Int>(arrayLiteral: a.hashValue, b.hashValue, c.hashValue)
|
let input: ContiguousArray<Int> = ContiguousArray<Int>(arrayLiteral: a.hashValue, b.hashValue, c.hashValue)
|
||||||
measure {
|
measure {
|
||||||
|
|
@ -53,9 +53,9 @@ class HashingTests: XCTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMeasureSetOfSetHash() {
|
func testMeasureSetOfSetHash() {
|
||||||
let a: Set<Int> = Set<Int>.init([14_561_291, 26_451_562, 34_562_182, 488_972_556, 5_128_426_962, 68_211_812])
|
let a: Set<Int> = Set<Int>([14_561_291, 26_451_562, 34_562_182, 488_972_556, 5_128_426_962, 68_211_812])
|
||||||
let b: Set<Int> = Set<Int>.init([1_083_838, 912_312, 83_333, 71_234_555, 4_343_234])
|
let b: Set<Int> = Set<Int>([1_083_838, 912_312, 83_333, 71_234_555, 4_343_234])
|
||||||
let c: Set<Int> = Set<Int>.init([3_410_346_899_765, 90_000_002, 12_212_321, 71, 6_123_345_676_543])
|
let c: Set<Int> = Set<Int>([3_410_346_899_765, 90_000_002, 12_212_321, 71, 6_123_345_676_543])
|
||||||
|
|
||||||
let input = Set<Set<Int>>(arrayLiteral: a, b, c)
|
let input = Set<Set<Int>>(arrayLiteral: a, b, c)
|
||||||
measure {
|
measure {
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,6 @@ class NexusTests: XCTestCase {
|
||||||
XCTAssertEqual(nexus.numEntities, 0)
|
XCTAssertEqual(nexus.numEntities, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func testComponentCreation() {
|
func testComponentCreation() {
|
||||||
|
|
||||||
XCTAssert(nexus.numEntities == 0)
|
XCTAssert(nexus.numEntities == 0)
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class SparseSetTests: XCTestCase {
|
||||||
let pos = Position(x: idx, y: idx)
|
let pos = Position(x: idx, y: idx)
|
||||||
set.insert(pos, at: idx)
|
set.insert(pos, at: idx)
|
||||||
XCTAssertEqual(set.sparse[idx], idx)
|
XCTAssertEqual(set.sparse[idx], idx)
|
||||||
XCTAssertEqual(set.dense.count, idx+1)
|
XCTAssertEqual(set.dense.count, idx + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(set.count, num)
|
XCTAssertEqual(set.count, num)
|
||||||
|
|
@ -120,14 +120,12 @@ class SparseSetTests: XCTestCase {
|
||||||
XCTAssertEqual(set.sparse[6], 6)
|
XCTAssertEqual(set.sparse[6], 6)
|
||||||
XCTAssertEqual(set.sparse[7], nil)
|
XCTAssertEqual(set.sparse[7], nil)
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
set.remove(at: 3)
|
set.remove(at: 3)
|
||||||
|
|
||||||
XCTAssertEqual(set.count, num-1)
|
XCTAssertEqual(set.count, num - 1)
|
||||||
XCTAssertEqual(set.sparse.count, num-1)
|
XCTAssertEqual(set.sparse.count, num - 1)
|
||||||
XCTAssertEqual(set.dense.count, num-1)
|
XCTAssertEqual(set.dense.count, num - 1)
|
||||||
|
|
||||||
|
|
||||||
XCTAssertEqual(set.get(at: 0)?.x, 0)
|
XCTAssertEqual(set.get(at: 0)?.x, 0)
|
||||||
XCTAssertEqual(set.get(at: 1)?.x, 1)
|
XCTAssertEqual(set.get(at: 1)?.x, 1)
|
||||||
|
|
@ -156,15 +154,12 @@ class SparseSetTests: XCTestCase {
|
||||||
XCTAssertEqual(set.sparse[6], 3)
|
XCTAssertEqual(set.sparse[6], 3)
|
||||||
XCTAssertEqual(set.sparse[7], nil)
|
XCTAssertEqual(set.sparse[7], nil)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
set.remove(at: 2)
|
set.remove(at: 2)
|
||||||
|
|
||||||
XCTAssertEqual(set.count, num-2)
|
XCTAssertEqual(set.count, num - 2)
|
||||||
XCTAssertEqual(set.sparse.count, num-2)
|
XCTAssertEqual(set.sparse.count, num - 2)
|
||||||
XCTAssertEqual(set.dense.count, num-2)
|
XCTAssertEqual(set.dense.count, num - 2)
|
||||||
|
|
||||||
|
|
||||||
XCTAssertEqual(set.get(at: 0)?.x, 0)
|
XCTAssertEqual(set.get(at: 0)?.x, 0)
|
||||||
XCTAssertEqual(set.get(at: 1)?.x, 1)
|
XCTAssertEqual(set.get(at: 1)?.x, 1)
|
||||||
|
|
@ -193,15 +188,12 @@ class SparseSetTests: XCTestCase {
|
||||||
XCTAssertEqual(set.sparse[6], 3)
|
XCTAssertEqual(set.sparse[6], 3)
|
||||||
XCTAssertEqual(set.sparse[7], nil)
|
XCTAssertEqual(set.sparse[7], nil)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
set.remove(at: 0)
|
set.remove(at: 0)
|
||||||
|
|
||||||
XCTAssertEqual(set.count, num-3)
|
XCTAssertEqual(set.count, num - 3)
|
||||||
XCTAssertEqual(set.sparse.count, num-3)
|
XCTAssertEqual(set.sparse.count, num - 3)
|
||||||
XCTAssertEqual(set.dense.count, num-3)
|
XCTAssertEqual(set.dense.count, num - 3)
|
||||||
|
|
||||||
|
|
||||||
XCTAssertEqual(set.get(at: 0)?.x, nil)
|
XCTAssertEqual(set.get(at: 0)?.x, nil)
|
||||||
XCTAssertEqual(set.get(at: 1)?.x, 1)
|
XCTAssertEqual(set.get(at: 1)?.x, 1)
|
||||||
|
|
@ -230,14 +222,12 @@ class SparseSetTests: XCTestCase {
|
||||||
XCTAssertEqual(set.sparse[6], 3)
|
XCTAssertEqual(set.sparse[6], 3)
|
||||||
XCTAssertEqual(set.sparse[7], nil)
|
XCTAssertEqual(set.sparse[7], nil)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
set.remove(at: 1)
|
set.remove(at: 1)
|
||||||
|
|
||||||
XCTAssertEqual(set.count, num-4)
|
XCTAssertEqual(set.count, num - 4)
|
||||||
XCTAssertEqual(set.sparse.count, num-4)
|
XCTAssertEqual(set.sparse.count, num - 4)
|
||||||
XCTAssertEqual(set.dense.count, num-4)
|
XCTAssertEqual(set.dense.count, num - 4)
|
||||||
|
|
||||||
XCTAssertEqual(set.get(at: 0)?.x, nil)
|
XCTAssertEqual(set.get(at: 0)?.x, nil)
|
||||||
XCTAssertEqual(set.get(at: 1)?.x, nil)
|
XCTAssertEqual(set.get(at: 1)?.x, nil)
|
||||||
|
|
@ -269,9 +259,9 @@ class SparseSetTests: XCTestCase {
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
set.remove(at: 6)
|
set.remove(at: 6)
|
||||||
|
|
||||||
XCTAssertEqual(set.count, num-5)
|
XCTAssertEqual(set.count, num - 5)
|
||||||
XCTAssertEqual(set.sparse.count, num-5)
|
XCTAssertEqual(set.sparse.count, num - 5)
|
||||||
XCTAssertEqual(set.dense.count, num-5)
|
XCTAssertEqual(set.dense.count, num - 5)
|
||||||
|
|
||||||
XCTAssertEqual(set.get(at: 0)?.x, nil)
|
XCTAssertEqual(set.get(at: 0)?.x, nil)
|
||||||
XCTAssertEqual(set.get(at: 1)?.x, nil)
|
XCTAssertEqual(set.get(at: 1)?.x, nil)
|
||||||
|
|
@ -303,9 +293,9 @@ class SparseSetTests: XCTestCase {
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
set.remove(at: 5)
|
set.remove(at: 5)
|
||||||
|
|
||||||
XCTAssertEqual(set.count, num-6)
|
XCTAssertEqual(set.count, num - 6)
|
||||||
XCTAssertEqual(set.sparse.count, num-6)
|
XCTAssertEqual(set.sparse.count, num - 6)
|
||||||
XCTAssertEqual(set.dense.count, num-6)
|
XCTAssertEqual(set.dense.count, num - 6)
|
||||||
|
|
||||||
XCTAssertEqual(set.get(at: 0)?.x, nil)
|
XCTAssertEqual(set.get(at: 0)?.x, nil)
|
||||||
XCTAssertEqual(set.get(at: 1)?.x, nil)
|
XCTAssertEqual(set.get(at: 1)?.x, nil)
|
||||||
|
|
@ -395,7 +385,6 @@ class SparseSetTests: XCTestCase {
|
||||||
XCTAssertEqual(set.get(at: 99)?.x, 99)
|
XCTAssertEqual(set.get(at: 99)?.x, 99)
|
||||||
XCTAssertEqual(set.get(at: 3)?.x, 3)
|
XCTAssertEqual(set.get(at: 3)?.x, 3)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSparseSetRemoveNonPresent() {
|
func testSparseSetRemoveNonPresent() {
|
||||||
|
|
@ -429,14 +418,12 @@ class SparseSetTests: XCTestCase {
|
||||||
XCTAssertEqual(set.sparse.count, 1)
|
XCTAssertEqual(set.sparse.count, 1)
|
||||||
XCTAssertEqual(set.dense.count, 1)
|
XCTAssertEqual(set.dense.count, 1)
|
||||||
|
|
||||||
|
|
||||||
XCTAssertNil(set.remove(at: 1))
|
XCTAssertNil(set.remove(at: 1))
|
||||||
|
|
||||||
XCTAssertEqual(set.count, 1)
|
XCTAssertEqual(set.count, 1)
|
||||||
XCTAssertEqual(set.sparse.count, 1)
|
XCTAssertEqual(set.sparse.count, 1)
|
||||||
XCTAssertEqual(set.dense.count, 1)
|
XCTAssertEqual(set.dense.count, 1)
|
||||||
|
|
||||||
|
|
||||||
XCTAssertTrue(set.get(at: 0) === a)
|
XCTAssertTrue(set.get(at: 0) === a)
|
||||||
|
|
||||||
XCTAssertEqual(set.count, 1)
|
XCTAssertEqual(set.count, 1)
|
||||||
|
|
@ -445,7 +432,6 @@ class SparseSetTests: XCTestCase {
|
||||||
|
|
||||||
func testSparseSetNonCongiuousData() {
|
func testSparseSetNonCongiuousData() {
|
||||||
|
|
||||||
|
|
||||||
var indices: Set<Int> = [0, 30, 1, 21, 78, 56, 99, 3]
|
var indices: Set<Int> = [0, 30, 1, 21, 78, 56, 99, 3]
|
||||||
|
|
||||||
for idx in indices {
|
for idx in indices {
|
||||||
|
|
@ -499,7 +485,6 @@ class SparseSetTests: XCTestCase {
|
||||||
func testSparseSetReduce() {
|
func testSparseSetReduce() {
|
||||||
let characters = UnorderedSparseSet<Character>()
|
let characters = UnorderedSparseSet<Character>()
|
||||||
|
|
||||||
|
|
||||||
characters.insert("H", at: 4)
|
characters.insert("H", at: 4)
|
||||||
characters.insert("e", at: 13)
|
characters.insert("e", at: 13)
|
||||||
characters.insert("l", at: 44)
|
characters.insert("l", at: 44)
|
||||||
|
|
@ -515,8 +500,8 @@ class SparseSetTests: XCTestCase {
|
||||||
|
|
||||||
XCTAssertEqual(characters.count, 11)
|
XCTAssertEqual(characters.count, 11)
|
||||||
|
|
||||||
let string: String = characters.reduce("") { (res, char) in
|
let string: String = characters.reduce("") { res, char in
|
||||||
return res + "\(char)"
|
res + "\(char)"
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: this tests only dense insertion order, this is no guarantee for the real ordering.
|
// NOTE: this tests only dense insertion order, this is no guarantee for the real ordering.
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
// Created by Christian Treffs on 10.05.18.
|
// Created by Christian Treffs on 10.05.18.
|
||||||
//
|
//
|
||||||
|
|
||||||
import XCTest
|
|
||||||
@testable import FirebladeECS
|
@testable import FirebladeECS
|
||||||
|
import XCTest
|
||||||
|
|
||||||
class SystemsTests: XCTestCase {
|
class SystemsTests: XCTestCase {
|
||||||
|
|
||||||
|
|
@ -86,7 +86,6 @@ class SystemsTests: XCTestCase {
|
||||||
XCTAssertEqual(colorSystem.family.memberIds.count, num)
|
XCTAssertEqual(colorSystem.family.memberIds.count, num)
|
||||||
XCTAssertEqual(positionSystem.family.memberIds.count, num)
|
XCTAssertEqual(positionSystem.family.memberIds.count, num)
|
||||||
|
|
||||||
|
|
||||||
colorSystem.update()
|
colorSystem.update()
|
||||||
positionSystem.update()
|
positionSystem.update()
|
||||||
|
|
||||||
|
|
@ -152,7 +151,6 @@ class ColorSystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PositionSystem {
|
class PositionSystem {
|
||||||
let family: Family
|
let family: Family
|
||||||
|
|
||||||
|
|
@ -170,8 +168,8 @@ class PositionSystem {
|
||||||
func update() {
|
func update() {
|
||||||
family.iterate { [unowned self](pos: Position!) in
|
family.iterate { [unowned self](pos: Position!) in
|
||||||
|
|
||||||
let deltaX: Double = self.velocity*((self.randNorm() * 2) - 1)
|
let deltaX: Double = self.velocity * ((self.randNorm() * 2) - 1)
|
||||||
let deltaY: Double = self.velocity*((self.randNorm() * 2) - 1)
|
let deltaY: Double = self.velocity * ((self.randNorm() * 2) - 1)
|
||||||
let x = pos.x + Int(deltaX)
|
let x = pos.x + Int(deltaX)
|
||||||
let y = pos.y + Int(deltaY)
|
let y = pos.y + Int(deltaY)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ bundle install
|
||||||
swift package update
|
swift package update
|
||||||
|
|
||||||
# generate project
|
# generate project
|
||||||
swift package generate-xcodeproj #--xcconfig-overrides settings.xcconfig
|
swift package generate-xcodeproj --enable-code-coverage #--xcconfig-overrides settings.xcconfig
|
||||||
|
|
||||||
# add project specialities
|
# add project specialities
|
||||||
bundle exec ./prepareXcodeProject.rb
|
bundle exec ./prepareXcodeProject.rb
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue