Skip to content

Commit 533c4c9

Browse files
committed
Chip away at Swift 6
1 parent 918eae5 commit 533c4c9

28 files changed

+125
-122
lines changed

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,9 @@ extension Array where Element == SwiftSetting {
708708
var settings: Self = []
709709

710710
#if compiler(>=6.2)
711+
#if !hasFeature(ImmutableWeakCaptures)
712+
enableFeature("ImmutableWeakCaptures")
713+
#endif
711714
#if !hasFeature(InferIsolatedConformances)
712715
enableFeature("InferIsolatedConformances")
713716
#endif

Sources/GateEngine/Helpers/TextureAtlas.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public final class TextureAtlasBuilder {
152152
- parameter sacrificePerformanceForSize: When `true` additional checks are performed to merge textures that are the same but with different paths. Resulting in a smaller atlas, at the cost of performance.
153153
*/
154154
public func insertTexture(withPath unresolvedPath: String, sacrificePerformanceForSize: Bool = false) throws {
155-
let importer = PNGImporter()
155+
var importer = PNGImporter()
156156
try importer.synchronousPrepareToImportResourceFrom(path: unresolvedPath)
157157
let rawTexture = try importer.synchronousLoadTexture(options: .none)
158158

Sources/GateEngine/Resources/Animation/ObjectAnimation3D.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ extension RawObjectAnimation3D: BinaryCodable {
189189
// MARK: - Resource Manager
190190

191191
public protocol ObjectAnimation3DImporter: ResourceImporter {
192-
func loadObjectAnimation(options: ObjectAnimation3DImporterOptions) async throws(GateEngineError) -> RawObjectAnimation3D
192+
mutating func loadObjectAnimation(options: ObjectAnimation3DImporterOptions) async throws(GateEngineError) -> RawObjectAnimation3D
193193
}
194194

195195
public struct ObjectAnimation3DImporterOptions: Equatable, Hashable, Sendable {
@@ -224,7 +224,7 @@ extension ResourceManager {
224224

225225
extension RawObjectAnimation3D {
226226
public init(path: String, options: ObjectAnimation3DImporterOptions = .none) async throws {
227-
let importer: any ObjectAnimation3DImporter = try await Game.unsafeShared.resourceManager.objectAnimation3DImporterForPath(path)
227+
var importer: any ObjectAnimation3DImporter = try await Game.unsafeShared.resourceManager.objectAnimation3DImporterForPath(path)
228228
self = try await importer.loadObjectAnimation(options: options)
229229
}
230230
}

Sources/GateEngine/Resources/CollisionMesh/CollisionMesh.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public final class CollisionMeshBackend {
9494
// MARK: - Resource Manager
9595

9696
public protocol CollisionMeshImporter: ResourceImporter {
97-
func loadCollisionMesh(options: CollisionMeshImporterOptions) async throws(GateEngineError) -> RawCollisionMesh
97+
mutating func loadCollisionMesh(options: CollisionMeshImporterOptions) async throws(GateEngineError) -> RawCollisionMesh
9898
}
9999

100100
public struct CollisionMeshImporterOptions: Equatable, Hashable, Sendable {
@@ -177,7 +177,7 @@ extension ResourceManager {
177177

178178
public extension RawCollisionMesh {
179179
init(path: String, options: CollisionMeshImporterOptions = .none) async throws {
180-
let importer: any CollisionMeshImporter = try await Game.unsafeShared.resourceManager.collisionMeshImporterForPath(path)
180+
var importer: any CollisionMeshImporter = try await Game.unsafeShared.resourceManager.collisionMeshImporterForPath(path)
181181
self = try await importer.loadCollisionMesh(options: options)
182182
}
183183
}

Sources/GateEngine/Resources/Geometry/Geometry.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ extension Geometry: Equatable, Hashable {
132132
// MARK: - Resource Manager
133133

134134
public protocol GeometryImporter: ResourceImporter {
135-
func loadGeometry(options: GeometryImporterOptions) async throws(GateEngineError) -> RawGeometry
135+
mutating func loadGeometry(options: GeometryImporterOptions) async throws(GateEngineError) -> RawGeometry
136136
}
137137

138138
public struct GeometryImporterOptions: Equatable, Hashable, Sendable {
@@ -194,7 +194,7 @@ extension RawGeometry {
194194
try await self.init(path: path.value, options: options)
195195
}
196196
public init(path: String, options: GeometryImporterOptions = .none) async throws(GateEngineError) {
197-
let importer = try await Game.unsafeShared.resourceManager.geometryImporterForPath(path)
197+
var importer = try await Game.unsafeShared.resourceManager.geometryImporterForPath(path)
198198
self = try await importer.loadGeometry(options: options)
199199
}
200200
}

Sources/GateEngine/Resources/Geometry/Lines.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extension RawLines {
6868
try await self.init(path: path.value, options: options)
6969
}
7070
public init(path: String, options: GeometryImporterOptions = .none) async throws(GateEngineError) {
71-
let importer = try await Game.unsafeShared.resourceManager.geometryImporterForPath(path)
71+
var importer = try await Game.unsafeShared.resourceManager.geometryImporterForPath(path)
7272
let rawGeometry = try await importer.loadGeometry(options: options)
7373
self.init(wireframeFrom: rawGeometry)
7474
}

Sources/GateEngine/Resources/Geometry/Points.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extension RawPoints {
6868
try await self.init(path: path.value, options: options)
6969
}
7070
public init(path: String, options: GeometryImporterOptions = .none) async throws(GateEngineError) {
71-
let importer = try await Game.unsafeShared.resourceManager.geometryImporterForPath(path)
71+
var importer = try await Game.unsafeShared.resourceManager.geometryImporterForPath(path)
7272
let rawGeometry = try await importer.loadGeometry(options: options)
7373
self.init(pointCloudFrom: rawGeometry)
7474
}

Sources/GateEngine/Resources/Import & Export/Importers/ApplePlatformImageImporter.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import CoreServices
1212
import GameMath
1313
import UniformTypeIdentifiers
1414

15-
public final class ApplePlatformImageImporter: TextureImporter {
15+
public struct ApplePlatformImageImporter: TextureImporter {
1616
var data: Data! = nil
1717
var size: Size2i! = nil
18-
public required init() {}
18+
public init() {}
1919

20-
public func synchronousPrepareToImportResourceFrom(path: String) throws(GateEngineError) {
20+
public mutating func synchronousPrepareToImportResourceFrom(path: String) throws(GateEngineError) {
2121
do {
2222
let data = try Platform.current.synchronousLoadResource(from: path)
2323
try self.populateFromData(data)
@@ -26,7 +26,7 @@ public final class ApplePlatformImageImporter: TextureImporter {
2626
}
2727
}
2828

29-
public func prepareToImportResourceFrom(path: String) async throws(GateEngineError) {
29+
public mutating func prepareToImportResourceFrom(path: String) async throws(GateEngineError) {
3030
do {
3131
let data = try await Platform.current.loadResource(from: path)
3232
try self.populateFromData(data)
@@ -35,7 +35,7 @@ public final class ApplePlatformImageImporter: TextureImporter {
3535
}
3636
}
3737

38-
func populateFromData(_ data: Data) throws(GateEngineError) {
38+
mutating func populateFromData(_ data: Data) throws(GateEngineError) {
3939
do {
4040
guard let imageSource = CGImageSourceCreateWithData(data as CFData, nil) else {
4141
throw GateEngineError.failedToDecode("Failed to decode image source.")
@@ -53,11 +53,11 @@ public final class ApplePlatformImageImporter: TextureImporter {
5353
}
5454
}
5555

56-
public func synchronousLoadTexture(options: TextureImporterOptions) throws(GateEngineError) -> RawTexture {
56+
public mutating func synchronousLoadTexture(options: TextureImporterOptions) throws(GateEngineError) -> RawTexture {
5757
return RawTexture(imageSize: size, imageData: data)
5858
}
5959

60-
public func loadTexture(options: TextureImporterOptions) async throws(GateEngineError) -> RawTexture {
60+
public mutating func loadTexture(options: TextureImporterOptions) async throws(GateEngineError) -> RawTexture {
6161
return try synchronousLoadTexture(options: options)
6262
}
6363

Sources/GateEngine/Resources/Import & Export/Importers/ApplePlatformModelImporter.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#if canImport(Darwin) && canImport(ModelIO)
88

99
import Foundation
10-
import ModelIO
10+
@preconcurrency import ModelIO
1111

12-
public final class ApplePlatformModelImporter: GeometryImporter {
13-
public required init() {}
12+
public struct ApplePlatformModelImporter: GeometryImporter {
13+
public init() {}
1414

1515
private func positions(from mesh: MDLMesh) throws(GateEngineError) -> [Float] {
1616
guard let attributeData = mesh.vertexAttributeData(
@@ -138,11 +138,11 @@ public final class ApplePlatformModelImporter: GeometryImporter {
138138
}
139139

140140
var asset: MDLAsset! = nil
141-
public func synchronousPrepareToImportResourceFrom(path: String) throws(GateEngineError) {
141+
public mutating func synchronousPrepareToImportResourceFrom(path: String) throws(GateEngineError) {
142142
guard let path = Platform.current.synchronousLocateResource(from: path) else {throw .failedToLocate(resource: path, nil) }
143143
self.asset = MDLAsset(url: URL(fileURLWithPath: path))
144144
}
145-
public func prepareToImportResourceFrom(path: String) async throws(GateEngineError) {
145+
public mutating func prepareToImportResourceFrom(path: String) async throws(GateEngineError) {
146146
guard let path = await Platform.current.locateResource(from: path) else {throw .failedToLocate(resource: path, nil) }
147147
self.asset = await withCheckedContinuation { continuation in
148148
Task.detached {
@@ -152,7 +152,7 @@ public final class ApplePlatformModelImporter: GeometryImporter {
152152
}
153153
}
154154

155-
public func loadGeometry(options: GeometryImporterOptions) async throws(GateEngineError) -> RawGeometry {
155+
public mutating func loadGeometry(options: GeometryImporterOptions) async throws(GateEngineError) -> RawGeometry {
156156
for meshIndex in 0 ..< asset.count {
157157
guard let mesh = asset.object(at: meshIndex) as? MDLMesh else {
158158
throw GateEngineError.failedToDecode("mesh[\(meshIndex)] is not a MDLMesh instance.")

Sources/GateEngine/Resources/Import & Export/Importers/GLTransmissionFormat.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension GLTF {
2626
case mat4 = "MAT4"
2727
}
2828
}
29-
private class GLTF: Decodable {
29+
private struct GLTF: Decodable, Sendable {
3030
var baseURL: URL? = nil
3131

3232
let scene: Int
@@ -259,7 +259,7 @@ private class GLTF: Decodable {
259259
}
260260

261261
lazy var cachedBuffers: [Data?] = Array(repeating: nil, count: buffers.count)
262-
func buffer(at index: Int) -> Data? {
262+
mutating func buffer(at index: Int) -> Data? {
263263
// Buffer 0 is pre-cached for glb files
264264
// So `existing` will always be present for index 0 of a glb file
265265
if let existing = cachedBuffers[index] {
@@ -282,7 +282,7 @@ private class GLTF: Decodable {
282282
return buffer
283283
}
284284

285-
func values<T: BinaryInteger>(forAccessor accessorIndex: Int) async -> [T]? {
285+
mutating func values<T: BinaryInteger>(forAccessor accessorIndex: Int) async -> [T]? {
286286
let accessor = accessors[accessorIndex]
287287
let bufferView = bufferViews[accessor.bufferView]
288288
let count = accessor.count * accessor.primitiveCount
@@ -366,7 +366,7 @@ private class GLTF: Decodable {
366366
}
367367
}
368368

369-
func values<T: BinaryFloatingPoint>(forAccessor accessorIndex: Int) async -> [T]? {
369+
mutating func values<T: BinaryFloatingPoint>(forAccessor accessorIndex: Int) async -> [T]? {
370370
let accessor = accessors[accessorIndex]
371371
let bufferView = bufferViews[accessor.bufferView]
372372
let count = accessor.count * accessor.primitiveCount
@@ -450,7 +450,7 @@ private class GLTF: Decodable {
450450
}
451451
}
452452

453-
func animationValues<T: BinaryFloatingPoint>(forAccessor accessorIndex: Int) async -> [T]? {
453+
mutating func animationValues<T: BinaryFloatingPoint>(forAccessor accessorIndex: Int) async -> [T]? {
454454
let accessor = accessors[accessorIndex]
455455
let bufferView = bufferViews[accessor.bufferView]
456456
let count = accessor.count * accessor.primitiveCount
@@ -693,32 +693,32 @@ public extension GLTransmissionFormat {
693693
}
694694
}
695695

696-
public final class GLTransmissionFormat: ResourceImporter {
696+
public struct GLTransmissionFormat: ResourceImporter {
697697
fileprivate var gltf: GLTF! = nil
698-
required public init() {}
698+
public init() {}
699699

700-
public func synchronousPrepareToImportResourceFrom(path: String) throws(GateEngineError) {
700+
public mutating func synchronousPrepareToImportResourceFrom(path: String) throws(GateEngineError) {
701701
guard let path = Platform.current.synchronousLocateResource(from: path) else { throw .failedToLocate(resource: path, nil) }
702702
let baseURL = URL(fileURLWithPath: path).deletingLastPathComponent()
703703
do {
704704
let data = try Platform.current.synchronousLoadResource(from: path)
705-
self.gltf = try gltf(from: data, baseURL: baseURL)
705+
self.gltf = try Self.gltf(from: data, baseURL: baseURL)
706706
}catch{
707707
throw GateEngineError(error)
708708
}
709709
}
710-
public func prepareToImportResourceFrom(path: String) async throws(GateEngineError) {
710+
public mutating func prepareToImportResourceFrom(path: String) async throws(GateEngineError) {
711711
guard let path = await Platform.current.locateResource(from: path) else { throw .failedToLocate(resource: path, nil) }
712712
let baseURL = URL(fileURLWithPath: path).deletingLastPathComponent()
713713
do {
714714
let data = try await Platform.current.loadResource(from: path)
715-
self.gltf = try gltf(from: data, baseURL: baseURL)
715+
self.gltf = try Self.gltf(from: data, baseURL: baseURL)
716716
}catch{
717717
throw GateEngineError(error)
718718
}
719719
}
720720

721-
fileprivate func gltf(from data: Data, baseURL: URL) throws -> GLTF {
721+
fileprivate static func gltf(from data: Data, baseURL: URL) throws -> GLTF {
722722
var jsonData: Data = data
723723
var bufferData: Data? = nil
724724
if data[0 ..< 4] == Data("glTF".utf8) {
@@ -728,7 +728,7 @@ public final class GLTransmissionFormat: ResourceImporter {
728728
jsonData = data.advanced(by: 20)[..<byteCount]
729729
bufferData = data.advanced(by: (byteCount + 28))
730730
}
731-
let gltf = try JSONDecoder().decode(GLTF.self, from: jsonData)
731+
var gltf = try JSONDecoder().decode(GLTF.self, from: jsonData)
732732
gltf.baseURL = baseURL
733733
gltf.cachedBuffers[0] = bufferData
734734
return gltf
@@ -749,7 +749,7 @@ public final class GLTransmissionFormat: ResourceImporter {
749749
}
750750

751751
extension GLTransmissionFormat: GeometryImporter {
752-
public func loadGeometry(options: GeometryImporterOptions) async throws(GateEngineError) -> RawGeometry {
752+
public mutating func loadGeometry(options: GeometryImporterOptions) async throws(GateEngineError) -> RawGeometry {
753753
guard gltf.meshes != nil else {throw GateEngineError.failedToDecode("File contains no geometry.")}
754754

755755
var mesh: GLTF.Mesh? = nil
@@ -921,7 +921,7 @@ extension GLTransmissionFormat: SkinImporter {
921921
}
922922
return nil
923923
}
924-
private func inverseBindMatrices(
924+
private mutating func inverseBindMatrices(
925925
from bufferView: GLTF.BufferView,
926926
expecting count: Int
927927
) async -> [Matrix4x4]? {
@@ -945,7 +945,7 @@ extension GLTransmissionFormat: SkinImporter {
945945
})
946946
}
947947

948-
public func loadSkin(options: SkinImporterOptions) async throws(GateEngineError) -> RawSkin {
948+
public mutating func loadSkin(options: SkinImporterOptions) async throws(GateEngineError) -> RawSkin {
949949
guard let skins = gltf.skins, skins.isEmpty == false else {
950950
throw GateEngineError.failedToDecode("File contains no skins.")
951951
}
@@ -1055,7 +1055,7 @@ extension GLTransmissionFormat: SkeletonImporter {
10551055
return gltf.scenes[gltf.scene].nodes?.first
10561056
}
10571057

1058-
public func loadSkeleton(options: SkeletonImporterOptions) async throws(GateEngineError) -> RawSkeleton {
1058+
public mutating func loadSkeleton(options: SkeletonImporterOptions) async throws(GateEngineError) -> RawSkeleton {
10591059
guard let rootNode = skeletonNode(named: options.subobjectName) else {
10601060
throw GateEngineError.failedToDecode("Couldn't find skeleton root.")
10611061
}
@@ -1095,7 +1095,7 @@ extension GLTransmissionFormat: SkeletalAnimationImporter {
10951095
return gltf.animations?.first
10961096
}
10971097

1098-
public func loadSkeletalAnimation(options: SkeletalAnimationImporterOptions) async throws(GateEngineError) -> RawSkeletalAnimation {
1098+
public mutating func loadSkeletalAnimation(options: SkeletalAnimationImporterOptions) async throws(GateEngineError) -> RawSkeletalAnimation {
10991099
guard let animation = animation(named: options.subobjectName) else {
11001100
throw GateEngineError.failedToDecode(
11011101
"Couldn't find animation: \"\(options.subobjectName!)\".\nAvailable Animations: \((gltf.animations ?? []).map({$0.name}))"
@@ -1238,7 +1238,7 @@ extension GLTransmissionFormat: SkeletalAnimationImporter {
12381238
}
12391239

12401240
extension GLTransmissionFormat: ObjectAnimation3DImporter {
1241-
public func loadObjectAnimation(options: ObjectAnimation3DImporterOptions) async throws(GateEngineError) -> RawObjectAnimation3D {
1241+
public mutating func loadObjectAnimation(options: ObjectAnimation3DImporterOptions) async throws(GateEngineError) -> RawObjectAnimation3D {
12421242
guard let animation = animation(named: options.subobjectName) else {
12431243
throw GateEngineError.failedToDecode(
12441244
"Couldn't find animation: \"\(options.subobjectName!)\".\nAvailable Animations: \((gltf.animations ?? []).map({$0.name}))"
@@ -1339,7 +1339,7 @@ extension GLTransmissionFormat: ObjectAnimation3DImporter {
13391339

13401340
extension GLTransmissionFormat: TextureImporter {
13411341
// TODO: Supports only PNG. Add other formats (JPEG, WebP, ...)
1342-
public func synchronousLoadTexture(options: TextureImporterOptions) throws(GateEngineError) -> RawTexture {
1342+
public mutating func synchronousLoadTexture(options: TextureImporterOptions) throws(GateEngineError) -> RawTexture {
13431343
let imageData: Data
13441344
func loadImageData(image: GLTF.Image) throws(GateEngineError) -> Data {
13451345
if let uri = image.uri {
@@ -1375,13 +1375,13 @@ extension GLTransmissionFormat: TextureImporter {
13751375
return try PNGDecoder().decode(imageData)
13761376
}
13771377

1378-
public func loadTexture(options: TextureImporterOptions) async throws(GateEngineError) -> RawTexture {
1378+
public mutating func loadTexture(options: TextureImporterOptions) async throws(GateEngineError) -> RawTexture {
13791379
return try synchronousLoadTexture(options: options)
13801380
}
13811381
}
13821382

13831383
extension GLTransmissionFormat: CollisionMeshImporter {
1384-
public func loadCollisionMesh(options: CollisionMeshImporterOptions) async throws(GateEngineError) -> RawCollisionMesh {
1384+
public mutating func loadCollisionMesh(options: CollisionMeshImporterOptions) async throws(GateEngineError) -> RawCollisionMesh {
13851385
guard gltf.meshes != nil else {throw GateEngineError.failedToDecode("File contains no geometry.")}
13861386

13871387
var mesh: GLTF.Mesh? = nil

0 commit comments

Comments
 (0)