diff --git a/apple/common/RAGameView.m b/apple/common/RAGameView.m index 66e18548d9..8bbea22ea1 100644 --- a/apple/common/RAGameView.m +++ b/apple/common/RAGameView.m @@ -553,9 +553,7 @@ void apple_gfx_ctx_update_window_title(void) (void)text; #ifdef OSX if (got_text) - { - [[g_view window] setTitle:[NSString stringWithCString:text encoding:NSUTF8StringEncoding]]; - } + [[g_view window] setTitle:[NSString stringWithCString:text encoding:NSUTF8StringEncoding]]; #endif if (fps_draw) msg_queue_push(g_extern.msg_queue, buf_fps, 1, 1); @@ -568,11 +566,13 @@ bool apple_gfx_ctx_has_focus(void) void apple_gfx_ctx_swap_buffers() { - if (--g_fast_forward_skips < 0) - { - [g_view display]; - g_fast_forward_skips = g_is_syncing ? 0 : 3; - } + bool swap = --g_fast_forward_skips < 0; + + if (!swap) + return; + + [g_view display]; + g_fast_forward_skips = g_is_syncing ? 0 : 3; } gfx_ctx_proc_t apple_gfx_ctx_get_proc_address(const char *symbol_name) diff --git a/apple/common/apple_gamecontroller.m b/apple/common/apple_gamecontroller.m index c1679b9ba9..767f1b2595 100644 --- a/apple/common/apple_gamecontroller.m +++ b/apple/common/apple_gamecontroller.m @@ -16,7 +16,6 @@ #include #ifdef IOS #include -static NSArray *versionCompatibility; #endif #if defined(__IPHONE_7_0) && !defined(OSX) @@ -26,10 +25,20 @@ static NSArray *versionCompatibility; #import #include "apple_input.h" +#ifdef IOS +bool apple_rarch_is_ios7_or_higher(void) +{ + NSArray *versionCompatibility = [[UIDevice currentDevice].systemVersion + componentsSeparatedByString:@(".")]; + bool ret = [[versionCompatibility objectAtIndex:0] intValue] < 7; + return ret; +} +#endif + static void apple_gamecontroller_poll(GCController* controller) { #ifdef IOS - if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 ) + if (apple_rarch_is_ios7_or_higher()) return; #endif if (!controller || controller.playerIndex == MAX_PLAYERS) @@ -79,7 +88,7 @@ static void apple_gamecontroller_poll(GCController* controller) void apple_gamecontroller_poll_all(void) { #ifdef IOS - if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 ) + if (apple_rarch_is_ios7_or_higher()) return; #endif NSArray* controllers = [GCController controllers]; @@ -91,7 +100,7 @@ void apple_gamecontroller_poll_all(void) void apple_gamecontroller_connect(GCController* controller) { #ifdef IOS - if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 ) + if (apple_rarch_is_ios7_or_higher()) return; #endif int32_t slot = apple_joypad_connect_gcapi(); @@ -112,7 +121,7 @@ void apple_gamecontroller_connect(GCController* controller) void apple_gamecontroller_disconnect(GCController* controller) { #ifdef IOS - if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 ) + if (apple_rarch_is_ios7_or_higher()) return; #endif if (controller.playerIndex == GCControllerPlayerIndexUnset) @@ -124,9 +133,7 @@ void apple_gamecontroller_disconnect(GCController* controller) void apple_gamecontroller_init(void) { #ifdef IOS - versionCompatibility = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."]; - - if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 ) + if (apple_rarch_is_ios7_or_higher()) return; #endif diff --git a/apple/common/main.m b/apple/common/main.m index 5e235a6bd4..952bdcf9e2 100644 --- a/apple/common/main.m +++ b/apple/common/main.m @@ -54,78 +54,79 @@ static void apple_rarch_exited() static void do_iteration() { - if (iterate_observer && apple_is_running && !g_extern.is_paused) - { - if (main_entry_iterate(0, NULL, NULL)) - { - main_exit(NULL); - apple_rarch_exited(); - } - else - CFRunLoopWakeUp(CFRunLoopGetMain()); - } + bool iterate = iterate_observer && apple_is_running && !g_extern.is_paused; + + if (!iterate) + return; + + if (main_entry_iterate(0, NULL, NULL)) + { + main_exit(NULL); + apple_rarch_exited(); + } + else + CFRunLoopWakeUp(CFRunLoopGetMain()); } void apple_start_iteration() { - if (!iterate_observer) - { - iterate_observer = CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting, true, 0, do_iteration, 0); - CFRunLoopAddObserver(CFRunLoopGetMain(), iterate_observer, kCFRunLoopCommonModes); - } + if (iterate_observer) + return; + + iterate_observer = CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting, true, 0, do_iteration, 0); + CFRunLoopAddObserver(CFRunLoopGetMain(), iterate_observer, kCFRunLoopCommonModes); } void apple_stop_iteration() { - if (iterate_observer) - { - CFRunLoopObserverInvalidate(iterate_observer); - CFRelease(iterate_observer); - iterate_observer = 0; - } + if (!iterate_observer) + return; + + CFRunLoopObserverInvalidate(iterate_observer); + CFRelease(iterate_observer); + iterate_observer = 0; } void apple_run_core(NSString* core, const char* file) { - if (!apple_is_running) - { - [apple_platform loadingCore:core withFile:file]; - - apple_core = core; - apple_is_running = true; - - static char config_path[PATH_MAX]; - static char core_path[PATH_MAX]; - static char file_path[PATH_MAX]; - - if (apple_core_info_has_custom_config(apple_core.UTF8String)) - apple_core_info_get_custom_config(apple_core.UTF8String, config_path, sizeof(config_path)); - else - strlcpy(config_path, apple_platform.globalConfigFile.UTF8String, sizeof(config_path)); - - static const char* const argv_game[] = { "retroarch", "-c", config_path, "-L", core_path, file_path, 0 }; - static const char* const argv_menu[] = { "retroarch", "-c", config_path, "--menu", 0 }; - - if (file && core) - { - strlcpy(core_path, apple_core.UTF8String, sizeof(core_path)); - strlcpy(file_path, file, sizeof(file_path)); - } - - int argc = (file && core) ? 6 : 4; - char** argv = (char**)((file && core) ? argv_game : argv_menu); - - if (apple_rarch_load_content(argc, argv)) - { - char basedir[256]; - fill_pathname_basedir(basedir, file ? file : "", sizeof(basedir)); - if (file && access(basedir, R_OK | W_OK | X_OK)) - apple_display_alert(@"The directory containing the selected file must have write premissions. This will " - "prevent zipped content from loading, and will cause some cores to not function.", 0); - else - apple_display_alert(@"Failed to load content.", 0); - - apple_rarch_exited(); - } - } + if (apple_is_running) + return; + + [apple_platform loadingCore:core withFile:file]; + + apple_core = core; + apple_is_running = true; + + static char config_path[PATH_MAX]; + static char core_path[PATH_MAX]; + static char file_path[PATH_MAX]; + + if (apple_core_info_has_custom_config(apple_core.UTF8String)) + apple_core_info_get_custom_config(apple_core.UTF8String, config_path, sizeof(config_path)); + else + strlcpy(config_path, apple_platform.globalConfigFile.UTF8String, sizeof(config_path)); + + static const char* const argv_game[] = { "retroarch", "-c", config_path, "-L", core_path, file_path, 0 }; + static const char* const argv_menu[] = { "retroarch", "-c", config_path, "--menu", 0 }; + + if (file && core) + { + strlcpy(core_path, apple_core.UTF8String, sizeof(core_path)); + strlcpy(file_path, file, sizeof(file_path)); + } + + int argc = (file && core) ? 6 : 4; + char** argv = (char**)((file && core) ? argv_game : argv_menu); + + if (apple_rarch_load_content(argc, argv)) + { + char basedir[256]; + fill_pathname_basedir(basedir, file ? file : "", sizeof(basedir)); + if (file && access(basedir, R_OK | W_OK | X_OK)) + apple_display_alert(BOXSTRING("The directory containing the selected file must have write premissions. This will prevent zipped content from loading, and will cause some cores to not function."), 0); + else + apple_display_alert(BOXSTRING("Failed to load content."), 0); + + apple_rarch_exited(); + } }