From 20de593a886ae7c919ce8baa2ac08f9d4c73e8b9 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Tue, 24 Jul 2018 14:27:58 +0200 Subject: [PATCH] Clean exit on OS X. Minor changes. --- core/hw/pvr/Renderer_if.cpp | 2 ++ core/nullDC.cpp | 2 ++ .../apple/emulator-osx/emulator-osx/AppDelegate.swift | 8 ++++---- shell/apple/emulator-osx/emulator-osx/EmuGLView.swift | 10 +++++++++- .../emulator-osx/emulator-osx-Bridging-Header.h | 1 + shell/apple/emulator-osx/emulator-osx/osx-main.mm | 11 +++++++++++ 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/core/hw/pvr/Renderer_if.cpp b/core/hw/pvr/Renderer_if.cpp index 174d4493f..223fe4027 100644 --- a/core/hw/pvr/Renderer_if.cpp +++ b/core/hw/pvr/Renderer_if.cpp @@ -497,7 +497,9 @@ bool rend_init() void rend_term() { renderer_enabled = false; +#if !defined(TARGET_NO_THREADS) rs.Set(); +#endif if (fCheckFrames) fclose(fCheckFrames); diff --git a/core/nullDC.cpp b/core/nullDC.cpp index d5deeeaf0..c2bdcdc8c 100755 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -225,6 +225,8 @@ void dc_term() SaveSettings(); #endif SaveRomFiles(get_writable_data_path("/data/")); + + TermAudio(); } void dc_stop() diff --git a/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift b/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift index 0119a128b..0cee0a3f3 100644 --- a/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift +++ b/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift @@ -15,15 +15,15 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { - // Insert code here to initialize your application emu_main(); } func applicationWillTerminate(_ aNotification: Notification) { - // Insert code here to tear down your application + emu_dc_stop() } - - + func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + return true + } } diff --git a/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift b/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift index c7a171012..7f9ac942b 100644 --- a/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift +++ b/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift @@ -8,7 +8,7 @@ import Cocoa -class EmuGLView: NSOpenGLView { +class EmuGLView: NSOpenGLView , NSWindowDelegate { override var acceptsFirstResponder: Bool { return true; @@ -71,4 +71,12 @@ class EmuGLView: NSOpenGLView { emu_key_input(e.characters!, 0); } + override func viewDidMoveToWindow() { + super.viewDidMoveToWindow() + self.window!.delegate = self + } + + func windowWillClose(_ notification: Notification) { + emu_dc_stop() + } } diff --git a/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h b/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h index 6183158b7..b6fce55e4 100644 --- a/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h +++ b/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h @@ -10,6 +10,7 @@ #define emulator_osx_osx_main_Bridging_Header_h void emu_main(); +void emu_dc_stop(); int emu_single_frame(int w, int h); void emu_gles_init(); void emu_key_input(const char* key, int state); diff --git a/shell/apple/emulator-osx/emulator-osx/osx-main.mm b/shell/apple/emulator-osx/emulator-osx/osx-main.mm index a50798401..caca6dcc6 100644 --- a/shell/apple/emulator-osx/emulator-osx/osx-main.mm +++ b/shell/apple/emulator-osx/emulator-osx/osx-main.mm @@ -90,6 +90,8 @@ void gl_swap() { int dc_init(int argc,wchar* argv[]); void dc_run(); +void dc_term(); +void dc_stop(); bool has_init = false; void* emuthread(void*) { @@ -115,9 +117,18 @@ void* emuthread(void*) { dc_run(); + has_init = false; + + dc_term(); + return 0; } +extern "C" void emu_dc_stop() +{ + dc_stop(); +} + pthread_t emu_thread; extern "C" void emu_main() { pthread_create(&emu_thread, 0, &emuthread, 0);