Get SDL Window Automatically

This commit is contained in:
stossy11 2024-11-03 15:09:01 +11:00
parent b86e3301bb
commit 10e45533e1
7 changed files with 214 additions and 31 deletions

View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1610"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4E80A98C2CD6F54500029585"
BuildableName = "MeloNX.app"
BlueprintName = "MeloNX"
ReferencedContainer = "container:MeloNX.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4E80A99C2CD6F54700029585"
BuildableName = "MeloNXTests.xctest"
BlueprintName = "MeloNXTests"
ReferencedContainer = "container:MeloNX.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4E80A9A62CD6F54700029585"
BuildableName = "MeloNXUITests.xctest"
BlueprintName = "MeloNXUITests"
ReferencedContainer = "container:MeloNX.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
enableGPUValidationMode = "1"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4E80A98C2CD6F54500029585"
BuildableName = "MeloNX.app"
BlueprintName = "MeloNX"
ReferencedContainer = "container:MeloNX.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4E80A98C2CD6F54500029585"
BuildableName = "MeloNX.app"
BlueprintName = "MeloNX"
ReferencedContainer = "container:MeloNX.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "271EB822-2830-4016-A3D7-CA2DEBEDCD27"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "1F3099D0-0456-4AD5-8EA1-52BABAF2AA89"
shouldBeEnabled = "Yes"
nameForDebugger = "Ignore-SIGUSR"
ignoreCount = "0"
continueAfterRunningActions = "Yes"
filePath = "MeloNX/MeloNXApp.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "14"
endingLineNumber = "14"
landmarkName = "body"
landmarkType = "24">
<Actions>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "process handle --stop false SIGUSR1">
</ActionContent>
</BreakpointActionProxy>
</Actions>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

View File

@ -10,5 +10,23 @@
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>4E80A98C2CD6F54500029585</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>4E80A99C2CD6F54700029585</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>4E80A9A62CD6F54700029585</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

View File

@ -17,14 +17,16 @@ class Ryujinx {
let debuglogs: Bool
let tracelogs: Bool
let listinputids: Bool
let fullscreen: Bool
var additionalArgs: [String]
init(gamepath: String, additionalArgs: [String] = [], debuglogs: Bool = false, tracelogs: Bool = false, listinputids: Bool = false, inputids: [String] = []) {
init(gamepath: String, additionalArgs: [String] = [], debuglogs: Bool = false, tracelogs: Bool = false, listinputids: Bool = false, inputids: [String] = [], ryufullscreen: Bool = false) {
self.gamepath = gamepath
self.debuglogs = debuglogs
self.tracelogs = tracelogs
self.inputids = inputids
self.listinputids = listinputids
self.fullscreen = ryufullscreen
self.additionalArgs = additionalArgs
}
}
@ -95,7 +97,9 @@ class Ryujinx {
args.append("Vulkan")
// Fixes the Stubs.DispatchLoop Crash
args.append(contentsOf: ["--memory-manager-mode", "SoftwarePageTable"])
args.append(contentsOf: ["--fullscreen", "true"])
if config.fullscreen {
args.append(contentsOf: ["--fullscreen", String(config.fullscreen)])
}
// Debug Logs
args.append(contentsOf: ["--enable-debug-logs", String(config.debuglogs)])
args.append(contentsOf: ["--enable-trace-logs", String(config.tracelogs)])

View File

@ -49,7 +49,7 @@ struct ContentView: View {
setupVirtualController()
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"], ryufullscreen: true)
// Starts the emulation
do {
try Ryujinx().start(with: config)

View File

@ -11,43 +11,68 @@ import SDL2
class SDLView: UIView {
var sdlwin: OpaquePointer?
var mtkview: UnsafeMutableRawPointer?
private var sdlWindowID: UInt32 = 1 // Adjust this ID based on Ryujinx window ID
override init(frame: CGRect) {
super.init(frame: frame)
makeSDLWindow()
startSDLWindowRetrieval()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
makeSDLWindow()
startSDLWindowRetrieval()
}
private func startSDLWindowRetrieval() {
Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { timer in
self.makeSDLWindow()
// Stop the timer once the window is successfully retrieved
if self.sdlwin != nil {
timer.invalidate()
}
}
}
private func makeSDLWindow() {
DispatchQueue.main.async { [self] in
// Attempt to retrieve the SDL window created by Ryujinx
sdlwin = SDL_GetWindowFromID(sdlWindowID)
// Gets window created from Ryujinx
sdlwin = SDL_GetWindowFromID(1)
// Check if it got the window.
// Check if we successfully retrieved the SDL 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
print("SDL window retrieved successfully.")
// Position SDL window over this UIView
DispatchQueue.main.async {
self.syncSDLWindowPosition()
}
}
// Convert Metal View to Sublayer
if let metalLayerPointer = SDL_Metal_GetLayer(mtkview) {
let metalLayer = Unmanaged<CAMetalLayer>.fromOpaque(metalLayerPointer).takeUnretainedValue()
metalLayer.device = MTLCreateSystemDefaultDevice()
layer.addSublayer(metalLayer)
private func syncSDLWindowPosition() {
guard let sdlwin = sdlwin else { return }
DispatchQueue.main.async {
// Get the frame of the UIView in screen coordinates
let viewFrameInWindow = self.convert(self.bounds, to: nil)
// Set the SDL window position and size to match the UIView frame
SDL_SetWindowPosition(sdlwin, Int32(viewFrameInWindow.origin.x), Int32(viewFrameInWindow.origin.y))
SDL_SetWindowSize(sdlwin, Int32(viewFrameInWindow.width), Int32(viewFrameInWindow.height))
// Bring SDL window to the front
SDL_RaiseWindow(sdlwin)
}
print("SDL window positioned over SDLView.")
}
override func layoutSubviews() {
super.layoutSubviews()
// Adjust SDL window whenever layout changes
syncSDLWindowPosition()
}
}