Increase coverage + cleanups
This commit is contained in:
parent
407a71a03f
commit
dd16ccce6b
|
|
@ -3,8 +3,8 @@
|
||||||
[](https://github.com/fireblade-engine/ecs/actions?query=workflow%3ACI)
|
[](https://github.com/fireblade-engine/ecs/actions?query=workflow%3ACI)
|
||||||
[](https://codecov.io/gh/fireblade-engine/ecs)
|
[](https://codecov.io/gh/fireblade-engine/ecs)
|
||||||
[](https://github.com/fireblade-engine/ecs/wiki)
|
[](https://github.com/fireblade-engine/ecs/wiki)
|
||||||
[](https://swiftpackageindex.com/fireblade-engine/ecs)
|
[](https://swiftpackageindex.com/fireblade-engine/ecs)
|
||||||
[](https://swiftpackageindex.com/fireblade-engine/ecs)
|
[](https://swiftpackageindex.com/fireblade-engine/ecs)
|
||||||
[](https://github.com/swiftwasm/swift#swiftwasm)
|
[](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).
|
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).
|
||||||
|
|
|
||||||
|
|
@ -65,12 +65,11 @@ public struct LinearIncrementingEntityIdGenerator: EntityIdentifierGenerator {
|
||||||
|
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
func nextId() -> EntityIdentifier {
|
func nextId() -> EntityIdentifier {
|
||||||
if stack.count == 1 {
|
guard stack.count == 1 else {
|
||||||
defer { stack[0] += 1 }
|
|
||||||
return EntityIdentifier(stack[0])
|
|
||||||
} else {
|
|
||||||
return EntityIdentifier(stack.removeLast())
|
return EntityIdentifier(stack.removeLast())
|
||||||
}
|
}
|
||||||
|
defer { stack[0] += 1 }
|
||||||
|
return EntityIdentifier(stack[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
|
|
|
||||||
|
|
@ -45,15 +45,6 @@ public func hash(combine seed: Int, _ value: Int) -> Int {
|
||||||
return Int(bitPattern: uSeed)
|
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<S: Sequence>(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.
|
/// Calculates the combined hash value of the elements. This implementation is based on boost::hash_range.
|
||||||
/// Is sensitive to the order of the elements.
|
/// Is sensitive to the order of the elements.
|
||||||
/// - Parameter hashValues: sequence of hash values to combine.
|
/// - Parameter hashValues: sequence of hash values to combine.
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,6 @@ extension Nexus {
|
||||||
componentIdsByEntity[entityId]!.insert(componentId)
|
componentIdsByEntity[entityId]!.insert(componentId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func assign(_ componentIds: Set<ComponentIdentifier>, _ entityId: EntityIdentifier) {
|
|
||||||
componentIdsByEntity[entityId]!.formUnion(componentIds)
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
// FIXME: this could be parallelized
|
// FIXME: this could be parallelized
|
||||||
|
|
|
||||||
|
|
@ -75,10 +75,7 @@ public struct UnorderedSparseSet<Element, Key: Hashable & Codable> {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
let entry = self.dense[denseIndex]
|
let entry = self.dense[denseIndex]
|
||||||
guard entry.key == key else {
|
assert(entry.key == key, "entry.key and findIndex(at: key) must be equal!")
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry.element
|
return entry.element
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ class FamilyTests: XCTestCase {
|
||||||
XCTAssertEqual(nexus.numFamilies, 1)
|
XCTAssertEqual(nexus.numFamilies, 1)
|
||||||
XCTAssertEqual(nexus.numComponents, 0)
|
XCTAssertEqual(nexus.numComponents, 0)
|
||||||
XCTAssertEqual(nexus.numEntities, 0)
|
XCTAssertEqual(nexus.numEntities, 0)
|
||||||
|
XCTAssertFalse(family.traits.description.isEmpty)
|
||||||
|
XCTAssertFalse(family.traits.debugDescription.isEmpty)
|
||||||
|
|
||||||
let traits = FamilyTraitSet(requiresAll: [Position.self], excludesAll: [Name.self])
|
let traits = FamilyTraitSet(requiresAll: [Position.self], excludesAll: [Name.self])
|
||||||
XCTAssertEqual(family.traits, traits)
|
XCTAssertEqual(family.traits, traits)
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ class NexusTests: XCTestCase {
|
||||||
|
|
||||||
XCTAssert(e1.identifier.id == 1)
|
XCTAssert(e1.identifier.id == 1)
|
||||||
XCTAssert(nexus.numEntities == 2)
|
XCTAssert(nexus.numEntities == 2)
|
||||||
|
XCTAssertFalse(nexus.debugDescription.isEmpty)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testEntityDestroy() {
|
func testEntityDestroy() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue