Cleanups and improvements

This commit is contained in:
Christian Treffs 2017-10-16 09:33:39 +02:00
parent 130a5a8edd
commit ca36926975
4 changed files with 12 additions and 8 deletions

View File

@ -103,7 +103,7 @@ extension Nexus {
}
// relocate remaining indices pointing in the componentsByEntity map
if let remainingComponents = componentIdsByEntity[entityId.index] {
if let remainingComponents: ComponentIdentifiers = componentIdsByEntity[entityId.index] {
// FIXME: may be expensive but is cheap for small entities
for (index, compId) in remainingComponents.enumerated() {
let cHash: EntityComponentHash = compId.hashValue(using: entityId.index)
@ -115,13 +115,14 @@ extension Nexus {
return true
}
public func clear(componentes entityId: EntityIdentifier) {
guard let componentIds = get(components: entityId) else { return }
componentIds.forEach { (componentId: ComponentIdentifier) in
remove(component: componentId, from: entityId)
@discardableResult
public func clear(componentes entityId: EntityIdentifier) -> Bool {
guard let allComponents: ComponentIdentifiers = get(components: entityId) else {
report("clearing components form entity \(entityId) with no components")
return true
}
let removedAll: Bool = allComponents.reduce(true, { $0 && remove(component: $1, from: entityId) })
return removedAll
}
}

View File

@ -64,7 +64,8 @@ extension Nexus {
return false
}
clear(componentes: entityId)
let cleared: Bool = clear(componentes: entityId)
assert(cleared, "Could not clear all components form entity \(entityId)")
entity.invalidate()

View File

@ -39,6 +39,7 @@ public class Nexus {
/// - Value: each element is an index pointing to the component identifier per entity in the componentIdsByEntity map
var componentIdsByEntityLookup: [EntityComponentHash: ComponentIdsByEntityIndex]
/// - Values: entity ids that are currently not used
var freeEntities: ContiguousArray<EntityIdentifier>
public init() {

View File

@ -5,6 +5,7 @@
// Created by Christian Treffs on 09.10.17.
//
import Darwin.C.stdlib
import XCTest
@testable import FirebladeECS