Merge branch 'feature/lint' into develop
This commit is contained in:
commit
d0db124960
|
|
@ -8,14 +8,14 @@
|
|||
public struct EntityIdentifier {
|
||||
static let invalid = EntityIdentifier(.max)
|
||||
|
||||
public typealias Id = Int
|
||||
public typealias Idx = Int
|
||||
|
||||
/// provides 4294967295 unique identifiers since it's constrained to UInt32 - invalid.
|
||||
@usableFromInline let id: Id
|
||||
@usableFromInline let id: Idx
|
||||
|
||||
@usableFromInline
|
||||
init(_ uint32: UInt32) {
|
||||
self.id = Id(uint32)
|
||||
self.id = Idx(uint32)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ private struct FamilyMemberContainer<R> where R: FamilyRequirementsManaging {
|
|||
}
|
||||
|
||||
extension CodingUserInfoKey {
|
||||
fileprivate static let nexusCodingStrategy = CodingUserInfoKey(rawValue: "nexusCodingStrategy")!
|
||||
static let nexusCodingStrategy = CodingUserInfoKey(rawValue: "nexusCodingStrategy").unsafelyUnwrapped
|
||||
}
|
||||
|
||||
// MARK: - encoding
|
||||
|
|
@ -43,7 +43,7 @@ extension Family where R: FamilyEncoding {
|
|||
/// - Returns: The encoded data.
|
||||
public func encodeMembers<Encoder>(using encoder: inout Encoder) throws -> Encoder.Output where Encoder: TopLevelEncoder {
|
||||
encoder.userInfo[.nexusCodingStrategy] = nexus.codingStrategy
|
||||
let components: [R.Components] = self.map { $0 }
|
||||
let components = [R.Components](self)
|
||||
let container = FamilyMemberContainer<R>(components: components)
|
||||
return try encoder.encode(container)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public struct Family<R> where R: FamilyRequirementsManaging {
|
|||
nexus.onFamilyInit(traits: traits)
|
||||
}
|
||||
|
||||
@inlinable public var memberIds: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id> {
|
||||
@inlinable public var memberIds: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx> {
|
||||
nexus.members(withFamilyTraits: traits)
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ extension Family: LazySequenceProtocol { }
|
|||
// MARK: - components iterator
|
||||
extension Family {
|
||||
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
|
||||
|
||||
public init(family: Family<R>) {
|
||||
|
|
@ -85,7 +85,7 @@ extension Family {
|
|||
}
|
||||
|
||||
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
|
||||
|
||||
public init(family: Family<R>) {
|
||||
|
|
@ -111,7 +111,7 @@ extension Family {
|
|||
}
|
||||
|
||||
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
|
||||
|
||||
public init(family: Family<R>) {
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ extension Nexus {
|
|||
return traits.isMatch(components: componentIds)
|
||||
}
|
||||
|
||||
public func members(withFamilyTraits traits: FamilyTraitSet) -> UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id> {
|
||||
familyMembersByTraits[traits] ?? UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>()
|
||||
public func members(withFamilyTraits traits: FamilyTraitSet) -> UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx> {
|
||||
familyMembersByTraits[traits] ?? UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>()
|
||||
}
|
||||
|
||||
public func isMember(_ entity: Entity, in family: FamilyTraitSet) -> Bool {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ extension Nexus {
|
|||
return
|
||||
}
|
||||
|
||||
familyMembersByTraits[traits] = UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>()
|
||||
familyMembersByTraits[traits] = UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>()
|
||||
update(familyMembership: traits)
|
||||
}
|
||||
|
||||
|
|
@ -127,10 +127,10 @@ extension Nexus {
|
|||
}
|
||||
|
||||
func add(entityWithId entityId: EntityIdentifier, toFamilyWithTraits traits: FamilyTraitSet) {
|
||||
familyMembersByTraits[traits]!.insert(entityId, at: entityId.id)
|
||||
familyMembersByTraits[traits].unsafelyUnwrapped.insert(entityId, at: entityId.id)
|
||||
}
|
||||
|
||||
func remove(entityWithId entityId: EntityIdentifier, fromFamilyWithTraits traits: FamilyTraitSet) {
|
||||
familyMembersByTraits[traits]!.remove(at: entityId.id)
|
||||
familyMembersByTraits[traits].unsafelyUnwrapped.remove(at: entityId.id)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
public final class Nexus {
|
||||
/// Main entity storage.
|
||||
/// 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.
|
||||
let entityIdGenerator: EntityIdentifierGenerator
|
||||
|
|
@ -29,14 +29,14 @@ public final class Nexus {
|
|||
|
||||
/// - 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.
|
||||
@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 weak var delegate: NexusEventDelegate?
|
||||
|
||||
public convenience init() {
|
||||
self.init(entityStorage: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>(),
|
||||
self.init(entityStorage: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>(),
|
||||
componentsByType: [:],
|
||||
componentsByEntity: [:],
|
||||
entityIdGenerator: EntityIdentifierGenerator(),
|
||||
|
|
@ -45,11 +45,11 @@ public final class Nexus {
|
|||
codingStrategy: DefaultCodingStrategy())
|
||||
}
|
||||
|
||||
internal init(entityStorage: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>,
|
||||
internal init(entityStorage: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>,
|
||||
componentsByType: [ComponentIdentifier: ManagedContiguousArray<Component>],
|
||||
componentsByEntity: [EntityIdentifier: Set<ComponentIdentifier>],
|
||||
entityIdGenerator: EntityIdentifierGenerator,
|
||||
familyMembersByTraits: [FamilyTraitSet: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Id>],
|
||||
familyMembersByTraits: [FamilyTraitSet: UnorderedSparseSet<EntityIdentifier, EntityIdentifier.Idx>],
|
||||
childrenByParentEntity: [EntityIdentifier: Set<EntityIdentifier>],
|
||||
codingStrategy: CodingStrategy) {
|
||||
self.entityStorage = entityStorage
|
||||
|
|
@ -87,6 +87,6 @@ public struct DefaultCodingStrategy: CodingStrategy {
|
|||
public init() { }
|
||||
|
||||
public func codingKey<C>(for componentType: C.Type) -> DynamicCodingKey where C: Component {
|
||||
DynamicCodingKey(stringValue: "\(C.self)")!
|
||||
DynamicCodingKey(stringValue: "\(C.self)").unsafelyUnwrapped
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,15 +13,20 @@
|
|||
///
|
||||
/// See <https://github.com/bombela/sparseset/blob/master/src/lib.rs> for a reference implementation.
|
||||
public struct UnorderedSparseSet<Element, Key: Hashable & Codable> {
|
||||
@usableFromInline final class Storage {
|
||||
// swiftlint:disable nesting
|
||||
@usableFromInline
|
||||
final class Storage {
|
||||
/// An index into the dense store.
|
||||
public typealias DenseIndex = Int
|
||||
@usableFromInline
|
||||
typealias DenseIndex = Int
|
||||
|
||||
/// A sparse store holding indices into the dense mapped to key.
|
||||
public typealias SparseStore = [Key: DenseIndex]
|
||||
@usableFromInline
|
||||
typealias SparseStore = [Key: DenseIndex]
|
||||
|
||||
/// A dense store holding all the entries.
|
||||
public typealias DenseStore = ContiguousArray<Entry>
|
||||
@usableFromInline
|
||||
typealias DenseStore = ContiguousArray<Entry>
|
||||
|
||||
@usableFromInline
|
||||
struct Entry {
|
||||
|
|
@ -122,7 +127,8 @@ public struct UnorderedSparseSet<Element, Key: Hashable & Codable> {
|
|||
dense.removeAll(keepingCapacity: keepingCapacity)
|
||||
}
|
||||
|
||||
@inlinable func makeIterator() -> IndexingIterator<ContiguousArray<Storage.Entry>> {
|
||||
@inlinable
|
||||
func makeIterator() -> IndexingIterator<ContiguousArray<Storage.Entry>> {
|
||||
dense.makeIterator()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue