ios: Now starts with a directory browser to let you choose the game you wan't to play.

This commit is contained in:
meancoot 2013-02-07 12:05:46 -05:00
parent ec51c819a3
commit 5d0828d009
6 changed files with 122 additions and 110 deletions

View File

@ -10,7 +10,6 @@
9629797716C3CD2400E6DCE0 /* dirlist.m in Sources */ = {isa = PBXBuildFile; fileRef = 9629797616C3CD2400E6DCE0 /* dirlist.m */; };
962979ED16C3E86F00E6DCE0 /* gameview.m in Sources */ = {isa = PBXBuildFile; fileRef = 962979EB16C3E86F00E6DCE0 /* gameview.m */; };
962979EF16C3EA3E00E6DCE0 /* ioseagl_ctx.c in Sources */ = {isa = PBXBuildFile; fileRef = 962979EE16C3EA3E00E6DCE0 /* ioseagl_ctx.c */; };
968A572A16C2A06800BE12F8 /* test.img in Resources */ = {isa = PBXBuildFile; fileRef = 968A572816C2A06800BE12F8 /* test.img */; };
96AFAE2A16C1D4EA009DE44C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE2916C1D4EA009DE44C /* UIKit.framework */; };
96AFAE2C16C1D4EA009DE44C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE2B16C1D4EA009DE44C /* Foundation.framework */; };
96AFAE2E16C1D4EA009DE44C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE2D16C1D4EA009DE44C /* CoreGraphics.framework */; };
@ -83,7 +82,6 @@
962979EB16C3E86F00E6DCE0 /* gameview.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = gameview.m; sourceTree = "<group>"; };
962979EC16C3E86F00E6DCE0 /* gameview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gameview.h; sourceTree = "<group>"; };
962979EE16C3EA3E00E6DCE0 /* ioseagl_ctx.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ioseagl_ctx.c; sourceTree = "<group>"; };
968A572816C2A06800BE12F8 /* test.img */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.img; sourceTree = "<group>"; };
96AFAE2516C1D4EA009DE44C /* RetroArch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RetroArch.app; sourceTree = BUILT_PRODUCTS_DIR; };
96AFAE2916C1D4EA009DE44C /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
96AFAE2B16C1D4EA009DE44C /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@ -294,7 +292,6 @@
isa = PBXGroup;
children = (
96CF014A16C2BA1900ABF9C9 /* libretro.dylib */,
968A572816C2A06800BE12F8 /* test.img */,
96AFAF2116C1DF88009DE44C /* libz.dylib */,
96AFAF1E16C1DF0A009DE44C /* OpenAL.framework */,
96AFAE9C16C1D976009DE44C /* core */,
@ -718,7 +715,6 @@
96AFAE4416C1D4EA009DE44C /* Default-568h@2x.png in Resources */,
96AFAE4E16C1D4EA009DE44C /* ViewController_iPhone.xib in Resources */,
96AFAE5116C1D4EA009DE44C /* ViewController_iPad.xib in Resources */,
968A572A16C2A06800BE12F8 /* test.img in Resources */,
96CF014F16C2BB9E00ABF9C9 /* libretro.dylib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -6,11 +6,8 @@
//
#import "AppDelegate.h"
#import "gameview.h"
#include "general.h"
#import "dirlist.h"
extern bool IOS_is_down;
extern int16_t IOS_touch_x, IOS_fix_x;
@ -19,103 +16,25 @@ extern int16_t IOS_full_x, IOS_full_y;
@implementation AppDelegate
{
BOOL ra_initialized;
BOOL ra_paused;
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
{
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;
const char* argv[] = {"retroarch", "-L", libretro, "-c", config_file, filename, 0};
if (rarch_main_init(6, (char**)argv) == 0)
{
rarch_init_msg_queue();
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();
#ifdef PERF_TEST
rarch_perf_log();
#endif
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.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
self.viewController = [[game_view alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
self.viewController = [[dirlist_view alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
else
self.viewController = [[game_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
self.viewController = [[dirlist_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[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];
CGPoint coord = [touch locationInView:self.window.rootViewController.view];
float scale = [[UIScreen mainScreen] scale];
IOS_is_down = true;
@ -126,8 +45,7 @@ extern int16_t IOS_full_x, IOS_full_y;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint coord = [touch locationInView:self.viewController.view];
CGPoint coord = [touch locationInView:self.window.rootViewController.view];
IOS_is_down = true;
IOS_touch_x = coord.x;
IOS_touch_y = coord.y;
@ -145,12 +63,10 @@ extern int16_t IOS_full_x, IOS_full_y;
- (void)applicationWillResignActive:(UIApplication *)application
{
ra_paused = YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
ra_paused = YES;
}
- (void)applicationWillEnterForeground:(UIApplication *)application
@ -159,11 +75,6 @@ extern int16_t IOS_full_x, IOS_full_y;
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (ra_paused)
{
ra_paused = NO;
[self schedule_iterate];
}
}
- (void)applicationWillTerminate:(UIApplication *)application

View File

@ -7,6 +7,6 @@
#import <UIKit/UIKit.h>
@interface DirectoryView : UIViewController <UITableViewDelegate, UITableViewDataSource>
@interface dirlist_view : UIViewController <UITableViewDelegate, UITableViewDataSource>
@end

View File

@ -8,6 +8,7 @@
#include <dirent.h>
#import "dirlist.h"
#import "gameview.h"
struct dirent_list
{
@ -41,14 +42,14 @@ unsigned get_dirent_list_count(struct dirent_list* list)
void free_dirent_list(struct dirent_list* list)
{
struct dirent_list* next = 0;
if (list)
{
next = list->next;
free(list);
}
struct dirent_list* next = list ? list : 0;
free_dirent_list(next);
while (next)
{
struct dirent_list* me = next;
next = next->next;
free(me);
}
}
struct dirent_list* build_dirent_list(const char* path)
@ -84,8 +85,9 @@ struct dirent_list* build_dirent_list(const char* path)
return result;
}
@implementation DirectoryView
@implementation dirlist_view
{
char path[4096];
UITableView* table;
struct dirent_list* files;
};
@ -102,7 +104,8 @@ struct dirent_list* build_dirent_list(const char* path)
{
[super viewDidLoad];
files = build_dirent_list([NSTemporaryDirectory() UTF8String]);
strcpy(path, "/");
files = build_dirent_list(path);
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) style:UITableViewStylePlain];
table.dataSource = self;
@ -114,6 +117,30 @@ struct dirent_list* build_dirent_list(const char* path)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
const struct dirent* item = get_dirent_at_index(files, indexPath.row);
if (!item) return;
strcat(path, "/");
strcat(path, item->d_name);
if (item->d_type & DT_DIR)
{
free_dirent_list(files);
files = build_dirent_list(path);
[table reloadData];
}
else
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
window.rootViewController = [[game_view alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
else
window.rootViewController = [[game_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
game_view* game = (game_view*)window.rootViewController;
[game load_game:path];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

View File

@ -9,5 +9,5 @@
#import <GLKit/GLKit.h>
@interface game_view : UIViewController
- (void)load_game:(const char*)file_name;
@end

View File

@ -15,6 +15,7 @@
*/
#import "gameview.h"
#include "general.h"
static GLKView *gl_view;
static float screen_scale;
@ -27,11 +28,87 @@ static float screen_scale;
@end
@implementation game_view
{
BOOL ra_initialized;
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
{
if (ra_initialized && !ra_done)
{
[self performSelector:@selector(rarch_iterate:) withObject:nil afterDelay:0.002f];
}
}
- (void)rarch_iterate:(id)sender
{
if (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();
#ifdef PERF_TEST
rarch_perf_log();
#endif
rarch_main_clear_state();
}
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
{
[super viewDidLoad];
ra_done = NO;
ra_initialized = NO;
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
self.view = [[GLKView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) context:self.context];
@ -59,3 +136,4 @@ void get_game_view_size(unsigned *width, unsigned *height)
*width = gl_view.bounds.size.width * screen_scale;
*height = gl_view.bounds.size.height * screen_scale;
}