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:
parent
2c1c5885ae
commit
11f46f354d
|
|
@ -0,0 +1 @@
|
||||||
|
5.8
|
||||||
|
|
@ -8,4 +8,6 @@
|
||||||
--stripunusedargs closure-only
|
--stripunusedargs closure-only
|
||||||
--commas inline
|
--commas inline
|
||||||
--self remove
|
--self remove
|
||||||
--selfrequired get
|
--selfrequired get
|
||||||
|
--disable preferKeyPath
|
||||||
|
--disable opaqueGenericParameters
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// swift-tools-version:5.1
|
// swift-tools-version:5.8
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
|
|
|
||||||
|
|
@ -25,19 +25,19 @@ These instructions will get you a copy of the project up and running on your loc
|
||||||
|
|
||||||
### 💻 Installing
|
### 💻 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.
|
Extend the following lines in your `Package.swift` file or use it to create a new project.
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
// swift-tools-version:5.1
|
// swift-tools-version:5.8
|
||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "YourPackageName",
|
name: "YourPackageName",
|
||||||
dependencies: [
|
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: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@ public struct ComponentIdentifier {
|
||||||
|
|
||||||
extension ComponentIdentifier {
|
extension ComponentIdentifier {
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
init<C>(_ componentType: C.Type) where C: Component {
|
init(_ componentType: (some Component).Type) {
|
||||||
id = Self.makeRuntimeHash(componentType)
|
id = Self.makeRuntimeHash(componentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// object identifier hash (only stable during runtime) - arbitrary hash is ok.
|
/// 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
|
ObjectIdentifier(componentType).hashValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,13 @@ public struct Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@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)
|
nexus.createEntity(with: components)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if a component with given type is assigned to this entity.
|
/// Checks if a component with given type is assigned to this entity.
|
||||||
/// - Parameter type: the component type.
|
/// - 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)
|
has(type.identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,13 +78,13 @@ public struct Entity {
|
||||||
/// Add a typed component to this entity.
|
/// Add a typed component to this entity.
|
||||||
/// - Parameter component: the typed component.
|
/// - Parameter component: the typed component.
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func assign<C>(_ component: C) -> Entity where C: Component {
|
public func assign(_ component: some Component) -> Entity {
|
||||||
assign(component)
|
assign(component)
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@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)
|
nexus.assign(components: components, to: self)
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
@ -92,14 +92,14 @@ public struct Entity {
|
||||||
/// Remove a component from this entity.
|
/// Remove a component from this entity.
|
||||||
/// - Parameter component: the component.
|
/// - Parameter component: the component.
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func remove<C>(_ component: C) -> Entity where C: Component {
|
public func remove(_ component: some Component) -> Entity {
|
||||||
remove(component.identifier)
|
remove(component.identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove a component by type from this entity.
|
/// Remove a component by type from this entity.
|
||||||
/// - Parameter compType: the component type.
|
/// - Parameter compType: the component type.
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func remove<C>(_ compType: C.Type) -> Entity where C: Component {
|
public func remove(_ compType: (some Component).Type) -> Entity {
|
||||||
remove(compType.identifier)
|
remove(compType.identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ public struct LinearIncrementingEntityIdGenerator: EntityIdentifierGenerator {
|
||||||
|
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
init<EntityIds>(startProviding initialEntityIds: EntityIds) where EntityIds: BidirectionalCollection, EntityIds.Element == EntityIdentifier {
|
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 maxInUseValue = initialInUse.max() ?? 0
|
||||||
let inUseSet = Set(initialInUse) // a set of all eIds in use
|
let inUseSet = Set(initialInUse) // a set of all eIds in use
|
||||||
let allSet = Set(0 ... maxInUseValue) // all eIds from 0 to including maxInUseValue
|
let allSet = Set(0 ... maxInUseValue) // all eIds from 0 to including maxInUseValue
|
||||||
|
|
|
||||||
|
|
@ -251,7 +251,7 @@ extension EntityState {
|
||||||
/// - Returns: This EntityState, so more modifications can be applied.
|
/// - Returns: This EntityState, so more modifications can be applied.
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
@discardableResult
|
@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)
|
addMapping(for: type).withProvider(provider)
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
@ -316,7 +316,7 @@ public class StateComponentMapping {
|
||||||
/// - Parameter closure: The Closure instance to return the component instance
|
/// - Parameter closure: The Closure instance to return the component instance
|
||||||
/// - Returns: This ComponentMapping, so more modifications can be applied
|
/// - Returns: This ComponentMapping, so more modifications can be applied
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func withMethod<C: Component>(_ closure: DynamicComponentProvider<C>.Closure) -> Self {
|
public func withMethod(_ closure: DynamicComponentProvider<some Component>.Closure) -> Self {
|
||||||
setProvider(DynamicComponentProvider(closure: closure))
|
setProvider(DynamicComponentProvider(closure: closure))
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
@ -401,7 +401,7 @@ public class EntityStateMachine<StateIdentifier: Hashable> {
|
||||||
|
|
||||||
var toAdd: [ComponentIdentifier: ComponentProvider]
|
var toAdd: [ComponentIdentifier: ComponentProvider]
|
||||||
|
|
||||||
if let currentState = currentState {
|
if let currentState {
|
||||||
toAdd = .init()
|
toAdd = .init()
|
||||||
for (identifier, provider) in newState.providers {
|
for (identifier, provider) in newState.providers {
|
||||||
toAdd[identifier] = provider
|
toAdd[identifier] = provider
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,12 @@ extension Nexus {
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@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)
|
assign(component: component, to: entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@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)
|
assign(components: components, to: entity.identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ extension Nexus {
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@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()
|
let entity = createEntity()
|
||||||
assign(components: components, to: entity.identifier)
|
assign(components: components, to: entity.identifier)
|
||||||
return entity
|
return entity
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
extension Nexus {
|
extension Nexus {
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
@discardableResult
|
@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()
|
var iter = components.makeIterator()
|
||||||
while let component = iter.next() {
|
while let component = iter.next() {
|
||||||
let componentId = component.identifier
|
let componentId = component.identifier
|
||||||
|
|
@ -103,7 +103,7 @@ extension Nexus {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let isMember: Bool = self.isMember(entity: entityId, inFamilyWithTraits: traits)
|
let isMember: Bool = isMember(entity: entityId, inFamilyWithTraits: traits)
|
||||||
if !exists(entity: entityId), isMember {
|
if !exists(entity: entityId), isMember {
|
||||||
remove(entityWithId: entityId, fromFamilyWithTraits: traits)
|
remove(entityWithId: entityId, fromFamilyWithTraits: traits)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ extension Single where A: SingleComponent {
|
||||||
|
|
||||||
extension Nexus {
|
extension Nexus {
|
||||||
public func single<S>(_ component: S.Type) -> Single<S> where S: SingleComponent {
|
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)")
|
precondition(family.count <= 1, "Singleton count of \(S.self) must be 0 or 1: \(family.count)")
|
||||||
let entityId: EntityIdentifier
|
let entityId: EntityIdentifier
|
||||||
if family.isEmpty {
|
if family.isEmpty {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue