Fix typos and cleanup

This commit is contained in:
Christian Treffs 2020-05-08 14:59:55 +02:00
parent 84d3419dfd
commit 09dd6d2645
No known key found for this signature in database
GPG Key ID: 49A4B4B460BE3ED4
8 changed files with 14 additions and 14 deletions

View File

@ -94,7 +94,7 @@ public struct Entity {
/// Remove all components from this entity. /// Remove all components from this entity.
public func removeAll() { public func removeAll() {
nexus.removeAll(componentes: identifier) nexus.removeAll(components: identifier)
} }
/// Destroy this entity. /// Destroy this entity.

View File

@ -9,7 +9,7 @@ public struct Family<R> where R: FamilyRequirementsManaging {
@usableFromInline unowned let nexus: Nexus @usableFromInline unowned let nexus: Nexus
public let traits: FamilyTraitSet public let traits: FamilyTraitSet
public init(nexus: Nexus, requiresAll: @autoclosure () -> (R.ComponentTypes), excludesAll: [Component.Type]) { public init(nexus: Nexus, requiresAll: @autoclosure () -> R.ComponentTypes, excludesAll: [Component.Type]) {
let required = R(requiresAll()) let required = R(requiresAll())
self.nexus = nexus self.nexus = nexus
let traits = FamilyTraitSet(requiresAll: required.componentTypes, excludesAll: excludesAll) let traits = FamilyTraitSet(requiresAll: required.componentTypes, excludesAll: excludesAll)

View File

@ -10,11 +10,11 @@ public typealias Family1<A: Component> = Family<Requires1<A>>
public struct Requires1<A>: FamilyRequirementsManaging where A: Component { public struct Requires1<A>: FamilyRequirementsManaging where A: Component {
public let componentTypes: [Component.Type] public let componentTypes: [Component.Type]
public init(_ components: (A.Type)) { public init(_ components: A.Type) {
componentTypes = [A.self] componentTypes = [A.self]
} }
public static func components(nexus: Nexus, entityId: EntityIdentifier) -> (A) { public static func components(nexus: Nexus, entityId: EntityIdentifier) -> A {
let compA: A = nexus.get(unsafeComponentFor: entityId) let compA: A = nexus.get(unsafeComponentFor: entityId)
return (compA) return (compA)
} }

View File

@ -51,16 +51,16 @@ public func hash(combine seed: Int, _ value: Int) -> Int {
/// - Returns: combined hash value. /// - Returns: combined hash value.
public func hash<S: Sequence>(combine hashValues: S) -> Int where S.Element == Int { public func hash<S: Sequence>(combine hashValues: S) -> Int where S.Element == Int {
/// http://www.boost.org/doc/libs/1_65_1/doc/html/hash/reference.html#boost.hash_range_idp517643120 /// http://www.boost.org/doc/libs/1_65_1/doc/html/hash/reference.html#boost.hash_range_idp517643120
return hashValues.reduce(0) { hash(combine: $0, $1) } hashValues.reduce(0) { hash(combine: $0, $1) }
} }
/// Calculates the combined hash value of the elements. This implementation is based on boost::hash_range. /// Calculates the combined hash value of the elements. This implementation is based on boost::hash_range.
/// Is sensitive to the order of the elements. /// Is sensitive to the order of the elements.
/// - Parameter hashValues: sequence of hash values to combine. /// - Parameter hashValues: sequence of hash values to combine.
/// - Returns: combined hash value. /// - Returns: combined hash value.
public func hash<H: Sequence>(combine hashables: H) -> Int where H.Element: Hashable { public func hash<H: Sequence>(combine hashValues: H) -> Int where H.Element: Hashable {
/// http://www.boost.org/doc/libs/1_65_1/doc/html/hash/reference.html#boost.hash_range_idp517643120 /// http://www.boost.org/doc/libs/1_65_1/doc/html/hash/reference.html#boost.hash_range_idp517643120
return hashables.reduce(0) { hash(combine: $0, $1.hashValue) } hashValues.reduce(0) { hash(combine: $0, $1.hashValue) }
} }
// MARK: - entity component hash // MARK: - entity component hash

View File

@ -76,7 +76,7 @@ extension Nexus {
@inlinable @inlinable
public final func get<C>(unsafeComponentFor entityId: EntityIdentifier) -> C where C: Component { public final func get<C>(unsafeComponentFor entityId: EntityIdentifier) -> C where C: Component {
let component: Component = get(unsafeComponent: C.identifier, for: entityId) let component: Component = get(unsafeComponent: C.identifier, for: entityId)
// components are guaranteed to be reference tyes so unsafeDowncast is applicable here // components are guaranteed to be reference types so unsafeDowncast is applicable here
return unsafeDowncast(component, to: C.self) return unsafeDowncast(component, to: C.self)
} }
@ -89,7 +89,7 @@ extension Nexus {
public final func remove(component componentId: ComponentIdentifier, from entityId: EntityIdentifier) -> Bool { public final func remove(component componentId: ComponentIdentifier, from entityId: EntityIdentifier) -> Bool {
// delete component instance // delete component instance
componentsByType[componentId]?.remove(at: entityId.id) componentsByType[componentId]?.remove(at: entityId.id)
// unasign component from entity // un-assign component from entity
componentIdsByEntity[entityId]?.remove(componentId) componentIdsByEntity[entityId]?.remove(componentId)
update(familyMembership: entityId) update(familyMembership: entityId)
@ -99,7 +99,7 @@ extension Nexus {
} }
@discardableResult @discardableResult
public final func removeAll(componentes entityId: EntityIdentifier) -> Bool { public final func removeAll(components entityId: EntityIdentifier) -> Bool {
guard let allComponents = get(components: entityId) else { guard let allComponents = get(components: entityId) else {
delegate?.nexusNonFatalError("clearing components form entity \(entityId) with no components") delegate?.nexusNonFatalError("clearing components form entity \(entityId) with no components")
return false return false

View File

@ -63,7 +63,7 @@ extension Nexus {
removeAllChildren(from: entityId) removeAllChildren(from: entityId)
if removeAll(componentes: entityId) { if removeAll(components: entityId) {
update(familyMembership: entityId) update(familyMembership: entityId)
} }

View File

@ -41,8 +41,8 @@ extension Single where A: SingleComponent {
@inlinable public var component: A { @inlinable public var component: A {
// Since we guarantee that the component will always be present by managing the complete lifecycle of the entity // Since we guarantee that the component will always be present by managing the complete lifecycle of the entity
// and component assignment we may unsafelyUnwrap here. // and component assignment we may unsafelyUnwrap here.
// Since components will allways be of reference type (class) we may use unsafeDowncast here for performance reasons. // Since components will always be of reference type (class) we may use unsafeDowncast here for performance reasons.
return nexus.get(unsafeComponentFor: entityId) nexus.get(unsafeComponentFor: entityId)
} }
public var entity: Entity { public var entity: Entity {

View File

@ -97,7 +97,7 @@ public struct UnorderedSparseSet<Element> {
dense.removeAll(keepingCapacity: keepingCapacity) dense.removeAll(keepingCapacity: keepingCapacity)
} }
/// Removes an element from the set and retuns it in O(1). /// Removes an element from the set and returns it in O(1).
/// The removed element is replaced with the last element of the set. /// The removed element is replaced with the last element of the set.
/// ///
/// - Parameter denseIndex: the dense index /// - Parameter denseIndex: the dense index