2013-07-27 15:40:21 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 16:46:50 +00:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2012-2014 - Jason Fetters
|
2015-01-07 16:46:50 +00:00
|
|
|
* Copyright (C) 2014-2015 - Jay McCarthy
|
2013-07-27 15:40:21 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2013-07-27 15:45:56 +00:00
|
|
|
* * You should have received a copy of the GNU General Public License along with RetroArch.
|
2013-07-27 15:40:21 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-10-17 15:05:27 +00:00
|
|
|
#include "../../apple/common/CFExtensions.h"
|
2013-07-28 21:01:16 +00:00
|
|
|
|
2014-05-03 05:17:59 +00:00
|
|
|
#include "../frontend.h"
|
2014-12-31 20:24:50 +00:00
|
|
|
#include "../../menu/disp/ios.h"
|
2013-07-27 15:40:21 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2014-10-21 03:05:52 +00:00
|
|
|
#include <boolean.h>
|
2013-07-27 15:40:21 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-10-15 01:14:57 +00:00
|
|
|
void apple_start_iteration(void);
|
2014-10-17 03:27:54 +00:00
|
|
|
|
2014-10-15 01:14:57 +00:00
|
|
|
void apple_stop_iteration(void);
|
|
|
|
|
2014-12-22 18:24:28 +00:00
|
|
|
static CFRunLoopObserverRef iterate_observer = NULL;
|
2014-05-03 05:11:23 +00:00
|
|
|
|
|
|
|
static void do_iteration(void)
|
|
|
|
{
|
2014-10-04 12:14:45 +00:00
|
|
|
int ret = main_entry_decide(0, NULL, NULL);
|
|
|
|
|
|
|
|
if (ret == -1)
|
2014-05-12 14:37:02 +00:00
|
|
|
{
|
|
|
|
main_exit(NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-04 13:11:26 +00:00
|
|
|
if (ret == 0)
|
2014-10-04 12:14:45 +00:00
|
|
|
CFRunLoopWakeUp(CFRunLoopGetMain());
|
|
|
|
|
2014-10-04 00:10:22 +00:00
|
|
|
/* TODO/FIXME
|
2014-10-04 12:14:45 +00:00
|
|
|
I am almost positive that this is not necessary and is actually a
|
|
|
|
bad thing.
|
|
|
|
|
|
|
|
1st. Why it is bad thing.
|
|
|
|
|
|
|
|
This wakes up the main event loop immediately and the main loop
|
|
|
|
has only one observer, which is this function. In other words,
|
|
|
|
this causes the function to be called immediately. I did an
|
|
|
|
experiment where I saved the time before calling this and then
|
|
|
|
reported the difference between it and the start of
|
|
|
|
do_iteration, and as expected it was about 0. As a result, when
|
|
|
|
we remove this, idle performance (i.e. displaying the RetroArch
|
|
|
|
menu) is 0% CPU as desired.
|
|
|
|
|
|
|
|
2nd. Why it is not necessary.
|
|
|
|
|
|
|
|
The event loop will wake up itself when there is input to the
|
|
|
|
process. This includes touch events, keyboard, bluetooth,
|
|
|
|
etc. Thus, it will be woken up and without any intervention so
|
|
|
|
that we can process that event.
|
|
|
|
|
|
|
|
Nota bene. Why this analysis might be wrong (and what to do about it).
|
|
|
|
|
|
|
|
If RA is not idle and is running a core, then I believe it is
|
|
|
|
designed to expect to be called in a busy loop like this because
|
|
|
|
it implements its own frame timer to ensure that the emulation
|
|
|
|
simulation isn't too fast. In that case, this change would only
|
|
|
|
allow emulation to run when there was input, which would make
|
|
|
|
all games turn-based. :)
|
|
|
|
|
|
|
|
There are two good ways to fix this and still have the desired
|
|
|
|
0% CPU idle behavior.
|
|
|
|
|
|
|
|
Approach 1: Change main_entry_decide from returning a boolean
|
|
|
|
(two-values) that are interpreted as CONTINUE and QUIT. Into
|
|
|
|
returning a char-sized enum with three values that are
|
|
|
|
interpreted as QUIT, WAIT, and AGAIN, such that QUIT calls
|
|
|
|
main_exit, WAIT doesn't wake up the loop, and AGAIN does. It
|
|
|
|
would then return AGAIN when a core was active. An ugly way to
|
|
|
|
get the same effect is to look have this code just look at
|
|
|
|
g_extern.is_menu and use the WAIT behavior in that case.
|
|
|
|
|
|
|
|
Approach 2: Instead of signalling outside of RA whether a core
|
|
|
|
is running, instead externalize the frame time that is inside
|
|
|
|
retroarch. change main_entry_decide to return a value in
|
|
|
|
[-1,MAX_INT] where -1 is interpreted as QUIT, [0,MAX_INT) is
|
|
|
|
interpreted as the amount of time to wait until continuing, and
|
|
|
|
MAX_INT is interpreted as WAIT. This could be more robust
|
|
|
|
because we'd be exposing the scheduling behavior of RA to iOS,
|
|
|
|
which might be good in other platforms as well.
|
|
|
|
|
|
|
|
Approach 1 is the simplest and essentially just pushes down
|
|
|
|
these requirements to rarch_main_iterate. I have gone with the
|
|
|
|
"ugly way" first because it is the most expedient and
|
|
|
|
safe. Other eyeballs should decide if it isn't necessary.
|
|
|
|
*/
|
2014-05-03 05:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void apple_start_iteration(void)
|
|
|
|
{
|
2015-01-09 01:12:08 +00:00
|
|
|
if (iterate_observer == NULL)
|
|
|
|
{
|
2014-12-22 18:24:28 +00:00
|
|
|
iterate_observer =
|
|
|
|
CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting,
|
|
|
|
true, 0, (CFRunLoopObserverCallBack)do_iteration, 0);
|
|
|
|
CFRunLoopAddObserver(CFRunLoopGetMain(), iterate_observer,
|
|
|
|
kCFRunLoopCommonModes);
|
|
|
|
}
|
2014-05-03 05:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void apple_stop_iteration(void)
|
|
|
|
{
|
2015-01-09 01:12:08 +00:00
|
|
|
if (iterate_observer != NULL)
|
|
|
|
{
|
2014-12-22 18:24:28 +00:00
|
|
|
CFRunLoopObserverInvalidate(iterate_observer);
|
|
|
|
CFRelease(iterate_observer);
|
|
|
|
iterate_observer = NULL;
|
|
|
|
}
|
2014-10-07 02:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void frontend_apple_get_environment_settings(int *argc, char *argv[],
|
|
|
|
void *args, void *params_data)
|
|
|
|
{
|
2015-01-09 01:12:08 +00:00
|
|
|
char bundle_path_buf[PATH_MAX + 1], home_dir_buf[PATH_MAX + 1],
|
|
|
|
support_path_buf[PATH_MAX + 1];
|
2014-10-07 02:43:59 +00:00
|
|
|
CFURLRef bundle_url;
|
2015-01-09 01:12:08 +00:00
|
|
|
CFStringRef bundle_path;
|
2014-10-07 02:43:59 +00:00
|
|
|
CFBundleRef bundle = CFBundleGetMainBundle();
|
2015-01-09 01:12:08 +00:00
|
|
|
|
2014-10-07 02:43:59 +00:00
|
|
|
if (!bundle)
|
|
|
|
return;
|
2015-01-09 01:12:08 +00:00
|
|
|
|
|
|
|
bundle_url = CFBundleCopyBundleURL(bundle);
|
|
|
|
bundle_path = CFURLCopyPath(bundle_url);
|
2014-10-07 14:51:25 +00:00
|
|
|
|
2014-10-18 02:36:02 +00:00
|
|
|
CFStringGetCString(bundle_path, bundle_path_buf, sizeof(bundle_path_buf), kCFStringEncodingUTF8);
|
2014-10-07 14:51:25 +00:00
|
|
|
(void)home_dir_buf;
|
2014-10-07 02:43:59 +00:00
|
|
|
|
|
|
|
#ifdef IOS
|
2014-10-24 17:18:05 +00:00
|
|
|
CFSearchPathForDirectoriesInDomains(CFDocumentDirectory, CFUserDomainMask, 1, home_dir_buf, sizeof(home_dir_buf));
|
|
|
|
|
2014-10-07 02:43:59 +00:00
|
|
|
fill_pathname_join(g_defaults.system_dir, home_dir_buf, ".RetroArch", sizeof(g_defaults.system_dir));
|
|
|
|
fill_pathname_join(g_defaults.core_dir, bundle_path_buf, "modules", sizeof(g_defaults.core_dir));
|
|
|
|
|
|
|
|
strlcpy(g_defaults.menu_config_dir, g_defaults.system_dir, sizeof(g_defaults.menu_config_dir));
|
|
|
|
fill_pathname_join(g_defaults.config_path, g_defaults.menu_config_dir, "retroarch.cfg", sizeof(g_defaults.config_path));
|
|
|
|
|
|
|
|
strlcpy(g_defaults.sram_dir, g_defaults.system_dir, sizeof(g_defaults.sram_dir));
|
|
|
|
strlcpy(g_defaults.savestate_dir, g_defaults.system_dir, sizeof(g_defaults.savestate_dir));
|
|
|
|
|
|
|
|
path_mkdir(bundle_path_buf);
|
|
|
|
|
2014-10-07 02:55:14 +00:00
|
|
|
if (access(bundle_path_buf, 0755) != 0)
|
2014-10-07 02:43:59 +00:00
|
|
|
RARCH_ERR("Failed to create or access base directory: %s\n", bundle_path_buf);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path_mkdir(g_defaults.system_dir);
|
|
|
|
|
|
|
|
if (access(g_defaults.system_dir, 0755) != 0)
|
|
|
|
RARCH_ERR("Failed to create or access system directory: %s.\n", g_defaults.system_dir);
|
|
|
|
}
|
2014-10-17 15:05:27 +00:00
|
|
|
#elif defined(OSX)
|
|
|
|
CFSearchPathForDirectoriesInDomains(CFApplicationSupportDirectory, CFUserDomainMask, 1, support_path_buf, sizeof(support_path_buf));
|
|
|
|
|
|
|
|
fill_pathname_join(g_defaults.core_dir, bundle_path_buf, "Contents/Resources/modules", sizeof(g_defaults.core_dir));
|
2014-10-29 06:36:15 +00:00
|
|
|
fill_pathname_join(g_defaults.core_info_dir, bundle_path_buf, "Contents/Resources/modules", sizeof(g_defaults.core_info_dir));
|
|
|
|
fill_pathname_join(g_defaults.overlay_dir, bundle_path_buf, "Contents/Resources/modules/overlays", sizeof(g_defaults.overlay_dir));
|
|
|
|
fill_pathname_join(g_defaults.autoconfig_dir, bundle_path_buf, "Contents/Resources/modules/autoconfig/apple", sizeof(g_defaults.autoconfig_dir));
|
|
|
|
fill_pathname_join(g_defaults.assets_dir, bundle_path_buf, "Contents/Resources/modules/assets", sizeof(g_defaults.assets_dir));
|
|
|
|
fill_pathname_join(g_defaults.shader_dir, bundle_path_buf, "Contents/Resources/modules/shaders", sizeof(g_defaults.shader_dir));
|
|
|
|
fill_pathname_join(g_defaults.audio_filter_dir, bundle_path_buf, "Contents/Resources/modules/audio_filters", sizeof(g_defaults.audio_filter_dir));
|
2014-10-29 06:42:07 +00:00
|
|
|
fill_pathname_join(g_defaults.video_filter_dir, bundle_path_buf, "Contents/Resources/modules/video_filters", sizeof(g_defaults.video_filter_dir));
|
2014-10-17 15:05:27 +00:00
|
|
|
fill_pathname_join(g_defaults.menu_config_dir, support_path_buf, "RetroArch", sizeof(g_defaults.menu_config_dir));
|
|
|
|
fill_pathname_join(g_defaults.config_path, g_defaults.menu_config_dir, "retroarch.cfg", sizeof(g_defaults.config_path));
|
2014-10-07 02:43:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
CFRelease(bundle_path);
|
|
|
|
CFRelease(bundle_url);
|
2014-05-03 05:11:23 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 03:13:48 +00:00
|
|
|
extern void apple_rarch_exited(void);
|
|
|
|
|
2014-10-17 03:27:54 +00:00
|
|
|
static void frontend_apple_load_content(void)
|
2014-10-17 01:55:16 +00:00
|
|
|
{
|
2015-01-05 01:43:44 +00:00
|
|
|
#ifdef IOS
|
|
|
|
if ( driver.menu_ctx && driver.menu_ctx == &menu_ctx_ios && driver.menu && driver.menu->userdata )
|
|
|
|
{
|
|
|
|
ios_handle_t *ih = (ios_handle_t*)driver.menu->userdata;
|
2015-01-09 01:12:08 +00:00
|
|
|
if (ih)
|
|
|
|
ih->notify_content_loaded();
|
2014-12-31 20:24:50 +00:00
|
|
|
}
|
2015-01-05 01:43:44 +00:00
|
|
|
#endif
|
2014-10-17 01:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 03:13:48 +00:00
|
|
|
static void frontend_apple_shutdown(bool unused)
|
|
|
|
{
|
|
|
|
apple_rarch_exited();
|
|
|
|
}
|
|
|
|
|
2014-05-16 20:20:33 +00:00
|
|
|
static int frontend_apple_get_rating(void)
|
|
|
|
{
|
|
|
|
/* TODO/FIXME - look at unique identifier per device and
|
|
|
|
* determine rating for some */
|
|
|
|
return -1;
|
|
|
|
}
|
2013-07-27 15:40:21 +00:00
|
|
|
const frontend_ctx_driver_t frontend_ctx_apple = {
|
2014-10-07 02:43:59 +00:00
|
|
|
frontend_apple_get_environment_settings, /* environment_get */
|
2013-07-27 15:40:21 +00:00
|
|
|
NULL, /* init */
|
|
|
|
NULL, /* deinit */
|
|
|
|
NULL, /* exitspawn */
|
|
|
|
NULL, /* process_args */
|
|
|
|
NULL, /* exec */
|
2014-10-02 19:39:29 +00:00
|
|
|
NULL, /* set_fork */
|
2014-07-22 03:13:48 +00:00
|
|
|
frontend_apple_shutdown, /* shutdown */
|
2014-06-12 14:26:33 +00:00
|
|
|
NULL, /* get_name */
|
2014-05-16 20:20:33 +00:00
|
|
|
frontend_apple_get_rating, /* get_rating */
|
2014-10-17 03:27:54 +00:00
|
|
|
frontend_apple_load_content, /* load_content */
|
2013-07-27 15:40:21 +00:00
|
|
|
"apple",
|
|
|
|
};
|