From 423f4944adb7c46a72490b9f7d826d051a8c9840 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 5 Jul 2013 03:56:41 +0200 Subject: [PATCH] (iOS/OSX) Make frontend code more generic --- frontend/{frontend_ios.c => frontend_objc.c} | 40 ++++++++++---------- griffin/griffin.c | 4 +- ios/RetroArch/main.m | 14 +++---- 3 files changed, 30 insertions(+), 28 deletions(-) rename frontend/{frontend_ios.c => frontend_objc.c} (83%) diff --git a/frontend/frontend_ios.c b/frontend/frontend_objc.c similarity index 83% rename from frontend/frontend_ios.c rename to frontend/frontend_objc.c index 2492711955..0a8d6e4f89 100644 --- a/frontend/frontend_ios.c +++ b/frontend/frontend_objc.c @@ -21,49 +21,51 @@ #include "../conf/config_file.h" #include "../file.h" +#ifdef IOS #include "../ios/RetroArch/rarch_wrapper.h" +#endif #ifdef HAVE_RGUI #include "../frontend/menu/rgui.h" #endif -static pthread_mutex_t ios_event_queue_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t apple_event_queue_lock = PTHREAD_MUTEX_INITIALIZER; static struct { void (*function)(void*); void* userdata; -} ios_event_queue[16]; -static uint32_t ios_event_queue_size; +} apple_event_queue[16]; -void ios_frontend_post_event(void (*fn)(void*), void* userdata) +static uint32_t apple_event_queue_size; + +void apple_frontend_post_event(void (*fn)(void*), void* userdata) { - pthread_mutex_lock(&ios_event_queue_lock); + pthread_mutex_lock(&apple_event_queue_lock); - if (ios_event_queue_size < 16) + if (apple_event_queue_size < 16) { - ios_event_queue[ios_event_queue_size].function = fn; - ios_event_queue[ios_event_queue_size].userdata = userdata; - ios_event_queue_size ++; + apple_event_queue[apple_event_queue_size].function = fn; + apple_event_queue[apple_event_queue_size].userdata = userdata; + apple_event_queue_size ++; } - pthread_mutex_unlock(&ios_event_queue_lock); + pthread_mutex_unlock(&apple_event_queue_lock); } static void process_events() { - pthread_mutex_lock(&ios_event_queue_lock); + pthread_mutex_lock(&apple_event_queue_lock); - for (int i = 0; i < ios_event_queue_size; i ++) - ios_event_queue[i].function(ios_event_queue[i].userdata); + for (int i = 0; i < apple_event_queue_size; i ++) + apple_event_queue[i].function(apple_event_queue[i].userdata); - ios_event_queue_size = 0; + apple_event_queue_size = 0; - pthread_mutex_unlock(&ios_event_queue_lock); + pthread_mutex_unlock(&apple_event_queue_lock); } - -static void ios_free_main_wrap(struct rarch_main_wrap* wrap) +static void apple_free_main_wrap(struct rarch_main_wrap* wrap) { if (wrap) { @@ -77,11 +79,11 @@ static void ios_free_main_wrap(struct rarch_main_wrap* wrap) free(wrap); } -void* rarch_main_ios(void* args) +void* rarch_main_apple(void* args) { struct rarch_main_wrap* argdata = (struct rarch_main_wrap*)args; int init_ret = rarch_main_init_wrap(argdata); - ios_free_main_wrap(argdata); + apple_free_main_wrap(argdata); if (init_ret) { diff --git a/griffin/griffin.c b/griffin/griffin.c index 8c9212e5f1..2e152170b3 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -411,8 +411,8 @@ MAIN #include "../frontend/frontend_bbqnx.c" #elif defined(ANDROID) #include "../frontend/frontend_android.c" -#elif defined(IOS) -#include "../frontend/frontend_ios.c" +#elif defined(__APPLE__) +#include "../frontend/frontend_objc.c" #endif #ifndef IS_XCODE diff --git a/ios/RetroArch/main.m b/ios/RetroArch/main.m index 63f61f35ca..6f552a6cf9 100644 --- a/ios/RetroArch/main.m +++ b/ios/RetroArch/main.m @@ -96,8 +96,8 @@ int main(int argc, char *argv[]) } // From frontend/frontend_ios.c -extern void* rarch_main_ios(void* args); -extern void ios_frontend_post_event(void (*fn)(void*), void* userdata); +extern void* rarch_main_apple(void* args); +extern void apple_frontend_post_event(void (*fn)(void*), void* userdata); // These are based on the tag property of the button used to trigger the event @@ -282,7 +282,7 @@ static void event_reload_config(void* userdata) else load_data->config_path = strdup(RAModuleInfo.globalConfigPath.UTF8String); - if (pthread_create(&_retroThread, 0, rarch_main_ios, load_data)) + if (pthread_create(&_retroThread, 0, rarch_main_apple, load_data)) { [self rarchExited:NO]; return; @@ -318,7 +318,7 @@ static void event_reload_config(void* userdata) - (void)refreshConfig { if (_isRunning) - ios_frontend_post_event(&event_reload_config, 0); + apple_frontend_post_event(&event_reload_config, 0); else objc_clear_config_hack(); } @@ -388,7 +388,7 @@ static void event_reload_config(void* userdata) - (IBAction)basicEvent:(id)sender { if (_isRunning) - ios_frontend_post_event(&event_basic_command, ((UIView*)sender).tag); + apple_frontend_post_event(&event_basic_command, ((UIView*)sender).tag); [self closePauseMenu:sender]; } @@ -396,13 +396,13 @@ static void event_reload_config(void* userdata) - (IBAction)chooseState:(id)sender { if (_isRunning) - ios_frontend_post_event(event_set_state_slot, (void*)((UISegmentedControl*)sender).selectedSegmentIndex); + apple_frontend_post_event(event_set_state_slot, (void*)((UISegmentedControl*)sender).selectedSegmentIndex); } - (IBAction)showRGUI:(id)sender { if (_isRunning) - ios_frontend_post_event(event_show_rgui, 0); + apple_frontend_post_event(event_show_rgui, 0); [self closePauseMenu:sender]; }