@@ -15,9 +15,9 @@ public struct LaunchOptions: OptionSet {
1515 }
1616}
1717
18- @ MainActor public protocol GameDelegate : AnyObject {
18+ public protocol GameDelegate : AnyObject {
1919 /// Called when the app finishes loading.
20- func didFinishLaunching( game: Game , options: LaunchOptions )
20+ @ MainActor func didFinishLaunching( game: Game , options: LaunchOptions )
2121
2222 /**
2323 Create a customized mainWindow
@@ -26,19 +26,19 @@ public struct LaunchOptions: OptionSet {
2626 - parameter game: The game to create the window from
2727 - parameter identifier: The identifier to give the window. You must use this identifier.
2828 */
29- func createMainWindow( game: Game , identifier: String ) throws -> Window
29+ @ MainActor func createMainWindow( game: Game , identifier: String ) throws -> Window
3030
3131 /// The end user has tried to open a window using the platforms mechanisms
32- func userRequestedWindow( game: Game ) throws -> Window ?
32+ @ MainActor func userRequestedWindow( game: Game ) throws -> Window ?
3333
3434 /**
3535 A display has been attached.
3636 - returns: A new window instance to put on the screen. Passing an existing window is undefined behaviour.
3737 */
38- func screenBecomeAvailable( game: Game ) throws -> Window ?
38+ @ MainActor func screenBecomeAvailable( game: Game ) throws -> Window ?
3939
4040 /// Might be called immediatley before the app closes.
41- func willTerminate( game: Game )
41+ @ MainActor func willTerminate( game: Game )
4242
4343 /**
4444 Start the game with no window and skip updating RenderingSystem(s).
@@ -51,7 +51,7 @@ public struct LaunchOptions: OptionSet {
5151 - returns: true if the game doesn't draw anything.
5252 - note: RenderingSystem(s) do not recive updates in headless mode.
5353 */
54- func isHeadless( ) -> Bool
54+ @ MainActor func isHeadless( ) -> Bool
5555
5656 /**
5757 Add additional search paths for resources.
@@ -60,13 +60,21 @@ public struct LaunchOptions: OptionSet {
6060 Search paths for your Swift Packages are already located automatically and don't need to be added here.
6161 - returns: An array of URLs each pointing to a directory containing game resources.
6262 */
63- func resourceSearchPaths( ) -> [ URL ]
63+ nonisolated func resourceSearchPaths( ) -> [ URL ]
6464
65- init ( )
65+ /**
66+ An ID for the current game. This identifier is used for storing user settings.
67+
68+ By providing a stable identifier, you're free to rename your executable without breaking user settings.
69+ By default the executablke name is used.
70+ */
71+ nonisolated func gameIdentifier( ) -> StaticString ?
72+
73+ @MainActor init ( )
6674}
6775
6876public extension GameDelegate {
69- func createMainWindow( game: Game , identifier: String ) throws -> Window {
77+ @ MainActor func createMainWindow( game: Game , identifier: String ) throws -> Window {
7078 return try game. windowManager. createWindow ( identifier: identifier, style: . system, options: . defaultForMainWindow)
7179 }
7280 func userRequestedWindow( game: Game ) throws -> Window ? { return nil }
@@ -75,13 +83,21 @@ public extension GameDelegate {
7583 func willTerminate( game: Game ) { }
7684 func isHeadless( ) -> Bool { return false }
7785 func resourceSearchPaths( ) -> [ URL ] { return [ ] }
86+
87+ func gameIdentifier( ) -> StaticString ? { return nil }
88+
89+ @_transparent
90+ internal func resolvedGameIdentifier( ) -> String {
91+ if let identifer: StaticString = self . gameIdentifier ( ) {
92+ return identifer. description
93+ }
94+ return CommandLine . arguments [ 0 ]
95+ }
7896}
7997
8098public extension GameDelegate {
81- static func main( ) {
99+ @ MainActor static func main( ) {
82100 Game . shared = Game ( delegate: Self ( ) )
83101 Game . shared. platform. main ( )
84102 }
85103}
86-
87-
0 commit comments