mirror of
https://github.com/libretro/RetroArch
synced 2025-02-04 21:40:02 +00:00
ios: Lifecycle fixes:
Fix crash when pressing home button. Add a hack to allow exiting the running game by triple-tapping on the top center of the screen. (Less than 10% from the top, and within the middle 20%)
This commit is contained in:
parent
625c2c6d48
commit
1fbe66cad0
@ -21,6 +21,9 @@ extern bool ios_keys[256];
|
||||
extern uint32_t ios_current_touch_count;
|
||||
|
||||
@implementation RetroArch_iOS
|
||||
{
|
||||
game_view* game;
|
||||
}
|
||||
|
||||
+ (RetroArch_iOS*)get
|
||||
{
|
||||
@ -29,12 +32,15 @@ extern uint32_t ios_current_touch_count;
|
||||
|
||||
- (void)runGame:(NSString*)path
|
||||
{
|
||||
self.window.rootViewController = [[game_view alloc] initWithGame:path];
|
||||
game = [[game_view alloc] initWithGame:path];
|
||||
self.window.rootViewController = game;
|
||||
self.navigator = nil;
|
||||
}
|
||||
|
||||
- (void)gameHasExited
|
||||
{
|
||||
game = nil;
|
||||
|
||||
self.navigator = [[UINavigationController alloc] init];
|
||||
[self.navigator pushViewController: [[module_list alloc] init] animated:YES];
|
||||
|
||||
@ -74,6 +80,22 @@ extern uint32_t ios_current_touch_count;
|
||||
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyReleased:) name: GSEventKeyUpNotification object: nil];
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application
|
||||
{
|
||||
if (game)
|
||||
{
|
||||
[game resume];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application
|
||||
{
|
||||
if (game)
|
||||
{
|
||||
[game pause];
|
||||
}
|
||||
}
|
||||
|
||||
-(void) keyPressed: (NSNotification*) notification
|
||||
{
|
||||
int keycode = [[notification.userInfo objectForKey:@"keycode"] intValue];
|
||||
@ -93,18 +115,34 @@ extern uint32_t ios_current_touch_count;
|
||||
|
||||
- (void)processTouches:(NSArray*)touches
|
||||
{
|
||||
ios_current_touch_count = [touches count];
|
||||
|
||||
for(int i = 0; i != [touches count]; i ++)
|
||||
if (game)
|
||||
{
|
||||
UITouch *touch = [touches objectAtIndex:i];
|
||||
CGPoint coord = [touch locationInView:self.window.rootViewController.view];
|
||||
float scale = [[UIScreen mainScreen] scale];
|
||||
ios_current_touch_count = [touches count];
|
||||
|
||||
for(int i = 0; i != [touches count]; i ++)
|
||||
{
|
||||
UITouch *touch = [touches objectAtIndex:i];
|
||||
CGPoint coord = [touch locationInView:game.view];
|
||||
float scale = [[UIScreen mainScreen] scale];
|
||||
|
||||
ios_touches[i].is_down = (touch.phase != UITouchPhaseEnded) && (touch.phase != UITouchPhaseCancelled);
|
||||
// Exit hack!
|
||||
if (touch.tapCount == 3)
|
||||
{
|
||||
if (coord.y < game.view.bounds.size.height / 10.0f)
|
||||
{
|
||||
float tenpct = game.view.bounds.size.width / 10.0f;
|
||||
if (coord.x >= tenpct * 4 && coord.x <= tenpct * 6)
|
||||
{
|
||||
[game exit];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ios_touches[i].screen_x = coord.x * scale;
|
||||
ios_touches[i].screen_y = coord.y * scale;
|
||||
ios_touches[i].is_down = (touch.phase != UITouchPhaseEnded) && (touch.phase != UITouchPhaseCancelled);
|
||||
|
||||
ios_touches[i].screen_x = coord.x * scale;
|
||||
ios_touches[i].screen_y = coord.y * scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,24 @@ static float screen_scale;
|
||||
static int frame_skips = 4;
|
||||
static bool is_syncing = true;
|
||||
|
||||
static bool active_iterate()
|
||||
{
|
||||
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true) == kCFRunLoopRunHandledSource);
|
||||
return rarch_main_iterate();
|
||||
}
|
||||
|
||||
static bool idle_iterate()
|
||||
{
|
||||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, .5, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@implementation game_view
|
||||
{
|
||||
EAGLContext *gl_context;
|
||||
NSString* game;
|
||||
bool paused;
|
||||
bool exiting;
|
||||
}
|
||||
|
||||
- (id)initWithGame:(NSString*)path
|
||||
@ -36,6 +50,21 @@ static bool is_syncing = true;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)pause
|
||||
{
|
||||
paused = true;
|
||||
}
|
||||
|
||||
- (void)resume
|
||||
{
|
||||
paused = false;
|
||||
}
|
||||
|
||||
- (void)exit
|
||||
{
|
||||
exiting = true;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
if ([EAGLContext currentContext] == gl_context) [EAGLContext setCurrentContext:nil];
|
||||
@ -67,8 +96,7 @@ static bool is_syncing = true;
|
||||
if (rarch_main_init_wrap(&main_wrapper) == 0)
|
||||
{
|
||||
rarch_init_msg_queue();
|
||||
while (rarch_main_iterate())
|
||||
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true) == kCFRunLoopRunHandledSource);
|
||||
while (!exiting && (paused ? idle_iterate() : active_iterate()));
|
||||
rarch_main_deinit();
|
||||
rarch_deinit_msg_queue();
|
||||
|
||||
|
@ -4,7 +4,10 @@
|
||||
#include "conf/config_file.h"
|
||||
|
||||
@interface game_view : UIViewController
|
||||
- (id)initWithGame:(NSString*)path;
|
||||
- (id)initWithGame:(NSString*)path;\
|
||||
- (void)pause;
|
||||
- (void)resume;
|
||||
- (void)exit;
|
||||
@end
|
||||
|
||||
@interface module_list : UITableViewController
|
||||
|
Loading…
x
Reference in New Issue
Block a user