diff --git a/README.md b/README.md index 7ab009f..9af39d3 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ # Fireblade ECS (Entity-Component System) -[![github CI](https://github.com/fireblade-engine/ecs/workflows/CI/badge.svg)](https://github.com/fireblade-engine/ecs/actions?query=workflow%3ACI) [![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) -[![swift version](https://img.shields.io/badge/swift-5.1+-brightgreen.svg)](https://swift.org) -[![platforms](https://img.shields.io/badge/platforms-%20macOS%20|%20iOS%20|%20tvOS%20|%20watchOS-brightgreen.svg)](#) -[![platforms](https://img.shields.io/badge/platforms-linux-brightgreen.svg)](#) -[![platforms](https://img.shields.io/badge/platforms-WebAssembly-brightgreen.svg)](https://github.com/swiftwasm/swift#swiftwasm) +[![github CI](https://github.com/fireblade-engine/ecs/workflows/CI/badge.svg)](https://github.com/fireblade-engine/ecs/actions?query=workflow%3ACI) [![codecov](https://codecov.io/gh/fireblade-engine/ecs/branch/master/graph/badge.svg)](https://codecov.io/gh/fireblade-engine/ecs) -[![documentation](https://github.com/fireblade-engine/ecs/workflows/Documentation/badge.svg)](https://github.com/fireblade-engine/ecs/wiki) +[![documentation](https://github.com/fireblade-engine/ecs/workflows/Documentation/badge.svg)](https://github.com/fireblade-engine/ecs/wiki) +[![spi-swift-versions](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ffireblade-engine%2Fecs%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/fireblade-engine/ecs) +[![spi-swift-platforms](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ffireblade-engine%2Fecs%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/fireblade-engine/ecs) +[![platform-webassembly](https://img.shields.io/badge/Platform-WebAssembly-blue.svg)](https://github.com/swiftwasm/swift#swiftwasm) This is a **dependency free**, **lightweight**, **fast** and **easy to use** [Entity-Component System](https://en.wikipedia.org/wiki/Entity_component_system) implementation in Swift. It is developed and maintained as part of the [Fireblade Game Engine project](https://github.com/fireblade-engine). @@ -36,7 +35,7 @@ import PackageDescription let package = Package( name: "YourPackageName", dependencies: [ - .package(url: "https://github.com/fireblade-engine/ecs.git", from: "0.15.4") + .package(url: "https://github.com/fireblade-engine/ecs.git", from: "0.16.0") ], targets: [ .target( diff --git a/Sources/FirebladeECS/EntityIdentifierGenerator.swift b/Sources/FirebladeECS/EntityIdentifierGenerator.swift index d4d9d3d..1c9a035 100644 --- a/Sources/FirebladeECS/EntityIdentifierGenerator.swift +++ b/Sources/FirebladeECS/EntityIdentifierGenerator.swift @@ -65,12 +65,11 @@ public struct LinearIncrementingEntityIdGenerator: EntityIdentifierGenerator { @usableFromInline func nextId() -> EntityIdentifier { - if stack.count == 1 { - defer { stack[0] += 1 } - return EntityIdentifier(stack[0]) - } else { + guard stack.count == 1 else { return EntityIdentifier(stack.removeLast()) } + defer { stack[0] += 1 } + return EntityIdentifier(stack[0]) } @usableFromInline diff --git a/Sources/FirebladeECS/Hashing.swift b/Sources/FirebladeECS/Hashing.swift index f9d4f2e..d319029 100644 --- a/Sources/FirebladeECS/Hashing.swift +++ b/Sources/FirebladeECS/Hashing.swift @@ -45,15 +45,6 @@ public func hash(combine seed: Int, _ value: Int) -> Int { return Int(bitPattern: uSeed) } -/// Calculates the combined hash value of the elements. This implementation is based on boost::hash_range. -/// Is sensitive to the order of the elements. -/// - Parameter hashValues: sequence of hash values to combine. -/// - Returns: combined hash value. -public func hash(combine hashValues: S) -> Int where S.Element == Int { - /// http://www.boost.org/doc/libs/1_65_1/doc/html/hash/reference.html#boost.hash_range_idp517643120 - hashValues.reduce(0) { hash(combine: $0, $1) } -} - /// Calculates the combined hash value of the elements. This implementation is based on boost::hash_range. /// Is sensitive to the order of the elements. /// - Parameter hashValues: sequence of hash values to combine. diff --git a/Sources/FirebladeECS/Nexus+Internal.swift b/Sources/FirebladeECS/Nexus+Internal.swift index cc6df19..ff6d7a5 100644 --- a/Sources/FirebladeECS/Nexus+Internal.swift +++ b/Sources/FirebladeECS/Nexus+Internal.swift @@ -59,10 +59,6 @@ extension Nexus { componentIdsByEntity[entityId]!.insert(componentId) } - func assign(_ componentIds: Set, _ entityId: EntityIdentifier) { - componentIdsByEntity[entityId]!.formUnion(componentIds) - } - func update(familyMembership entityId: EntityIdentifier) { // FIXME: iterating all families is costly for many families // FIXME: this could be parallelized diff --git a/Sources/FirebladeECS/UnorderedSparseSet.swift b/Sources/FirebladeECS/UnorderedSparseSet.swift index 046f43c..bc9904c 100644 --- a/Sources/FirebladeECS/UnorderedSparseSet.swift +++ b/Sources/FirebladeECS/UnorderedSparseSet.swift @@ -75,10 +75,7 @@ public struct UnorderedSparseSet { return nil } let entry = self.dense[denseIndex] - guard entry.key == key else { - return nil - } - + assert(entry.key == key, "entry.key and findIndex(at: key) must be equal!") return entry.element } diff --git a/Tests/FirebladeECSTests/EntityIdGenTests.swift b/Tests/FirebladeECSTests/EntityIdGenTests.swift index bab14de..d804f49 100644 --- a/Tests/FirebladeECSTests/EntityIdGenTests.swift +++ b/Tests/FirebladeECSTests/EntityIdGenTests.swift @@ -20,6 +20,12 @@ final class EntityIdGenTests: XCTestCase { XCTAssertEqual(gen.nextId(), 0) } + func testGeneratorWithDefaultEmptyCollection() { + gen = DefaultEntityIdGenerator(startProviding: []) + XCTAssertEqual(gen.nextId(), 0) + XCTAssertEqual(gen.nextId(), 1) + } + func testLinearIncrement() { for i in 0..<1_000_000 { XCTAssertEqual(gen.nextId(), EntityIdentifier(EntityIdentifier.Identifier(i))) diff --git a/Tests/FirebladeECSTests/FamilyTests.swift b/Tests/FirebladeECSTests/FamilyTests.swift index 3b3909d..030b87a 100644 --- a/Tests/FirebladeECSTests/FamilyTests.swift +++ b/Tests/FirebladeECSTests/FamilyTests.swift @@ -35,6 +35,8 @@ class FamilyTests: XCTestCase { XCTAssertEqual(nexus.numFamilies, 1) XCTAssertEqual(nexus.numComponents, 0) XCTAssertEqual(nexus.numEntities, 0) + XCTAssertFalse(family.traits.description.isEmpty) + XCTAssertFalse(family.traits.debugDescription.isEmpty) let traits = FamilyTraitSet(requiresAll: [Position.self], excludesAll: [Name.self]) XCTAssertEqual(family.traits, traits) diff --git a/Tests/FirebladeECSTests/NexusTests.swift b/Tests/FirebladeECSTests/NexusTests.swift index c86c30e..714db97 100644 --- a/Tests/FirebladeECSTests/NexusTests.swift +++ b/Tests/FirebladeECSTests/NexusTests.swift @@ -33,6 +33,7 @@ class NexusTests: XCTestCase { XCTAssert(e1.identifier.id == 1) XCTAssert(nexus.numEntities == 2) + XCTAssertFalse(nexus.debugDescription.isEmpty) } func testEntityDestroy() { diff --git a/Tests/FirebladeECSTests/XCTestManifests.swift b/Tests/FirebladeECSTests/XCTestManifests.swift index dc8b4df..f29280b 100644 --- a/Tests/FirebladeECSTests/XCTestManifests.swift +++ b/Tests/FirebladeECSTests/XCTestManifests.swift @@ -40,6 +40,7 @@ extension EntityIdGenTests { ("testGenerateWithInitialIds", testGenerateWithInitialIds), ("testGeneratorDefaultInit", testGeneratorDefaultInit), ("testGeneratorMarkUnused", testGeneratorMarkUnused), + ("testGeneratorWithDefaultEmptyCollection", testGeneratorWithDefaultEmptyCollection), ("testLinearIncrement", testLinearIncrement) ] }