mirror of
https://github.com/libretro/RetroArch
synced 2025-04-25 00:02:31 +00:00
Cleanups
This commit is contained in:
parent
ca413ff132
commit
e15018a85a
@ -84,7 +84,8 @@ static void rarch_draw_observer(CFRunLoopObserverRef observer,
|
|||||||
|
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
{
|
{
|
||||||
ui_companion_cocoatouch_event_command(NULL, CMD_EVENT_MENU_SAVE_CURRENT_CONFIG);
|
ui_companion_cocoatouch_event_command(
|
||||||
|
NULL, CMD_EVENT_MENU_SAVE_CURRENT_CONFIG);
|
||||||
main_exit(NULL);
|
main_exit(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -122,13 +123,8 @@ static void handle_touch_event(NSArray* touches)
|
|||||||
|
|
||||||
for (i = 0; i < touches.count && (apple->touch_count < MAX_TOUCHES); i++)
|
for (i = 0; i < touches.count && (apple->touch_count < MAX_TOUCHES); i++)
|
||||||
{
|
{
|
||||||
CGPoint coord;
|
|
||||||
UITouch *touch = [touches objectAtIndex:i];
|
UITouch *touch = [touches objectAtIndex:i];
|
||||||
|
CGPoint coord = [touch locationInView:[touch view]];
|
||||||
// if (touch.view != [CocoaView get].view)
|
|
||||||
// continue;
|
|
||||||
|
|
||||||
coord = [touch locationInView:[touch view]];
|
|
||||||
if (touch.phase != UITouchPhaseEnded && touch.phase != UITouchPhaseCancelled)
|
if (touch.phase != UITouchPhaseEnded && touch.phase != UITouchPhaseCancelled)
|
||||||
{
|
{
|
||||||
apple->touches[apple->touch_count ].screen_x = coord.x * scale;
|
apple->touches[apple->touch_count ].screen_x = coord.x * scale;
|
||||||
@ -138,7 +134,7 @@ static void handle_touch_event(NSArray* touches)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HAVE_APPLE_STORE
|
#ifndef HAVE_APPLE_STORE
|
||||||
// iOS7 Keyboard support
|
/* iOS7 Keyboard support */
|
||||||
@interface UIEvent(iOS7Keyboard)
|
@interface UIEvent(iOS7Keyboard)
|
||||||
@property(readonly, nonatomic) long long _keyCode;
|
@property(readonly, nonatomic) long long _keyCode;
|
||||||
@property(readonly, nonatomic) _Bool _isKeyDown;
|
@property(readonly, nonatomic) _Bool _isKeyDown;
|
||||||
@ -176,8 +172,9 @@ enum
|
|||||||
NSDeviceIndependentModifierFlagsMask = 0xffff0000U
|
NSDeviceIndependentModifierFlagsMask = 0xffff0000U
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is specifically for iOS 9, according to the private headers
|
/* This is specifically for iOS 9, according to the private headers */
|
||||||
-(void)handleKeyUIEvent:(UIEvent *)event {
|
-(void)handleKeyUIEvent:(UIEvent *)event
|
||||||
|
{
|
||||||
/* This gets called twice with the same timestamp
|
/* This gets called twice with the same timestamp
|
||||||
* for each keypress, that's fine for polling
|
* for each keypress, that's fine for polling
|
||||||
* but is bad for business with events. */
|
* but is bad for business with events. */
|
||||||
@ -226,7 +223,7 @@ enum
|
|||||||
[super handleKeyUIEvent:event];
|
[super handleKeyUIEvent:event];
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is for iOS versions < 9.0
|
/* This is for iOS versions < 9.0 */
|
||||||
- (id)_keyCommandForEvent:(UIEvent*)event
|
- (id)_keyCommandForEvent:(UIEvent*)event
|
||||||
{
|
{
|
||||||
/* This gets called twice with the same timestamp
|
/* This gets called twice with the same timestamp
|
||||||
@ -296,7 +293,8 @@ enum
|
|||||||
/* Keyboard event hack for iOS versions prior to iOS 7.
|
/* Keyboard event hack for iOS versions prior to iOS 7.
|
||||||
*
|
*
|
||||||
* Derived from:
|
* Derived from:
|
||||||
* http://nacho4d-nacho4d.blogspot.com/2012/01/catching-keyboard-events-in-ios.html
|
* http://nacho4d-nacho4d.blogspot.com/2012/01/
|
||||||
|
* catching-keyboard-events-in-ios.html
|
||||||
*/
|
*/
|
||||||
const uint8_t *eventMem = objc_unretainedPointer([event performSelector:@selector(_gsEvent)]);
|
const uint8_t *eventMem = objc_unretainedPointer([event performSelector:@selector(_gsEvent)]);
|
||||||
int eventType = eventMem ? *(int*)&eventMem[8] : 0;
|
int eventType = eventMem ? *(int*)&eventMem[8] : 0;
|
||||||
@ -318,13 +316,11 @@ enum
|
|||||||
@implementation RetroArch_iOS
|
@implementation RetroArch_iOS
|
||||||
|
|
||||||
#pragma mark - ApplePlatform
|
#pragma mark - ApplePlatform
|
||||||
-(id)renderView {
|
-(id)renderView { return _renderView; }
|
||||||
return _renderView;
|
-(bool)hasFocus { return YES; }
|
||||||
}
|
|
||||||
-(bool)hasFocus {
|
- (void)setViewType:(apple_view_type_t)vt
|
||||||
return YES;
|
{
|
||||||
}
|
|
||||||
- (void)setViewType:(apple_view_type_t)vt {
|
|
||||||
if (vt == _vt)
|
if (vt == _vt)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -356,61 +352,50 @@ enum
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case APPLE_VIEW_TYPE_NONE:
|
case APPLE_VIEW_TYPE_NONE:
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_renderView.translatesAutoresizingMaskIntoConstraints = NO;
|
_renderView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
UIView *rootView = [CocoaView get].view;
|
UIView *rootView = [CocoaView get].view;
|
||||||
[rootView addSubview:_renderView];
|
[rootView addSubview:_renderView];
|
||||||
[[_renderView.topAnchor constraintEqualToAnchor:rootView.topAnchor] setActive:YES];
|
[[_renderView.topAnchor constraintEqualToAnchor:rootView.topAnchor] setActive:YES];
|
||||||
[[_renderView.bottomAnchor constraintEqualToAnchor:rootView.bottomAnchor] setActive:YES];
|
[[_renderView.bottomAnchor constraintEqualToAnchor:rootView.bottomAnchor] setActive:YES];
|
||||||
[[_renderView.leadingAnchor constraintEqualToAnchor:rootView.leadingAnchor] setActive:YES];
|
[[_renderView.leadingAnchor constraintEqualToAnchor:rootView.leadingAnchor] setActive:YES];
|
||||||
[[_renderView.trailingAnchor constraintEqualToAnchor:rootView.trailingAnchor] setActive:YES];
|
[[_renderView.trailingAnchor constraintEqualToAnchor:rootView.trailingAnchor] setActive:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (apple_view_type_t)viewType {
|
- (apple_view_type_t)viewType { return _vt; }
|
||||||
return _vt;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setVideoMode:(gfx_ctx_mode_t)mode {
|
- (void)setVideoMode:(gfx_ctx_mode_t)mode
|
||||||
#ifdef HAVE_COCOA_METAL
|
|
||||||
MetalView *metalView = (MetalView*) _renderView;
|
|
||||||
CGFloat scale = [[UIScreen mainScreen] scale];
|
|
||||||
[metalView setDrawableSize:CGSizeMake(
|
|
||||||
_renderView.bounds.size.width * scale,
|
|
||||||
_renderView.bounds.size.height * scale
|
|
||||||
)
|
|
||||||
];
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setCursorVisible:(bool)v {
|
|
||||||
// no-op for iOS
|
|
||||||
}
|
|
||||||
|
|
||||||
- (bool)setDisableDisplaySleep:(bool)disable {
|
|
||||||
// no-op for iOS
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (RetroArch_iOS*)get
|
|
||||||
{
|
{
|
||||||
return (RetroArch_iOS*)[[UIApplication sharedApplication] delegate];
|
#ifdef HAVE_COCOA_METAL
|
||||||
|
MetalView *metalView = (MetalView*) _renderView;
|
||||||
|
CGFloat scale = [[UIScreen mainScreen] scale];
|
||||||
|
[metalView setDrawableSize:CGSizeMake(
|
||||||
|
_renderView.bounds.size.width * scale,
|
||||||
|
_renderView.bounds.size.height * scale
|
||||||
|
)];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
-(NSString*)documentsDirectory {
|
- (void)setCursorVisible:(bool)v { /* no-op for iOS */ }
|
||||||
if (_documentsDirectory == nil)
|
- (bool)setDisableDisplaySleep:(bool)disable { /* no-op for iOS */ return NO; }
|
||||||
{
|
+ (RetroArch_iOS*)get { return (RetroArch_iOS*)[[UIApplication sharedApplication] delegate]; }
|
||||||
|
|
||||||
|
-(NSString*)documentsDirectory
|
||||||
|
{
|
||||||
|
if (_documentsDirectory == nil)
|
||||||
|
{
|
||||||
#if TARGET_OS_IOS
|
#if TARGET_OS_IOS
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||||
#elif TARGET_OS_TV
|
#elif TARGET_OS_TV
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_documentsDirectory = paths.firstObject;
|
_documentsDirectory = paths.firstObject;
|
||||||
}
|
}
|
||||||
return _documentsDirectory;
|
return _documentsDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationDidFinishLaunching:(UIApplication *)application
|
- (void)applicationDidFinishLaunching:(UIApplication *)application
|
||||||
@ -424,13 +409,10 @@ enum
|
|||||||
[self setDelegate:self];
|
[self setDelegate:self];
|
||||||
|
|
||||||
/* Setup window */
|
/* Setup window */
|
||||||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||||
[self.window makeKeyAndVisible];
|
[self.window makeKeyAndVisible];
|
||||||
|
|
||||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error];
|
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error];
|
||||||
if (error) {
|
|
||||||
NSLog(@"Could not set audio session category: %@",error.localizedDescription);
|
|
||||||
}
|
|
||||||
|
|
||||||
[self refreshSystemConfig];
|
[self refreshSystemConfig];
|
||||||
[self showGameView];
|
[self showGameView];
|
||||||
@ -438,20 +420,17 @@ enum
|
|||||||
if (rarch_main(argc, argv, NULL))
|
if (rarch_main(argc, argv, NULL))
|
||||||
apple_rarch_exited();
|
apple_rarch_exited();
|
||||||
|
|
||||||
iterate_observer = CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting,
|
iterate_observer = CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting,
|
||||||
true, 0, rarch_draw_observer, 0);
|
true, 0, rarch_draw_observer, 0);
|
||||||
CFRunLoopAddObserver(CFRunLoopGetMain(), iterate_observer, kCFRunLoopCommonModes);
|
CFRunLoopAddObserver(CFRunLoopGetMain(), iterate_observer, kCFRunLoopCommonModes);
|
||||||
|
|
||||||
#ifdef HAVE_MFI
|
#ifdef HAVE_MFI
|
||||||
extern bool apple_gamecontroller_joypad_init(void *data);
|
extern bool apple_gamecontroller_joypad_init(void *data);
|
||||||
apple_gamecontroller_joypad_init(NULL);
|
apple_gamecontroller_joypad_init(NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationDidEnterBackground:(UIApplication *)application
|
- (void)applicationDidEnterBackground:(UIApplication *)application { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationWillTerminate:(UIApplication *)application
|
- (void)applicationWillTerminate:(UIApplication *)application
|
||||||
{
|
{
|
||||||
@ -465,10 +444,8 @@ enum
|
|||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
bool ui_companion_start_on_boot = settings->bools.ui_companion_start_on_boot;
|
bool ui_companion_start_on_boot = settings->bools.ui_companion_start_on_boot;
|
||||||
|
|
||||||
if (ui_companion_start_on_boot)
|
if (!ui_companion_start_on_boot)
|
||||||
return;
|
[self showGameView];
|
||||||
|
|
||||||
[self showGameView];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
|
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
|
||||||
@ -494,19 +471,19 @@ enum
|
|||||||
|
|
||||||
- (void)showGameView
|
- (void)showGameView
|
||||||
{
|
{
|
||||||
[self popToRootViewControllerAnimated:NO];
|
[self popToRootViewControllerAnimated:NO];
|
||||||
|
|
||||||
#if TARGET_OS_IOS
|
#if TARGET_OS_IOS
|
||||||
[self setToolbarHidden:true animated:NO];
|
[self setToolbarHidden:true animated:NO];
|
||||||
[[UIApplication sharedApplication] setStatusBarHidden:true withAnimation:UIStatusBarAnimationNone];
|
[[UIApplication sharedApplication] setStatusBarHidden:true withAnimation:UIStatusBarAnimationNone];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[[UIApplication sharedApplication] setIdleTimerDisabled:true];
|
[[UIApplication sharedApplication] setIdleTimerDisabled:true];
|
||||||
[self.window setRootViewController:[CocoaView get]];
|
[self.window setRootViewController:[CocoaView get]];
|
||||||
|
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
||||||
command_event(CMD_EVENT_AUDIO_START, NULL);
|
command_event(CMD_EVENT_AUDIO_START, NULL);
|
||||||
});
|
});
|
||||||
rarch_disable_ui();
|
rarch_disable_ui();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,17 +506,16 @@ enum
|
|||||||
apple_frontend_settings.orientation_flags = UIInterfaceOrientationMaskAll;
|
apple_frontend_settings.orientation_flags = UIInterfaceOrientationMaskAll;
|
||||||
|
|
||||||
if (string_is_equal(apple_frontend_settings.orientations, "landscape"))
|
if (string_is_equal(apple_frontend_settings.orientations, "landscape"))
|
||||||
apple_frontend_settings.orientation_flags = UIInterfaceOrientationMaskLandscape;
|
apple_frontend_settings.orientation_flags =
|
||||||
|
UIInterfaceOrientationMaskLandscape;
|
||||||
else if (string_is_equal(apple_frontend_settings.orientations, "portrait"))
|
else if (string_is_equal(apple_frontend_settings.orientations, "portrait"))
|
||||||
apple_frontend_settings.orientation_flags = UIInterfaceOrientationMaskPortrait
|
apple_frontend_settings.orientation_flags =
|
||||||
|
UIInterfaceOrientationMaskPortrait
|
||||||
| UIInterfaceOrientationMaskPortraitUpsideDown;
|
| UIInterfaceOrientationMaskPortraitUpsideDown;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)supportOtherAudioSessions
|
- (void)supportOtherAudioSessions { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@ -551,9 +527,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
static void apple_rarch_exited(void)
|
static void apple_rarch_exited(void)
|
||||||
{
|
{
|
||||||
RetroArch_iOS *ap = (RetroArch_iOS *)apple_platform;
|
RetroArch_iOS *ap = (RetroArch_iOS *)apple_platform;
|
||||||
|
|
||||||
if (!ap)
|
if (!ap)
|
||||||
return;
|
return;
|
||||||
[ap showPauseMenu:ap];
|
[ap showPauseMenu:ap];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user