Cleanups and improvements
This commit is contained in:
parent
130a5a8edd
commit
ca36926975
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
// Created by Christian Treffs on 09.10.17.
|
||||
//
|
||||
|
||||
import Darwin.C.stdlib
|
||||
import XCTest
|
||||
@testable import FirebladeECS
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue