2013-02-17 14:04:44 +00:00
|
|
|
//
|
|
|
|
// ViewController.m
|
|
|
|
//
|
|
|
|
// Created by rock88
|
|
|
|
// Modified by xSacha
|
|
|
|
//
|
|
|
|
|
2019-06-09 14:15:39 +00:00
|
|
|
#import "AppDelegate.h"
|
2013-02-17 14:04:44 +00:00
|
|
|
#import "ViewController.h"
|
2019-06-10 17:24:58 +00:00
|
|
|
#import "DisplayManager.h"
|
2023-03-21 11:08:03 +00:00
|
|
|
#import "iOSCoreAudio.h"
|
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
#import <GLKit/GLKit.h>
|
2017-10-20 09:53:07 +00:00
|
|
|
#include <cassert>
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/Net/Resolve.h"
|
|
|
|
#include "Common/UI/Screen.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/GPU/thin3d.h"
|
|
|
|
#include "Common/GPU/thin3d_create.h"
|
|
|
|
#include "Common/GPU/OpenGL/GLRenderManager.h"
|
|
|
|
#include "Common/GPU/OpenGL/GLFeatures.h"
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2020-10-04 08:30:18 +00:00
|
|
|
#include "Common/System/Display.h"
|
|
|
|
#include "Common/System/System.h"
|
2023-06-30 15:32:21 +00:00
|
|
|
#include "Common/System/OSD.h"
|
2020-10-04 08:30:18 +00:00
|
|
|
#include "Common/System/NativeApp.h"
|
2020-10-04 11:24:12 +00:00
|
|
|
#include "Common/File/VFS/VFS.h"
|
2020-10-04 07:29:36 +00:00
|
|
|
#include "Common/Log.h"
|
|
|
|
#include "Common/TimeUtil.h"
|
|
|
|
#include "Common/Input/InputState.h"
|
|
|
|
#include "Common/Input/KeyCodes.h"
|
|
|
|
#include "Common/GraphicsContext.h"
|
2020-10-04 08:30:18 +00:00
|
|
|
|
2013-02-24 12:17:52 +00:00
|
|
|
#include "Core/Config.h"
|
2018-06-17 01:42:31 +00:00
|
|
|
#include "Core/ConfigValues.h"
|
2022-07-04 19:49:38 +00:00
|
|
|
#include "Core/KeyMap.h"
|
2017-12-26 23:59:02 +00:00
|
|
|
#include "Core/System.h"
|
2020-01-25 20:34:50 +00:00
|
|
|
#include "Core/HLE/sceUsbCam.h"
|
|
|
|
#include "Core/HLE/sceUsbGps.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
|
|
|
|
2020-07-19 09:03:46 +00:00
|
|
|
class IOSGraphicsContext : public GraphicsContext {
|
2016-01-03 14:19:43 +00:00
|
|
|
public:
|
2018-01-22 08:15:41 +00:00
|
|
|
IOSGraphicsContext() {
|
2017-02-06 10:20:27 +00:00
|
|
|
CheckGLExtensions();
|
2023-08-13 11:33:38 +00:00
|
|
|
draw_ = Draw::T3DCreateGLContext(false);
|
2018-01-23 09:30:58 +00:00
|
|
|
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
2020-03-03 03:21:15 +00:00
|
|
|
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
|
2017-12-26 23:59:02 +00:00
|
|
|
SetGPUBackend(GPUBackend::OPENGL);
|
2017-10-20 12:45:00 +00:00
|
|
|
bool success = draw_->CreatePresets();
|
2020-07-19 15:47:02 +00:00
|
|
|
_assert_msg_(success, "Failed to compile preset shaders");
|
2017-02-06 10:20:27 +00:00
|
|
|
}
|
2018-01-22 08:15:41 +00:00
|
|
|
~IOSGraphicsContext() {
|
2017-02-06 10:20:27 +00:00
|
|
|
delete draw_;
|
|
|
|
}
|
|
|
|
Draw::DrawContext *GetDrawContext() override {
|
|
|
|
return draw_;
|
|
|
|
}
|
2020-07-19 09:03:46 +00:00
|
|
|
|
|
|
|
void Resize() override {}
|
|
|
|
void Shutdown() override {}
|
|
|
|
|
2018-01-23 09:28:16 +00:00
|
|
|
void ThreadStart() override {
|
2018-12-23 20:46:48 +00:00
|
|
|
renderManager_->ThreadStart(draw_);
|
2018-01-23 09:28:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ThreadFrame() override {
|
|
|
|
return renderManager_->ThreadFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadEnd() override {
|
|
|
|
renderManager_->ThreadEnd();
|
|
|
|
}
|
2018-02-11 19:46:26 +00:00
|
|
|
|
|
|
|
void StopThread() override {
|
|
|
|
renderManager_->StopThread();
|
|
|
|
}
|
2020-07-19 09:03:46 +00:00
|
|
|
|
2017-02-06 10:20:27 +00:00
|
|
|
private:
|
|
|
|
Draw::DrawContext *draw_;
|
2018-01-23 09:28:16 +00:00
|
|
|
GLRenderManager *renderManager_;
|
2016-01-03 14:19:43 +00:00
|
|
|
};
|
|
|
|
|
2018-01-02 03:06:08 +00:00
|
|
|
static float dp_xscale = 1.0f;
|
|
|
|
static float dp_yscale = 1.0f;
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2018-01-02 03:06:08 +00:00
|
|
|
static double lastSelectPress = 0.0f;
|
|
|
|
static double lastStartPress = 0.0f;
|
|
|
|
static bool simulateAnalog = false;
|
2022-07-04 19:49:38 +00:00
|
|
|
static bool iCadeConnectNotified = false;
|
2018-01-22 08:15:41 +00:00
|
|
|
static bool threadEnabled = true;
|
2018-02-22 11:04:12 +00:00
|
|
|
static bool threadStopped = false;
|
2021-02-20 12:09:54 +00:00
|
|
|
static UITouch *g_touches[10];
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2018-02-22 11:04:12 +00:00
|
|
|
__unsafe_unretained ViewController* sharedViewController;
|
2016-01-01 11:23:41 +00:00
|
|
|
static GraphicsContext *graphicsContext;
|
2020-01-09 13:57:09 +00:00
|
|
|
static CameraHelper *cameraHelper;
|
|
|
|
static LocationHelper *locationHelper;
|
2013-02-24 03:47:45 +00:00
|
|
|
|
2018-04-08 00:15:49 +00:00
|
|
|
@interface ViewController () {
|
2023-05-26 16:40:13 +00:00
|
|
|
std::map<uint16_t, InputKeyCode> iCadeToKeyMap;
|
2013-07-19 21:36:12 +00:00
|
|
|
}
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2017-12-31 02:26:47 +00:00
|
|
|
@property (nonatomic, strong) EAGLContext* context;
|
2021-02-20 12:09:54 +00:00
|
|
|
|
2017-09-04 07:05:46 +00:00
|
|
|
//@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
|
|
|
-(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;
|
2021-02-20 12:09:54 +00:00
|
|
|
memset(g_touches, 0, sizeof(g_touches));
|
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
|
|
|
|
2018-02-22 11:04:12 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-05-19 21:02:14 +00:00
|
|
|
- (BOOL)prefersHomeIndicatorAutoHidden {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2020-04-25 07:07:35 +00:00
|
|
|
- (void)shareText:(NSString *)text {
|
|
|
|
NSArray *items = @[text];
|
|
|
|
UIActivityViewController * viewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self presentViewController:viewController animated:YES completion:nil];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-22 22:25:00 +00:00
|
|
|
extern float g_safeInsetLeft;
|
|
|
|
extern float g_safeInsetRight;
|
|
|
|
extern float g_safeInsetTop;
|
|
|
|
extern float g_safeInsetBottom;
|
|
|
|
|
2020-03-31 16:45:39 +00:00
|
|
|
- (void)viewSafeAreaInsetsDidChange {
|
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
|
[super viewSafeAreaInsetsDidChange];
|
|
|
|
char safeArea[100];
|
|
|
|
// we use 0.0f instead of safeAreaInsets.bottom because the bottom overlay isn't disturbing (for now)
|
2023-03-22 21:55:53 +00:00
|
|
|
g_safeInsetLeft = self.view.safeAreaInsets.left;
|
|
|
|
g_safeInsetRight = self.view.safeAreaInsets.right;
|
|
|
|
g_safeInsetTop = self.view.safeAreaInsets.top;
|
|
|
|
g_safeInsetBottom = 0.0f;
|
2020-03-31 16:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
- (void)viewDidLoad {
|
2013-02-17 14:04:44 +00:00
|
|
|
[super viewDidLoad];
|
2019-06-10 17:24:58 +00:00
|
|
|
[[DisplayManager shared] setupDisplayListener];
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2020-03-31 16:45:39 +00:00
|
|
|
UIScreen* screen = [(AppDelegate*)[UIApplication sharedApplication].delegate screen];
|
2019-06-09 14:15:39 +00:00
|
|
|
self.view.frame = [screen bounds];
|
2013-02-17 14:04:44 +00:00
|
|
|
self.view.multipleTouchEnabled = YES;
|
2014-05-17 06:02:57 +00:00
|
|
|
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
|
2023-03-21 09:42:23 +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
|
|
|
|
2024-05-20 14:12:25 +00:00
|
|
|
UISwipeGestureRecognizer *mSwipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
|
|
|
|
|
|
|
|
[mSwipeLeftRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)];
|
|
|
|
|
|
|
|
[[self view] addGestureRecognizer:mSwipeLeftRecognizer];
|
|
|
|
|
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;
|
2021-01-17 10:34:27 +00:00
|
|
|
view.drawableStencilFormat = GLKViewDrawableStencilFormat8;
|
2013-02-17 14:04:44 +00:00
|
|
|
[EAGLContext setCurrentContext:self.context];
|
2024-05-20 13:38:04 +00:00
|
|
|
self.preferredFramesPerSecond = 60; // NOTE: We don't yet take advantage of 120hz screens
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2019-06-10 17:24:58 +00:00
|
|
|
[[DisplayManager shared] updateResolution:[UIScreen mainScreen]];
|
2015-12-24 22:32:24 +00:00
|
|
|
|
2018-01-22 08:15:41 +00:00
|
|
|
graphicsContext = new IOSGraphicsContext();
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2020-11-04 23:48:35 +00:00
|
|
|
graphicsContext->GetDrawContext()->SetErrorCallback([](const char *shortDesc, const char *details, void *userdata) {
|
2023-06-20 14:10:13 +00:00
|
|
|
g_OSD.Show(OSDType::MESSAGE_ERROR, details, 0.0f, "error_callback");
|
2020-11-04 23:48:35 +00:00
|
|
|
}, nullptr);
|
|
|
|
|
2018-01-23 09:33:02 +00:00
|
|
|
graphicsContext->ThreadStart();
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2023-02-25 12:09:44 +00:00
|
|
|
dp_xscale = (float)g_display.dp_xres / (float)g_display.pixel_xres;
|
|
|
|
dp_yscale = (float)g_display.dp_yres / (float)g_display.pixel_yres;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2017-09-04 07:05:46 +00:00
|
|
|
/*self.iCadeView = [[iCadeReaderView alloc] init];
|
2013-07-19 21:36:12 +00:00
|
|
|
[self.view addSubview:self.iCadeView];
|
|
|
|
self.iCadeView.delegate = self;
|
2017-09-04 07:05:46 +00:00
|
|
|
self.iCadeView.active = YES;*/
|
2023-03-21 09:42:23 +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
|
2020-01-09 13:57:09 +00:00
|
|
|
|
|
|
|
cameraHelper = [[CameraHelper alloc] init];
|
|
|
|
[cameraHelper setDelegate:self];
|
|
|
|
|
|
|
|
locationHelper = [[LocationHelper alloc] init];
|
|
|
|
[locationHelper setDelegate:self];
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2018-01-23 09:28:16 +00:00
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
|
2018-02-11 19:46:26 +00:00
|
|
|
NativeInitGraphics(graphicsContext);
|
|
|
|
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(SYSTEM, "Emulation thread starting\n");
|
2018-01-23 09:28:16 +00:00
|
|
|
while (threadEnabled) {
|
2023-08-07 20:44:06 +00:00
|
|
|
NativeFrame(graphicsContext);
|
2018-01-23 09:28:16 +00:00
|
|
|
}
|
2018-02-11 19:46:26 +00:00
|
|
|
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(SYSTEM, "Emulation thread shutting down\n");
|
2018-02-11 19:46:26 +00:00
|
|
|
NativeShutdownGraphics();
|
|
|
|
|
|
|
|
// Also ask the main thread to stop, so it doesn't hang waiting for a new frame.
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(SYSTEM, "Emulation thread stopping\n");
|
2018-02-11 19:46:26 +00:00
|
|
|
graphicsContext->StopThread();
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2019-06-11 06:44:06 +00:00
|
|
|
threadStopped = true;
|
2018-01-23 09:28:16 +00:00
|
|
|
});
|
2013-02-17 14:04:44 +00:00
|
|
|
}
|
|
|
|
|
2024-05-20 14:12:25 +00:00
|
|
|
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer
|
|
|
|
{
|
|
|
|
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
|
|
|
|
INFO_LOG(SYSTEM, "LEFT");
|
|
|
|
} else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) {
|
|
|
|
INFO_LOG(SYSTEM, "RIGHT");
|
|
|
|
} else {
|
|
|
|
INFO_LOG(SYSTEM, "OTHER SWIPE: %d", (int)recognizer.direction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-22 11:04:12 +00:00
|
|
|
- (void)appWillTerminate:(NSNotification *)notification
|
2013-02-17 14:04:44 +00:00
|
|
|
{
|
2018-02-22 11:04:12 +00:00
|
|
|
[self shutdown];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)shutdown
|
|
|
|
{
|
|
|
|
if (sharedViewController == nil) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-21 11:08:03 +00:00
|
|
|
iOSCoreAudioShutdown();
|
2018-02-22 11:04:12 +00:00
|
|
|
|
|
|
|
if (threadEnabled) {
|
|
|
|
threadEnabled = false;
|
|
|
|
while (graphicsContext->ThreadFrame()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
while (!threadStopped) {}
|
|
|
|
graphicsContext->ThreadEnd();
|
|
|
|
}
|
|
|
|
|
2018-01-01 03:53:59 +00:00
|
|
|
sharedViewController = nil;
|
2018-02-22 11:04:12 +00:00
|
|
|
|
|
|
|
if (self.context) {
|
|
|
|
if ([EAGLContext currentContext] == self.context) {
|
|
|
|
[EAGLContext setCurrentContext:nil];
|
|
|
|
}
|
|
|
|
self.context = nil;
|
2017-12-31 02:26:47 +00:00
|
|
|
}
|
2018-02-22 11:04:12 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
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
|
|
|
self.gameController = nil;
|
|
|
|
}
|
2014-01-27 14:32:19 +00:00
|
|
|
#endif
|
2018-02-22 11:04:12 +00:00
|
|
|
|
|
|
|
if (graphicsContext) {
|
2018-04-21 15:33:53 +00:00
|
|
|
graphicsContext->Shutdown();
|
2018-02-22 11:04:12 +00:00
|
|
|
delete graphicsContext;
|
|
|
|
graphicsContext = NULL;
|
|
|
|
}
|
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
NativeShutdown();
|
|
|
|
}
|
|
|
|
|
2018-02-22 11:04:12 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[self shutdown];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2018-02-22 11:04:12 +00:00
|
|
|
if (sharedViewController)
|
|
|
|
graphicsContext->ThreadFrame();
|
2013-02-17 14:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (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;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2014-10-16 00:11:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-02-20 12:09:54 +00:00
|
|
|
int ToTouchID(UITouch *uiTouch, bool allowAllocate) {
|
2021-04-17 10:07:40 +00:00
|
|
|
// Find the id for the touch.
|
|
|
|
for (int localId = 0; localId < (int)ARRAY_SIZE(g_touches); ++localId) {
|
2021-02-20 12:09:54 +00:00
|
|
|
if (g_touches[localId] == uiTouch) {
|
|
|
|
return localId;
|
|
|
|
}
|
2013-07-19 21:36:12 +00:00
|
|
|
}
|
2013-03-30 23:57:11 +00:00
|
|
|
|
2021-02-20 12:09:54 +00:00
|
|
|
// Allocate a new one, perhaps?
|
|
|
|
if (allowAllocate) {
|
2021-04-17 10:07:40 +00:00
|
|
|
for (int localId = 0; localId < (int)ARRAY_SIZE(g_touches); ++localId) {
|
2021-02-20 12:09:54 +00:00
|
|
|
if (g_touches[localId] == 0) {
|
2021-02-20 15:03:39 +00:00
|
|
|
g_touches[localId] = uiTouch;
|
2021-02-20 12:09:54 +00:00
|
|
|
return localId;
|
|
|
|
}
|
|
|
|
}
|
2013-03-30 23:57:11 +00:00
|
|
|
|
2021-02-20 12:09:54 +00:00
|
|
|
// None were free. Ignore?
|
|
|
|
return 0;
|
2013-07-19 21:36:12 +00:00
|
|
|
}
|
2013-03-30 23:57:11 +00:00
|
|
|
|
2021-02-20 12:09:54 +00:00
|
|
|
return -1;
|
2013-03-30 23:57:11 +00:00
|
|
|
}
|
|
|
|
|
2021-02-20 12:09:54 +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-02-17 14:04:44 +00:00
|
|
|
CGPoint point = [touch locationInView:self.view];
|
2021-02-20 12:09:54 +00:00
|
|
|
int touchId = ToTouchID(touch, true);
|
|
|
|
[self touchX:point.x y:point.y code:1 pointerId:touchId];
|
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];
|
2021-02-20 12:09:54 +00:00
|
|
|
int touchId = ToTouchID(touch, true);
|
|
|
|
[self touchX:point.x y:point.y code:0 pointerId: touchId];
|
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];
|
2021-02-20 12:09:54 +00:00
|
|
|
int touchId = ToTouchID(touch, false);
|
|
|
|
if (touchId >= 0) {
|
|
|
|
[self touchX:point.x y:point.y code:2 pointerId: touchId];
|
|
|
|
g_touches[touchId] = nullptr;
|
|
|
|
}
|
2013-02-17 14:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-01 09:58:35 +00:00
|
|
|
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
|
|
|
{
|
2018-04-08 17:29:07 +00:00
|
|
|
for(UITouch* touch in touches)
|
|
|
|
{
|
|
|
|
CGPoint point = [touch locationInView:self.view];
|
2021-02-20 12:09:54 +00:00
|
|
|
int touchId = ToTouchID(touch, false);
|
|
|
|
if (touchId >= 0) {
|
|
|
|
[self touchX:point.x y:point.y code:2 pointerId: touchId];
|
|
|
|
g_touches[touchId] = nullptr;
|
|
|
|
}
|
2018-04-08 17:29:07 +00:00
|
|
|
}
|
2017-05-01 09:58:35 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
case iCadeJoystickDown :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_Y;
|
|
|
|
axis.value = 1.0f;
|
|
|
|
break;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
case iCadeJoystickLeft :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_X;
|
|
|
|
axis.value = -1.0f;
|
|
|
|
break;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
case iCadeJoystickRight :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_X;
|
|
|
|
axis.value = 1.0f;
|
|
|
|
break;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
axis.deviceId = DEVICE_ID_PAD_0;
|
2023-08-31 09:41:34 +00:00
|
|
|
NativeAxis(&axis, 1);
|
2013-07-19 21:36:12 +00:00
|
|
|
} 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
|
|
|
|
{
|
2022-07-04 19:49:38 +00:00
|
|
|
if (!iCadeConnectNotified) {
|
|
|
|
iCadeConnectNotified = true;
|
|
|
|
KeyMap::NotifyPadConnected(DEVICE_ID_PAD_0, "iCade");
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
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();
|
|
|
|
}
|
2023-03-21 09:42:23 +00:00
|
|
|
|
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 = 0.0f;
|
|
|
|
break;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
case iCadeJoystickDown :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_Y;
|
|
|
|
axis.value = 0.0f;
|
|
|
|
break;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
case iCadeJoystickLeft :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_X;
|
|
|
|
axis.value = 0.0f;
|
|
|
|
break;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
case iCadeJoystickRight :
|
|
|
|
axis.axisId = JOYSTICK_AXIS_X;
|
|
|
|
axis.value = 0.0f;
|
|
|
|
break;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2013-07-19 21:36:12 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
axis.deviceId = DEVICE_ID_PAD_0;
|
2023-08-31 09:41:34 +00:00
|
|
|
NativeAxis(&axis, 1);
|
2013-07-19 21:36:12 +00:00
|
|
|
} else {
|
|
|
|
KeyInput key;
|
|
|
|
key.flags = KEY_UP;
|
|
|
|
key.keyCode = iCadeToKeyMap[button];
|
|
|
|
key.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
NativeKey(key);
|
|
|
|
}
|
2023-03-21 09:42:23 +00:00
|
|
|
|
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;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
if (self.gameController != nil) return; // already have a connected controller
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
[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;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
if ([[GCController controllers] count] > 0) {
|
|
|
|
[self setupController:[[GCController controllers] firstObject]];
|
|
|
|
}
|
|
|
|
}
|
2014-01-24 18:39:45 +00:00
|
|
|
}
|
|
|
|
|
2023-05-26 16:40:13 +00:00
|
|
|
- (void)controllerButtonPressed:(BOOL)pressed keyCode:(InputKeyCode)keyCode
|
2014-01-24 18:39:45 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2019-03-27 02:01:20 +00:00
|
|
|
// Enables tapping for edge area.
|
|
|
|
-(UIRectEdge)preferredScreenEdgesDeferringSystemGestures
|
|
|
|
{
|
|
|
|
return UIRectEdgeAll;
|
|
|
|
}
|
|
|
|
|
2014-01-24 18:39:45 +00:00
|
|
|
- (void)setupController:(GCController *)controller
|
|
|
|
{
|
2015-12-28 19:10:38 +00:00
|
|
|
self.gameController = controller;
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
GCGamepad *baseProfile = self.gameController.gamepad;
|
|
|
|
if (baseProfile == nil) {
|
|
|
|
self.gameController = nil;
|
|
|
|
return;
|
|
|
|
}
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
self.gameController.controllerPausedHandler = ^(GCController *controller) {
|
|
|
|
KeyInput key;
|
|
|
|
key.flags = KEY_DOWN;
|
|
|
|
key.keyCode = NKCODE_ESCAPE;
|
|
|
|
key.deviceId = DEVICE_ID_KEYBOARD;
|
|
|
|
NativeKey(key);
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
baseProfile.buttonA.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_2]; // Cross
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
baseProfile.buttonB.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_3]; // Circle
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
baseProfile.buttonX.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_4]; // Square
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
baseProfile.buttonY.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_1]; // Triangle
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
baseProfile.leftShoulder.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_7]; // LTrigger
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
baseProfile.rightShoulder.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_8]; // RTrigger
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
baseProfile.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_DPAD_UP];
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
baseProfile.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_DPAD_DOWN];
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
baseProfile.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_DPAD_LEFT];
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
baseProfile.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_DPAD_RIGHT];
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
GCExtendedGamepad *extendedProfile = self.gameController.extendedGamepad;
|
|
|
|
if (extendedProfile == nil)
|
|
|
|
return; // controller doesn't support extendedGamepad profile
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
extendedProfile.leftTrigger.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_9]; // Select
|
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
extendedProfile.rightTrigger.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_10]; // Start
|
|
|
|
};
|
2021-01-02 20:57:58 +00:00
|
|
|
|
|
|
|
#if defined(__IPHONE_12_1) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_1
|
2021-06-03 04:20:18 +00:00
|
|
|
if ([extendedProfile respondsToSelector:@selector(leftThumbstickButton)] && extendedProfile.leftThumbstickButton != nil) {
|
2021-01-02 20:57:58 +00:00
|
|
|
extendedProfile.leftThumbstickButton.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_11];
|
|
|
|
};
|
|
|
|
}
|
2021-06-03 04:20:18 +00:00
|
|
|
if ([extendedProfile respondsToSelector:@selector(rightThumbstickButton)] && extendedProfile.rightThumbstickButton != nil) {
|
2021-01-02 20:57:58 +00:00
|
|
|
extendedProfile.rightThumbstickButton.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_12];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|
2021-01-05 15:21:58 +00:00
|
|
|
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
|
2021-06-03 04:20:18 +00:00
|
|
|
if ([extendedProfile respondsToSelector:@selector(buttonOptions)] && extendedProfile.buttonOptions != nil) {
|
2021-01-02 20:57:58 +00:00
|
|
|
extendedProfile.buttonOptions.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_13];
|
|
|
|
};
|
|
|
|
}
|
2021-06-03 04:20:18 +00:00
|
|
|
if ([extendedProfile respondsToSelector:@selector(buttonMenu)] && extendedProfile.buttonMenu != nil) {
|
2021-01-02 20:57:58 +00:00
|
|
|
extendedProfile.buttonMenu.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_14];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
|
2021-06-03 04:20:18 +00:00
|
|
|
if ([extendedProfile respondsToSelector:@selector(buttonHome)] && extendedProfile.buttonHome != nil) {
|
2021-01-02 20:57:58 +00:00
|
|
|
extendedProfile.buttonHome.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
|
|
|
[self controllerButtonPressed:pressed keyCode:NKCODE_BUTTON_15];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
extendedProfile.leftThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value) {
|
|
|
|
AxisInput axisInput;
|
|
|
|
axisInput.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
axisInput.axisId = JOYSTICK_AXIS_X;
|
2021-06-27 03:16:52 +00:00
|
|
|
axisInput.value = value;
|
2023-08-31 09:41:34 +00:00
|
|
|
NativeAxis(&axisInput, 1);
|
2015-12-28 19:10:38 +00:00
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
extendedProfile.leftThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value) {
|
|
|
|
AxisInput axisInput;
|
|
|
|
axisInput.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
axisInput.axisId = JOYSTICK_AXIS_Y;
|
2021-06-27 03:16:52 +00:00
|
|
|
axisInput.value = -value;
|
2023-08-31 09:41:34 +00:00
|
|
|
NativeAxis(&axisInput, 1);
|
2015-12-28 19:10:38 +00:00
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
// 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.axisId = JOYSTICK_AXIS_Z;
|
2021-06-27 03:16:52 +00:00
|
|
|
axisInput.value = value;
|
2023-08-31 09:41:34 +00:00
|
|
|
NativeAxis(&axisInput, 1);
|
2015-12-28 19:10:38 +00:00
|
|
|
};
|
2023-03-21 09:42:23 +00:00
|
|
|
|
2015-12-28 19:10:38 +00:00
|
|
|
extendedProfile.rightThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value) {
|
|
|
|
AxisInput axisInput;
|
|
|
|
axisInput.deviceId = DEVICE_ID_PAD_0;
|
|
|
|
axisInput.axisId = JOYSTICK_AXIS_RZ;
|
2021-06-27 03:16:52 +00:00
|
|
|
axisInput.value = -value;
|
2023-08-31 09:41:34 +00:00
|
|
|
NativeAxis(&axisInput, 1);
|
2015-12-28 19:10:38 +00:00
|
|
|
};
|
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
|
|
|
|
2020-01-25 08:06:00 +00:00
|
|
|
void setCameraSize(int width, int height) {
|
|
|
|
[cameraHelper setCameraSize: width h:height];
|
|
|
|
}
|
|
|
|
|
2020-01-09 13:57:09 +00:00
|
|
|
void startVideo() {
|
2020-01-25 08:06:00 +00:00
|
|
|
[cameraHelper startVideo];
|
2020-01-09 13:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void stopVideo() {
|
2020-03-31 16:45:39 +00:00
|
|
|
[cameraHelper stopVideo];
|
2020-01-09 13:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-(void) PushCameraImageIOS:(long long)len buffer:(unsigned char*)data {
|
2020-03-31 16:45:39 +00:00
|
|
|
Camera::pushCameraImage(len, data);
|
2020-01-09 13:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void startLocation() {
|
2020-03-31 16:45:39 +00:00
|
|
|
[locationHelper startLocationUpdates];
|
2020-01-09 13:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void stopLocation() {
|
2020-03-31 16:45:39 +00:00
|
|
|
[locationHelper stopLocationUpdates];
|
2020-01-09 13:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-(void) SetGpsDataIOS:(CLLocation *)newLocation {
|
2020-03-31 16:45:39 +00:00
|
|
|
GPS::setGpsData((long long)newLocation.timestamp.timeIntervalSince1970,
|
2020-01-26 10:30:46 +00:00
|
|
|
newLocation.horizontalAccuracy/5.0,
|
|
|
|
newLocation.coordinate.latitude, newLocation.coordinate.longitude,
|
|
|
|
newLocation.altitude,
|
|
|
|
MAX(newLocation.speed * 3.6, 0.0), /* m/s to km/h */
|
|
|
|
0 /* bearing */);
|
2020-01-09 13:57:09 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
@end
|
2014-05-17 05:58:36 +00:00
|
|
|
|
2023-03-21 09:42:23 +00:00
|
|
|
void System_LaunchUrl(LaunchUrlType urlType, char const* url)
|
2014-05-17 05:58:36 +00:00
|
|
|
{
|
2024-05-20 13:38:04 +00:00
|
|
|
NSURL *nsUrl = [NSURL URLWithString:[NSString stringWithCString:url encoding:NSStringEncodingConversionAllowLossy]];
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2024-05-20 14:12:25 +00:00
|
|
|
[[UIApplication sharedApplication] openURL:nsUrl options:@{} completionHandler:nil];
|
2024-05-20 13:38:04 +00:00
|
|
|
});
|
2014-05-17 05:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bindDefaultFBO()
|
|
|
|
{
|
|
|
|
[sharedViewController bindDefaultFBO];
|
|
|
|
}
|
2022-10-10 16:35:29 +00:00
|
|
|
|
|
|
|
void EnableFZ(){};
|
|
|
|
void DisableFZ(){};
|