Cleanups and FIXMEs
This commit is contained in:
parent
8f74d8b4eb
commit
05b4115d14
|
|
@ -61,4 +61,23 @@ public extension Family {
|
|||
}
|
||||
}
|
||||
|
||||
func iterate<A>(_ apply: @escaping (EntityIdentifier, A?) -> Void) where A: Component {
|
||||
iterate(components: A.self, apply)
|
||||
}
|
||||
|
||||
func iterate<A, B>(_ apply: @escaping (EntityIdentifier, A?, B?) -> Void) where A: Component, B: Component {
|
||||
iterate(components: A.self, B.self, apply)
|
||||
}
|
||||
|
||||
func iterate<A, B, C>(_ apply: @escaping (EntityIdentifier, A?, B?, C?) -> Void) where A: Component, B: Component, C: Component {
|
||||
iterate(components: A.self, B.self, C.self, apply)
|
||||
}
|
||||
|
||||
func iterate<A, B, C, D>(_ apply: @escaping (EntityIdentifier, A?, B?, C?, D?) -> Void) where A: Component, B: Component, C: Component, D: Component {
|
||||
iterate(components: A.self, B.self, C.self, D.self, apply)
|
||||
}
|
||||
|
||||
func iterate<A, B, C, D, E>(_ apply: @escaping (EntityIdentifier, A?, B?, C?, D?, E?) -> Void) where A: Component, B: Component, C: Component, D: Component, E: Component {
|
||||
iterate(components: A.self, B.self, C.self, D.self, E.self, apply)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,15 @@ public final class Family {
|
|||
// members of this Family must conform to these traits
|
||||
public let traits: FamilyTraitSet
|
||||
|
||||
// TODO: add family configuration feature
|
||||
// a) define sort order of entities
|
||||
// b) define read/write access
|
||||
// c) set size and storage constraints
|
||||
|
||||
// TODO: family unions
|
||||
// a) iterate family A and family B in pairs
|
||||
// b) pair-wise comparison inside families or between families
|
||||
|
||||
init(_ nexus: Nexus, traits: FamilyTraitSet) {
|
||||
self.nexus = nexus
|
||||
self.traits = traits
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ extension Nexus {
|
|||
/// will be called on family init defer
|
||||
func onFamilyInit(family: Family) {
|
||||
// FIXME: this is costly for many entities
|
||||
// FIXME: we iterate invalid entities here
|
||||
for entity: Entity in entityStorage {
|
||||
update(membership: family, for: entity.identifier)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public class Nexus {
|
|||
|
||||
/// - Index: index value matching entity identifier shifted to Int
|
||||
/// - Value: each element is a entity instance
|
||||
// FIXME: sparse set my be valuable
|
||||
var entityStorage: Entities
|
||||
|
||||
/// - Key: component type identifier
|
||||
|
|
@ -51,7 +52,7 @@ public class Nexus {
|
|||
var freeEntities: ContiguousArray<EntityIdentifier>
|
||||
|
||||
var familiesByTraitHash: [FamilyTraitSetHash: Family]
|
||||
var familyMembersByTraitHash: [FamilyTraitSetHash: UniformEntityIdentifiers] // SparseSet for EntityIdentifier
|
||||
var familyMembersByTraitHash: [FamilyTraitSetHash: UniformEntityIdentifiers]
|
||||
|
||||
public init() {
|
||||
entityStorage = Entities()
|
||||
|
|
|
|||
|
|
@ -162,4 +162,27 @@ class FamilyTests: XCTestCase {
|
|||
|
||||
}
|
||||
|
||||
|
||||
func testIterationSimple() {
|
||||
let nexus = Nexus()
|
||||
|
||||
for i in 0..<1000 {
|
||||
nexus.create(entity: "\(i)").assign(Position(x: i + 1, y: i + 2))
|
||||
}
|
||||
|
||||
let familyA = nexus.family(requiresAll: [Position.self], excludesAll: [Velocity.self])
|
||||
let familyB = nexus.family(requiresAll: [Velocity.self], excludesAll: [Position.self])
|
||||
|
||||
familyA.iterate { (_: EntityIdentifier, pos: Position!, vel: Velocity!) in
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue