diff --git a/CMakeLists.txt b/CMakeLists.txt index 37509ed442..c0c7004b83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -410,6 +410,16 @@ if(ANDROID) native/android/native-audio-so.h) target_link_libraries(native_audio OpenSLES) # No target +elseif(IOS) + set(nativeExtra ${nativeExtra} + ios/main.m + ios/AppDelegate.m + ios/AppDelegate.h + ios/ViewController.mm + ios/ViewController.h) + set(CMAKE_EXE_LINKER_FLAGS "-framework Foundation -framework CoreGraphics -framework QuartzCore -framework OpenGLES -framework UIKit") + # No target + # set(TargetBin PPSSPP) elseif(USING_QT_UI) # Currently unused find_package(Qt4 COMPONENTS QtMultimedia QtOpenGL QtGui QtCore) @@ -433,9 +443,7 @@ elseif(SDL_FOUND) elseif(PANDORA) set(nativeExtraLibs ${nativeExtraLibs} pthread EGL X11) endif() - if(NOT IOS) # No target - set(TargetBin PPSSPPSDL) - endif() + set(TargetBin PPSSPPSDL) else() message(FATAL_ERROR "Could not find SDL. Failing.") endif() @@ -950,4 +958,9 @@ endif() file(INSTALL ${NativeAssets} DESTINATION assets) +# code signing +if (IOS) + set_target_properties(${NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST PPSSPP-Info.plist XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer: My Name") +endif() + #include(CPack) diff --git a/ios/AppDelegate.h b/ios/AppDelegate.h new file mode 100644 index 0000000000..263e85d369 --- /dev/null +++ b/ios/AppDelegate.h @@ -0,0 +1,13 @@ +// AppDelegate.h boilerplate + +#import + +@class ViewController; + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + +@property (strong, nonatomic) ViewController *viewController; + +@end diff --git a/ios/AppDelegate.m b/ios/AppDelegate.m new file mode 100644 index 0000000000..8601d4fee7 --- /dev/null +++ b/ios/AppDelegate.m @@ -0,0 +1,25 @@ +// AppDelegate.m boilerplate + +#import "AppDelegate.h" + +#import "ViewController.h" + +@implementation AppDelegate + +- (void)dealloc +{ + [_window release]; + [_viewController release]; + [super dealloc]; +} + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; + self.viewController = [[[ViewController alloc] init] autorelease]; + self.window.rootViewController = self.viewController; + [self.window makeKeyAndVisible]; + return YES; +} + +@end diff --git a/ios/PPSSPP-Info.plist b/ios/PPSSPP-Info.plist new file mode 100644 index 0000000000..5fe1a739c6 --- /dev/null +++ b/ios/PPSSPP-Info.plist @@ -0,0 +1,46 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.rock88dev.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIRequiredDeviceCapabilities + + armv7 + + UIStatusBarHidden + + UISupportedInterfaceOrientations + + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/ios/PPSSPP-Prefix.pch b/ios/PPSSPP-Prefix.pch new file mode 100644 index 0000000000..6cc2cfc1a8 --- /dev/null +++ b/ios/PPSSPP-Prefix.pch @@ -0,0 +1,9 @@ +#import + +#ifndef __IPHONE_4_0 +#warning "This project uses features only available in iOS SDK 4.0 and later." +#endif + +#ifdef __OBJC__ + #import +#endif diff --git a/ios/ViewController.h b/ios/ViewController.h new file mode 100644 index 0000000000..b505050d44 --- /dev/null +++ b/ios/ViewController.h @@ -0,0 +1,8 @@ +// ViewController.h boilerplate + +#import +#import + +@interface ViewController : GLKViewController + +@end diff --git a/ios/ViewController.mm b/ios/ViewController.mm new file mode 100644 index 0000000000..576d3b68ca --- /dev/null +++ b/ios/ViewController.mm @@ -0,0 +1,241 @@ +// +// ViewController.m +// +// Created by rock88 +// Modified by xSacha +// + +#import "ViewController.h" +#import + +#include "base/display.h" +#include "base/timeutil.h" +#include "file/zip_read.h" +#include "input/input_state.h" +#include "net/resolve.h" +#include "ui_atlas.h" +#include "ui/screen.h" + +#include "Config.h" +#include "gfx_es2/fbo.h" + +#define IS_IPAD() ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) + +extern void UIUpdateMouse(int i, float x, float y, bool down); + +float dp_xscale = 1.0f; +float dp_yscale = 1.0f; + +static uint32_t pad_buttons_async_set = 0; +static uint32_t pad_buttons_async_clear = 0; + +extern ScreenManager *screenManager; +InputState input_state; + +extern std::string ram_temp_file; + +@interface ViewController () + +@property (strong, nonatomic) EAGLContext *context; +@property (nonatomic,retain) NSString* documentsPath; +@property (nonatomic,retain) NSString* bundlePath; +@property (nonatomic,retain) NSMutableArray* touches; + +@end + +@implementation ViewController +@synthesize documentsPath,bundlePath,touches; + +- (id)init +{ + self = [super init]; + if (self) { + self.touches = [[[NSMutableArray alloc] init] autorelease]; + + self.documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; + self.bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/"]; + + memset(&input_state, 0, sizeof(input_state)); + + net::Init(); + + ram_temp_file = [[NSTemporaryDirectory() stringByAppendingPathComponent:@"ram_tmp.file"] fileSystemRepresentation]; + NativeInit(0, NULL, [self.bundlePath UTF8String], [self.documentsPath UTF8String], NULL); + + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.view.frame = [[UIScreen mainScreen] bounds]; + self.view.multipleTouchEnabled = YES; + self.context = [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2] autorelease]; + + GLKView *view = (GLKView *)self.view; + view.context = self.context; + view.drawableDepthFormat = GLKViewDrawableDepthFormat24; + [EAGLContext setCurrentContext:self.context]; + + float scale = [UIScreen mainScreen].scale; + CGSize size = [[UIApplication sharedApplication].delegate window].frame.size; + + if (size.height > size.width) { + 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; + pixel_xres = size.width * scale; + pixel_yres = size.height * scale; + pixel_in_dps = (float)pixel_xres / (float)dp_xres; + + dp_xres = pixel_xres * g_dpi_scale; + dp_yres = pixel_yres * g_dpi_scale; + + NativeInitGraphics(); + + dp_xscale = (float)dp_xres / (float)pixel_xres; + dp_yscale = (float)dp_yres / (float)pixel_yres; + +/* + UISwipeGestureRecognizer* gesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)] autorelease]; + [self.view addGestureRecognizer:gesture]; +*/ +} + +- (void)viewDidUnload +{ + [super viewDidUnload]; + + if ([EAGLContext currentContext] == self.context) { + [EAGLContext setCurrentContext:nil]; + } + self.context = nil; +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; +} + +- (void)dealloc +{ + [self viewDidUnload]; + + self.touches = nil; + self.documentsPath = nil; + self.bundlePath = nil; + + NativeShutdown(); + [super dealloc]; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation +{ + return YES; +} + +//static BOOL menuDown = NO; + +- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect +{ + lock_guard guard(input_state.lock); + input_state.pad_buttons |= pad_buttons_async_set; + input_state.pad_buttons &= ~pad_buttons_async_clear; + UpdateInputState(&input_state); + + { + lock_guard guard(input_state.lock); + UIUpdateMouse(0, input_state.pointer_x[0], input_state.pointer_y[0], input_state.pointer_down[0]); + screenManager->update(input_state); + } + + { + lock_guard guard(input_state.lock); + EndInputState(&input_state); + } + + NativeRender(); + time_update(); +} + +- (void)swipeGesture:(id)sender +{ + // TODO: Use a swipe gesture to handle BACK +/* + pad_buttons_async_set |= PAD_BUTTON_MENU; + pad_buttons_async_clear &= PAD_BUTTON_MENU; + + int64_t delayInSeconds = 1.5; + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); + dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ + pad_buttons_async_set &= PAD_BUTTON_MENU; + pad_buttons_async_clear |= PAD_BUTTON_MENU; + }); + + if (g_Config.bBufferedRendering) + fbo_unbind(); + + screenManager->push(new InGameMenuScreen()); +*/ +} + +- (void)touchX:(float)x y:(float)y code:(int)code pointerId:(int)pointerId +{ + lock_guard guard(input_state.lock); + + float scale = [UIScreen mainScreen].scale; + + float scaledX = (int)(x * dp_xscale) * scale; + float scaledY = (int)(y * dp_yscale) * scale; + + input_state.pointer_x[pointerId] = scaledX; + input_state.pointer_y[pointerId] = scaledY; + if (code == 1) { + input_state.pointer_down[pointerId] = true; + } else if (code == 2) { + input_state.pointer_down[pointerId] = false; + } + input_state.mouse_valid = true; +} + +- (void)touchesBegan:(NSSet *)_touches withEvent:(UIEvent *)event +{ + for(UITouch* touch in _touches) { + [self.touches addObject:touch]; + CGPoint point = [touch locationInView:self.view]; + [self touchX:point.x y:point.y code:1 pointerId:[self.touches indexOfObject:touch]]; + } +} + +- (void)touchesMoved:(NSSet *)_touches withEvent:(UIEvent *)event +{ + for(UITouch* touch in _touches) { + CGPoint point = [touch locationInView:self.view]; + [self touchX:point.x y:point.y code:0 pointerId:[self.touches indexOfObject:touch]]; + } +} + +- (void)touchesEnded:(NSSet *)_touches withEvent:(UIEvent *)event +{ + for(UITouch* touch in _touches) { + CGPoint point = [touch locationInView:self.view]; + [self touchX:point.x y:point.y code:2 pointerId:[self.touches indexOfObject:touch]]; + [self.touches removeObject:touch]; + } +} + +void LaunchBrowser(char const* url) +{ + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithCString:url encoding:NSStringEncodingConversionAllowLossy]]]; +} + +void EnableFZ(){}; +void DisableFZ(){}; + +@end diff --git a/ios/ios.toolchain.cmake b/ios/ios.toolchain.cmake index 469e83acf1..eeb0fd3deb 100644 --- a/ios/ios.toolchain.cmake +++ b/ios/ios.toolchain.cmake @@ -141,7 +141,7 @@ set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS su # set the architecture for iOS # NOTE: Currently both ARCHS_STANDARD_32_BIT and ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually if (${IOS_PLATFORM} STREQUAL "OS") - set (IOS_ARCH armv6 armv7) + set (IOS_ARCH armv7) else (${IOS_PLATFORM} STREQUAL "OS") set (IOS_ARCH i386) endif (${IOS_PLATFORM} STREQUAL "OS") diff --git a/ios/main.m b/ios/main.m new file mode 100644 index 0000000000..2c76d754c1 --- /dev/null +++ b/ios/main.m @@ -0,0 +1,12 @@ +// main.m boilerplate + +#import + +#import "AppDelegate.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +}