ios: Start to fix lifecycle management. The home button no longer closes the running game, pressing the exit key returns you to the loader.
This commit is contained in:
parent
1ebc0ab81a
commit
0d99d9fbf8
|
@ -37,7 +37,7 @@
|
|||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIApplicationExitsOnSuspend</key>
|
||||
<true/>
|
||||
<false/>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
|
|
|
@ -13,7 +13,8 @@ extern NSString *const GSEventKeyUpNotification;
|
|||
@interface RetroArch_iOS : UIResponder <UIApplicationDelegate>
|
||||
|
||||
+ (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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#import <GLKit/GLKit.h>
|
||||
|
||||
@interface game_view : UIViewController
|
||||
|
||||
- (id)initWithGame:(NSString*)path;
|
||||
@end
|
||||
|
||||
@interface module_list : UITableViewController
|
||||
|
|
Loading…
Reference in New Issue