Merge branch 'develop' into feature/serialization

This commit is contained in:
Christian Treffs 2020-08-21 12:05:40 +02:00
commit dc1d2f67b4
No known key found for this signature in database
GPG Key ID: 49A4B4B460BE3ED4
1 changed files with 10 additions and 3 deletions

View File

@ -32,9 +32,16 @@ public protocol EntityIdentifierGenerator {
} }
/// A default entity identifier generator implementation. /// A default entity identifier generator implementation.
public typealias DefaultEntityIdGenerator = LinearIncrementingEntityIdGenerator
/// **Linear incrementing entity id generator**
/// ///
/// Provides entity ids starting at `0` incrementing until `UInt32.max`. /// This entity id generator creates linearly incrementing entity ids
public struct DefaultEntityIdGenerator: EntityIdentifierGenerator { /// unless an entity is marked as unused then the marked id is returned next in a FIFO order.
///
/// Furthermore it respects order of entity ids on initialization, meaning the provided ids on initialization will be provided in order
/// until all are in use. After that the free entities start at the lowest available id increasing linearly skipping already in-use entity ids.
public struct LinearIncrementingEntityIdGenerator: EntityIdentifierGenerator {
@usableFromInline @usableFromInline
final class Storage { final class Storage {
@usableFromInline var stack: [EntityIdentifier.Identifier] @usableFromInline var stack: [EntityIdentifier.Identifier]
@ -85,7 +92,7 @@ public struct DefaultEntityIdGenerator: EntityIdentifierGenerator {
self.storage = Storage() self.storage = Storage()
} }
//@inline(__always) @inline(__always)
public func nextId() -> EntityIdentifier { public func nextId() -> EntityIdentifier {
storage.nextId() storage.nextId()
} }