diff --git a/ios/RetroArch/AppDelegate.h b/ios/RetroArch/AppDelegate.h index 2f02605b45..a1c6c7f0ad 100644 --- a/ios/RetroArch/AppDelegate.h +++ b/ios/RetroArch/AppDelegate.h @@ -7,12 +7,8 @@ #import -@class ViewController; - @interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; -@property (strong, nonatomic) UIViewController *viewController; - @end diff --git a/ios/RetroArch/AppDelegate.m b/ios/RetroArch/AppDelegate.m index 38d1976ed6..72f671ded0 100644 --- a/ios/RetroArch/AppDelegate.m +++ b/ios/RetroArch/AppDelegate.m @@ -6,14 +6,10 @@ // #import "AppDelegate.h" -#import "gameview.h" #import "dirlist.h" extern bool IOS_is_down; -extern int16_t IOS_touch_x, IOS_fix_x; -extern int16_t IOS_touch_y, IOS_fix_y; -extern int16_t IOS_full_x, IOS_full_y; - +extern int16_t IOS_touch_x, IOS_touch_y; @implementation AppDelegate @@ -23,11 +19,10 @@ extern int16_t IOS_full_x, IOS_full_y; // Override point for customization after application launch. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) - self.viewController = [[dirlist_view alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; + self.window.rootViewController = [[dirlist_view alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; else - self.viewController = [[dirlist_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; - - self.window.rootViewController = self.viewController; + self.window.rootViewController = [[dirlist_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; + [self.window makeKeyAndVisible]; } @@ -61,25 +56,5 @@ extern int16_t IOS_full_x, IOS_full_y; IOS_is_down = false; } -- (void)applicationWillResignActive:(UIApplication *)application -{ -} - -- (void)applicationDidEnterBackground:(UIApplication *)application -{ -} - -- (void)applicationWillEnterForeground:(UIApplication *)application -{ -} - -- (void)applicationDidBecomeActive:(UIApplication *)application -{ -} - -- (void)applicationWillTerminate:(UIApplication *)application -{ -} - @end diff --git a/ios/RetroArch/dirlist.m b/ios/RetroArch/dirlist.m index d923f24b2d..95a2a3ded4 100644 --- a/ios/RetroArch/dirlist.m +++ b/ios/RetroArch/dirlist.m @@ -96,8 +96,6 @@ struct dirent_list* build_dirent_list(const char* path) { free_dirent_list(files); files = 0; - - // Do I need to kill table here? } - (void)viewDidLoad @@ -120,11 +118,11 @@ struct dirent_list* build_dirent_list(const char* path) if (!item) return; - strcat(path, "/"); strcat(path, item->d_name); if (item->d_type & DT_DIR) { + strcat(path, "/"); free_dirent_list(files); files = build_dirent_list(path); [table reloadData]; diff --git a/ios/RetroArch/gameview.m b/ios/RetroArch/gameview.m index 0beef6a225..4c7e7bcc5f 100644 --- a/ios/RetroArch/gameview.m +++ b/ios/RetroArch/gameview.m @@ -20,42 +20,17 @@ static GLKView *gl_view; static float screen_scale; -@interface game_view () - -@property (strong, nonatomic) EAGLContext *context; -@property (strong, nonatomic) GLKView *view; - -@end - @implementation game_view { - BOOL ra_initialized; - BOOL ra_done; -} + EAGLContext *gl_context; -- (const char*)generate_config -{ - const char* overlay = [[[NSBundle mainBundle] pathForResource:@"overlay" ofType:@"cfg"] UTF8String]; - const char* config = [[NSTemporaryDirectory() stringByAppendingPathComponent: @"retroarch.cfg"] UTF8String]; - - FILE* config_file = fopen(config, "wb"); - - if (config_file) - { - if (overlay) fprintf(config_file, "input_overlay = \"%s\"\n", overlay); - fclose(config_file); - return config; - } - - return 0; + 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 @@ -66,7 +41,26 @@ static float screen_scale; [self schedule_iterate]; } -- (void)rarch_deinit +- (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) { @@ -83,24 +77,6 @@ static float screen_scale; ra_initialized = FALSE; } -- (void)load_game:(const char*)file_name -{ - if(!ra_initialized && file_name) - { - const char* libretro = [[[NSBundle mainBundle] pathForResource:@"libretro" ofType:@"dylib"] UTF8String]; - const char* config_file = [self generate_config]; - - if(!config_file) return; - - const char* argv[] = {"retroarch", "-L", libretro, "-c", config_file, file_name, 0}; - if (rarch_main_init(6, (char**)argv) == 0) - { - rarch_init_msg_queue(); - ra_initialized = TRUE; - [self schedule_iterate]; - } - } -} - (void)viewDidLoad { @@ -109,31 +85,39 @@ static float screen_scale; ra_done = NO; ra_initialized = NO; - self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; - self.view = [[GLKView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) context:self.context]; + gl_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + [EAGLContext setCurrentContext:gl_context]; - [EAGLContext setCurrentContext:self.context]; + gl_view = [[GLKView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) context:gl_context]; + self.view = gl_view; - gl_view = self.view; screen_scale = [[UIScreen mainScreen] scale]; } - (void)dealloc { - if ([EAGLContext currentContext] == self.context) [EAGLContext setCurrentContext:nil]; + if ([EAGLContext currentContext] == gl_context) [EAGLContext setCurrentContext:nil]; + gl_context = nil; + gl_view = nil; } @end void flip_game_view() { - [gl_view setNeedsDisplay]; - [gl_view bindDrawable]; + if (gl_view) + { + [gl_view setNeedsDisplay]; + [gl_view bindDrawable]; + } } void get_game_view_size(unsigned *width, unsigned *height) { - *width = gl_view.bounds.size.width * screen_scale; - *height = gl_view.bounds.size.height * screen_scale; + if (gl_view) + { + *width = gl_view.bounds.size.width * screen_scale; + *height = gl_view.bounds.size.height * screen_scale; + } }