Refine ComponentIdentifier

This commit is contained in:
Christian Treffs 2020-08-21 16:27:35 +02:00
parent e351de9fb3
commit 37618d5b4f
No known key found for this signature in database
GPG Key ID: 49A4B4B460BE3ED4
1 changed files with 4 additions and 8 deletions

View File

@ -7,22 +7,18 @@
/// Identifies a component by it's meta type
public struct ComponentIdentifier {
@usableFromInline
typealias Hash = Int
@usableFromInline
typealias StableId = UInt64
@usableFromInline let hash: Hash
public typealias Identifier = Int
public let id: Identifier
}
extension ComponentIdentifier {
@usableFromInline
init<C>(_ componentType: C.Type) where C: Component {
self.hash = Self.makeRuntimeHash(componentType)
self.id = Self.makeRuntimeHash(componentType)
}
/// object identifier hash (only stable during runtime) - arbitrary hash is ok.
internal static func makeRuntimeHash<C>(_ componentType: C.Type) -> Hash where C: Component {
internal static func makeRuntimeHash<C>(_ componentType: C.Type) -> Identifier where C: Component {
ObjectIdentifier(componentType).hashValue
}
}