parent
bf62fde5db
commit
5994c37b52
|
|
@ -15,11 +15,6 @@ extension Component {
|
|||
public var identifier: ComponentIdentifier { return Self.identifier }
|
||||
}
|
||||
|
||||
// MARK: Equatable
|
||||
public func ==<A: Component, B: Component>(lhs: A, rhs: B) -> Bool {
|
||||
return A.identifier == B.identifier // FIXME: this may be wrong
|
||||
}
|
||||
|
||||
// MARK: - entity component hashable
|
||||
public extension Component {
|
||||
|
||||
|
|
|
|||
|
|
@ -24,4 +24,3 @@ public protocol UniqueComponentIdentifiable {
|
|||
static var identifier: ComponentIdentifier { get }
|
||||
var identifier: ComponentIdentifier { get }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,6 @@ extension Entity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - component tuple access
|
||||
public extension Entity {
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,9 @@ public extension EntityIdentifier {
|
|||
}
|
||||
|
||||
public extension EntityIndex {
|
||||
public var identifier: EntityIdentifier { return EntityIdentifier(self & -0xffffffff) } // shifts entity identifier by -UInt32.max
|
||||
public var identifier: EntityIdentifier { return EntityIdentifier(self & 0xffffffff ) } // shifts entity identifier by UInt32.max
|
||||
}
|
||||
|
||||
|
||||
// MARK: Unique Entity Identifiable
|
||||
public protocol UniqueEntityIdentifiable: Hashable {
|
||||
var identifier: EntityIdentifier { get }
|
||||
|
|
@ -32,4 +31,3 @@ public protocol UniqueEntityIdentifiable: Hashable {
|
|||
public extension UniqueEntityIdentifiable {
|
||||
public var hashValue: Int { return identifier.hashValue }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,14 +46,12 @@ extension Nexus {
|
|||
componentIdsByEntityIdx[entityIdx]!.append(componentId)
|
||||
}
|
||||
|
||||
|
||||
// assign entity / component to index
|
||||
componentIndexByEntityComponentHash[hash] = newComponentIndex
|
||||
|
||||
notify(ComponentAdded(component: componentId, to: entityId))
|
||||
}
|
||||
|
||||
|
||||
public func get<C>(component componentId: ComponentIdentifier, for entityId: EntityIdentifier) -> C? where C: Component {
|
||||
let hash: EntityComponentHash = componentId.hashValue(using: entityId.index)
|
||||
return get(hash)
|
||||
|
|
@ -98,7 +96,6 @@ extension Nexus {
|
|||
return false
|
||||
}
|
||||
|
||||
|
||||
notify(ComponentRemoved(component: componentId, from: entityId))
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ extension Nexus {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Number of entities in nexus.
|
||||
public var count: Int {
|
||||
return entities.count - freeEntities.count
|
||||
|
|
@ -79,5 +78,4 @@ extension Nexus {
|
|||
return true
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ public class Nexus {
|
|||
freeEntities = ContiguousArray<EntityIdentifier>()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension Nexus {
|
||||
|
|
|
|||
|
|
@ -10,16 +10,16 @@ import FirebladeECS
|
|||
struct EmptyComponent: Component { }
|
||||
|
||||
struct Name: Component {
|
||||
let name: String
|
||||
var name: String
|
||||
}
|
||||
|
||||
struct Position: Component {
|
||||
let x: Int
|
||||
let y: Int
|
||||
var x: Int
|
||||
var y: Int
|
||||
}
|
||||
|
||||
struct Velocity: Component {
|
||||
let a: Float
|
||||
var a: Float
|
||||
}
|
||||
|
||||
class DebugEventHandler: EventHandler {
|
||||
|
|
|
|||
|
|
@ -8,17 +8,9 @@
|
|||
import XCTest
|
||||
/*@testable */import FirebladeECS
|
||||
|
||||
|
||||
class EntityComponentTests: XCTestCase {
|
||||
|
||||
func testComponentAccess() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -10,5 +10,4 @@ import XCTest
|
|||
|
||||
class FamilyTests: XCTestCase {
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ import XCTest
|
|||
|
||||
class NexusTests: XCTestCase {
|
||||
|
||||
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
}
|
||||
|
|
@ -20,6 +18,18 @@ class NexusTests: XCTestCase {
|
|||
super.tearDown()
|
||||
}
|
||||
|
||||
func testEntityIdentifierAndIndex() {
|
||||
|
||||
let min: EntityIndex = EntityIdentifier(UInt64.min).index
|
||||
XCTAssert(EntityIndex(min).identifier == min)
|
||||
|
||||
let rand: EntityIndex = EntityIdentifier(UInt64(arc4random())).index
|
||||
XCTAssert(EntityIndex(rand).identifier == rand)
|
||||
|
||||
let max: EntityIndex = EntityIdentifier(UInt64.max).index
|
||||
XCTAssert(EntityIndex(max).identifier == max)
|
||||
|
||||
}
|
||||
|
||||
func testCreateEntity() {
|
||||
let nexus: Nexus = Nexus()
|
||||
|
|
@ -113,7 +123,6 @@ class NexusTests: XCTestCase {
|
|||
|
||||
e0.remove(Name.self)
|
||||
|
||||
|
||||
XCTAssert(e0.numComponents == 0)
|
||||
XCTAssert(!e0.hasComponents)
|
||||
|
||||
|
|
@ -144,6 +153,37 @@ class NexusTests: XCTestCase {
|
|||
|
||||
}
|
||||
|
||||
func testComponentUniqueness() {
|
||||
let nexus = Nexus()
|
||||
let a = nexus.create()
|
||||
let b = nexus.create()
|
||||
let c = nexus.create()
|
||||
|
||||
XCTAssert(nexus.count == 3)
|
||||
|
||||
let p = Position(x: 0, y: 0)
|
||||
|
||||
a.assign(p)
|
||||
b.assign(p)
|
||||
c.assign(p)
|
||||
|
||||
var pA: Position = a.component(Position.self)
|
||||
let pB: Position = b.component(Position.self)
|
||||
|
||||
pA.x = 23
|
||||
pA.y = 32
|
||||
|
||||
XCTAssert(pB.x != pA.x)
|
||||
XCTAssert(pB.y != pA.y)
|
||||
|
||||
}
|
||||
|
||||
func testComponentStorage() {
|
||||
let nexus = Nexus()
|
||||
let a = nexus.create()
|
||||
let b = nexus.create()
|
||||
let c = nexus.create()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,4 @@ import XCTest
|
|||
|
||||
class PerformanceTests: XCTestCase {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,9 @@
|
|||
// Created by Christian Treffs on 11.10.17.
|
||||
//
|
||||
|
||||
|
||||
|
||||
import XCTest
|
||||
import FirebladeECS
|
||||
|
||||
|
||||
class SystemTests: XCTestCase {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue