Raise minimum Swift version to 5.8 (#67)

* Raise Swift tools version to 5.8

* Update README

* Add Swift version file

* Format code for 5.8

* Update swiftformat config
This commit is contained in:
Christian Treffs 2024-10-09 20:52:56 +02:00 committed by GitHub
parent 2c1c5885ae
commit 11f46f354d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 26 additions and 23 deletions

1
.swift-version Normal file
View File

@ -0,0 +1 @@
5.8

View File

@ -8,4 +8,6 @@
--stripunusedargs closure-only
--commas inline
--self remove
--selfrequired get
--selfrequired get
--disable preferKeyPath
--disable opaqueGenericParameters

View File

@ -1,4 +1,4 @@
// swift-tools-version:5.1
// swift-tools-version:5.8
import PackageDescription
let package = Package(

View File

@ -25,19 +25,19 @@ These instructions will get you a copy of the project up and running on your loc
### 💻 Installing
Fireblade ECS is available for all platforms that support [Swift 5.1](https://swift.org/) and higher and the [Swift Package Manager (SPM)](https://github.com/apple/swift-package-manager).
Fireblade ECS is available for all platforms that support [Swift 5.8](https://swift.org/) and higher and the [Swift Package Manager (SPM)](https://github.com/apple/swift-package-manager).
Extend the following lines in your `Package.swift` file or use it to create a new project.
```swift
// swift-tools-version:5.1
// swift-tools-version:5.8
import PackageDescription
let package = Package(
name: "YourPackageName",
dependencies: [
.package(url: "https://github.com/fireblade-engine/ecs.git", from: "0.17.4")
.package(url: "https://github.com/fireblade-engine/ecs.git", from: "0.17.5")
],
targets: [
.target(

View File

@ -13,12 +13,12 @@ public struct ComponentIdentifier {
extension ComponentIdentifier {
@usableFromInline
init<C>(_ componentType: C.Type) where C: Component {
init(_ componentType: (some Component).Type) {
id = Self.makeRuntimeHash(componentType)
}
/// object identifier hash (only stable during runtime) - arbitrary hash is ok.
static func makeRuntimeHash<C>(_ componentType: C.Type) -> Identifier where C: Component {
static func makeRuntimeHash(_ componentType: (some Component).Type) -> Identifier {
ObjectIdentifier(componentType).hashValue
}
}

View File

@ -38,13 +38,13 @@ public struct Entity {
}
@discardableResult
public func createEntity<C>(with components: C) -> Entity where C: Collection, C.Element == Component {
public func createEntity(with components: some Collection<Component>) -> Entity {
nexus.createEntity(with: components)
}
/// Checks if a component with given type is assigned to this entity.
/// - Parameter type: the component type.
public func has<C>(_ type: C.Type) -> Bool where C: Component {
public func has(_ type: (some Component).Type) -> Bool {
has(type.identifier)
}
@ -78,13 +78,13 @@ public struct Entity {
/// Add a typed component to this entity.
/// - Parameter component: the typed component.
@discardableResult
public func assign<C>(_ component: C) -> Entity where C: Component {
public func assign(_ component: some Component) -> Entity {
assign(component)
return self
}
@discardableResult
public func assign<C>(_ components: C) -> Entity where C: Collection, C.Element == Component {
public func assign(_ components: some Collection<Component>) -> Entity {
nexus.assign(components: components, to: self)
return self
}
@ -92,14 +92,14 @@ public struct Entity {
/// Remove a component from this entity.
/// - Parameter component: the component.
@discardableResult
public func remove<C>(_ component: C) -> Entity where C: Component {
public func remove(_ component: some Component) -> Entity {
remove(component.identifier)
}
/// Remove a component by type from this entity.
/// - Parameter compType: the component type.
@discardableResult
public func remove<C>(_ compType: C.Type) -> Entity where C: Component {
public func remove(_ compType: (some Component).Type) -> Entity {
remove(compType.identifier)
}

View File

@ -49,7 +49,7 @@ public struct LinearIncrementingEntityIdGenerator: EntityIdentifierGenerator {
@usableFromInline
init<EntityIds>(startProviding initialEntityIds: EntityIds) where EntityIds: BidirectionalCollection, EntityIds.Element == EntityIdentifier {
let initialInUse: [EntityIdentifier.Identifier] = initialEntityIds.map { $0.id }
let initialInUse: [EntityIdentifier.Identifier] = initialEntityIds.map(\.id)
let maxInUseValue = initialInUse.max() ?? 0
let inUseSet = Set(initialInUse) // a set of all eIds in use
let allSet = Set(0 ... maxInUseValue) // all eIds from 0 to including maxInUseValue

View File

@ -251,7 +251,7 @@ extension EntityState {
/// - Returns: This EntityState, so more modifications can be applied.
@inline(__always)
@discardableResult
public func addProvider<C: ComponentInitializable>(type: C.Type, provider: ComponentProvider) -> Self {
public func addProvider(type: (some ComponentInitializable).Type, provider: ComponentProvider) -> Self {
addMapping(for: type).withProvider(provider)
return self
}
@ -316,7 +316,7 @@ public class StateComponentMapping {
/// - Parameter closure: The Closure instance to return the component instance
/// - Returns: This ComponentMapping, so more modifications can be applied
@discardableResult
public func withMethod<C: Component>(_ closure: DynamicComponentProvider<C>.Closure) -> Self {
public func withMethod(_ closure: DynamicComponentProvider<some Component>.Closure) -> Self {
setProvider(DynamicComponentProvider(closure: closure))
return self
}
@ -401,7 +401,7 @@ public class EntityStateMachine<StateIdentifier: Hashable> {
var toAdd: [ComponentIdentifier: ComponentProvider]
if let currentState = currentState {
if let currentState {
toAdd = .init()
for (identifier, provider) in newState.providers {
toAdd[identifier] = provider

View File

@ -28,12 +28,12 @@ extension Nexus {
}
@discardableResult
public final func assign<C>(component: C, to entity: Entity) -> Bool where C: Component {
public final func assign(component: some Component, to entity: Entity) -> Bool {
assign(component: component, to: entity)
}
@discardableResult
public final func assign<C>(components: C, to entity: Entity) -> Bool where C: Collection, C.Element == Component {
public final func assign(components: some Collection<Component>, to entity: Entity) -> Bool {
assign(components: components, to: entity.identifier)
}

View File

@ -22,7 +22,7 @@ extension Nexus {
}
@discardableResult
public func createEntity<C>(with components: C) -> Entity where C: Collection, C.Element == Component {
public func createEntity(with components: some Collection<Component>) -> Entity {
let entity = createEntity()
assign(components: components, to: entity.identifier)
return entity

View File

@ -8,7 +8,7 @@
extension Nexus {
@usableFromInline
@discardableResult
func assign<C>(components: C, to entityId: EntityIdentifier) -> Bool where C: Collection, C.Element == Component {
func assign(components: some Collection<Component>, to entityId: EntityIdentifier) -> Bool {
var iter = components.makeIterator()
while let component = iter.next() {
let componentId = component.identifier
@ -103,7 +103,7 @@ extension Nexus {
return
}
let isMember: Bool = self.isMember(entity: entityId, inFamilyWithTraits: traits)
let isMember: Bool = isMember(entity: entityId, inFamilyWithTraits: traits)
if !exists(entity: entityId), isMember {
remove(entityWithId: entityId, fromFamilyWithTraits: traits)
return

View File

@ -38,7 +38,7 @@ extension Single where A: SingleComponent {
extension Nexus {
public func single<S>(_ component: S.Type) -> Single<S> where S: SingleComponent {
let family = self.family(requires: S.self)
let family = family(requires: S.self)
precondition(family.count <= 1, "Singleton count of \(S.self) must be 0 or 1: \(family.count)")
let entityId: EntityIdentifier
if family.isEmpty {