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
|
// 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
|
// FIXME: may be expensive but is cheap for small entities
|
||||||
for (index, compId) in remainingComponents.enumerated() {
|
for (index, compId) in remainingComponents.enumerated() {
|
||||||
let cHash: EntityComponentHash = compId.hashValue(using: entityId.index)
|
let cHash: EntityComponentHash = compId.hashValue(using: entityId.index)
|
||||||
|
|
@ -115,13 +115,14 @@ extension Nexus {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
public func clear(componentes entityId: EntityIdentifier) {
|
@discardableResult
|
||||||
|
public func clear(componentes entityId: EntityIdentifier) -> Bool {
|
||||||
guard let componentIds = get(components: entityId) else { return }
|
guard let allComponents: ComponentIdentifiers = get(components: entityId) else {
|
||||||
|
report("clearing components form entity \(entityId) with no components")
|
||||||
componentIds.forEach { (componentId: ComponentIdentifier) in
|
return true
|
||||||
remove(component: componentId, from: entityId)
|
|
||||||
}
|
}
|
||||||
|
let removedAll: Bool = allComponents.reduce(true, { $0 && remove(component: $1, from: entityId) })
|
||||||
|
return removedAll
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,8 @@ extension Nexus {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
clear(componentes: entityId)
|
let cleared: Bool = clear(componentes: entityId)
|
||||||
|
assert(cleared, "Could not clear all components form entity \(entityId)")
|
||||||
|
|
||||||
entity.invalidate()
|
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
|
/// - Value: each element is an index pointing to the component identifier per entity in the componentIdsByEntity map
|
||||||
var componentIdsByEntityLookup: [EntityComponentHash: ComponentIdsByEntityIndex]
|
var componentIdsByEntityLookup: [EntityComponentHash: ComponentIdsByEntityIndex]
|
||||||
|
|
||||||
|
/// - Values: entity ids that are currently not used
|
||||||
var freeEntities: ContiguousArray<EntityIdentifier>
|
var freeEntities: ContiguousArray<EntityIdentifier>
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
// Created by Christian Treffs on 09.10.17.
|
// Created by Christian Treffs on 09.10.17.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import Darwin.C.stdlib
|
||||||
import XCTest
|
import XCTest
|
||||||
@testable import FirebladeECS
|
@testable import FirebladeECS
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue