From cc37476c7953b11c5187fd667d5a7c7abb70f9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 22 May 2024 15:59:23 +0200 Subject: [PATCH 1/3] Add a ViewControllerCommon.h --- CMakeLists.txt | 1 + ios/ViewController.h | 12 +----------- ios/ViewController.mm | 10 +++++----- ios/ViewControllerCommon.h | 17 +++++++++++++++++ ios/main.mm | 4 ++-- 5 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 ios/ViewControllerCommon.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e0d117728b..b1e38b10a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1292,6 +1292,7 @@ elseif(IOS AND NOT LIBRETRO) ios/DisplayManager.mm ios/Controls.h ios/Controls.mm + ios/ViewControllerCommon.h ios/ViewController.mm ios/ViewController.h ios/iOSCoreAudio.mm diff --git a/ios/ViewController.h b/ios/ViewController.h index 1e1678685d..fcacaff1ac 100644 --- a/ios/ViewController.h +++ b/ios/ViewController.h @@ -7,15 +7,7 @@ #import "CameraHelper.h" #import "LocationHelper.h" -@protocol PPSSPPViewController -@optional -- (void)hideKeyboard; -- (void)showKeyboard; -- (void)shareText:(NSString *)text; -- (void)shutdown; -- (void)bindDefaultFBO; -- (UIView *)getView; -@end +#include "ViewControllerCommon.h" @interface PPSSPPViewControllerGL : GLKViewController < iCadeEventDelegate, LocationHandlerDelegate, CameraFrameDelegate, @@ -27,5 +19,3 @@ extern id sharedViewController; void setCameraSize(int width, int height); void startVideo(); void stopVideo(); -void startLocation(); -void stopLocation(); diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 169cc32de9..224ee01fe6 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -95,13 +95,13 @@ id sharedViewController; // TODO: Reach these through sharedViewController static CameraHelper *cameraHelper; -static LocationHelper *locationHelper; @interface PPSSPPViewControllerGL () { ICadeTracker g_iCadeTracker; TouchTracker g_touchTracker; GraphicsContext *graphicsContext; + LocationHelper *locationHelper; } @property (nonatomic, strong) EAGLContext* context; @@ -394,19 +394,19 @@ void stopVideo() { [cameraHelper stopVideo]; } --(void) PushCameraImageIOS:(long long)len buffer:(unsigned char*)data { +- (void)PushCameraImageIOS:(long long)len buffer:(unsigned char*)data { Camera::pushCameraImage(len, data); } -void startLocation() { +- (void)startLocation { [locationHelper startLocationUpdates]; } -void stopLocation() { +- (void)stopLocation { [locationHelper stopLocationUpdates]; } --(void) SetGpsDataIOS:(CLLocation *)newLocation { +- (void)SetGpsDataIOS:(CLLocation *)newLocation { GPS::setGpsData((long long)newLocation.timestamp.timeIntervalSince1970, newLocation.horizontalAccuracy/5.0, newLocation.coordinate.latitude, newLocation.coordinate.longitude, diff --git a/ios/ViewControllerCommon.h b/ios/ViewControllerCommon.h new file mode 100644 index 0000000000..bdcd0ee255 --- /dev/null +++ b/ios/ViewControllerCommon.h @@ -0,0 +1,17 @@ +#pragma once + +#import + +@protocol PPSSPPViewController +@optional + +- (void)hideKeyboard; +- (void)showKeyboard; +- (void)shareText:(NSString *)text; +- (void)shutdown; +- (void)bindDefaultFBO; +- (UIView *)getView; +- (void)startLocation; +- (void)stopLocation; + +@end diff --git a/ios/main.mm b/ios/main.mm index 0466c67000..94a0028668 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -437,9 +437,9 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string return true; case SystemRequestType::GPS_COMMAND: if (param1 == "open") { - startLocation(); + [sharedViewController startLocation]; } else if (param1 == "close") { - stopLocation(); + [sharedViewController stopLocation]; } return true; case SystemRequestType::SHARE_TEXT: From 538cc62f1633ea29ccc426f694772e246a5ce930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 22 May 2024 16:02:13 +0200 Subject: [PATCH 2/3] Remove a redundant function --- ios/CameraHelper.h | 3 +-- ios/CameraHelper.mm | 10 +++------- ios/ViewController.h | 3 +-- ios/ViewController.mm | 8 ++------ ios/main.mm | 3 +-- 5 files changed, 8 insertions(+), 19 deletions(-) diff --git a/ios/CameraHelper.h b/ios/CameraHelper.h index 45de67d5d9..4690a5ff5f 100644 --- a/ios/CameraHelper.h +++ b/ios/CameraHelper.h @@ -10,8 +10,7 @@ @property (nonatomic, strong) id delegate; -- (void) setCameraSize:(int)width h:(int)height; -- (void) startVideo; +- (void) startVideo:(int)width h:(int)height; - (void) stopVideo; @end diff --git a/ios/CameraHelper.mm b/ios/CameraHelper.mm index 86dc9f1aec..ffdb282365 100644 --- a/ios/CameraHelper.mm +++ b/ios/CameraHelper.mm @@ -37,7 +37,7 @@ NSString *getSelectedCamera() { if (granted) { NSLog(@"camera permission granted"); dispatch_async(dispatch_get_main_queue(), ^{ - [self startVideo]; + [self startVideo:mWidth h:mHeight]; }); } else { NSLog(@"camera permission denied"); @@ -56,14 +56,10 @@ NSString *getSelectedCamera() { } } --(void) setCameraSize: (int)width h:(int)height { - NSLog(@"CameraHelper::setCameraSize %dx%d", width, height); +-(void) startVideo: (int)width h:(int)height { + NSLog(@"CameraHelper::startVideo %dx%d", width, height); mWidth = width; mHeight = height; -} - --(void) startVideo { - NSLog(@"CameraHelper::startVideo"); if ([self checkPermission]) { return; } diff --git a/ios/ViewController.h b/ios/ViewController.h index fcacaff1ac..be207a839f 100644 --- a/ios/ViewController.h +++ b/ios/ViewController.h @@ -16,6 +16,5 @@ extern id sharedViewController; -void setCameraSize(int width, int height); -void startVideo(); +void startVideo(int width, int height); void stopVideo(); diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 224ee01fe6..d67ae849ee 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -382,12 +382,8 @@ extern float g_safeInsetBottom; } } -void setCameraSize(int width, int height) { - [cameraHelper setCameraSize: width h:height]; -} - -void startVideo() { - [cameraHelper startVideo]; +void startVideo(int width, int height) { + [cameraHelper startVideo: width h:height]; } void stopVideo() { diff --git a/ios/main.mm b/ios/main.mm index 94a0028668..5f12970d9d 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -429,8 +429,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string if (!strncmp(param1.c_str(), "startVideo", 10)) { int width = 0, height = 0; sscanf(param1.c_str(), "startVideo_%dx%d", &width, &height); - setCameraSize(width, height); - startVideo(); + startVideo(width, height); } else if (!strcmp(param1.c_str(), "stopVideo")) { stopVideo(); } From 4726e1f4b37964b4afb8e8ddb5a06e629b4edf52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 22 May 2024 16:35:27 +0200 Subject: [PATCH 3/3] Remove the last non-interface function on the ViewController --- ios/ViewController.h | 3 --- ios/ViewController.mm | 6 +++--- ios/ViewControllerCommon.h | 2 ++ ios/main.mm | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ios/ViewController.h b/ios/ViewController.h index be207a839f..fb4fe1c9dc 100644 --- a/ios/ViewController.h +++ b/ios/ViewController.h @@ -15,6 +15,3 @@ @end extern id sharedViewController; - -void startVideo(int width, int height); -void stopVideo(); diff --git a/ios/ViewController.mm b/ios/ViewController.mm index d67ae849ee..e97d67406f 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -382,11 +382,11 @@ extern float g_safeInsetBottom; } } -void startVideo(int width, int height) { - [cameraHelper startVideo: width h:height]; +- (void)startVideo:(int)width height:(int)height { + [cameraHelper startVideo:width h:height]; } -void stopVideo() { +- (void)stopVideo { [cameraHelper stopVideo]; } diff --git a/ios/ViewControllerCommon.h b/ios/ViewControllerCommon.h index bdcd0ee255..52766bff4d 100644 --- a/ios/ViewControllerCommon.h +++ b/ios/ViewControllerCommon.h @@ -13,5 +13,7 @@ - (UIView *)getView; - (void)startLocation; - (void)stopLocation; +- (void)startVideo:(int)width height:(int)height; +- (void)stopVideo; @end diff --git a/ios/main.mm b/ios/main.mm index 5f12970d9d..bc0909e8f6 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -429,9 +429,9 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string if (!strncmp(param1.c_str(), "startVideo", 10)) { int width = 0, height = 0; sscanf(param1.c_str(), "startVideo_%dx%d", &width, &height); - startVideo(width, height); + [sharedViewController startVideo:width height:height]; } else if (!strcmp(param1.c_str(), "stopVideo")) { - stopVideo(); + [sharedViewController stopVideo]; } return true; case SystemRequestType::GPS_COMMAND: