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
// 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

View File

@ -15,11 +15,13 @@ struct ContentView: View {
init() {
// Initialize SDL
DispatchQueue.main.async {
SDL_SetMainReady()
SDL_iPhoneSetEventPump(SDL_TRUE)
SDL_Init(SDL_INIT_VIDEO)
}
}
func setupVirtualController() {
let configuration = GCVirtualController.Configuration()
@ -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 {

View File

@ -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<CAMetalLayer>.fromOpaque(metalLayerPointer).takeUnretainedValue()
metalLayer.device = MTLCreateSystemDefaultDevice()

View File

@ -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