ios: Fix size on retina screens; 'improve' life cycle management.

This commit is contained in:
meancoot 2013-02-06 20:48:32 -05:00
parent 7e4e028fc8
commit 7b9490db48
2 changed files with 54 additions and 18 deletions

View File

@ -29,6 +29,7 @@
#import "../../ios/RetroArch/ViewController.h"
static GLKView *gl_view;
static float screen_scale;
// Objective-C interface used to interact with the GLES context and display.
@interface ViewController ()
@ -50,6 +51,7 @@ static GLKView *gl_view;
[EAGLContext setCurrentContext:self.context];
gl_view = self.view;
screen_scale = [[UIScreen mainScreen] scale];
}
- (void)dealloc
@ -73,8 +75,8 @@ static void gfx_ctx_destroy(void)
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height)
{
*width = gl_view.bounds.size.width;
*height = gl_view.bounds.size.height;
*width = gl_view.bounds.size.width * screen_scale;
*height = gl_view.bounds.size.height * screen_scale;
}
static bool gfx_ctx_init(void)
@ -95,8 +97,6 @@ static void gfx_ctx_check_window(bool *quit,
*quit = false;
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource);
unsigned new_width, new_height;
gfx_ctx_get_video_size(&new_width, &new_height);
if (new_width != *width || new_height != *height)

View File

@ -19,6 +19,11 @@ extern int16_t IOS_full_x, IOS_full_y;
@implementation AppDelegate
{
BOOL ra_initialized;
BOOL ra_paused;
BOOL ra_done;
}
- (const char*)generate_config
{
@ -37,19 +42,42 @@ extern int16_t IOS_full_x, IOS_full_y;
return 0;
}
- (void)runMain:(id)sender
- (void)schedule_iterate
{
if (ra_initialized && !ra_paused && !ra_done)
{
[self performSelector:@selector(rarch_iterate:) withObject:nil afterDelay:0.002f];
}
}
- (void)rarch_init
{
const char* filename = [[[NSBundle mainBundle] pathForResource:@"test" ofType:@"img"] UTF8String];
const char* libretro = [[[NSBundle mainBundle] pathForResource:@"libretro" ofType:@"dylib"] UTF8String];
const char* config_file = [self generate_config];
if (!config_file) return;
if(!config_file) return;
const char* argv[] = {"retroarch", "-L", libretro, "-c", config_file, filename, 0};
if (rarch_main_init(6, (char**)argv) == 0)
{
rarch_init_msg_queue();
while (rarch_main_iterate());
ra_initialized = TRUE;
}
}
- (void)rarch_iterate:(id)sender
{
if (!ra_paused && ra_initialized && !ra_done)
ra_done = !rarch_main_iterate();
[self schedule_iterate];
}
- (void)rarch_deinit
{
if (ra_initialized)
{
rarch_main_deinit();
rarch_deinit_msg_queue();
@ -59,10 +87,16 @@ extern int16_t IOS_full_x, IOS_full_y;
rarch_main_clear_state();
}
ra_initialized = FALSE;
}
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
ra_paused = NO;
ra_done = NO;
ra_initialized = NO;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
@ -73,18 +107,20 @@ extern int16_t IOS_full_x, IOS_full_y;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self performSelector:@selector(runMain:) withObject:nil afterDelay:0.2f];
[self rarch_init];
[self performSelector:@selector(rarch_iterate:) withObject:nil afterDelay:1];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint coord = [touch locationInView:self.viewController.view];
float scale = [[UIScreen mainScreen] scale];
IOS_is_down = true;
IOS_touch_x = coord.x;
IOS_touch_y = coord.y;
IOS_touch_x = coord.x * scale;
IOS_touch_y = coord.y * scale;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
@ -109,29 +145,29 @@ extern int16_t IOS_full_x, IOS_full_y;
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
ra_paused = YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
ra_paused = YES;
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
if (ra_paused)
{
ra_paused = NO;
[self schedule_iterate];
}
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end