Rename EntityIdentifier.Id to Idx
This commit is contained in:
parent
5d7b021402
commit
040b36d983
|
|
@ -8,14 +8,14 @@
|
||||||
public struct EntityIdentifier {
|
public struct EntityIdentifier {
|
||||||
static let invalid = EntityIdentifier(.max)
|
static let invalid = EntityIdentifier(.max)
|
||||||
|
|
||||||
public typealias Id = Int
|
public typealias Idx = Int
|
||||||
|
|
||||||
/// provides 4294967295 unique identifiers since it's constrained to UInt32 - invalid.
|
/// provides 4294967295 unique identifiers since it's constrained to UInt32 - invalid.
|
||||||
@usableFromInline let id: Id
|
@usableFromInline let id: Idx
|
||||||
|
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
init(_ uint32: UInt32) {
|
init(_ uint32: UInt32) {
|
||||||
self.id = Id(uint32)
|
self.id = Idx(uint32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public struct Family<R> where R: FamilyRequirementsManaging {
|
||||||
nexus.onFamilyInit(traits: traits)
|
nexus.onFamilyInit(traits: traits)
|
||||||
}
|
}
|
||||||
|
|
||||||
@inlinable public var memberIds: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id> {
|
@inlinable public var memberIds: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx> {
|
||||||
nexus.members(withFamilyTraits: traits)
|
nexus.members(withFamilyTraits: traits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ extension Family: LazySequenceProtocol { }
|
||||||
// MARK: - components iterator
|
// MARK: - components iterator
|
||||||
extension Family {
|
extension Family {
|
||||||
public struct ComponentsIterator: IteratorProtocol {
|
public struct ComponentsIterator: IteratorProtocol {
|
||||||
@usableFromInline var memberIdsIterator: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>.ElementIterator
|
@usableFromInline var memberIdsIterator: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>.ElementIterator
|
||||||
@usableFromInline unowned let nexus: Nexus
|
@usableFromInline unowned let nexus: Nexus
|
||||||
|
|
||||||
public init(family: Family<R>) {
|
public init(family: Family<R>) {
|
||||||
|
|
@ -85,7 +85,7 @@ extension Family {
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct EntityIterator: IteratorProtocol {
|
public struct EntityIterator: IteratorProtocol {
|
||||||
@usableFromInline var memberIdsIterator: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>.ElementIterator
|
@usableFromInline var memberIdsIterator: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>.ElementIterator
|
||||||
@usableFromInline unowned let nexus: Nexus
|
@usableFromInline unowned let nexus: Nexus
|
||||||
|
|
||||||
public init(family: Family<R>) {
|
public init(family: Family<R>) {
|
||||||
|
|
@ -111,7 +111,7 @@ extension Family {
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct EntityComponentIterator: IteratorProtocol {
|
public struct EntityComponentIterator: IteratorProtocol {
|
||||||
@usableFromInline var memberIdsIterator: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>.ElementIterator
|
@usableFromInline var memberIdsIterator: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>.ElementIterator
|
||||||
@usableFromInline unowned let nexus: Nexus
|
@usableFromInline unowned let nexus: Nexus
|
||||||
|
|
||||||
public init(family: Family<R>) {
|
public init(family: Family<R>) {
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ extension Nexus {
|
||||||
return traits.isMatch(components: componentIds)
|
return traits.isMatch(components: componentIds)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func members(withFamilyTraits traits: FamilyTraitSet) -> UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id> {
|
public func members(withFamilyTraits traits: FamilyTraitSet) -> UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx> {
|
||||||
familyMembersByTraits[traits] ?? UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>()
|
familyMembersByTraits[traits] ?? UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func isMember(_ entity: Entity, in family: FamilyTraitSet) -> Bool {
|
public func isMember(_ entity: Entity, in family: FamilyTraitSet) -> Bool {
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ extension Nexus {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
familyMembersByTraits[traits] = UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>()
|
familyMembersByTraits[traits] = UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>()
|
||||||
update(familyMembership: traits)
|
update(familyMembership: traits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
public final class Nexus {
|
public final class Nexus {
|
||||||
/// Main entity storage.
|
/// Main entity storage.
|
||||||
/// Entities are tightly packed by EntityIdentifier.
|
/// Entities are tightly packed by EntityIdentifier.
|
||||||
@usableFromInline final var entityStorage: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>
|
@usableFromInline final var entityStorage: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>
|
||||||
|
|
||||||
/// Entity ids that are currently not used.
|
/// Entity ids that are currently not used.
|
||||||
let entityIdGenerator: EntityIdentifierGenerator
|
let entityIdGenerator: EntityIdentifierGenerator
|
||||||
|
|
@ -29,14 +29,14 @@ public final class Nexus {
|
||||||
|
|
||||||
/// - Key: FamilyTraitSet aka component types that make up one distinct family.
|
/// - Key: FamilyTraitSet aka component types that make up one distinct family.
|
||||||
/// - Value: Tightly packed EntityIdentifiers that represent the association of an entity to the family.
|
/// - Value: Tightly packed EntityIdentifiers that represent the association of an entity to the family.
|
||||||
@usableFromInline final var familyMembersByTraits: [FamilyTraitSet: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>]
|
@usableFromInline final var familyMembersByTraits: [FamilyTraitSet: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>]
|
||||||
|
|
||||||
public final var codingStrategy: CodingStrategy
|
public final var codingStrategy: CodingStrategy
|
||||||
|
|
||||||
public final weak var delegate: NexusEventDelegate?
|
public final weak var delegate: NexusEventDelegate?
|
||||||
|
|
||||||
public convenience init() {
|
public convenience init() {
|
||||||
self.init(entityStorage: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>(),
|
self.init(entityStorage: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>(),
|
||||||
componentsByType: [:],
|
componentsByType: [:],
|
||||||
componentsByEntity: [:],
|
componentsByEntity: [:],
|
||||||
entityIdGenerator: EntityIdentifierGenerator(),
|
entityIdGenerator: EntityIdentifierGenerator(),
|
||||||
|
|
@ -45,11 +45,11 @@ public final class Nexus {
|
||||||
codingStrategy: DefaultCodingStrategy())
|
codingStrategy: DefaultCodingStrategy())
|
||||||
}
|
}
|
||||||
|
|
||||||
internal init(entityStorage: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>,
|
internal init(entityStorage: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>,
|
||||||
componentsByType: [ComponentIdentifier: ManagedContiguousArray<Component>],
|
componentsByType: [ComponentIdentifier: ManagedContiguousArray<Component>],
|
||||||
componentsByEntity: [EntityIdentifier: Set<ComponentIdentifier>],
|
componentsByEntity: [EntityIdentifier: Set<ComponentIdentifier>],
|
||||||
entityIdGenerator: EntityIdentifierGenerator,
|
entityIdGenerator: EntityIdentifierGenerator,
|
||||||
familyMembersByTraits: [FamilyTraitSet: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>],
|
familyMembersByTraits: [FamilyTraitSet: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>],
|
||||||
childrenByParentEntity: [EntityIdentifier: Set<EntityIdentifier>],
|
childrenByParentEntity: [EntityIdentifier: Set<EntityIdentifier>],
|
||||||
codingStrategy: CodingStrategy) {
|
codingStrategy: CodingStrategy) {
|
||||||
self.entityStorage = entityStorage
|
self.entityStorage = entityStorage
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue