This commit is contained in:
stossy11 2024-11-03 13:32:35 +11:00
parent 165bb0c5d2
commit b86e3301bb
5 changed files with 26 additions and 15 deletions

View File

@ -35,21 +35,24 @@ class Ryujinx {
} }
isRunning = true isRunning = true
// Start The Emulation on the main thread
DispatchQueue.main.async { DispatchQueue.main.async {
do { do {
let args = self.buildCommandLineArgs(from: config) let args = self.buildCommandLineArgs(from: config)
// Convert Arguments to ones that Ryujinx can Read
let cArgs = args.map { strdup($0) } let cArgs = args.map { strdup($0) }
defer { cArgs.forEach { free($0) } } defer { cArgs.forEach { free($0) } }
var argvPtrs = cArgs var argvPtrs = cArgs
// Start the emulation
let result = main_ryujinx_sdl(Int32(args.count), &argvPtrs) let result = main_ryujinx_sdl(Int32(args.count), &argvPtrs)
if result != 0 { if result != 0 {
self.isRunning = false self.isRunning = false
throw RyujinxError.executionError(code: result) throw RyujinxError.executionError(code: result)
} }
// Start The Emulation loop (probably not needed)
self.runEmulationLoop() self.runEmulationLoop()
} catch { } catch {
self.isRunning = false self.isRunning = false
@ -87,27 +90,29 @@ class Ryujinx {
// Add the game path // Add the game path
args.append(config.gamepath) args.append(config.gamepath)
// Starts with vulkan
args.append("--graphics-backend") args.append("--graphics-backend")
args.append("Vulkan") args.append("Vulkan")
// Fixes the Stubs.DispatchLoop Crash
args.append(contentsOf: ["--memory-manager-mode", "SoftwarePageTable"]) args.append(contentsOf: ["--memory-manager-mode", "SoftwarePageTable"])
args.append(contentsOf: ["--fullscreen", "true"]) args.append(contentsOf: ["--fullscreen", "true"])
// Debug Logs
args.append(contentsOf: ["--enable-debug-logs", String(config.debuglogs)]) args.append(contentsOf: ["--enable-debug-logs", String(config.debuglogs)])
args.append(contentsOf: ["--enable-trace-logs", String(config.tracelogs)]) args.append(contentsOf: ["--enable-trace-logs", String(config.tracelogs)])
// Add list input IDs option // List the input ids
if config.listinputids { if config.listinputids {
args.append(contentsOf: ["--list-inputs-ids"]) 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 { if !config.inputids.isEmpty {
config.inputids.prefix(4).enumerated().forEach { index, inputId in config.inputids.prefix(4).enumerated().forEach { index, inputId in
args.append(contentsOf: ["--input-id-\(index + 1)", inputId]) args.append(contentsOf: ["--input-id-\(index + 1)", inputId])
} }
} }
// Add any additional arguments // Apped any additional arguments
args.append(contentsOf: config.additionalArgs) args.append(contentsOf: config.additionalArgs)
return args return args

View File

@ -15,10 +15,12 @@ struct ContentView: View {
init() { init() {
// Initialize SDL // Initialize SDL
SDL_SetMainReady() DispatchQueue.main.async {
SDL_iPhoneSetEventPump(SDL_TRUE) SDL_SetMainReady()
SDL_iPhoneSetEventPump(SDL_TRUE)
SDL_Init(SDL_INIT_VIDEO)
SDL_Init(SDL_INIT_VIDEO)
}
} }
func setupVirtualController() { 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"]) let config = Ryujinx.Configuration(gamepath: game.path, debuglogs: true, tracelogs: true, listinputids: false, inputids: ["1-47150005-05ac-0000-0100-00004f066d01"])
// Starts the emulation
do { do {
try Ryujinx().start(with: config) try Ryujinx().start(with: config)
} catch { } catch {

View File

@ -26,20 +26,23 @@ class SDLView: UIView {
private func makeSDLWindow() { private func makeSDLWindow() {
DispatchQueue.main.async { [self] in DispatchQueue.main.async { [self] in
// Gets window created from Ryujinx
sdlwin = SDL_GetWindowFromID(1) sdlwin = SDL_GetWindowFromID(1)
// Check if it got the window.
guard sdlwin != nil else { guard sdlwin != nil else {
print("Error getting SDL window: \(String(cString: SDL_GetError()))") print("Error getting SDL window: \(String(cString: SDL_GetError()))")
return return
} }
// Create metal View from the Window
mtkview = SDL_Metal_CreateView(sdlwin) mtkview = SDL_Metal_CreateView(sdlwin)
if mtkview == nil { if mtkview == nil {
print("Failed to create SDL Metal view.") print("Failed to create SDL Metal view.")
return return
} }
// Convert Metal View to Sublayer
if let metalLayerPointer = SDL_Metal_GetLayer(mtkview) { if let metalLayerPointer = SDL_Metal_GetLayer(mtkview) {
let metalLayer = Unmanaged<CAMetalLayer>.fromOpaque(metalLayerPointer).takeUnretainedValue() let metalLayer = Unmanaged<CAMetalLayer>.fromOpaque(metalLayerPointer).takeUnretainedValue()
metalLayer.device = MTLCreateSystemDefaultDevice() metalLayer.device = MTLCreateSystemDefaultDevice()

View File

@ -11,6 +11,7 @@ import SwiftUI
struct SDLViewRepresentable: UIViewRepresentable { struct SDLViewRepresentable: UIViewRepresentable {
let configure: () -> Void let configure: () -> Void
func makeUIView(context: Context) -> SDLView { func makeUIView(context: Context) -> SDLView {
// Configure (start ryu) before initialsing SDLView so SDLView can get the SDL_Window from Ryu
configure() configure()
let view = SDLView(frame: .zero) let view = SDLView(frame: .zero)
return view return view