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