From a44c1c87f7d1f014d064244d2fc0068207a49695 Mon Sep 17 00:00:00 2001 From: arbee Date: Tue, 17 Sep 2019 17:17:30 -0400 Subject: OSD_MAC: don't run MAME on a thread, it upsets the debugger very much (nw) --- src/osd/mac/appdelegate.mm | 16 ----------- src/osd/mac/macmain.cpp | 21 ++++++--------- src/osd/mac/main.mm | 25 ++++++++++++++++- src/osd/mac/windowcontroller.mm | 54 ++++++++++++++++++++----------------- src/osd/modules/input/input_mac.cpp | 3 +++ 5 files changed, 65 insertions(+), 54 deletions(-) (limited to 'src/osd') diff --git a/src/osd/mac/appdelegate.mm b/src/osd/mac/appdelegate.mm index 4207f515beb..8aa80e4fdb8 100644 --- a/src/osd/mac/appdelegate.mm +++ b/src/osd/mac/appdelegate.mm @@ -10,29 +10,13 @@ #import "appdelegate.h" -extern int mac_run_emulator(); - -@interface MAMEThread : NSThread -@end - -@implementation MAMEThread -- (void)main -{ - mac_run_emulator(); -} -@end - @interface MAMEAppDelegate () @end @implementation MAMEAppDelegate -MAMEThread *appThread; - (void)applicationDidFinishLaunching:(NSNotification *)notification { - // run MAME on a thread so event dispatching happens normally - appThread = [[MAMEThread alloc] init]; - [appThread start]; } - (void)applicationWillTerminate:(NSNotification *)notification diff --git a/src/osd/mac/macmain.cpp b/src/osd/mac/macmain.cpp index 8e50361a2b1..40bcd7d1882 100644 --- a/src/osd/mac/macmain.cpp +++ b/src/osd/mac/macmain.cpp @@ -62,15 +62,12 @@ mac_options::mac_options() } //============================================================ -// main +// mac_run_emulator - this is the MAME entry point from the +// Cocoa shell //============================================================ -// we do some special sauce on Win32... -int mac_run_emulator() +int mac_run_emulator(int argc, char *argv[]) { - int argc = *_NSGetArgc(); - char **argv = *_NSGetArgv(); - std::vector args = osd_get_command_line(argc, argv); int res = 0; @@ -81,14 +78,12 @@ int mac_run_emulator() // Initialize crash diagnostics diagnostics_module::get_instance()->init_crash_diagnostics(); - { - mac_options options; - mac_osd_interface osd(options); - osd.register_options(); - res = emulator_info::start_frontend(options, osd, args); - } + mac_options options; + mac_osd_interface osd(options); + osd.register_options(); + res = emulator_info::start_frontend(options, osd, args); - exit(res); + return res; } //============================================================ diff --git a/src/osd/mac/main.mm b/src/osd/mac/main.mm index fdc50be53fe..d11eb0c79a8 100644 --- a/src/osd/mac/main.mm +++ b/src/osd/mac/main.mm @@ -10,10 +10,33 @@ #import "appdelegate.h" +extern int mac_run_emulator(int argc, char *argv[]); + int main(int argc, char * argv[]) { [NSApplication sharedApplication]; [NSApp setDelegate: [MAMEAppDelegate new]]; + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + [NSApp activateIgnoringOtherApps:YES]; + [NSApp finishLaunching]; + [[NSNotificationCenter defaultCenter] + postNotificationName:NSApplicationWillFinishLaunchingNotification + object:NSApp]; + [[NSNotificationCenter defaultCenter] + postNotificationName:NSApplicationDidFinishLaunchingNotification + object:NSApp]; + id quitMenuItem = [NSMenuItem new]; + [quitMenuItem + initWithTitle:@"Quit" + action:@selector(terminate:) + keyEquivalent:@"q"]; + id appMenu = [NSMenu new]; + [appMenu addItem:quitMenuItem]; + id appMenuItem = [NSMenuItem new]; + [appMenuItem setSubmenu:appMenu]; + id menubar = [[NSMenu new] autorelease]; + [menubar addItem:appMenuItem]; + [NSApp setMainMenu:menubar]; - return NSApplicationMain(argc, (const char**)argv); + return mac_run_emulator(argc, argv); } diff --git a/src/osd/mac/windowcontroller.mm b/src/osd/mac/windowcontroller.mm index aa09e96b0d5..dd49d559b0b 100644 --- a/src/osd/mac/windowcontroller.mm +++ b/src/osd/mac/windowcontroller.mm @@ -88,6 +88,20 @@ } @end +void MacPollInputs() +{ + NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny + untilDate:[NSDate distantPast] // do not wait for event + inMode:NSDefaultRunLoopMode + dequeue:YES]; + + if (event) + { + [NSApp sendEvent:event]; + [NSApp updateWindows]; + } +} + void *GetOSWindow(void *wincontroller) { MAMEWindowController *wc = (MAMEWindowController *)wincontroller; @@ -102,30 +116,22 @@ void *CreateMAMEWindow(char *title, int x, int y, int w, int h, bool isFullscree NSWindow *window = [NSWindow alloc]; MAMEWindowController *controller = [MAMEWindowController alloc]; - /* To avoid event handling issues like SDL has, we run MAME in - a separate NSThread. This means all UI calls from MAME - must be delegated over to the main thread because the - Cocoa UI stuff is not thread-safe */ - dispatch_sync(dispatch_get_main_queue(), ^{ - [window initWithContentRect:bounds - styleMask:style - backing:NSBackingStoreBuffered - defer:NO]; - [controller initWithWindow:window]; - - NSString *nstitle = [[NSString alloc] initWithUTF8String:title]; - [window setTitle:nstitle]; - [nstitle release]; - - if (isFullscreen) - { - [controller goFullscreen]; - } - else - { - [window makeKeyAndOrderFront:nil]; - } - }); + [window initWithContentRect:bounds + styleMask:style + backing:NSBackingStoreBuffered + defer:NO]; + [controller initWithWindow:window]; + NSString *nstitle = [[NSString alloc] initWithUTF8String:title]; + [window setTitle:nstitle]; + [nstitle release]; + if (isFullscreen) + { + [controller goFullscreen]; + } + else + { + [window makeKeyAndOrderFront:nil]; + } return (void *)controller; } diff --git a/src/osd/modules/input/input_mac.cpp b/src/osd/modules/input/input_mac.cpp index ac2d4e4e5b6..4dd030b331a 100644 --- a/src/osd/modules/input/input_mac.cpp +++ b/src/osd/modules/input/input_mac.cpp @@ -31,12 +31,15 @@ #include "../../mac/osdmac.h" #include "input_common.h" +extern void MacPollInputs(); + void mac_osd_interface::customize_input_type_list(simple_list &typelist) { } void mac_osd_interface::poll_inputs(running_machine &machine) { + MacPollInputs(); } void mac_osd_interface::release_keys() -- cgit v1.2.3