Extend scene graph implementation
This commit is contained in:
parent
6f40250fdb
commit
4a2ad80dd6
|
|
@ -143,7 +143,7 @@ extension Family {
|
||||||
@usableFromInline unowned let nexus: Nexus
|
@usableFromInline unowned let nexus: Nexus
|
||||||
@usableFromInline let familyTraits: FamilyTraitSet
|
@usableFromInline let familyTraits: FamilyTraitSet
|
||||||
|
|
||||||
@usableFromInline var relatives: [(EntityIdentifier, EntityIdentifier)]
|
@usableFromInline var relatives: ContiguousArray<(EntityIdentifier, EntityIdentifier)>
|
||||||
|
|
||||||
public init(family: Family<R>, root: Entity) {
|
public init(family: Family<R>, root: Entity) {
|
||||||
self.nexus = family.nexus
|
self.nexus = family.nexus
|
||||||
|
|
|
||||||
|
|
@ -94,8 +94,10 @@ class SceneGraphTests: XCTestCase {
|
||||||
|
|
||||||
func addChild(to parent: Entity, index: Int) -> Entity {
|
func addChild(to parent: Entity, index: Int) -> Entity {
|
||||||
let randComp = otherComponents.randomElement()!
|
let randComp = otherComponents.randomElement()!
|
||||||
let child = nexus.createEntity(with: Index(index: index), randComp)
|
let badChild = nexus.createEntity(with: randComp)
|
||||||
|
let child = nexus.createEntity(with: Index(index: index))
|
||||||
parent.addChild(child)
|
parent.addChild(child)
|
||||||
|
parent.addChild(badChild)
|
||||||
return child
|
return child
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,16 +108,20 @@ class SceneGraphTests: XCTestCase {
|
||||||
parent = addChild(to: parent, index: i)
|
parent = addChild(to: parent, index: i)
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(nexus.numEntities, 10)
|
XCTAssertEqual(nexus.numEntities, 19)
|
||||||
|
|
||||||
var parentSum: Int = 0
|
var parentSum: Int = 0
|
||||||
var childSum: Int = 0
|
var childSum: Int = 0
|
||||||
|
|
||||||
|
var lastIndex: Int = -1
|
||||||
|
|
||||||
nexus
|
nexus
|
||||||
.family(requires: Index.self)
|
.family(requires: Index.self)
|
||||||
.descendRelatives(from: root)
|
.descendRelatives(from: root)
|
||||||
.forEach { (parent: Index, child: Index) in
|
.forEach { (parent: Index, child: Index) in
|
||||||
XCTAssertEqual(parent.index + 1, child.index)
|
XCTAssertEqual(parent.index + 1, child.index)
|
||||||
|
XCTAssertGreaterThan(parent.index, lastIndex)
|
||||||
|
lastIndex = parent.index
|
||||||
parentSum += parent.index
|
parentSum += parent.index
|
||||||
childSum += child.index
|
childSum += child.index
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue