From b1767601b0e05dcfeded978ccc403cf0999bf527 Mon Sep 17 00:00:00 2001 From: meancoot Date: Fri, 13 Dec 2013 19:23:22 -0500 Subject: [PATCH] (Apple) More fixes for building on snow leopard. --- apple/OSX/platform.h | 12 +-- apple/OSX/platform.m | 81 ++++++++++++------- apple/OSX/settings.m | 27 ++++--- apple/RetroArch_OSX.xcodeproj/project.pbxproj | 10 ++- apple/common/RAGameView.m | 35 ++++---- apple/common/main.m | 11 ++- apple/common/utility.m | 5 +- 7 files changed, 110 insertions(+), 71 deletions(-) diff --git a/apple/OSX/platform.h b/apple/OSX/platform.h index 80243aaa8e..718999e955 100644 --- a/apple/OSX/platform.h +++ b/apple/OSX/platform.h @@ -27,20 +27,16 @@ @end @interface RetroArch_OSX : NSObject -{ -@public - NSWindow IBOutlet *window; -} +@property (nonatomic, retain) NSWindow IBOutlet* window; +@property (nonatomic, copy) NSString* configDirectory; // e.g. /var/mobile/Documents/.RetroArch +@property (nonatomic, copy) NSString* globalConfigFile; // e.g. /var/mobile/Documents/.RetroArch/retroarch.cfg +@property (nonatomic, copy) NSString* coreDirectory; // e.g. /Applications/RetroArch.app/modules + (RetroArch_OSX*)get; - (void)loadingCore:(NSString*)core withFile:(const char*)file; - (void)unloadingCore:(NSString*)core; -@property (nonatomic) NSString* configDirectory; // e.g. /var/mobile/Documents/.RetroArch -@property (nonatomic) NSString* globalConfigFile; // e.g. /var/mobile/Documents/.RetroArch/retroarch.cfg -@property (nonatomic) NSString* coreDirectory; // e.g. /Applications/RetroArch.app/modules - @end #endif diff --git a/apple/OSX/platform.m b/apple/OSX/platform.m index 8b1c3a432e..2df53e0f0f 100644 --- a/apple/OSX/platform.m +++ b/apple/OSX/platform.m @@ -24,7 +24,7 @@ #include "file.h" -static const void* const associated_core_key = &associated_core_key; +static void* const associated_core_key = (void*)&associated_core_key; @interface RApplication : NSApplication @end @@ -72,15 +72,40 @@ static const void* const associated_core_key = &associated_core_key; @end +@interface RetroArch_OSX() +@property (nonatomic, retain) NSWindowController* settingsWindow; +@property (nonatomic, retain) NSWindow IBOutlet* coreSelectSheet; +@property (nonatomic, copy) NSString* file; +@property (nonatomic, copy) NSString* core; +@end + @implementation RetroArch_OSX { - NSWindow IBOutlet* _coreSelectSheet; - bool _isTerminating; bool _loaded; bool _wantReload; - NSString* _file; - NSString* _core; +} + +@synthesize window = _window; +@synthesize configDirectory = _configDirectory; +@synthesize globalConfigFile = _globalConfigFile; +@synthesize coreDirectory = _coreDirectory; +@synthesize settingsWindow = _settingsWindow; +@synthesize coreSelectSheet = _coreSelectSheet; +@synthesize file = _file; +@synthesize core = _core; + +- (void)dealloc +{ + [_window release]; + [_configDirectory release]; + [_globalConfigFile release]; + [_coreDirectory release]; + [_coreSelectSheet release]; + [_settingsWindow release]; + [_file release]; + [_core release]; + [super dealloc]; } + (RetroArch_OSX*)get @@ -94,20 +119,21 @@ static const void* const associated_core_key = &associated_core_key; _loaded = true; NSArray* paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); - self.configDirectory = [paths[0] stringByAppendingPathComponent:@"RetroArch"]; + self.configDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"RetroArch"]; self.globalConfigFile = [NSString stringWithFormat:@"%@/retroarch.cfg", self.configDirectory]; self.coreDirectory = [NSBundle.mainBundle.bundlePath stringByAppendingPathComponent:@"Contents/Resources/modules"]; - [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; - window.acceptsMouseMovedEvents = YES; + self.window.acceptsMouseMovedEvents = YES; - RAGameView.get.frame = [window.contentView bounds]; - [window.contentView setAutoresizesSubviews:YES]; - [window.contentView addSubview:RAGameView.get]; - [window makeFirstResponder:RAGameView.get]; + RAGameView.get.frame = [self.window.contentView bounds]; + [self.window.contentView setAutoresizesSubviews:YES]; + [self.window.contentView addSubview:RAGameView.get]; + [self.window makeFirstResponder:RAGameView.get]; + + self.settingsWindow = [[[NSWindowController alloc] initWithWindowNibName:@"Settings"] autorelease]; // Create core select list - NSComboBox* cb = (NSComboBox*)[_coreSelectSheet.contentView viewWithTag:1]; + NSComboBox* cb = (NSComboBox*)[self.coreSelectSheet.contentView viewWithTag:1]; apple_core_info_set_core_path(self.coreDirectory.UTF8String); apple_core_info_set_config_path(self.configDirectory.UTF8String); @@ -154,9 +180,9 @@ static const void* const associated_core_key = &associated_core_key; - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames { - if (filenames.count == 1 && filenames[0]) + if (filenames.count == 1 && [filenames objectAtIndex:0]) { - _file = filenames[0]; + self.file = [filenames objectAtIndex:0]; if (!_loaded) _wantReload = true; @@ -175,48 +201,48 @@ static const void* const associated_core_key = &associated_core_key; - (void)openDocument:(id)sender { NSOpenPanel* panel = [NSOpenPanel openPanel]; - [panel beginSheetModalForWindow:window completionHandler:^(NSInteger result) + [panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) { [NSApplication.sharedApplication stopModal]; if (result == NSOKButton && panel.URL) { - _file = panel.URL.path; + self.file = panel.URL.path; [self performSelector:@selector(chooseCore) withObject:nil afterDelay:.5f]; } }]; [NSApplication.sharedApplication runModalForWindow:panel]; } -// This utility function will queue the _core and _file instance values for running. +// This utility function will queue the self.core and self.file instance values for running. // If the emulator thread is already running it will tell it to quit. - (void)runCore { _wantReload = apple_is_running; if (!apple_is_running) - apple_run_core(_core, _file.UTF8String); + apple_run_core(self.core, self.file.UTF8String); else apple_frontend_post_event(apple_event_basic_command, (void*)QUIT); } - (void)chooseCore { - [NSApplication.sharedApplication beginSheet:_coreSelectSheet modalForWindow:window modalDelegate:nil didEndSelector:nil contextInfo:nil]; - [NSApplication.sharedApplication runModalForWindow:_coreSelectSheet]; + [NSApplication.sharedApplication beginSheet:self.coreSelectSheet modalForWindow:self.window modalDelegate:nil didEndSelector:nil contextInfo:nil]; + [NSApplication.sharedApplication runModalForWindow:self.coreSelectSheet]; } - (IBAction)coreWasChosen:(id)sender { [NSApplication.sharedApplication stopModal]; - [NSApplication.sharedApplication endSheet:_coreSelectSheet returnCode:0]; - [_coreSelectSheet orderOut:self]; + [NSApplication.sharedApplication endSheet:self.coreSelectSheet returnCode:0]; + [self.coreSelectSheet orderOut:self]; if (_isTerminating) return; - NSComboBox* cb = (NSComboBox*)[_coreSelectSheet.contentView viewWithTag:1]; - _core = objc_getAssociatedObject(cb.objectValueOfSelectedItem, associated_core_key); + NSComboBox* cb = (NSComboBox*)[self.coreSelectSheet.contentView viewWithTag:1]; + self.core = objc_getAssociatedObject(cb.objectValueOfSelectedItem, associated_core_key); [self runCore]; } @@ -234,7 +260,7 @@ static const void* const associated_core_key = &associated_core_key; [NSApplication.sharedApplication terminate:nil]; if (_wantReload) - apple_run_core(_core, _file.UTF8String); + apple_run_core(self.core, self.file.UTF8String); else if(apple_use_tv_mode) apple_run_core(nil, 0); else @@ -251,8 +277,7 @@ static const void* const associated_core_key = &associated_core_key; - (IBAction)showPreferences:(id)sender { - NSWindowController* wc = [[NSWindowController alloc] initWithWindowNibName:@"Settings"]; - [NSApp runModalForWindow:wc.window]; + [NSApp runModalForWindow:self.settingsWindow.window]; } - (IBAction)basicEvent:(id)sender diff --git a/apple/OSX/settings.m b/apple/OSX/settings.m index 79b16e2aea..ae3e5f1bf9 100644 --- a/apple/OSX/settings.m +++ b/apple/OSX/settings.m @@ -21,7 +21,7 @@ #include "driver.h" #include "input/input_common.h" -static const void* associated_name_tag = (void*)&associated_name_tag; +static void* const associated_name_tag = (void*)&associated_name_tag; @interface RAInputBinder : NSWindow @property (nonatomic, retain) NSTimer* timer; @@ -29,14 +29,14 @@ static const void* associated_name_tag = (void*)&associated_name_tag; @end @implementation RAInputBinder +@synthesize timer = _timer; +@synthesize setting = _setting; -#if 0 - (void)dealloc { [_timer release]; [super dealloc]; } -#endif - (void)runForSetting:(const rarch_setting_t*)setting onWindow:(NSWindow*)window { @@ -95,8 +95,14 @@ static const void* associated_name_tag = (void*)&associated_name_tag; @end @implementation RASettingsDelegate +@synthesize binderWindow = _binderWindow; +@synthesize booleanCell = _booleanCell; +@synthesize binderCell = _binderCell; +@synthesize table = _table; +@synthesize outline = _outline; +@synthesize settings = _settings; +@synthesize currentGroup = _currentGroup; -#if 0 - (void)dealloc { [_binderWindow release]; @@ -109,7 +115,6 @@ static const void* associated_name_tag = (void*)&associated_name_tag; [super dealloc]; } -#endif - (void)awakeFromNib { @@ -136,7 +141,8 @@ static const void* associated_name_tag = (void*)&associated_name_tag; case ST_END_GROUP: { - [self.settings addObject:thisGroup]; + if (thisGroup) + [self.settings addObject:thisGroup]; thisGroup = nil; break; } @@ -150,7 +156,8 @@ static const void* associated_name_tag = (void*)&associated_name_tag; case ST_END_SUB_GROUP: { - [thisGroup addObject:thisSubGroup]; + if (thisSubGroup) + [thisGroup addObject:thisSubGroup]; thisSubGroup = nil; break; } @@ -183,12 +190,12 @@ static const void* associated_name_tag = (void*)&associated_name_tag; - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { - return objc_getAssociatedObject(self.settings[row], associated_name_tag); + return objc_getAssociatedObject([self.settings objectAtIndex:row], associated_name_tag); } - (void)tableViewSelectionDidChange:(NSNotification *)aNotification { - self.currentGroup = self.settings[self.table.selectedRow]; + self.currentGroup = [self.settings objectAtIndex:self.table.selectedRow]; [self.outline reloadData]; } @@ -200,7 +207,7 @@ static const void* associated_name_tag = (void*)&associated_name_tag; - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { - return (item == nil) ? self.currentGroup[index] : [item objectAtIndex:index]; + return (item == nil) ? [self.currentGroup objectAtIndex:index] : [item objectAtIndex:index]; } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item diff --git a/apple/RetroArch_OSX.xcodeproj/project.pbxproj b/apple/RetroArch_OSX.xcodeproj/project.pbxproj index 4af4c3c6c6..a1f8146636 100644 --- a/apple/RetroArch_OSX.xcodeproj/project.pbxproj +++ b/apple/RetroArch_OSX.xcodeproj/project.pbxproj @@ -270,10 +270,11 @@ ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "compiler-default"; CLANG_CXX_LIBRARY = "compiler-default"; - CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_ARC = NO; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; @@ -316,7 +317,7 @@ "-DHAVE_NETPLAY", ); PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = ""; + SDKROOT = macosx; WRAPPER_EXTENSION = app; }; name = Debug; @@ -327,10 +328,11 @@ ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "compiler-default"; CLANG_CXX_LIBRARY = "compiler-default"; - CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_ARC = NO; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; @@ -369,7 +371,7 @@ "-DHAVE_NETPLAY", ); PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = ""; + SDKROOT = macosx; WRAPPER_EXTENSION = app; }; name = Release; diff --git a/apple/common/RAGameView.m b/apple/common/RAGameView.m index e0983464fd..9433d166ee 100644 --- a/apple/common/RAGameView.m +++ b/apple/common/RAGameView.m @@ -312,32 +312,30 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer static RAScreen* get_chosen_screen() { -#ifdef MAC_OS_X_VERSION_10_7 - @autoreleasepool { - if (g_settings.video.monitor_index >= RAScreen.screens.count) - { - RARCH_WARN("video_monitor_index is greater than the number of connected monitors; using main screen instead.\n"); - return RAScreen.mainScreen; - } - - NSArray *screens = [RAScreen screens]; - RAScreen *s = (RAScreen*)[screens objectAtIndex:g_settings.video.monitor_index]; - return s; - } -#else +#ifdef OSX NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - +#else + @autoreleasepool { +#endif + if (g_settings.video.monitor_index >= RAScreen.screens.count) { RARCH_WARN("video_monitor_index is greater than the number of connected monitors; using main screen instead.\n"); +#ifdef OSX [pool drain]; +#endif return RAScreen.mainScreen; } NSArray *screens = [RAScreen screens]; RAScreen *s = (RAScreen*)[screens objectAtIndex:g_settings.video.monitor_index]; +#ifdef OSX [pool drain]; + [pool release]; +#endif return s; +#ifdef IOS + } #endif } @@ -390,20 +388,23 @@ bool apple_gfx_ctx_bind_api(enum gfx_ctx_api api, unsigned major, unsigned minor #ifdef OSX [g_context clearDrawable]; - g_context = nil; - g_format = nil; + [g_context release], g_context = nil; + [g_format release], g_format = nil; NSOpenGLPixelFormatAttribute attributes [] = { NSOpenGLPFADoubleBuffer, // double buffered NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer #ifdef MAC_OS_X_VERSION_10_7 - (major || minor) ? NSOpenGLPFAOpenGLProfile : 0, + (major || minor) ? NSOpenGLPFAOpenGLProfile : 0, (major << 12) | (minor << 8), #endif (NSOpenGLPixelFormatAttribute)nil }; + [g_format release]; + [g_context release]; + g_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; g_context = [[NSOpenGLContext alloc] initWithFormat:g_format shareContext:nil]; g_context.view = g_view; diff --git a/apple/common/main.m b/apple/common/main.m index 88623c2775..11afb82de1 100644 --- a/apple/common/main.m +++ b/apple/common/main.m @@ -51,7 +51,10 @@ void apple_run_core(NSString* core, const char* file) [apple_platform loadingCore:core withFile:file]; - apple_core = core; +#ifdef OSX + [apple_core release]; +#endif + apple_core = [core copy]; apple_is_running = true; static char config_path[PATH_MAX]; @@ -97,7 +100,7 @@ void apple_rarch_exited(void* result) apple_display_alert(@"Failed to load content.", 0); NSString* used_core = apple_core; - apple_core = 0; + apple_core = 0; if (apple_is_running) { @@ -105,6 +108,10 @@ void apple_rarch_exited(void* result) [apple_platform unloadingCore:used_core]; } +#ifdef OSX + [used_core release]; +#endif + if (apple_use_tv_mode) apple_run_core(nil, 0); } diff --git a/apple/common/utility.m b/apple/common/utility.m index 09a940ff28..3f8631836d 100644 --- a/apple/common/utility.m +++ b/apple/common/utility.m @@ -31,11 +31,12 @@ void apple_display_alert(NSString* message, NSString* title) otherButtonTitles:nil]; [alert show]; #else - NSAlert* alert = [NSAlert new]; + NSAlert* alert = [[NSAlert new] autorelease]; + alert.messageText = title ? title : @"RetroArch"; alert.informativeText = message; alert.alertStyle = NSInformationalAlertStyle; - [alert beginSheetModalForWindow:RetroArch_OSX.get->window + [alert beginSheetModalForWindow:RetroArch_OSX.get.window modalDelegate:apple_platform didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];