diff --git a/ios/RetroArch/AppDelegate.m b/ios/RetroArch/AppDelegate.m
index 72f671ded0..5226907a47 100644
--- a/ios/RetroArch/AppDelegate.m
+++ b/ios/RetroArch/AppDelegate.m
@@ -56,5 +56,11 @@ extern int16_t IOS_touch_x, IOS_touch_y;
IOS_is_down = false;
}
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+ extern void ios_close_game();
+ ios_close_game();
+}
+
@end
diff --git a/ios/RetroArch/RetroArch-Info.plist b/ios/RetroArch/RetroArch-Info.plist
index 858508d759..6a3d2960f5 100644
--- a/ios/RetroArch/RetroArch-Info.plist
+++ b/ios/RetroArch/RetroArch-Info.plist
@@ -36,6 +36,8 @@
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
+ UIApplicationExitsOnSuspend
+
UISupportedInterfaceOrientations~ipad
UIInterfaceOrientationPortrait
diff --git a/ios/RetroArch/dirlist.m b/ios/RetroArch/dirlist.m
index 95a2a3ded4..024bda1ebe 100644
--- a/ios/RetroArch/dirlist.m
+++ b/ios/RetroArch/dirlist.m
@@ -137,7 +137,9 @@ struct dirent_list* build_dirent_list(const char* path)
window.rootViewController = [[game_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
game_view* game = (game_view*)window.rootViewController;
- [game load_game:path];
+
+ extern void ios_load_game(const char*);
+ ios_load_game(path);
}
}
diff --git a/ios/RetroArch/gameview.m b/ios/RetroArch/gameview.m
index 4c7e7bcc5f..33d837abb8 100644
--- a/ios/RetroArch/gameview.m
+++ b/ios/RetroArch/gameview.m
@@ -17,20 +17,21 @@
#import "gameview.h"
#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;
@implementation game_view
{
EAGLContext *gl_context;
-
- BOOL ra_initialized;
- BOOL ra_done;
}
- (void)schedule_iterate
{
- if (ra_initialized && !ra_done) [self performSelector:@selector(rarch_iterate:) withObject:nil afterDelay:0.002f];
+ if (ra_initialized && !ra_done)
+ [self performSelector:@selector(rarch_iterate:) withObject:nil afterDelay:0.002f];
}
- (void)rarch_iterate:(id)sender
@@ -41,50 +42,10 @@ static float screen_scale;
[self schedule_iterate];
}
-- (void)load_game:(const char*)file_name
-{
- if(!ra_initialized && file_name)
- {
- const char* libretro = [[[NSBundle mainBundle] pathForResource:@"libretro" ofType:@"dylib"] UTF8String];
- const char* overlay = [[[NSBundle mainBundle] pathForResource:@"overlay" ofType:@"cfg"] UTF8String];
-
- strcpy(g_settings.input.overlay, overlay ? overlay : "");
-
- const char* argv[] = {"retroarch", "-L", libretro, file_name, 0};
- if (rarch_main_init(6, (char**)argv) == 0)
- {
- rarch_init_msg_queue();
- ra_initialized = TRUE;
- [self schedule_iterate];
- }
- }
-}
-
-- (void)close_game
-{
- if (ra_initialized)
- {
- rarch_main_deinit();
- rarch_deinit_msg_queue();
-
-#ifdef PERF_TEST
- rarch_perf_log();
-#endif
-
- rarch_main_clear_state();
- }
-
- ra_initialized = FALSE;
-}
-
-
- (void)viewDidLoad
{
[super viewDidLoad];
- ra_done = NO;
- ra_initialized = NO;
-
gl_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
[EAGLContext setCurrentContext:gl_context];
@@ -92,10 +53,11 @@ static float screen_scale;
self.view = gl_view;
screen_scale = [[UIScreen mainScreen] scale];
+ current_view = self;
}
- (void)dealloc
-{
+{
if ([EAGLContext currentContext] == gl_context) [EAGLContext setCurrentContext:nil];
gl_context = nil;
gl_view = nil;
@@ -121,3 +83,41 @@ void get_game_view_size(unsigned *width, unsigned *height)
}
}
+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;
+}
+
+void ios_load_game(const char* file_name)
+{
+ if(!ra_initialized && file_name)
+ {
+ const char* libretro = [[[NSBundle mainBundle] pathForResource:@"libretro" ofType:@"dylib"] UTF8String];
+ const char* overlay = [[[NSBundle mainBundle] pathForResource:@"overlay" ofType:@"cfg"] UTF8String];
+
+ strcpy(g_settings.input.overlay, overlay ? overlay : "");
+
+ const char* argv[] = {"retroarch", "-L", libretro, file_name, 0};
+ if (rarch_main_init(6, (char**)argv) == 0)
+ {
+ rarch_init_msg_queue();
+ ra_initialized = TRUE;
+
+ if (current_view) [current_view schedule_iterate];
+ }
+ }
+}