Skip to content

Commit e43aa4b

Browse files
committed
Chip away at Swift 6
1 parent 9692277 commit e43aa4b

34 files changed

+118
-117
lines changed

Macros/ECSMacros/ECSComponentMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public struct ECSComponentMacro: MemberMacro, ExtensionMacro {
5555
return false
5656
})?.trimmedDescription ?? ""
5757

58-
var extensionBody = "\(access) static let componentID: GateEngine.ComponentID = .init()"
58+
let extensionBody = "\(access) static let componentID: GateEngine.ComponentID = .init()"
5959

6060
// let find = try InitializerDeclSyntax("init()") {
6161
//

Macros/ECSMacros/ECSSystemMacro.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public struct ECSSystemMacro: MemberMacro, ExtensionMacro {
5353
) throws -> [SwiftSyntax.ExtensionDeclSyntax] {
5454
guard protocols.contains(where: {$0 == "GateEngine.System"}) == false else { return [] }
5555

56-
guard let classDecl = declaration.as(ClassDeclSyntax.self) else {
56+
guard let /*classDecl*/_ = declaration.as(ClassDeclSyntax.self) else {
5757
throw SystemMacroError.notClass
5858
}
5959

60-
let className = classDecl.name.trimmed
60+
// let className = classDecl.name.trimmed
6161

6262
// var protocols: [ExtensionDeclSyntax] = [try ProtocolDeclSyntax("GateEngine.System")] + protocols
6363
// return protocols

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ let package = Package(
269269
path: "Dependencies/miniz",
270270
cSettings: [
271271
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
272+
.unsafeFlags(["-Wno-conversion"]),
272273
]),
273274

274275
// libspng
@@ -281,6 +282,7 @@ let package = Package(
281282
// When public, the miniz.h header crashes Clang on Windows since Swift 5.8.0
282283
.headerSearchPath("src/"),
283284
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
285+
.unsafeFlags(["-Wno-conversion"]),
284286
]),
285287

286288
// TrueType
@@ -290,6 +292,7 @@ let package = Package(
290292
.define("STB_TRUETYPE_IMPLEMENTATION"), .define("STB_RECT_PACK_IMPLEMENTATION"),
291293
.define("extern", to: "__declspec(dllexport) extern", .when(platforms: [.windows])),
292294
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])), // Silence warnings
295+
.unsafeFlags(["-Wno-conversion"]),
293296
]),
294297

295298
// Gravity

Sources/GateEngine/ECS/3D Specific/ObjectAnimation/ObjectAnimation3DComponent.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ extension ObjectAnimation3DComponent {
119119
}
120120

