OSD_MAC: don't run MAME on a thread, it upsets the debugger very much (nw)

This commit is contained in:
arbee 2019-09-17 17:17:30 -04:00
parent 461fb82524
commit a44c1c87f7
5 changed files with 65 additions and 54 deletions

View File

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

View File

@ -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<std::string> 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;
}
//============================================================

View File

@ -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);
}

View File

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

View File

@ -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<input_type_entry> &typelist)
{
}
void mac_osd_interface::poll_inputs(running_machine &machine)
{
MacPollInputs();
}
void mac_osd_interface::release_keys()