2013-02-17 14:04:44 +00:00
|
|
|
//
|
|
|
|
// ViewController.m
|
|
|
|
//
|
|
|
|
// Created by rock88
|
|
|
|
// Modified by xSacha
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "ViewController.h"
|
2013-03-16 14:50:55 +00:00
|
|
|
#import "AudioEngine.h"
|
2013-02-17 14:04:44 +00:00
|
|
|
#import <GLKit/GLKit.h>
|
|
|
|
|
|
|
|
#include "base/display.h"
|
|
|
|
#include "base/timeutil.h"
|
|
|
|
#include "file/zip_read.h"
|
|
|
|
#include "input/input_state.h"
|
|
|
|
#include "net/resolve.h"
|
|
|
|
#include "ui/screen.h"
|
2016-01-03 14:19:43 +00:00
|
|
|
#include "thin3d/thin3d.h"
|
2013-07-19 21:36:12 +00:00
|
|
|
#include "input/keycodes.h"
|
2016-01-07 04:10:42 +00:00
|
|
|
#include "gfx_es2/gpu_features.h"
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2013-02-24 12:17:52 +00:00
|
|
|
#include "Core/Config.h"
|
2016-01-01 11:23:41 +00:00
|
|
|
#include "Common/GraphicsContext.h"
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <mach/machine.h>
|
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
#define IS_IPAD() ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
|
2014-10-15 16:38:17 +00:00
|
|
|
#define IS_IPHONE() ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2015-11-03 17:34:33 +00:00
|
|
|
#ifndef kCFCoreFoundationVersionNumber_IOS_9_0
|
|
|
|
#define kCFCoreFoundationVersionNumber_IOS_9_0 1240.10
|
|
|
|
#endif
|
|
|
|
|
2016-01-03 14:19:43 +00:00
|
|
|
class IOSDummyGraphicsContext : public DummyGraphicsContext {
|
|
|
|
public:
|
2017-02-06 10:20:27 +00:00
|
|
|
IOSDummyGraphicsContext() {
|
|
|
|
CheckGLExtensions();
|
|
|
|
draw_ = Draw::T3DCreateGLContext();
|
|
|
|
}
|
|
|
|
~IOSDummyGraphicsContext() {
|
|
|
|
delete draw_;
|
|
|
|
}
|
|
|
|
Draw::DrawContext *GetDrawContext() override {
|
|
|
|
return draw_;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Draw::DrawContext *draw_;
|
2016-01-03 14:19:43 +00:00
|
|
|
};
|
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
float dp_xscale = 1.0f;
|
|
|
|
float dp_yscale = 1.0f;
|
|
|
|
|
2013-05-31 01:58:41 +00:00
|
|
|
double lastSelectPress = 0.0f;
|
2013-07-19 21:36:12 +00:00
|
|
|
double lastStartPress = 0.0f;
|
2013-05-31 01:58:41 +00:00
|
|
|
bool simulateAnalog = false;
|
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
extern ScreenManager *screenManager;
|
|
|
|
|
2013-12-01 19:28:20 +00:00
|
|
|
extern bool iosCanUseJit;
|
2015-11-03 17:34:33 +00:00
|
|
|
extern bool targetIsJailbroken;
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2013-02-24 03:47:45 +00:00
|
|
|
ViewController* sharedViewController;
|
2016-01-01 11:23:41 +00:00
|
|
|
static GraphicsContext *graphicsContext;
|
2013-02-24 03:47:45 +00:00
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
@interface ViewController ()
|
2013-07-19 21:36:12 +00:00
|
|
|
{
|
|
|
|
std::map<uint16_t, uint16_t> iCadeToKeyMap;
|
|
|
|
}
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2014-05-17 05:58:36 +00:00
|
|
|
@property (nonatomic) EAGLContext* context;
|
|
|
|
@property (nonatomic) NSString* documentsPath;
|
|
|
|
@property (nonatomic) NSString* bundlePath;
|
|
|
|
@property (nonatomic) NSMutableArray* touches;
|
|
|
|
@property (nonatomic) AudioEngine* audioEngine;
|
|
|
|
@property (nonatomic) iCadeReaderView* iCadeView;
|
2014-01-27 14:32:19 +00:00
|
|
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
|
2014-05-17 05:58:36 +00:00
|
|
|
@property (nonatomic) GCController *gameController __attribute__((weak_import));
|
2014-01-27 14:32:19 +00:00
|
|
|
#endif
|
2013-02-17 14:04:44 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ViewController
|
2015-12-28 19:10:38 +00:00
|
|
|
-(bool) isArm64 {
|
|
|
|
size_t size;
|
|
|
|
cpu_type_t type;
|
|
|
|
size = sizeof(type);
|
|
|
|
sysctlbyname("hw.cputype", &type, &size, NULL, 0);
|
|
|
|
return type == CPU_TYPE_ARM64;
|
|
|
|
}
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
-(id) init {
|
2013-02-17 14:04:44 +00:00
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
2013-02-24 03:47:45 +00:00
|
|
|
sharedViewController = self;
|
2014-05-17 05:58:36 +00:00
|
|
|
self.touches = [NSMutableArray array];
|
2013-02-17 14:04:44 +00:00
|
|
|
self.documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
2013-02-28 00:28:29 +00:00
|
|
|
self.bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/assets/"];
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2016-08-28 11:43:46 +00:00
|
|
|
iosCanUseJit = true;
|
2015-11-03 17:34:33 +00:00
|
|
|
targetIsJailbroken = false;
|
2013-04-23 07:31:57 +00:00
|
|
|
NSArray *jailPath = [NSArray arrayWithObjects:
|
|
|
|
@"/Applications/Cydia.app",
|
2015-11-03 17:34:33 +00:00
|
|
|
@"/private/var/lib/apt",
|
|
|
|
@"/private/var/stash",
|
|
|
|
@"/usr/sbin/sshd",
|
|
|
|
@"/usr/bin/sshd", nil];
|
|
|
|
|
|
|
|
for (NSString *string in jailPath) {
|
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:string]) {
|
|
|
|
// checking device jailbreak status in order to determine which message to show in GameSettingsScreen
|
|
|
|
targetIsJailbroken = true;
|
|
|
|
}
|
2013-04-23 07:31:57 +00:00
|
|
|
}
|
2015-12-28 19:10:38 +00:00
|
|
|
|
2016-01-17 21:11:28 +00:00
|
|
|
NativeInit(0, NULL, [self.documentsPath UTF8String], [self.bundlePath UTF8String], NULL);
|
2013-07-19 21:36:12 +00:00
|
|
|
|
2013-08-04 17:31:40 +00:00
|
|
|
iCadeToKeyMap[iCadeJoystickUp] = NKCODE_DPAD_UP;
|
|
|
|
iCadeToKeyMap[iCadeJoystickRight] = NKCODE_DPAD_RIGHT;
|
|
|
|
iCadeToKeyMap[iCadeJoystickDown] = NKCODE_DPAD_DOWN;
|
|
|
|
iCadeToKeyMap[iCadeJoystickLeft] = NKCODE_DPAD_LEFT;
|
|
|
|
iCadeToKeyMap[iCadeButtonA] = NKCODE_BUTTON_9; // Select
|
|
|
|
iCadeToKeyMap[iCadeButtonB] = NKCODE_BUTTON_7; // LTrigger
|
|
|
|
iCadeToKeyMap[iCadeButtonC] = NKCODE_BUTTON_10; // Start
|
|
|
|
iCadeToKeyMap[iCadeButtonD] = NKCODE_BUTTON_8; // RTrigger
|
|
|
|
iCadeToKeyMap[iCadeButtonE] = NKCODE_BUTTON_4; // Square
|
|
|
|
iCadeToKeyMap[iCadeButtonF] = NKCODE_BUTTON_2; // Cross
|
|
|
|
iCadeToKeyMap[iCadeButtonG] = NKCODE_BUTTON_1; // Triangle
|
|
|
|
iCadeToKeyMap[iCadeButtonH] = NKCODE_BUTTON_3; // Circle
|
2014-01-27 14:32:19 +00:00
|
|
|
|
|
|
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
|
2014-05-17 05:58:36 +00:00
|
|
|
if ([GCController class]) // Checking the availability of a GameController framework
|
2015-12-28 19:10:38 +00:00
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidConnect:) name:GCControllerDidConnectNotification object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidDisconnect:) name:GCControllerDidDisconnectNotification object:nil];
|
2014-01-24 18:46:30 +00:00
|
|
|
}
|
2014-01-27 14:32:19 +00:00
|
|
|
#endif
|
2013-02-17 14:04:44 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
- (void)viewDidLoad {
|
2013-02-17 14:04:44 +00:00
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
|
|
self.view.frame = [[UIScreen mainScreen] bounds];
|
|
|
|
self.view.multipleTouchEnabled = YES;
|
2014-05-17 06:02:57 +00:00
|
|
|
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
|
2015-12-28 19:10:38 +00:00
|
|
|
|
2016-12-21 16:40:16 +00:00
|
|
|
if (!self.context) {
|
2015-12-28 19:10:38 +00:00
|
|
|
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
|
|
|
}
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2014-05-17 05:58:36 +00:00
|
|
|
GLKView* view = (GLKView *)self.view;
|
2013-02-17 14:04:44 +00:00
|
|
|
view.context = self.context;
|
|
|
|
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
|
|
|
|
[EAGLContext setCurrentContext:self.context];
|
2013-03-15 02:30:40 +00:00
|
|
|
self.preferredFramesPerSecond = 60;
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2016-12-21 16:40:16 +00:00
|
|
|
// Might be useful for a speed boot, sacrificing resolution:
|
|
|
|
// view.contentScaleFactor = 1.0;
|
|
|
|
|
2014-10-16 00:11:26 +00:00
|
|
|
float scale = [UIScreen mainScreen].scale;
|
|
|
|
|
|
|
|
if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)]) {
|
|
|
|
scale = [UIScreen mainScreen].nativeScale;
|
|
|
|
}
|
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
CGSize size = [[UIApplication sharedApplication].delegate window].frame.size;
|
|
|
|
|
2016-12-21 16:40:16 +00:00
|
|
|
if (size.height > size.width) {
|
2013-02-17 14:04:44 +00:00
|
|
|
float h = size.height;
|
|
|
|
size.height = size.width;
|
|
|
|
size.width = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_dpi = (IS_IPAD() ? 200 : 150) * scale;
|
|
|
|
g_dpi_scale = 240.0f / (float)g_dpi;
|
2017-03-12 19:17:35 +00:00
|
|
|
g_dpi_scale_real = g_dpi_scale;
|
2013-02-17 14:04:44 +00:00
|
|
|
pixel_xres = size.width * scale;
|
|
|
|
pixel_yres = size.height * scale;
|
|
|
|
|
|
|
|
dp_xres = pixel_xres * g_dpi_scale;
|
|
|
|
dp_yres = pixel_yres * g_dpi_scale;
|
|
|
|
|
2015-12-24 22:32:24 +00:00
|
|
|
pixel_in_dps = (float)pixel_xres / (float)dp_xres;
|
|
|
|
|
2016-01-03 14:19:43 +00:00
|
|
|
graphicsContext = new IOSDummyGraphicsContext();
|
2016-01-01 11:23:41 +00:00
|
|
|
|
2016-01-03 14:19:43 +00:00
|
|
|
NativeInitGraphics(graphicsContext);
|
2013-02-17 14:04:44 +00:00
|
|
|
|
|
|
|
dp_xscale = (float)dp_xres / (float)pixel_xres;
|
|
|
|
dp_yscale = (float)dp_yres / (float)pixel_yres;
|
2015-12-28 19:10:38 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
self.iCadeView = [[iCadeReaderView alloc] init];
|
|
|
|
[self.view addSubview:self.iCadeView];
|
|
|
|
self.iCadeView.delegate = self;
|
|
|
|
self.iCadeView.active = YES;
|
2015-12-28 19:10:38 +00:00
|
|
|
|
2014-02-02 14:44:06 +00:00
|
|
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
|
2015-12-28 19:10:38 +00:00
|
|
|
if ([GCController class]) {
|
|
|
|
if ([[GCController controllers] count] > 0) {
|
|
|
|
[self setupController:[[GCController controllers] firstObject]];
|
|
|
|
}
|
|
|
|
}
|
2014-02-02 14:44:06 +00:00
|
|
|
#endif
|
2013-02-17 14:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidUnload
|
|
|
|
{
|
|
|
|
[super viewDidUnload];
|
2013-07-19 21:36:12 +00:00
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
if ([EAGLContext currentContext] == self.context) {
|
|
|
|
[EAGLContext setCurrentContext:nil];
|
|
|
|
}
|
|
|
|
self.context = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didReceiveMemoryWarning
|
|
|
|
{
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[self viewDidUnload];
|
2013-07-19 21:36:12 +00:00
|
|
|
|
2014-01-27 14:32:19 +00:00
|
|
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
|
|
|
|
if ([GCController class]) {
|
2015-12-28 19:10:38 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:GCControllerDidConnectNotification object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:GCControllerDidDisconnectNotification object:nil];
|
|
|
|
self.gameController = nil;
|
|
|
|
}
|
2014-01-27 14:32:19 +00:00
|
|
|
#endif
|
2016-01-01 11:23:41 +00:00
|
|
|
NativeShutdownGraphics();
|
|
|
|
graphicsContext->Shutdown();
|
|
|
|
delete graphicsContext;
|
|
|
|
graphicsContext = NULL;
|
2013-02-17 14:04:44 +00:00
|
|
|
NativeShutdown();
|
|
|
|
}
|
|
|
|
|
2013-03-16 05:23:59 +00:00
|
|
|
// For iOS before 6.0
|
2013-02-17 14:04:44 +00:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
|
|
|
|
{
|
2013-03-16 05:23:59 +00:00
|
|
|
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For iOS 6.0 and up
|
|
|
|
- (NSUInteger)supportedInterfaceOrientations
|
|
|
|
{
|
|
|
|
return UIInterfaceOrientationMaskLandscape;
|
2013-02-17 14:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
|
|
|
|
{
|
2017-03-15 05:01:18 +00:00
|
|
|
NativeUpdate();
|
2016-01-01 11:23:41 +00:00
|
|
|
NativeRender(graphicsContext);
|
2013-02-17 14:04:44 +00:00
|
|
|
time_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchX:(float)x y:(float)y code:(int)code pointerId:(int)pointerId
|
|
|
|
{
|
2014-10-16 00:11:26 +00:00
|
|
|
float scale = [UIScreen mainScreen].scale;
|
|
|
|
|
|
|
|
if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)]) {
|
|
|
|
scale = [UIScreen mainScreen].nativeScale;
|
|
|
|
}
|
2013-07-19 21:36:12 +00:00
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
float scaledX = (int)(x * dp_xscale) * scale;
|
|
|
|
float scaledY = (int)(y * dp_yscale) * scale;
|
2013-07-19 21:36:12 +00:00
|
|
|
|
|
|
|
TouchInput input;
|
|
|
|
input.x = scaledX;
|
|
|
|
input.y = scaledY;
|
|
|
|
switch (code) {
|
|
|
|
case 1 :
|
|
|
|
input.flags = TOUCH_DOWN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2 :
|
|
|
|
input.flags = TOUCH_UP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
input.flags = TOUCH_MOVE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
input.id = pointerId;
|
|
|
|
NativeTouch(input);
|
2013-02-17 14:04:44 +00:00
|
|
|
}
|
|
|
|
|
2013-03-30 23:57:11 +00:00
|
|
|
- (NSDictionary*)touchDictBy:(UITouch*)touch
|
|
|
|
{
|
2013-07-19 21:36:12 +00:00
|
|
|
for (NSDictionary* dict in self.touches) {
|
|
|
|
if ([dict objectForKey:@"touch"] == touch)
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
return nil;
|
2013-03-30 23:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int)freeTouchIndex
|
|
|
|
{
|
2013-07-19 21:36:12 +00:00
|
|
|
int index = 0;
|
2013-03-30 23:57:11 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
for (NSDictionary* dict in self.touches)
|
|
|
|
{
|
|
|
|
int i = [[dict objectForKey:@"index"] intValue];
|
|
|
|
if (index == i)
|
|
|
|
index = i+1;
|
|
|
|
}
|
2013-03-30 23:57:11 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
return index;
|
2013-03-30 23:57:11 +00:00
|
|
|
}
|
|
|
|
|
2014-05-17 05:58:36 +00:00
|
|
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
2013-02-17 14:04:44 +00:00
|
|
|
{
|
2014-05-17 05:58:36 +00:00
|
|
|
for(UITouch* touch in touches)
|
2015-12-28 19:10:38 +00:00
|
|
|
{
|
2013-03-30 23:57:11 +00:00
|
|
|
NSDictionary* dict = @{@"touch":touch,@"index":@([self freeTouchIndex])};
|
|
|
|
[self.touches addObject:dict];
|
2013-02-17 14:04:44 +00:00
|
|
|
CGPoint point = [touch locationInView:self.view];
|
2013-03-30 23:57:11 +00:00
|
|
|
[self touchX:point.x y:point.y code:1 pointerId:[[dict objectForKey:@"index"] intValue]];
|
2013-02-17 14:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-17 05:58:36 +00:00
|
|
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
2013-02-17 14:04:44 +00:00
|
|
|
{
|
2014-05-17 05:58:36 +00:00
|
|
|
for(UITouch* touch in touches)
|
2015-12-28 19:10:38 +00:00
|
|
|
{
|
2013-02-17 14:04:44 +00:00
|
|
|
CGPoint point = [touch locationInView:self.view];
|
2013-03-30 23:57:11 +00:00
|
|
|
NSDictionary* dict = [self touchDictBy:touch];
|
|
|
|
[self touchX:point.x y:point.y code:0 pointerId:[[dict objectForKey:@"index"] intValue]];
|
2013-02-17 14:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-17 05:58:36 +00:00
|
|
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
2013-02-17 14:04:44 +00:00
|
|
|
{
|
2014-05-17 05:58:36 +00:00
|
|
|
for(UITouch* touch in touches)
|
2015-12-28 19:10:38 +00:00
|
|
|
{
|
2013-02-17 14:04:44 +00:00
|
|
|
CGPoint point = [touch locationInView:self.view];
|
2013-03-30 23:57:11 +00:00
|
|
|
NSDictionary* dict = [self touchDictBy:touch];
|
|
|
|
[self touchX:point.x y:point.y code:2 pointerId:[[dict objectForKey:@"index"] intValue]];
|
|
|
|
[self.touches removeObject:dict];
|
2013-02-17 14:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-01 09:58:35 +00:00
|
|
|
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
|
|
|
{
|
|
|
|
for(UITouch* touch in touches)
|
|
|
|
{
|
|
|
|
CGPoint point = [touch locationInView:self.view];
|
|
|
|
NSDictionary* dict = [self touchDictBy:touch];
|
|
|
|
[self touchX:point.x y:point.y code:2 pointerId:[[dict objectForKey:@"index"] intValue]];
|
|
|
|
[self.touches removeObject:dict];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-24 03:47:45 +00:00
|
|
|
- (void)bindDefaultFBO
|
|
|
|
{
|
|
|
|
[(GLKView*)self.view bindDrawable];
|
|
|
|
}
|
|
|
|
|
2013-05-31 01:58:41 +00:00
|
|
|
- (void)buttonDown:(iCadeState)button
|
|
|
|
{
|
2013-07-19 21:36:12 +00:00
|
|
|
if (simulateAnalog &&
|
|
|
|
((button == iCadeJoystickUp) ||
|
|
|
|
(button == iCadeJoystickDown) ||
|
|
|
|
(button == iCadeJoystickLeft) ||
|
|
|
|
(button == iCadeJoystickRight))) {
|
|
|
|
AxisInput axis;
|
|
|
|
switch (button) {
|
|
|
|
case iCadeJoystickUp :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_Y;
|
|
|
|
axis.value = -1.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case iCadeJoystickDown :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_Y;
|
|
|
|
axis.value = 1.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case iCadeJoystickLeft :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_X;
|
|
|
|
axis.value = -1.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case iCadeJoystickRight :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_X;
|
|
|
|
axis.value = 1.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
axis.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
axis.flags = 0;
|
|
|
|
NativeAxis(axis);
|
|
|
|
} else {
|
|
|
|
KeyInput key;
|
|
|
|
key.flags = KEY_DOWN;
|
|
|
|
key.keyCode = iCadeToKeyMap[button];
|
|
|
|
key.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
NativeKey(key);
|
|
|
|
}
|
2013-05-31 01:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)buttonUp:(iCadeState)button
|
|
|
|
{
|
2013-07-19 21:36:12 +00:00
|
|
|
if (button == iCadeButtonA) {
|
|
|
|
// Pressing Select twice within 1 second toggles the DPad between
|
|
|
|
// normal operation and simulating the Analog stick.
|
|
|
|
if ((lastSelectPress + 1.0f) > time_now_d())
|
|
|
|
simulateAnalog = !simulateAnalog;
|
|
|
|
lastSelectPress = time_now_d();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (button == iCadeButtonC) {
|
|
|
|
// Pressing Start twice within 1 second will take to the Emu menu
|
|
|
|
if ((lastStartPress + 1.0f) > time_now_d()) {
|
|
|
|
KeyInput key;
|
|
|
|
key.flags = KEY_DOWN;
|
2013-08-04 17:31:40 +00:00
|
|
|
key.keyCode = NKCODE_ESCAPE;
|
2013-07-19 21:36:12 +00:00
|
|
|
key.deviceId = DEVICE_ID_KEYBOARD;
|
|
|
|
NativeKey(key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastStartPress = time_now_d();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (simulateAnalog &&
|
|
|
|
((button == iCadeJoystickUp) ||
|
|
|
|
(button == iCadeJoystickDown) ||
|
|
|
|
(button == iCadeJoystickLeft) ||
|
|
|
|
(button == iCadeJoystickRight))) {
|
|
|
|
AxisInput axis;
|
|
|
|
switch (button) {
|
|
|
|
case iCadeJoystickUp :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_Y;
|
|
|
|
axis.value = 0.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case iCadeJoystickDown :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_Y;
|
|
|
|
axis.value = 0.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case iCadeJoystickLeft :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_X;
|
|
|
|
axis.value = 0.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case iCadeJoystickRight :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_X;
|
|
|
|
axis.value = 0.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
axis.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
axis.flags = 0;
|
|
|
|
NativeAxis(axis);
|
|
|
|
} else {
|
|
|
|
KeyInput key;
|
|
|
|
key.flags = KEY_UP;
|
|
|
|
key.keyCode = iCadeToKeyMap[button];
|
|
|
|
key.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
NativeKey(key);
|
|
|
|
}
|
|
|
|
|
2013-05-31 01:58:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 14:32:19 +00:00
|
|
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
|
2014-01-24 18:39:45 +00:00
|
|
|
- (void)controllerDidConnect:(NSNotification *)note
|
|
|
|
{
|
2015-12-28 19:10:38 +00:00
|
|
|
if (![[GCController controllers] containsObject:self.gameController]) self.gameController = nil;
|
|
|
|
|
|
|
|
if (self.gameController != nil) return; // already have a connected controller
|
|
|
|
|
|
|
|
[self setupController:(GCController *)note.object];
|
2014-01-24 18:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)controllerDidDisconnect:(NSNotification *)note
|
|
|
|
{
|
2015-12-28 19:10:38 +00:00
|
|
|
if (self.gameController == note.object) {
|
|
|
|
self.gameController = nil;
|
|
|
|
|
|
|
|
if ([[GCController controllers] count] > 0) {
|
|
|
|
[self setupController:[[GCController controllers] firstObject]];
|
|
|
|
} else {
|
|
|
|
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
|
|
|
|
}
|
|
|
|
}
|
2014-01-24 18:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)controllerButtonPressed:(BOOL)pressed keyCode:(keycode_t)keyCode
|
|
|
|
{
|
2015-12-28 19:10:38 +00:00
|
|
|
KeyInput key;
|
|
|
|
key.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
key.flags = pressed ? KEY_DOWN : KEY_UP;
|
|
|
|
key.keyCode = keyCode;
|
|
|
|
NativeKey(key);
|
2014-01-24 18:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setupController:(GCController *)controller
|
|
|
|
{
|
2015-12-28 19:10:38 +00:00
|
|
|
self.gameController = controller;
|
|
|
|
|
|
|
|
GCGamepad *baseProfile = self.gameController.gamepad;
|
|
|
|
if (baseProfile == nil) {
|
|
|
|
self.gameController = nil;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[UIApplication sharedApplication] setIdleTimerDisabled:YES]; // prevent auto-lock
|
|
|
|
|
|
|
|
self.gameController.controllerPausedHandler = ^(GCController *controller) {
|
|
|
|
KeyInput key;
|
|
|
|
key.flags = KEY_DOWN;
|
|
|
|
key.keyCode = NKCODE_ESCAPE;
|
|
|
|
key.deviceId = DEVICE_ID_KEYBOARD;
|
|
|
|
NativeKey(key);
|
|
|
|
};
|
|
|
|
|
|
|
|
baseProfile.buttonA.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_2]; // Cross
|
|
|
|
};
|
|
|
|
|
|
|
|
baseProfile.buttonB.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_3]; // Circle
|
|
|
|
};
|
|
|
|
|
|
|
|
baseProfile.buttonX.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_4]; // Square
|
|
|
|
};
|
|
|
|
|
|
|
|
baseProfile.buttonY.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_1]; // Triangle
|
|
|
|
};
|
|
|
|
|
|
|
|
baseProfile.leftShoulder.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_7]; // LTrigger
|
|
|
|
};
|
|
|
|
|
|
|
|
baseProfile.rightShoulder.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_8]; // RTrigger
|
|
|
|
};
|
|
|
|
|
|
|
|
baseProfile.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_DPAD_UP];
|
|
|
|
};
|
|
|
|
|
|
|
|
baseProfile.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_DPAD_DOWN];
|
|
|
|
};
|
|
|
|
|
|
|
|
baseProfile.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_DPAD_LEFT];
|
|
|
|
};
|
|
|
|
|
|
|
|
baseProfile.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_DPAD_RIGHT];
|
|
|
|
};
|
|
|
|
|
|
|
|
GCExtendedGamepad *extendedProfile = self.gameController.extendedGamepad;
|
|
|
|
if (extendedProfile == nil)
|
|
|
|
return; // controller doesn't support extendedGamepad profile
|
|
|
|
|
|
|
|
extendedProfile.leftTrigger.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_9]; // Select
|
|
|
|
};
|
|
|
|
|
|
|
|
extendedProfile.rightTrigger.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_10]; // Start
|
|
|
|
};
|
|
|
|
|
|
|
|
extendedProfile.leftThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value) {
|
|
|
|
AxisInput axisInput;
|
|
|
|
axisInput.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
axisInput.flags = 0;
|
|
|
|
axisInput.axisId = JOYSTICK_AXIS_X;
|
2017-05-10 12:26:35 +00:00
|
|
|
axisInput.value = value * g_Config.fXInputAnalogSensitivity;
|
2015-12-28 19:10:38 +00:00
|
|
|
NativeAxis(axisInput);
|
|
|
|
};
|
|
|
|
|
|
|
|
extendedProfile.leftThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value) {
|
|
|
|
AxisInput axisInput;
|
|
|
|
axisInput.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
axisInput.flags = 0;
|
|
|
|
axisInput.axisId = JOYSTICK_AXIS_Y;
|
2017-05-10 12:26:35 +00:00
|
|
|
axisInput.value = -value * g_Config.fXInputAnalogSensitivity;
|
2015-12-28 19:10:38 +00:00
|
|
|
NativeAxis(axisInput);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Map right thumbstick as another analog stick, particularly useful for controllers like the DualShock 3/4 when connected to an iOS device
|
|
|
|
extendedProfile.rightThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value) {
|
|
|
|
AxisInput axisInput;
|
|
|
|
axisInput.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
axisInput.flags = 0;
|
|
|
|
axisInput.axisId = JOYSTICK_AXIS_Z;
|
2017-05-10 12:26:35 +00:00
|
|
|
axisInput.value = value * g_Config.fXInputAnalogSensitivity;
|
2015-12-28 19:10:38 +00:00
|
|
|
NativeAxis(axisInput);
|
|
|
|
};
|
|
|
|
|
|
|
|
extendedProfile.rightThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value) {
|
|
|
|
AxisInput axisInput;
|
|
|
|
axisInput.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
axisInput.flags = 0;
|
|
|
|
axisInput.axisId = JOYSTICK_AXIS_RZ;
|
2017-05-10 12:26:35 +00:00
|
|
|
axisInput.value = -value * g_Config.fXInputAnalogSensitivity;
|
2015-12-28 19:10:38 +00:00
|
|
|
NativeAxis(axisInput);
|
|
|
|
};
|
2014-01-24 18:39:45 +00:00
|
|
|
}
|
2014-01-27 14:32:19 +00:00
|
|
|
#endif
|
2014-01-24 18:39:45 +00:00
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
@end
|
2014-05-17 05:58:36 +00:00
|
|
|
|
|
|
|
void LaunchBrowser(char const* url)
|
|
|
|
{
|
|
|
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithCString:url encoding:NSStringEncodingConversionAllowLossy]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
void bindDefaultFBO()
|
|
|
|
{
|
|
|
|
[sharedViewController bindDefaultFBO];
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableFZ(){};
|
|
|
|
void DisableFZ(){};
|