Rework conformances

This commit is contained in:
Christian Treffs 2020-04-30 19:56:30 +02:00
parent 81cbb0f2b4
commit 6600cba5ae
No known key found for this signature in database
GPG Key ID: 49A4B4B460BE3ED4
4 changed files with 26 additions and 24 deletions

View File

@ -127,10 +127,20 @@ public struct Entity {
}
}
// MARK: - Equatable
extension Entity: Equatable {
public static func == (lhs: Entity, rhs: Entity) -> Bool {
return lhs.nexus == rhs.nexus &&
lhs.identifier == rhs.identifier
lhs.nexus === rhs.nexus && lhs.identifier == rhs.identifier
}
}
extension Entity: CustomStringConvertible {
public var description: String {
"<Entity id:\(identifier.id)>"
}
}
extension Entity: CustomDebugStringConvertible {
public var debugDescription: String {
"<Entity id:\(identifier.id) numComponents:\(numComponents)>"
}
}

View File

@ -5,24 +5,17 @@
// Created by Christian Treffs on 08.10.17.
//
public struct EntityIdentifier: Identifiable {
/// provides 4294967295 unique identifiers since it's constrained to UInt32 - invalid.
public let id: Int
public struct EntityIdentifier {
static let invalid = EntityIdentifier(.max)
public init(_ uint32: UInt32) {
/// provides 4294967295 unique identifiers since it's constrained to UInt32 - invalid.
@usableFromInline let id: Int
@usableFromInline init(_ uint32: UInt32) {
self.id = Int(uint32)
}
}
extension EntityIdentifier {
public static let invalid = EntityIdentifier(.max)
}
extension EntityIdentifier: Equatable { }
extension EntityIdentifier: Hashable { }
extension EntityIdentifier: Codable { }
extension EntityIdentifier: Comparable {
@inlinable
public static func < (lhs: EntityIdentifier, rhs: EntityIdentifier) -> Bool {
return lhs.id < rhs.id
}
}

View File

@ -23,7 +23,6 @@ public struct FamilyTraitSet {
self.setHash = FirebladeECS.hash(combine: [requiresAll, excludesAll])
}
// MARK: - match
@inlinable
public func isMatch(components: Set<ComponentIdentifier>) -> Bool {
return hasAll(components) && hasNone(components)
@ -39,7 +38,6 @@ public struct FamilyTraitSet {
return excludesAll.isDisjoint(with: components)
}
// MARK: - valid
@inlinable
public static func isValid(requiresAll: Set<ComponentIdentifier>, excludesAll: Set<ComponentIdentifier>) -> Bool {
return !requiresAll.isEmpty &&
@ -47,14 +45,12 @@ public struct FamilyTraitSet {
}
}
// MARK: - Equatable
extension FamilyTraitSet: Equatable {
public static func == (lhs: FamilyTraitSet, rhs: FamilyTraitSet) -> Bool {
return lhs.setHash == rhs.setHash
}
}
// MARK: - Hashable
extension FamilyTraitSet: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(setHash)
@ -72,6 +68,3 @@ extension FamilyTraitSet: CustomDebugStringConvertible {
return "<FamilyTraitSet [requiresAll:\(requiresAll.debugDescription) excludesAll: \(excludesAll.debugDescription)]>"
}
}
// MARK: - Codable
extension FamilyTraitSet: Codable { }

View File

@ -29,7 +29,13 @@ public struct Single<A> where A: SingleComponent {
public let entityId: EntityIdentifier
}
extension Single: Equatable { }
extension Single: Equatable {
public static func == (lhs: Single<A>, rhs: Single<A>) -> Bool {
lhs.traits == rhs.traits &&
lhs.entityId == rhs.entityId &&
lhs.nexus === rhs.nexus
}
}
extension Single where A: SingleComponent {
@inlinable public var component: A {