121121
extension Entity {
122+
@MainActor
122123
@inlinable
123-
public var objectAnimation3DComponent: ObjectAnimation3DComponent {
124-
return self[ObjectAnimation3DComponent.self]
124+
public var objectAnimation3DComponent: ObjectAnimation3DComponent? {
125+
return self.component(ofType: ObjectAnimation3DComponent.self)
125126
}
126127
}

Sources/GateEngine/ECS/3D Specific/Physics/OctreeComponent.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ extension OctreeComponent {
177177

178178
self.cleanEmptyNodes()
179179

180-
Task {@MainActor in
181-
self.didLoad = true
182-
}
180+
self.didLoad = true
183181
}
184182

185183
private func setup(size: Size3, offset: Position3, position: Position3) {

Sources/GateEngine/ECS/3D Specific/Rig/Rig3DComponent.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,9 @@ public class RigAttachmentComponent: Component {
341341
}
342342

343343
extension Entity {
344+
@MainActor
344345
@inlinable
345-
public var rig3DComponent: Rig3DComponent {
346-
return self[Rig3DComponent.self]
346+
public var rig3DComponent: Rig3DComponent? {
347+
return self.component(ofType: Rig3DComponent.self)
347348
}
348349
}

Sources/GateEngine/ECS/Base/Entity.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ extension Entity {
9898
}
9999

100100
@inlinable
101-
@available(*, deprecated, message: "Accessing a ResourceConstrainedComponent directly is never safe. Use Entity.component(ofType:) instead.", renamed: "component(ofType:)")
102101
public subscript<T: ResourceConstrainedComponent>(_ type: T.Type) -> T {
103102
get {
104103
let componentID = type.componentID.value

Sources/GateEngine/Game.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ public final class Game {
1616

1717
public let delegate: any GameDelegate
1818

19-
@MainActor public private(set) var state: State! = nil
20-
@MainActor internal private(set) var internalState: State! = nil
21-
22-
nonisolated(unsafe) public internal(set) lazy var info: Game.Info = Game.Info()
19+
nonisolated public let info: Game.Info
2320

2421
nonisolated public let isHeadless: Bool
2522
@MainActor internal init(delegate: any GameDelegate) {
2623
self.delegate = delegate
24+
self.info = Game.Info(gameDelegate: delegate)
2725
if delegate.isHeadless() {
2826
self.renderer = nil
2927
self.isHeadless = true
@@ -54,13 +52,9 @@ public final class Game {
5452
@usableFromInline
5553
@MainActor internal private(set) lazy var ecs: ECSContext = ECSContext()
5654
@MainActor public private(set) lazy var hid: HID = HID()
57-
public private(set) lazy var resourceManager: ResourceManager = {
58-
return ResourceManager(game: self)
59-
}()
55+
nonisolated public let resourceManager: ResourceManager = ResourceManager()
6056

6157
@MainActor func didFinishLaunching() async {
62-
self.state = await platform.loadState(named: "SaveState.json")
63-
self.internalState = await platform.loadState(named: "GateEngine.json")
6458
#if !GATEENGINE_PLATFORM_CREATES_MAINWINDOW
6559
if isHeadless == false {
6660
do {

Sources/GateEngine/GameDelegate.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public struct LaunchOptions: OptionSet {
1515
}
1616
}
1717

18+
@MainActor
1819
public protocol GameDelegate: AnyObject {
1920
/// Return false exit the program
2021
func shouldFinishLaunching(game: Game) async throws -> Bool
2122

2223
/// Called when the app finishes loading.
23-
@MainActor
2424
func didFinishLaunching(game: Game, options: LaunchOptions) async
2525

2626
/**
@@ -30,22 +30,18 @@ public protocol GameDelegate: AnyObject {
3030
- parameter game: The game to create the window from
3131
- parameter identifier: The identifier to give the window. You must use this identifier.
3232
*/
33-
@MainActor
3433
func createMainWindow(using manager: WindowManager, with identifier: String) throws -> Window
3534

3635
/// The end user has tried to open a window using the platforms mechanisms
37-
@MainActor
3836
func createUserRequestedWindow(using manager: WindowManager) throws -> Window?
3937

4038
/**
4139
A display has been attached.
4240
- returns: A new window instance to put on the screen. Passing an existing window is undefined behaviour.
4341
*/
44-
@MainActor
4542
func createWindowForExternalScreen(using manager: WindowManager) throws -> Window?
4643

4744
/// Might be called immediately before the app closes.
48-
@MainActor
4945
func willTerminate(game: Game)
5046

5147
/**
@@ -59,7 +55,6 @@ public protocol GameDelegate: AnyObject {
5955
- returns: true if the game doesn't draw anything.
6056
- note: RenderingSystem(s) do not receive updates in headless mode.
6157
*/
62-
@MainActor
6358
func isHeadless() -> Bool
6459

6560
/**
@@ -97,13 +92,13 @@ extension GameDelegate {
9792
public func willTerminate(game: Game) {}
9893
public func isHeadless() -> Bool { return false }
9994
public func customResourceLocations() -> [String] { return [] }
100-
internal func resolvedCustomResourceLocations() -> [URL] {
95+
internal nonisolated func resolvedCustomResourceLocations() -> [URL] {
10196
return customResourceLocations().compactMap({ URL(string: $0) })
10297
}
10398

104-
public func gameIdentifier() -> StaticString? { return nil }
99+
public nonisolated func gameIdentifier() -> StaticString? { return nil }
105100

106-
internal func resolvedGameIdentifier() -> String {
101+
internal nonisolated func resolvedGameIdentifier() -> String {
107102
let charSet = CharacterSet(
108103
charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-."
109104
)
@@ -159,8 +154,9 @@ extension GameDelegate {
159154
}
160155
}
161156

157+
@MainActor
162158
extension GameDelegate {
163-
@MainActor public static func main() async throws {
159+
public static func main() async throws {
164160
let delegate = Self()
165161
Game._shared = Game(delegate: delegate)
166162
if try await delegate.shouldFinishLaunching(game: Game.shared) == true {

Sources/GateEngine/GameInfo.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public extension Game {
99
struct Info: Sendable {
10-
public let identifier: String = Game.unsafeShared.delegate.resolvedGameIdentifier()
10+
public let identifier: String
1111

1212
public var executableName: String {
1313
if let executableName = executableURL?.lastPathComponent {
@@ -28,5 +28,9 @@ public extension Game {
2828
}
2929
return nil
3030
}()
31+
32+
init(gameDelegate delegate: any GameDelegate) {
33+
self.identifier = delegate.resolvedGameIdentifier()
34+
}
3135
}
3236
}

0 commit comments

Comments
 (0)