(iOS Thread) Rough draft, needs a lot of work

This commit is contained in:
meancoot 2013-04-02 20:39:51 -04:00
parent 5a06fe347d
commit f4a3345f0b
4 changed files with 178 additions and 134 deletions

113
frontend/frontend_ios.c Normal file
View File

@ -0,0 +1,113 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
* Copyright (C) 2011-2013 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../general.h"
#include "../conf/config_file.h"
#include "../file.h"
#ifdef HAVE_RGUI
#include "../frontend/menu/rgui.h"
#endif
void ios_free_main_wrap(struct rarch_main_wrap* wrap)
{
if (wrap)
{
free((char*)wrap->libretro_path);
free((char*)wrap->rom_path);
free((char*)wrap->sram_path);
free((char*)wrap->state_path);
free((char*)wrap->config_path);
}
free(wrap);
}
void rarch_main_ios(void* args)
{
rarch_init_msg_queue();
menu_init();
int init_ret;
if ((init_ret = rarch_main_init_wrap((struct rarch_main_wrap*)args))) return;
ios_free_main_wrap(args);
#ifdef HAVE_RGUI
menu_init();
g_extern.lifecycle_mode_state |= 1ULL << MODE_GAME;
for (;;)
{
if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))
{
while ((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate());
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_INIT))
{
if (g_extern.main_is_init)
rarch_main_deinit();
struct rarch_main_wrap args = {0};
args.verbose = g_extern.verbose;
args.config_path = *g_extern.config_path ? g_extern.config_path : NULL;
args.sram_path = NULL;
args.state_path = NULL;
args.rom_path = g_extern.fullpath;
args.libretro_path = g_settings.libretro;
int init_ret = rarch_main_init_wrap(&args);
if (init_ret == 0)
{
RARCH_LOG("rarch_main_init() succeeded.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
}
else
{
RARCH_ERR("rarch_main_init() failed.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
}
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_INIT);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))
{
g_extern.lifecycle_mode_state |= 1ULL << MODE_MENU_PREINIT;
while (menu_iterate());
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU);
}
else
break;
}
menu_free();
if (g_extern.main_is_init)
rarch_main_deinit();
#else
while ((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate());
rarch_main_deinit();
#endif
rarch_deinit_msg_queue();
#ifdef PERF_TEST
rarch_perf_log();
#endif
rarch_main_clear_state();
}

View File

@ -393,6 +393,8 @@ MAIN
#include "../frontend/frontend_bbqnx.c"
#elif defined(ANDROID)
#include "../frontend/frontend_android.c"
#elif defined(IOS)
#include "../frontend/frontend_ios.c"
#endif
#if !defined(ANDROID) && !defined(IOS)

View File

