ios: Some cleanup and simplifications

This commit is contained in:
meancoot 2013-02-07 12:38:30 -05:00
parent 5d0828d009
commit 16759620b5
4 changed files with 46 additions and 93 deletions

View File

@ -7,12 +7,8 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate> @interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIViewController *viewController;
@end @end

View File

@ -6,14 +6,10 @@
// //
#import "AppDelegate.h" #import "AppDelegate.h"
#import "gameview.h"
#import "dirlist.h" #import "dirlist.h"
extern bool IOS_is_down; extern bool IOS_is_down;
extern int16_t IOS_touch_x, IOS_fix_x; extern int16_t IOS_touch_x, IOS_touch_y;
extern int16_t IOS_touch_y, IOS_fix_y;
extern int16_t IOS_full_x, IOS_full_y;
@implementation AppDelegate @implementation AppDelegate
@ -23,11 +19,10 @@ extern int16_t IOS_full_x, IOS_full_y;
// Override point for customization after application launch. // Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 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 else
self.viewController = [[dirlist_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; self.window.rootViewController = [[dirlist_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];
} }
@ -61,25 +56,5 @@ extern int16_t IOS_full_x, IOS_full_y;
IOS_is_down = false; 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 @end

View File

@ -96,8 +96,6 @@ struct dirent_list* build_dirent_list(const char* path)
{ {
free_dirent_list(files); free_dirent_list(files);
files = 0; files = 0;
// Do I need to kill table here?
} }
- (void)viewDidLoad - (void)viewDidLoad
@ -120,11 +118,11 @@ struct dirent_list* build_dirent_list(const char* path)
if (!item) return; if (!item) return;
strcat(path, "/");
strcat(path, item->d_name); strcat(path, item->d_name);
if (item->d_type & DT_DIR) if (item->d_type & DT_DIR)
{ {
strcat(path, "/");
free_dirent_list(files); free_dirent_list(files);
files = build_dirent_list(path); files = build_dirent_list(path);
[table reloadData]; [table reloadData];

View File

@ -20,42 +20,17 @@
static GLKView *gl_view; static GLKView *gl_view;
static float screen_scale; static float screen_scale;
@interface game_view ()
@property (strong, nonatomic) EAGLContext *context;
@property (strong, nonatomic) GLKView *view;
@end
@implementation game_view @implementation game_view
{ {
EAGLContext *gl_context;
BOOL ra_initialized; BOOL ra_initialized;
BOOL ra_done; BOOL ra_done;
} }
- (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;
}
- (void)schedule_iterate - (void)schedule_iterate
{ {
if (ra_initialized && !ra_done) if (ra_initialized && !ra_done) [self performSelector:@selector(rarch_iterate:) withObject:nil afterDelay:0.002f];
{
[self performSelector:@selector(rarch_iterate:) withObject:nil afterDelay:0.002f];
}
} }
- (void)rarch_iterate:(id)sender - (void)rarch_iterate:(id)sender
@ -66,7 +41,26 @@ static float screen_scale;
[self schedule_iterate]; [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) if (ra_initialized)
{ {
@ -83,24 +77,6 @@ static float screen_scale;
ra_initialized = FALSE; 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 - (void)viewDidLoad
{ {
@ -109,31 +85,39 @@ static float screen_scale;
ra_done = NO; ra_done = NO;
ra_initialized = NO; ra_initialized = NO;
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; gl_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
self.view = [[GLKView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) context:self.context]; [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]; screen_scale = [[UIScreen mainScreen] scale];
} }
- (void)dealloc - (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 @end
void flip_game_view() void flip_game_view()
{ {
if (gl_view)
{
[gl_view setNeedsDisplay]; [gl_view setNeedsDisplay];
[gl_view bindDrawable]; [gl_view bindDrawable];
}
} }
void get_game_view_size(unsigned *width, unsigned *height) void get_game_view_size(unsigned *width, unsigned *height)
{ {
if (gl_view)
{
*width = gl_view.bounds.size.width * screen_scale; *width = gl_view.bounds.size.width * screen_scale;
*height = gl_view.bounds.size.height * screen_scale; *height = gl_view.bounds.size.height * screen_scale;
}
} }