Skip to content

Commit 2625eeb

Browse files
committed
Chip away as Swift 6
1 parent bd9e230 commit 2625eeb

File tree

9 files changed

+91
-78
lines changed

9 files changed

+91
-78
lines changed

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,9 @@ extension Array where Element == SwiftSetting {
704704
#endif
705705
#endif
706706
#if compiler(>=5.10)
707+
#if hasFeature(StrictConcurrency)
708+
enableFeature("StrictConcurrency=complete") // complete mode shows Swift v6 errors as warnings when in Swift v5
709+
#endif
707710
#if !hasFeature(GlobalConcurrency)
708711
enableFeature("GlobalConcurrency")
709712
#endif
@@ -737,7 +740,7 @@ extension Array where Element == SwiftSetting {
737740
#endif
738741
#if compiler(>=5.6)
739742
#if !hasFeature(StrictConcurrency)
740-
enableFeature("StrictConcurrency=complete")
743+
enableFeature("StrictConcurrency")
741744
#endif
742745
#if !hasFeature(ExistentialAny)
743746
enableFeature("ExistentialAny")

Sources/GateEngine/System/HID/HID.swift

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

8+
import Foundation
89
import GameMath
910

1011
public struct InputReceipts {
@@ -113,7 +114,7 @@ extension HID {
113114
}
114115

115116
internal func screenTouchChange(
116-
id: AnyHashable,
117+
id: UUID,
117118
kind: TouchKind,
118119
event: TouchChangeEvent,
119120
position: Position2,
@@ -127,9 +128,9 @@ extension HID {
127128
}
128129

129130
internal func surfaceTouchChange(
130-
id: AnyHashable,
131+
id: UUID,
131132
event: TouchChangeEvent,
132-
surfaceID: AnyHashable,
133+
surfaceID: UUID,
133134
normalizedPosition: Position2,
134135
pressure: Float,
135136
window: Window?

Sources/GateEngine/System/HID/Touch/Touch.swift

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

8+
import Foundation
89
import GameMath
910

1011
@MainActor public class Touch {
11-
public internal(set) var id: AnyHashable
12+
public let id: UUID
1213
public internal(set) weak var window: Window?
1314
public internal(set) var position: Position2
1415
internal var _precisionPosition: Position2?
@@ -35,7 +36,7 @@ import GameMath
3536
return p
3637
}
3738

38-
init(id: AnyHashable, window: Window? = nil, position: Position2, precisionPosition: Position2?, pressure: Float, phase: Phase, kind: TouchKind) {
39+
init(id: UUID, window: Window? = nil, position: Position2, precisionPosition: Position2?, pressure: Float, phase: Phase, kind: TouchKind) {
3940
self.id = id
4041
self.window = window
4142
self.position = position
@@ -56,13 +57,13 @@ import GameMath
5657

5758
extension Touch: Equatable {
5859
@inlinable
59-
public static func == (lhs: Touch, rhs: Touch) -> Bool {
60+
public nonisolated static func == (lhs: Touch, rhs: Touch) -> Bool {
6061
return lhs.id == rhs.id
6162
}
6263
}
6364
extension Touch: Hashable {
6465
@inlinable
65-
public func hash(into hasher: inout Hasher) {
66+
public nonisolated func hash(into hasher: inout Hasher) {
6667
hasher.combine(id)
6768
}
6869
}

Sources/GateEngine/System/HID/Touch/TouchScreen.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* http://stregasgate.com
66
*/
77

8+
import Foundation
89
import GameMath
910

1011
extension HID {
@@ -28,12 +29,12 @@ extension HID {
2829
return touches.first(where: { $0.phase == phase })
2930
}
3031

31-
private func existingTouch(_ id: AnyHashable) -> Touch? {
32+
private func existingTouch(_ id: UUID) -> Touch? {
3233
return touches.first(where: { $0.id == id })
3334
}
3435

3536
internal func touchChange(
36-
id: AnyHashable,
37+
id: UUID,
3738
kind: TouchKind,
3839
event: TouchChangeEvent,
3940
position: Position2,

Sources/GateEngine/System/HID/Touch/TouchSurface.swift

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

8+
import Foundation
89
import GameMath
910

1011
extension HID {
1112
@MainActor public final class SurfaceDevices {
1213
public private(set) var surfaces: Set<TouchSurface> = []
1314

14-
internal func surfaceForID(_ surfaceID: AnyHashable) -> TouchSurface {
15+
internal func surfaceForID(_ surfaceID: UUID) -> TouchSurface {
1516
if let existing = surfaces.first(where: { $0.id == surfaceID }) {
1617
return existing
1718
}
@@ -21,9 +22,9 @@ extension HID {
2122
}
2223

2324
func surfaceTouchChange(
24-
id: AnyHashable,
25+
id: UUID,
2526
event: TouchChangeEvent,
26-
surfaceID: AnyHashable,
27+
surfaceID: UUID,
2728
normalizedPosition: Position2
2829
) {
2930
self.surfaceForID(surfaceID).touchChange(
@@ -45,11 +46,11 @@ extension HID {
4546
}
4647

4748
@MainActor public final class TouchSurface {
48-
nonisolated let id: AnyHashable
49+
public let id: UUID
4950
public internal(set) var touches: Set<SurfaceTouch> = []
5051
internal var nextTouches: Set<SurfaceTouch> = []
5152

52-
internal init(id: AnyHashable) {
53+
internal init(id: UUID) {
5354
self.id = id
5455
}
5556

@@ -69,12 +70,12 @@ extension HID {
6970
return touches.first(where: { $0.phase == phase })
7071
}
7172

72-
private func existingTouch(_ id: AnyHashable) -> SurfaceTouch? {
73+
private func existingTouch(_ id: UUID) -> SurfaceTouch? {
7374
return touches.first(where: { $0.id == id })
7475
}
7576

7677
internal func touchChange(
77-
id: AnyHashable,
78+
id: UUID,
7879
event: TouchChangeEvent,
7980
normalizedPosition: Position2
8081
) {
@@ -118,7 +119,7 @@ extension HID.TouchSurface: Hashable {
118119
}
119120

120121
@MainActor public class SurfaceTouch {
121-
public internal(set) var id: AnyHashable
122+
public let id: UUID
122123
public internal(set) var position: Position2
123124
public internal(set) var phase: Phase
124125
public enum Phase {
@@ -127,7 +128,7 @@ extension HID.TouchSurface: Hashable {
127128
case cancelled
128129
}
129130

130-
init(id: AnyHashable, normalizedPosition: Position2, phase: Phase) {
131+
init(id: UUID, normalizedPosition: Position2, phase: Phase) {
131132
self.id = id
132133
self.position = normalizedPosition
133134
self.phase = phase
@@ -136,13 +137,13 @@ extension HID.TouchSurface: Hashable {
136137

137138
extension SurfaceTouch: Equatable {
138139
@inlinable
139-
public static func == (lhs: SurfaceTouch, rhs: SurfaceTouch) -> Bool {
140+
public nonisolated static func == (lhs: SurfaceTouch, rhs: SurfaceTouch) -> Bool {
140141
return lhs.id == rhs.id
141142
}
142143
}
143144
extension SurfaceTouch: Hashable {
144145
@inlinable
145-
public func hash(into hasher: inout Hasher) {
146+
public nonisolated func hash(into hasher: inout Hasher) {
146147
hasher.combine(id)
147148
}
148149
}

Sources/GateEngine/System/Platforms/Platform Implementations/Apple/AppKit/AppKit/AppKitWindow.swift

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,26 @@ extension AppKitWindow {
300300
final class UGNSWindow: AppKit.NSWindow {
301301
weak var window: Window!
302302
private var touchesIDs: [ObjectIdentifier: UUID] = [:]
303+
private var surfaceIDs: [ObjectIdentifier: UUID] = [:]
304+
305+
func id(forTouch touch: NSTouch) -> UUID {
306+
let objectID = ObjectIdentifier(touch.identity)
307+
if let id = touchesIDs[objectID] {
308+
return id
309+
}
310+
let id = UUID()
311+
touchesIDs[objectID] = id
312+
return id
313+
}
314+
func id(forSurface device: AnyObject) -> UUID {
315+
let objectID = ObjectIdentifier(device)
316+
if let id = surfaceIDs[objectID] {
317+
return id
318+
}
319+
let id = UUID()
320+
surfaceIDs[objectID] = id
321+
return id
322+
}
303323

304324
init(window: Window,
305325
contentRect: NSRect,
@@ -544,8 +564,7 @@ extension UGNSWindow {
544564
let touches = event.touches(matching: .began, in: nil)
545565

546566
for touch in touches {
547-
let id = UUID()
548-
touchesIDs[ObjectIdentifier(touch.identity)] = id
567+
let id = self.id(forTouch: touch)
549568
let type = type(for: touch)
550569
if let position = locationOfTouch(touch, from: event) {
551570
switch touch.type {
@@ -564,7 +583,7 @@ extension UGNSWindow {
564583
Game.shared.hid.surfaceTouchChange(
565584
id: id,
566585
event: .began,
567-
surfaceID: ObjectIdentifier(device),
586+
surfaceID: self.id(forSurface: device),
568587
normalizedPosition: position,
569588
pressure: 0,
570589
window: window
@@ -581,7 +600,7 @@ extension UGNSWindow {
581600
let touches = event.touches(matching: .moved, in: nil)
582601

583602
for touch in touches {
584-
guard let id = touchesIDs[ObjectIdentifier(touch.identity)] else { continue }
603+
let id = self.id(forTouch: touch)
585604
let type = type(for: touch)
586605
if let position = locationOfTouch(touch, from: event) {
587606
switch touch.type {
@@ -600,7 +619,7 @@ extension UGNSWindow {
600619
Game.shared.hid.surfaceTouchChange(
601620
id: id,
602621
event: .moved,
603-
surfaceID: ObjectIdentifier(device),
622+
surfaceID: self.id(forSurface: device),
604623
normalizedPosition: position,
605624
pressure: 0,
606625
window: window
@@ -617,7 +636,7 @@ extension UGNSWindow {
617636
let touches = event.touches(matching: .ended, in: nil)
618637

619638
for touch in touches {
620-
guard let id = touchesIDs[ObjectIdentifier(touch.identity)] else { continue }
639+
let id = self.id(forTouch: touch)
621640
let type = type(for: touch)
622641
if let position = locationOfTouch(touch, from: event) {
623642
switch touch.type {
@@ -636,7 +655,7 @@ extension UGNSWindow {
636655
Game.shared.hid.surfaceTouchChange(
637656
id: id,
638657
event: .ended,
639-
surfaceID: ObjectIdentifier(device),
658+
surfaceID: self.id(forSurface: device),
640659
normalizedPosition: position,
641660
pressure: 0,
642661
window: window
@@ -654,7 +673,7 @@ extension UGNSWindow {
654673
let touches = event.touches(matching: .cancelled, in: nil)
655674

656675
for touch in touches {
657-
guard let id = touchesIDs[ObjectIdentifier(touch.identity)] else { continue }
676+
let id = self.id(forTouch: touch)
658677
let type = type(for: touch)
659678
if let position = locationOfTouch(touch, from: event) {
660679
switch touch.type {
@@ -673,7 +692,7 @@ extension UGNSWindow {
673692
Game.shared.hid.surfaceTouchChange(
674693
id: id,
675694
event: .canceled,
676-
surfaceID: ObjectIdentifier(device),
695+
surfaceID: self.id(forSurface: device),
677696
normalizedPosition: position,
678697
pressure: 0,
679698
window: window

0 commit comments

Comments
 (0)