@ -79,6 +79,8 @@ static UIView* g_pause_indicator_view;
UISegmentedControl* stateSelect = (UISegmentedControl*)[g_pause_view viewWithTag:1];
stateSelect.selectedSegmentIndex = (g_extern.state_slot < 10) ? g_extern.state_slot : -1;
g_extern.is_paused = true;
//
[UIView animateWithDuration:0.2
animations:^ { g_pause_view.alpha = 1.0f; }
@ -91,6 +93,8 @@ static UIView* g_pause_indicator_view;
animations:^ { g_pause_view.alpha = 0.0f; }
completion:^(BOOL finished) { }
];
g_extern.is_paused = false;
}
- (void)hidePauseButton
@ -105,34 +109,44 @@ static UIView* g_pause_indicator_view;
bool ios_init_game_view()
{
// Make sure the view was created
[RAGameView get];
dispatch_sync(dispatch_get_main_queue(), ^{
// Make sure the view was created
[RAGameView get];
g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
[EAGLContext setCurrentContext:g_context];
g_view.context = g_context;
// Show pause button for a few seconds, so people know it's there
g_pause_indicator_view.alpha = 1.0f;
[g_instance performSelector:@selector(hidePauseButton) withObject:g_instance afterDelay:3.0f];
});
g_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
[EAGLContext setCurrentContext:g_context];
g_view.context = g_context;
// Show pause button for a few seconds, so people know it's there
g_pause_indicator_view.alpha = 1.0f;
[g_instance performSelector:@selector(hidePauseButton) withObject:g_instance afterDelay:3.0f];
return true;
}
void ios_destroy_game_view()
{
glFinish();
dispatch_sync(dispatch_get_main_queue(), ^{
glFinish();
g_view.context = nil;
g_view.context = nil;
[EAGLContext setCurrentContext:nil];
g_context = nil;
});
[EAGLContext setCurrentContext:nil];
g_context = nil;
}
void ios_flip_game_view()
{
{
if (--g_fast_forward_skips < 0)
{
[g_view display];
dispatch_sync(dispatch_get_main_queue(), ^{
[g_view display];
});
g_fast_forward_skips = g_is_syncing ? 0 : 3;
}
}
@ -154,6 +168,8 @@ void ios_get_game_view_size(unsigned *width, unsigned *height)
void ios_bind_game_view_fbo()
{
[g_view bindDrawable];
dispatch_sync(dispatch_get_main_queue(), ^{
[g_view bindDrawable];
});
}

View File

@ -14,6 +14,8 @@
*/
#include <sys/stat.h>
#include <dispatch/dispatch.h>
#include "rarch_wrapper.h"
#include "general.h"
#include "frontend/menu/rmenu.h"
@ -26,13 +28,14 @@
#define kDOCSFOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
// From frontend/frontend_ios.c
extern void rarch_main_ios(void* args);
extern void ios_free_main_wrap(struct rarch_main_wrap* wrap);
@implementation RetroArch_iOS
{
UIWindow* _window;
bool _isIterating;
bool _isScheduled;
bool _isGameTop;
bool _isPaused;
bool _isRunning;
@ -72,17 +75,6 @@
menu_init();
}
- (void)applicationDidBecomeActive:(UIApplication*)application
{
[self schedule];
}
- (void)applicationWillResignActive:(UIApplication*)application
{
[self lapse];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
if (_isRunning)
@ -101,9 +93,6 @@
_isGameTop = [viewController isKindOfClass:[RAGameView class]];
[[UIApplication sharedApplication] setStatusBarHidden:_isGameTop withAnimation:UIStatusBarAnimationNone];
self.navigationBarHidden = _isGameTop;
if (_isGameTop)
[self schedule];
self.topViewController.navigationItem.rightBarButtonItem = [self createBluetoothButton];
}
@ -122,38 +111,40 @@
#pragma mark EMULATION
- (void)runGame:(NSString*)path
{
if (_isRunning)
return;
assert(self.moduleInfo);
[RASettingsList refreshConfigFile];
[self pushViewController:RAGameView.get animated:NO];
_isRunning = true;
const char* const sd = [[RetroArch_iOS get].system_directory UTF8String];
const char* const cf = (ra_ios_is_file(self.moduleInfo.configPath)) ? [self.moduleInfo.configPath UTF8String] : 0;
const char* const libretro = [self.moduleInfo.path UTF8String];
struct rarch_main_wrap main_wrapper = {[path UTF8String], sd, sd, cf, libretro};
if (rarch_main_init_wrap(&main_wrapper) == 0)
{
rarch_init_msg_queue();
struct rarch_main_wrap* load_data = malloc(sizeof(struct rarch_main_wrap));
load_data->libretro_path = strdup(libretro);
load_data->rom_path = strdup([path UTF8String]);
load_data->sram_path = strdup(sd);
load_data->state_path = strdup(sd);
load_data->verbose = false;
load_data->config_path = strdup(cf);
dispatch_async_f(dispatch_get_global_queue(0, 0), load_data, rarch_main_ios);
_isRunning = true;
// Read load time settings
config_file_t* conf = config_file_new([self.moduleInfo.configPath UTF8String]);
bool autoStartBluetooth = false;
if (conf && config_get_bool(conf, "ios_auto_bluetooth", &autoStartBluetooth) && autoStartBluetooth)
[self startBluetooth];
config_file_free(conf);
//
[self pushViewController:RAGameView.get animated:NO];
_isRunning = true;
g_extern.lifecycle_mode_state |= 1ULL << MODE_GAME;
}
else
{
_isRunning = false;
[RetroArch_iOS displayErrorMessage:@"Failed to load game."];
}
// Read load time settings
// TODO: Do this better
config_file_t* conf = config_file_new([self.moduleInfo.configPath UTF8String]);
bool autoStartBluetooth = false;
if (conf && config_get_bool(conf, "ios_auto_bluetooth", &autoStartBluetooth) && autoStartBluetooth)
[self startBluetooth];
config_file_free(conf);
}
#if 0
- (void)closeGame
{
if (_isRunning)
@ -172,6 +163,7 @@
[self popViewControllerAnimated:NO];
}
}
#endif
- (void)refreshConfig
{
@ -179,92 +171,14 @@
memset(g_settings.input.overlay, 0, sizeof(g_settings.input.overlay));
memset(g_settings.video.xml_shader_path, 0, sizeof(g_settings.video.xml_shader_path));
#if 0
if (_isRunning)
{
uninit_drivers();
config_load();
init_drivers();
}
}
- (void)iterate
{
RARCH_LOG("Iterate Began\n");
if (_isIterating)
{
RARCH_LOG("Recursive Iterate");
return;
}
_isIterating = true;
while (!_isPaused && _isRunning && _isGameTop && _isScheduled)
{
if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))
{
if (((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate()))
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true) == kCFRunLoopRunHandledSource);
else
{
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME);
if (g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU_PREINIT);
}
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_INIT))
{
if (g_extern.main_is_init)
rarch_main_deinit();
struct rarch_main_wrap args = {0};
args.verbose = g_extern.verbose;
args.config_path = *g_extern.config_path ? g_extern.config_path : NULL;
args.sram_path = NULL;
args.state_path = NULL;
args.rom_path = g_extern.fullpath;
args.libretro_path = g_settings.libretro;
int init_ret = rarch_main_init_wrap(&args);
if (init_ret == 0)
{
RARCH_LOG("rarch_main_init() succeeded.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
}
else
{
RARCH_ERR("rarch_main_init() failed.\n");
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
}
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_INIT);
}
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))
{
if (menu_iterate())
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true) == kCFRunLoopRunHandledSource);
else
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU);
}
else
[self closeGame];
}
RARCH_LOG("Iterate Ended\n");
_isIterating = false;
}
- (void)schedule
{
_isScheduled = true;
[self performSelector:@selector(iterate) withObject:self afterDelay:.01f];
}
- (void)lapse
{
_isScheduled = false;
#endif
}
#pragma mark PAUSE MENU
@ -304,13 +218,12 @@
{
[[RAGameView get] closePauseMenu];
_isPaused = false;
[self schedule];
}
- (IBAction)closeGamePressed:(id)sender
{
[self closePauseMenu:sender];
[self closeGame];
// [self closeGame];
}
- (IBAction)showSettings