mirror of
https://github.com/libretro/RetroArch
synced 2025-02-05 06:40:07 +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;
|
extern uint32_t ios_current_touch_count;
|
||||||
|
|
||||||
@implementation RetroArch_iOS
|
@implementation RetroArch_iOS
|
||||||
|
{
|
||||||
|
game_view* game;
|
||||||
|
}
|
||||||
|
|
||||||
+ (RetroArch_iOS*)get
|
+ (RetroArch_iOS*)get
|
||||||
{
|
{
|
||||||
@ -29,12 +32,15 @@ extern uint32_t ios_current_touch_count;
|
|||||||
|
|
||||||
- (void)runGame:(NSString*)path
|
- (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;
|
self.navigator = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)gameHasExited
|
- (void)gameHasExited
|
||||||
{
|
{
|
||||||
|
game = nil;
|
||||||
|
|
||||||
self.navigator = [[UINavigationController alloc] init];
|
self.navigator = [[UINavigationController alloc] init];
|
||||||
[self.navigator pushViewController: [[module_list alloc] init] animated:YES];
|
[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];
|
[[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
|
-(void) keyPressed: (NSNotification*) notification
|
||||||
{
|
{
|
||||||
int keycode = [[notification.userInfo objectForKey:@"keycode"] intValue];
|
int keycode = [[notification.userInfo objectForKey:@"keycode"] intValue];
|
||||||
@ -93,19 +115,35 @@ extern uint32_t ios_current_touch_count;
|
|||||||
|
|
||||||
- (void)processTouches:(NSArray*)touches
|
- (void)processTouches:(NSArray*)touches
|
||||||
{
|
{
|
||||||
|
if (game)
|
||||||
|
{
|
||||||
ios_current_touch_count = [touches count];
|
ios_current_touch_count = [touches count];
|
||||||
|
|
||||||
for(int i = 0; i != [touches count]; i ++)
|
for(int i = 0; i != [touches count]; i ++)
|
||||||
{
|
{
|
||||||
UITouch *touch = [touches objectAtIndex:i];
|
UITouch *touch = [touches objectAtIndex:i];
|
||||||
CGPoint coord = [touch locationInView:self.window.rootViewController.view];
|
CGPoint coord = [touch locationInView:game.view];
|
||||||
float scale = [[UIScreen mainScreen] scale];
|
float scale = [[UIScreen mainScreen] scale];
|
||||||
|
|
||||||
|
// 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].is_down = (touch.phase != UITouchPhaseEnded) && (touch.phase != UITouchPhaseCancelled);
|
ios_touches[i].is_down = (touch.phase != UITouchPhaseEnded) && (touch.phase != UITouchPhaseCancelled);
|
||||||
|
|
||||||
ios_touches[i].screen_x = coord.x * scale;
|
ios_touches[i].screen_x = coord.x * scale;
|
||||||
ios_touches[i].screen_y = coord.y * scale;
|
ios_touches[i].screen_y = coord.y * scale;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
|
@ -21,10 +21,24 @@ static float screen_scale;
|
|||||||
static int frame_skips = 4;
|
static int frame_skips = 4;
|
||||||
static bool is_syncing = true;
|
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
|
@implementation game_view
|
||||||
{
|
{
|
||||||
EAGLContext *gl_context;
|
EAGLContext *gl_context;
|
||||||
NSString* game;
|
NSString* game;
|
||||||
|
bool paused;
|
||||||
|
bool exiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithGame:(NSString*)path
|
- (id)initWithGame:(NSString*)path
|
||||||
@ -36,6 +50,21 @@ static bool is_syncing = true;
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)pause
|
||||||
|
{
|
||||||
|
paused = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)resume
|
||||||
|
{
|
||||||
|
paused = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)exit
|
||||||
|
{
|
||||||
|
exiting = true;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
if ([EAGLContext currentContext] == gl_context) [EAGLContext setCurrentContext:nil];
|
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)
|
if (rarch_main_init_wrap(&main_wrapper) == 0)
|
||||||
{
|
{
|
||||||
rarch_init_msg_queue();
|
rarch_init_msg_queue();
|
||||||
while (rarch_main_iterate())
|
while (!exiting && (paused ? idle_iterate() : active_iterate()));
|
||||||
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true) == kCFRunLoopRunHandledSource);
|
|
||||||
rarch_main_deinit();
|
rarch_main_deinit();
|
||||||
rarch_deinit_msg_queue();
|
rarch_deinit_msg_queue();
|
||||||
|
|
||||||
|
@ -4,7 +4,10 @@
|
|||||||
#include "conf/config_file.h"
|
#include "conf/config_file.h"
|
||||||
|
|
||||||
@interface game_view : UIViewController
|
@interface game_view : UIViewController
|
||||||
- (id)initWithGame:(NSString*)path;
|
- (id)initWithGame:(NSString*)path;\
|
||||||
|
- (void)pause;
|
||||||
|
- (void)resume;
|
||||||
|
- (void)exit;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface module_list : UITableViewController
|
@interface module_list : UITableViewController
|
||||||
|
Loading…
x
Reference in New Issue
Block a user