diff --git a/src/MeloNX/MeloNX.xcodeproj/project.xcworkspace/xcuserdata/stossy11.xcuserdatad/UserInterfaceState.xcuserstate b/src/MeloNX/MeloNX.xcodeproj/project.xcworkspace/xcuserdata/stossy11.xcuserdatad/UserInterfaceState.xcuserstate index a14a186c8..c3855c670 100644 Binary files a/src/MeloNX/MeloNX.xcodeproj/project.xcworkspace/xcuserdata/stossy11.xcuserdatad/UserInterfaceState.xcuserstate and b/src/MeloNX/MeloNX.xcodeproj/project.xcworkspace/xcuserdata/stossy11.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/src/MeloNX/MeloNX/Core/Swift/Ryujinx.swift b/src/MeloNX/MeloNX/Core/Swift/Ryujinx.swift index e444c30bd..3a1c8c454 100644 --- a/src/MeloNX/MeloNX/Core/Swift/Ryujinx.swift +++ b/src/MeloNX/MeloNX/Core/Swift/Ryujinx.swift @@ -35,21 +35,24 @@ class Ryujinx { } isRunning = true - + // Start The Emulation on the main thread DispatchQueue.main.async { do { let args = self.buildCommandLineArgs(from: config) + + // Convert Arguments to ones that Ryujinx can Read let cArgs = args.map { strdup($0) } defer { cArgs.forEach { free($0) } } - var argvPtrs = cArgs + + // Start the emulation let result = main_ryujinx_sdl(Int32(args.count), &argvPtrs) - + if result != 0 { self.isRunning = false throw RyujinxError.executionError(code: result) } - + // Start The Emulation loop (probably not needed) self.runEmulationLoop() } catch { self.isRunning = false @@ -87,27 +90,29 @@ class Ryujinx { // Add the game path args.append(config.gamepath) - + // Starts with vulkan args.append("--graphics-backend") args.append("Vulkan") + // Fixes the Stubs.DispatchLoop Crash args.append(contentsOf: ["--memory-manager-mode", "SoftwarePageTable"]) args.append(contentsOf: ["--fullscreen", "true"]) + // Debug Logs args.append(contentsOf: ["--enable-debug-logs", String(config.debuglogs)]) args.append(contentsOf: ["--enable-trace-logs", String(config.tracelogs)]) - // Add list input IDs option + // List the input ids if config.listinputids { args.append(contentsOf: ["--list-inputs-ids"]) } - // Add input IDs, limiting to the first 4 + // Append the input ids (limit to 4 just in case) if !config.inputids.isEmpty { config.inputids.prefix(4).enumerated().forEach { index, inputId in args.append(contentsOf: ["--input-id-\(index + 1)", inputId]) } } - // Add any additional arguments + // Apped any additional arguments args.append(contentsOf: config.additionalArgs) return args diff --git a/src/MeloNX/MeloNX/Views/ContentView.swift b/src/MeloNX/MeloNX/Views/ContentView.swift index a145e06aa..3652fbb4e 100644 --- a/src/MeloNX/MeloNX/Views/ContentView.swift +++ b/src/MeloNX/MeloNX/Views/ContentView.swift @@ -15,10 +15,12 @@ struct ContentView: View { init() { // Initialize SDL - SDL_SetMainReady() - SDL_iPhoneSetEventPump(SDL_TRUE) - - SDL_Init(SDL_INIT_VIDEO) + DispatchQueue.main.async { + SDL_SetMainReady() + SDL_iPhoneSetEventPump(SDL_TRUE) + + SDL_Init(SDL_INIT_VIDEO) + } } func setupVirtualController() { @@ -48,7 +50,7 @@ struct ContentView: View { let config = Ryujinx.Configuration(gamepath: game.path, debuglogs: true, tracelogs: true, listinputids: false, inputids: ["1-47150005-05ac-0000-0100-00004f066d01"]) - + // Starts the emulation do { try Ryujinx().start(with: config) } catch { diff --git a/src/MeloNX/MeloNX/Views/SDLView/SDLView.swift b/src/MeloNX/MeloNX/Views/SDLView/SDLView.swift index a8f97332b..07a7f910e 100644 --- a/src/MeloNX/MeloNX/Views/SDLView/SDLView.swift +++ b/src/MeloNX/MeloNX/Views/SDLView/SDLView.swift @@ -26,20 +26,23 @@ class SDLView: UIView { private func makeSDLWindow() { DispatchQueue.main.async { [self] in + + // Gets window created from Ryujinx sdlwin = SDL_GetWindowFromID(1) + // Check if it got the window. guard sdlwin != nil else { print("Error getting SDL window: \(String(cString: SDL_GetError()))") return } - + // Create metal View from the Window mtkview = SDL_Metal_CreateView(sdlwin) if mtkview == nil { print("Failed to create SDL Metal view.") return } - + // Convert Metal View to Sublayer if let metalLayerPointer = SDL_Metal_GetLayer(mtkview) { let metalLayer = Unmanaged.fromOpaque(metalLayerPointer).takeUnretainedValue() metalLayer.device = MTLCreateSystemDefaultDevice() diff --git a/src/MeloNX/MeloNX/Views/SDLView/SDLViewRepresentable.swift b/src/MeloNX/MeloNX/Views/SDLView/SDLViewRepresentable.swift index 4ab086466..a8b985693 100644 --- a/src/MeloNX/MeloNX/Views/SDLView/SDLViewRepresentable.swift +++ b/src/MeloNX/MeloNX/Views/SDLView/SDLViewRepresentable.swift @@ -11,6 +11,7 @@ import SwiftUI struct SDLViewRepresentable: UIViewRepresentable { let configure: () -> Void func makeUIView(context: Context) -> SDLView { + // Configure (start ryu) before initialsing SDLView so SDLView can get the SDL_Window from Ryu configure() let view = SDLView(frame: .zero) return view