Skip to content

Commit 763f693

Browse files
committed
Peck away at Swift 6 requirements
1 parent a40ce90 commit 763f693

26 files changed

+83
-513
lines changed

Dependencies/OpenGL/OpenGL_GateEngine/OpenGL_GateEngine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ public enum OpenGL {
652652
self.possibleReasons = possibleReasons
653653
}
654654

655-
public enum Kind: Int {
655+
public enum Kind: Int, Sendable {
656656
case none
657657
case invalidEnum
658658
case invalidValue

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -61,7 +61,7 @@ let package = Package(
6161
])
6262
dependencies.append(
6363
.target(name: "Vorbis",
64-
condition: .when(platforms: .any(except: .wasi)))
64+
condition: .when(platforms: .any(except: .macOS, .wasi)))
6565
)
6666

6767
#if os(macOS) || os(Linux)
@@ -417,7 +417,7 @@ let package = Package(
417417

418418
return targets
419419
}(),
420-
swiftLanguageVersions: [.v5],
420+
swiftLanguageModes: [.v5],
421421
cLanguageStandard: .gnu11,
422422
cxxLanguageStandard: .gnucxx14
423423
)

Sources/GateEngine/ECS/Base/ECSContext.swift

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@
108108
}
109109

110110
@MainActor public final class ECSContext {
111+
/**
112+
An immutable copy of the View this ECSContext will be drawn into.
113+
Use this copy for size and color information from witin your simulation
114+
*/
115+
public internal(set) var gameView: GameViewSnapshot = .empty
116+
111117
private var previousFrameWasDropped: Bool = false
112118
private var platformSystemsNeedSorting = true
113119
private var _platformSystems: [PlatformSystem] = []
@@ -378,8 +384,7 @@ extension ECSContext {
378384
}
379385

380386
//MARK: System Management
381-
extension ECSContext {
382-
@usableFromInline
387+
public extension ECSContext {
383388
func system(ofType systemType: System.Type) -> System {
384389
for system in _systems {
385390
if type(of: system) == systemType {
@@ -388,7 +393,6 @@ extension ECSContext {
388393
}
389394
return insertSystem(systemType)
390395
}
391-
@usableFromInline
392396
func hasSystem(ofType systemType: System.Type) -> Bool {
393397
for system in _systems {
394398
if type(of: system) == systemType {
@@ -397,7 +401,6 @@ extension ECSContext {
397401
}
398402
return false
399403
}
400-
@usableFromInline
401404
func system(ofType systemType: RenderingSystem.Type) -> RenderingSystem {
402405
for system in _renderingSystems {
403406
if type(of: system) == systemType {
@@ -406,15 +409,14 @@ extension ECSContext {
406409
}
407410
return insertSystem(systemType)
408411
}
409-
func system(ofType systemType: PlatformSystem.Type) -> PlatformSystem {
412+
internal func system(ofType systemType: PlatformSystem.Type) -> PlatformSystem {
410413
for system in _platformSystems {
411414
if type(of: system) == systemType {
412415
return system
413416
}
414417
}
415418
return insertSystem(systemType)
416419
}
417-
@usableFromInline
418420
func insertSystem(_ newSystem: System) {
419421
let systemType = type(of: newSystem)
420422
guard _systems.contains(where: { type(of: $0) == systemType }) == false else { return }
@@ -423,7 +425,6 @@ extension ECSContext {
423425
_systems = systems
424426
systemsNeedSorting = true
425427
}
426-
@usableFromInline
427428
func insertSystem(_ newSystem: RenderingSystem) {
428429
let systemType = type(of: newSystem)
429430
guard _renderingSystems.contains(where: { type(of: $0) == systemType }) == false else {
@@ -434,7 +435,7 @@ extension ECSContext {
434435
_renderingSystems = renderingSystems
435436
renderingSystemsNeedSorting = true
436437
}
437-
func insertSystem(_ newSystem: PlatformSystem) {
438+
internal func insertSystem(_ newSystem: PlatformSystem) {
438439
let systemType = type(of: newSystem)
439440
guard _platformSystems.contains(where: { type(of: $0) == systemType }) == false else {
440441
return
@@ -444,42 +445,40 @@ extension ECSContext {
444445
_platformSystems = platformSystems
445446
platformSystemsNeedSorting = true
446447
}
447-
@usableFromInline @discardableResult
448+
@discardableResult
448449
func insertSystem(_ system: System.Type) -> System {
449450
let system = system.init()
450451
self.insertSystem(system)
451452
return system
452453
}
453-
@usableFromInline @discardableResult
454+
@discardableResult
454455
func insertSystem(_ system: RenderingSystem.Type) -> RenderingSystem {
455456
let system = system.init()
456457
self.insertSystem(system)
457458
return system
458459
}
459460
@inline(__always) @discardableResult
460-
func insertSystem(_ system: PlatformSystem.Type) -> PlatformSystem {
461+
internal func insertSystem(_ system: PlatformSystem.Type) -> PlatformSystem {
461462
let system = system.init()
462463
self.insertSystem(system)
463464
return system
464465
}
465-
@usableFromInline
466466
func removeSystem(_ system: System) {
467467
if let index = self._systems.firstIndex(where: { $0 === system }) {
468468
self._systems.remove(at: index).teardown(context: self)
469469
}
470470
}
471-
@usableFromInline
472471
func removeSystem(_ system: RenderingSystem) {
473472
if let index = self._renderingSystems.firstIndex(where: { $0 === system }) {
474473
self._renderingSystems.remove(at: index).teardown(context: self)
475474
}
476475
}
477-
func removeSystem(_ system: PlatformSystem) {
476+
internal func removeSystem(_ system: PlatformSystem) {
478477
if let index = self._platformSystems.firstIndex(where: { $0 === system }) {
479478
self._platformSystems.remove(at: index).teardown(context: self)
480479
}
481480
}
482-
@usableFromInline @discardableResult
481+
@discardableResult
483482
func removeSystem<T: System>(_ system: T.Type) -> System? {
484483
if let index = self._systems.firstIndex(where: { type(of: $0) == system }) {
485484
let system = self._systems.remove(at: index)
@@ -488,7 +487,7 @@ extension ECSContext {
488487
}
489488
return nil
490489
}
491-
@usableFromInline @discardableResult
490+
@discardableResult
492491
func removeSystem<T: RenderingSystem>(_ system: T.Type) -> RenderingSystem? {
493492
if let index = self._renderingSystems.firstIndex(where: { type(of: $0) == system }) {
494493
let system = self._renderingSystems.remove(at: index)
@@ -498,7 +497,7 @@ extension ECSContext {
498497
return nil
499498
}
500499
@discardableResult
501-
func removeSystem<T: PlatformSystem>(_ system: T.Type) -> PlatformSystem? {
500+
internal func removeSystem<T: PlatformSystem>(_ system: T.Type) -> PlatformSystem? {
502501
if let index = self._platformSystems.firstIndex(where: { type(of: $0) == system }) {
503502
let system = self._platformSystems.remove(at: index)
504503
system.teardown(context: self)

Sources/GateEngine/ECS/Base/System.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ extension System {
122122
return state == .running
123123
}
124124

125-
@MainActor public func run(_ block: @escaping () async -> Void) {
125+
public func run(_ block: @escaping () async -> Void) {
126126
assert(self.isRunning == false, "A Task cannot be run when it's running.")
127127
self.state = .running
128128
Task.detached(priority: .low) {
@@ -137,10 +137,10 @@ extension System {
137137
}
138138

139139
extension System: Hashable {
140-
public static func == (lhs: System, rhs: System) -> Bool {
140+
public nonisolated static func == (lhs: System, rhs: System) -> Bool {
141141
return type(of: lhs) == type(of: rhs)
142142
}
143-
public func hash(into hasher: inout Hasher) {
143+
public nonisolated func hash(into hasher: inout Hasher) {
144144
hasher.combine("\(type(of: self))")
145145
}
146146
}

Sources/GateEngine/Game.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@
55
* http://stregasgate.com
66
*/
77

8+
extension Game {
9+
static public fileprivate(set) var identifier: String = ""
10+
}
11+
812
public final class Game {
913
public let platform: CurrentPlatform
1014
public let delegate: any GameDelegate
1115

1216
@MainActor public private(set) var state: State! = nil
1317
@MainActor internal private(set) var internalState: State! = nil
1418

15-
@MainActor
16-
lazy private(set) var identifier: String = delegate.resolvedGameIdentifier()
17-
19+
@inlinable @inline(__always)
20+
nonisolated var identifier: String {
21+
return Self.identifier
22+
}
23+
1824
nonisolated public let isHeadless: Bool
1925
@MainActor internal init(delegate: any GameDelegate, currentPlatform: CurrentPlatform) {
2026
self.platform = currentPlatform
@@ -29,9 +35,10 @@ public final class Game {
2935
self.renderingAPI = renderer._backend.renderingAPI
3036
self.isHeadless = false
3137
}
38+
Self.identifier = delegate.resolvedGameIdentifier()
3239
}
3340

34-
public struct Attributes: OptionSet {
41+
public struct Attributes: OptionSet, Sendable {
3542
public let rawValue: UInt
3643
public init(rawValue: UInt) {
3744
self.rawValue = rawValue

Sources/GateEngine/System/HID/Keyboard/Keyboard.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import GameMath
99

10-
@MainActor public final class Keyboard {
10+
public final class Keyboard {
1111
internal var modifiers: KeyboardModifierMask = []
1212
internal var buttons: [KeyboardKey: ButtonState] = [:]
1313

@@ -90,7 +90,7 @@ import GameMath
9090
}
9191

9292
extension Keyboard {
93-
@MainActor public final class ButtonState: CustomStringConvertible {
93+
public final class ButtonState: CustomStringConvertible {
9494
internal unowned let keyboard: Keyboard
9595
let key: KeyboardKey
9696
// true if the key is a representation instead of a physical key

Sources/GateEngine/System/HID/Keyboard/KeyboardKey.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/// input.keyboard.button(.azerty("z")).isPressed
1616
/// ```
1717
/// The underlying key is still the qwerty representation.
18-
public enum KeyboardKey: Hashable {
18+
public enum KeyboardKey: Hashable, Sendable {
1919
/// The Esc key
2020
case escape
2121

@@ -51,7 +51,7 @@ public enum KeyboardKey: Hashable {
5151
*/
5252
case function(_ number: Int)
5353

54-
public enum KeyOrigin {
54+
public enum KeyOrigin: Sendable {
5555
// Any part of the keyboard
5656
case anyVariation
5757
// The main keyboard area
@@ -96,7 +96,7 @@ public enum KeyboardKey: Hashable {
9696
*/
9797
case unhandledPlatformKeyCode(_ int: Int?, _ string: Character?)
9898

99-
public enum Alignment {
99+
public enum Alignment: Sendable {
100100
// Any key
101101
case anyVariation
102102
// On the left of the space bar

Sources/GateEngine/System/HID/Keyboard/KeyboardModifierMask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* http://stregasgate.com
66
*/
77

8-
public struct KeyboardModifierMask: OptionSet {
8+
public struct KeyboardModifierMask: OptionSet, Sendable {
99
public typealias RawValue = UInt32
1010
public let rawValue: RawValue
1111

Sources/GateEngine/System/Platforms/Apple/AppleFileSystem.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import Foundation
99

1010
public struct AppleFileSystem: FileSystem {
11-
@MainActor
1211
public func pathForSearchPath(_ searchPath: FileSystemSearchPath,
1312
in domain: FileSystemSearchPathDomain = .currentUser) throws -> String {
1413
let foundationSearchPath: FileManager.SearchPathDirectory
@@ -19,7 +18,7 @@ public struct AppleFileSystem: FileSystem {
1918
foundationSearchPath = .cachesDirectory
2019
case .temporary:
2120
let tmpDir = FileManager.default.temporaryDirectory
22-
return tmpDir.appendingPathComponent(Game.shared.identifier).path
21+
return tmpDir.appendingPathComponent(Game.identifier).path
2322
}
2423
let foundationDomainMask: FileManager.SearchPathDomainMask
2524
switch domain {
@@ -32,7 +31,7 @@ public struct AppleFileSystem: FileSystem {
3231
in: foundationDomainMask,
3332
appropriateFor: nil,
3433
create: false)
35-
url = url.appendingPathComponent(Game.shared.identifier)
34+
url = url.appendingPathComponent(Game.identifier)
3635
return url.path
3736
}
3837
}

Sources/GateEngine/UI/GameViewController.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@
77

88
import Foundation
99

10+
public struct GameViewSnapshot: Sendable {
11+
let frame: Rect
12+
let bounds: Rect
13+
let backgroundColor: Color?
14+
15+
static var empty: GameViewSnapshot {
16+
return .init(frame: .zero, bounds: .zero, backgroundColor: nil)
17+
}
18+
}
19+
internal extension GameView {
20+
func snapshot() -> GameViewSnapshot {
21+
return GameViewSnapshot(
22+
frame: self.frame,
23+
bounds: self.bounds,
24+
backgroundColor: self.backgroundColor
25+
)
26+
}
27+
}
28+
1029
public final class GameView: View {
1130
@usableFromInline
1231
var _drawables: [any Drawable] = []
@@ -154,6 +173,7 @@ open class GameViewController: ViewController {
154173

155174
final public override func loadView() {
156175
self.view = GameView()
176+
self.setup(context: self.context)
157177
}
158178

159179
internal var shouldSkipRendering: Bool = false
@@ -163,6 +183,10 @@ open class GameViewController: ViewController {
163183
self.shouldSkipRendering = (await context.shouldRenderAfterUpdate(withTimePassed: deltaTime) == false)
164184
}
165185

186+
open func setup(context: ECSContext) {
187+
188+
}
189+
166190
open func render(context: ECSContext, into view: GameView, withTimePassed deltaTime: Float) {
167191

168192
}

0 commit comments

Comments
 (0)