Add Exit Emulation (broken)

This commit is contained in:
Stossy11 2024-12-19 12:43:20 +11:00
parent 438c1a896f
commit 2e6e4eb2a0
6 changed files with 74 additions and 10 deletions

View File

@ -31,6 +31,8 @@ void install_firmware(const char* inputPtr);
char* installed_firmware_version(); char* installed_firmware_version();
void stop_emulation();
int main_ryujinx_sdl(int argc, char **argv); int main_ryujinx_sdl(int argc, char **argv);
void initialize(); void initialize();

View File

@ -33,6 +33,10 @@ struct ContentView: View {
@State var onscreencontroller: Controller = Controller(id: "", name: "") @State var onscreencontroller: Controller = Controller(id: "", name: "")
@AppStorage("JIT") var isJITEnabled: Bool = false @AppStorage("JIT") var isJITEnabled: Bool = false
@AppStorage("quit") var quit: Bool = false
@State var quits: Bool = false
// MARK: - Initialization // MARK: - Initialization
init() { init() {
let defaultConfig = loadSettings() ?? Ryujinx.Configuration(gamepath: "") let defaultConfig = loadSettings() ?? Ryujinx.Configuration(gamepath: "")
@ -52,10 +56,25 @@ struct ContentView: View {
// MARK: - Body // MARK: - Body
var body: some View { var body: some View {
if let game { if let game, quits == false {
emulationView emulationView
.onAppear() {
Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { timer in
print(quit)
quits = quit
if quits {
quit = false
timer.invalidate()
}
}
}
} else { } else {
mainMenuView mainMenuView
.onAppear() {
quits = false
}
} }
} }

View File

@ -11,10 +11,24 @@ import SwiftUIJoystick
import CoreMotion import CoreMotion
struct ControllerView: View { struct ControllerView: View {
@AppStorage("quit") var quit: Bool = false
var body: some View { var body: some View {
GeometryReader { geometry in GeometryReader { geometry in
if geometry.size.height > geometry.size.width && UIDevice.current.userInterfaceIdiom != .pad { if geometry.size.height > geometry.size.width && UIDevice.current.userInterfaceIdiom != .pad {
VStack { VStack {
/*
HStack {
Spacer()
Button("Stop emulation") {
DispatchQueue.main.async {
stop_emulation()
quit = true
}
}
}
*/
Spacer() Spacer()
VStack { VStack {
HStack { HStack {
@ -48,6 +62,19 @@ struct ControllerView: View {
} else { } else {
// could be landscape // could be landscape
VStack { VStack {
/*
HStack {
Spacer()
Button("Stop emulation") {
DispatchQueue.main.async {
stop_emulation()
quit = true
}
}
}
*/
Spacer() Spacer()
VStack { VStack {
HStack { HStack {

View File

@ -93,6 +93,7 @@ using Silk.NET.Vulkan;
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SDL2;
public class GamepadInfo public class GamepadInfo
{ {
@ -288,6 +289,21 @@ namespace Ryujinx.Headless.SDL2
return String.Empty; return String.Empty;
} }
[UnmanagedCallersOnly(EntryPoint = "stop_emulation")]
public static void StopEmulation()
{
if (_window != null)
{
_window.Exit();
_emulationContext.Dispose();
_emulationContext = null;
}
}
[UnmanagedCallersOnly(EntryPoint = "get_game_controllers")] [UnmanagedCallersOnly(EntryPoint = "get_game_controllers")]
public static unsafe IntPtr GetGamepadList() public static unsafe IntPtr GetGamepadList()

View File

@ -45,14 +45,14 @@ namespace Ryujinx.Headless.SDL2
_mainThreadActions.Enqueue(action); _mainThreadActions.Enqueue(action);
} }
public NpadManager NpadManager { get; } public NpadManager NpadManager;
public TouchScreenManager TouchScreenManager { get; } public TouchScreenManager TouchScreenManager;
public Switch Device { get; private set; } public Switch Device;
public IRenderer Renderer { get; private set; } public IRenderer Renderer;
public event EventHandler<StatusUpdatedEventArgs> StatusUpdatedEvent; public event EventHandler<StatusUpdatedEventArgs> StatusUpdatedEvent;
protected IntPtr WindowHandle { get; set; } public IntPtr WindowHandle;
public IHostUiTheme HostUiTheme { get; } public IHostUiTheme HostUiTheme { get; }
public int Width { get; private set; } public int Width { get; private set; }
@ -66,18 +66,18 @@ namespace Ryujinx.Headless.SDL2
public ScalingFilter ScalingFilter { get; set; } public ScalingFilter ScalingFilter { get; set; }
public int ScalingFilterLevel { get; set; } public int ScalingFilterLevel { get; set; }
protected SDL2MouseDriver MouseDriver; public SDL2MouseDriver MouseDriver;
private readonly InputManager _inputManager; private readonly InputManager _inputManager;
private readonly IKeyboard _keyboardInterface; private readonly IKeyboard _keyboardInterface;
private readonly GraphicsDebugLevel _glLogLevel; private readonly GraphicsDebugLevel _glLogLevel;
private readonly Stopwatch _chrono; private readonly Stopwatch _chrono;
private readonly long _ticksPerFrame; private readonly long _ticksPerFrame;
private readonly CancellationTokenSource _gpuCancellationTokenSource; private readonly CancellationTokenSource _gpuCancellationTokenSource;
private readonly ManualResetEvent _exitEvent; public ManualResetEvent _exitEvent;
private readonly ManualResetEvent _gpuDoneEvent; public ManualResetEvent _gpuDoneEvent;
private long _ticks; private long _ticks;
private bool _isActive; public bool _isActive;
private bool _isStopped; private bool _isStopped;
private uint _windowId; private uint _windowId;