diff --git a/ios/RetroArch/RetroArch-Info.plist b/ios/RetroArch/RetroArch-Info.plist
index 6a3d2960f5..381fc886b6 100644
--- a/ios/RetroArch/RetroArch-Info.plist
+++ b/ios/RetroArch/RetroArch-Info.plist
@@ -37,7 +37,7 @@
UIInterfaceOrientationLandscapeRight
UIApplicationExitsOnSuspend
-
+
UISupportedInterfaceOrientations~ipad
UIInterfaceOrientationPortrait
diff --git a/ios/RetroArch/RetroArch_iOS.h b/ios/RetroArch/RetroArch_iOS.h
index d5eacee460..ced57264bf 100644
--- a/ios/RetroArch/RetroArch_iOS.h
+++ b/ios/RetroArch/RetroArch_iOS.h
@@ -13,7 +13,8 @@ extern NSString *const GSEventKeyUpNotification;
@interface RetroArch_iOS : UIResponder
+ (RetroArch_iOS*)get;
-- (void)game_has_started;
+- (void)runGame:(NSString*)path;
+- (void)gameHasExited;
@property (strong, nonatomic) NSString* system_directory;
@property (strong, nonatomic) NSString* config_file_path;
diff --git a/ios/RetroArch/RetroArch_iOS.m b/ios/RetroArch/RetroArch_iOS.m
index 2f26890426..ed5b6fd67d 100644
--- a/ios/RetroArch/RetroArch_iOS.m
+++ b/ios/RetroArch/RetroArch_iOS.m
@@ -27,6 +27,20 @@ extern uint32_t ios_current_touch_count;
return (RetroArch_iOS*)[[UIApplication sharedApplication] delegate];
}
+- (void)runGame:(NSString*)path
+{
+ self.window.rootViewController = [[game_view alloc] initWithGame:path];
+ self.navigator = nil;
+}
+
+- (void)gameHasExited
+{
+ self.navigator = [[UINavigationController alloc] init];
+ [self.navigator pushViewController: [[module_list alloc] init] animated:YES];
+
+ self.window.rootViewController = self.navigator;
+}
+
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// TODO: Relocate this!
@@ -77,11 +91,6 @@ extern uint32_t ios_current_touch_count;
[self.navigator pushViewController: [[settings_list alloc] init] animated:YES];
}
-- (void)game_has_started
-{
- self.navigator = nil;
-}
-
- (void)processTouches:(NSArray*)touches
{
ios_current_touch_count = [touches count];
@@ -123,11 +132,5 @@ extern uint32_t ios_current_touch_count;
[self processTouches:[[event allTouches] allObjects]];
}
-- (void)applicationWillTerminate:(UIApplication *)application
-{
- extern void ios_close_game();
- ios_close_game();
-}
-
@end
diff --git a/ios/RetroArch/directory_list.m b/ios/RetroArch/directory_list.m
index de985884a9..f1243428ed 100644
--- a/ios/RetroArch/directory_list.m
+++ b/ios/RetroArch/directory_list.m
@@ -63,10 +63,7 @@ static BOOL is_directory(NSString* path)
}
else
{
- [RetroArch_iOS get].window.rootViewController = [[game_view alloc] init];
-
- extern void ios_load_game(const char*);
- ios_load_game([path UTF8String]);
+ [[RetroArch_iOS get] runGame:path];
}
}
diff --git a/ios/RetroArch/game_view.m b/ios/RetroArch/game_view.m
index 850d5463a5..89c43b70be 100644
--- a/ios/RetroArch/game_view.m
+++ b/ios/RetroArch/game_view.m
@@ -16,76 +16,23 @@
#include "general.h"
-static game_view *current_view;
static GLKView *gl_view;
static float screen_scale;
-static bool ra_initialized = false;
-static bool ra_done = false;
static int frame_skips = 4;
static bool is_syncing = true;
-void ios_load_game(const char* file_name)
-{
- if(!ra_initialized && file_name)
- {
- [settings_list refresh_config_file];
-
- const char* const sd = [[RetroArch_iOS get].system_directory UTF8String];
- const char* const cf =[[RetroArch_iOS get].config_file_path UTF8String];
- const char* const libretro = [[RetroArch_iOS get].module_path UTF8String];
-
- bool have_config = 0 == access(cf, R_OK);
-
- struct rarch_main_wrap main_wrapper = {file_name, sd, sd, have_config ? cf : 0, libretro};
- if (rarch_main_init_wrap(&main_wrapper) == 0)
- {
- rarch_init_msg_queue();
- ra_initialized = TRUE;
-
- [[RetroArch_iOS get ]game_has_started];
- [current_view performSelector:@selector(rarch_iterate:) withObject:nil afterDelay:0.2f];
- }
- }
-}
-
-void ios_close_game()
-{
- if (ra_initialized)
- {
- rarch_main_deinit();
- rarch_deinit_msg_queue();
-
-#ifdef PERF_TEST
- rarch_perf_log();
-#endif
-
- rarch_main_clear_state();
-
- ra_done = true;
- }
-
- ra_initialized = false;
-}
-
@implementation game_view
{
EAGLContext *gl_context;
+ NSString* game;
}
-- (id)init
+- (id)initWithGame:(NSString*)path
{
self = [super init];
-
- gl_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
- [EAGLContext setCurrentContext:gl_context];
-
- gl_view = [[GLKView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) context:gl_context];
- gl_view.multipleTouchEnabled = YES;
- self.view = gl_view;
-
+ game = path;
screen_scale = [[UIScreen mainScreen] scale];
- current_view = self;
-
+
return self;
}
@@ -96,20 +43,43 @@ void ios_close_game()
gl_view = nil;
}
-
-- (void)rarch_iterate:(id)sender
+- (void)loadView
{
- if (ra_initialized && !ra_done)
- {
- while (!ra_done && rarch_main_iterate())
- {
- while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true) == kCFRunLoopRunHandledSource);
- }
+ gl_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
+ [EAGLContext setCurrentContext:gl_context];
+
+ gl_view = [[GLKView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) context:gl_context];
+ gl_view.multipleTouchEnabled = YES;
+ self.view = gl_view;
+
+ [self performSelector:@selector(runGame) withObject:nil afterDelay:0.2f];
+}
- ios_close_game();
+- (void)runGame
+{
+ [settings_list refresh_config_file];
+
+ const char* const sd = [[RetroArch_iOS get].system_directory UTF8String];
+ const char* const cf =[[RetroArch_iOS get].config_file_path UTF8String];
+ const char* const libretro = [[RetroArch_iOS get].module_path UTF8String];
+
+ struct rarch_main_wrap main_wrapper = {[game UTF8String], sd, sd, cf, libretro};
+ if (rarch_main_init_wrap(&main_wrapper) == 0)
+ {
+ rarch_init_msg_queue();
+ while (rarch_main_iterate())
+ while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true) == kCFRunLoopRunHandledSource);
+ rarch_main_deinit();
+ rarch_deinit_msg_queue();
- ra_done = true;
+#ifdef PERF_TEST
+ rarch_perf_log();
+#endif
+
+ rarch_main_clear_state();
}
+
+ [[RetroArch_iOS get] gameHasExited];
}
@end
diff --git a/ios/RetroArch/views.h b/ios/RetroArch/views.h
index 19bda460db..bd3a138bfd 100644
--- a/ios/RetroArch/views.h
+++ b/ios/RetroArch/views.h
@@ -2,7 +2,7 @@
#import
@interface game_view : UIViewController
-
+- (id)initWithGame:(NSString*)path;
@end
@interface module_list : UITableViewController