From e9378ccf3e07fc564daafd5099f95439d7b612a3 Mon Sep 17 00:00:00 2001 From: Vincent Bénony Date: Mon, 7 Dec 2015 14:12:16 +0100 Subject: IOS: Avoid subclassing UIApplication, and handle multitasking --- backends/platform/ios7/iOS7AppDelegate.h | 9 ++ backends/platform/ios7/iOS7AppDelegate.mm | 85 ++++++++++++++++++ backends/platform/ios7/iOS7MainApplication.h | 39 --------- backends/platform/ios7/iOS7MainApplication.mm | 121 -------------------------- backends/platform/ios7/ios7_main.mm | 2 +- backends/platform/ios7/ios7_osys_events.cpp | 32 +++++-- backends/platform/ios7/ios7_osys_main.cpp | 2 +- backends/platform/ios7/ios7_osys_main.h | 4 + backends/platform/ios7/module.mk | 2 +- 9 files changed, 124 insertions(+), 172 deletions(-) create mode 100644 backends/platform/ios7/iOS7AppDelegate.h create mode 100644 backends/platform/ios7/iOS7AppDelegate.mm delete mode 100644 backends/platform/ios7/iOS7MainApplication.h delete mode 100644 backends/platform/ios7/iOS7MainApplication.mm (limited to 'backends') diff --git a/backends/platform/ios7/iOS7AppDelegate.h b/backends/platform/ios7/iOS7AppDelegate.h new file mode 100644 index 0000000000..49411698c1 --- /dev/null +++ b/backends/platform/ios7/iOS7AppDelegate.h @@ -0,0 +1,9 @@ +// +// Created by Vincent Bénony on 07/12/2015. +// + +#import + + +@interface iOS7AppDelegate : NSObject +@end diff --git a/backends/platform/ios7/iOS7AppDelegate.mm b/backends/platform/ios7/iOS7AppDelegate.mm new file mode 100644 index 0000000000..784566228c --- /dev/null +++ b/backends/platform/ios7/iOS7AppDelegate.mm @@ -0,0 +1,85 @@ +// +// Created by Vincent Bénony on 07/12/2015. +// + +#define FORBIDDEN_SYMBOL_ALLOW_ALL +#import "iOS7AppDelegate.h" +#import "iOS7ScummVMViewController.h" +#import "ios7_video.h" + +@implementation iOS7AppDelegate { + UIWindow *_window; + iOS7ScummVMViewController *_controller; + iPhoneView *_view; +} + +- (id)init { + if (self = [super init]) { + _window = nil; + _view = nil; + } + return self; +} + +- (void)mainLoop:(id)param { + @autoreleasepool { + iOS7_main(iOS7_argc, iOS7_argv); + } + + exit(0); +} + +- (void)applicationDidFinishLaunching:(UIApplication *)application { + CGRect rect = [[UIScreen mainScreen] bounds]; + + // Create the directory for savegames +#ifdef IPHONE_OFFICIAL + NSFileManager *fm = [NSFileManager defaultManager]; + NSString *documentPath = [NSString stringWithUTF8String:iOS7_getDocumentsDir()]; + NSString *savePath = [documentPath stringByAppendingPathComponent:@"Savegames"]; + if (![fm fileExistsAtPath:savePath]) { + [fm createDirectoryAtPath:savePath withIntermediateDirectories:YES attributes:nil error:nil]; + } +#endif + + _window = [[UIWindow alloc] initWithFrame:rect]; + [_window retain]; + + _controller = [[iOS7ScummVMViewController alloc] init]; + + _view = [[iPhoneView alloc] initWithFrame:rect]; + _view.multipleTouchEnabled = YES; + _controller.view = _view; + + [_window setRootViewController:_controller]; + [_window makeKeyAndVisible]; + + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(didRotate:) + name:@"UIDeviceOrientationDidChangeNotification" + object:nil]; + + [NSThread detachNewThreadSelector:@selector(mainLoop:) toTarget:self withObject:nil]; +} + +- (void)applicationDidEnterBackground:(UIApplication *)application { + [_view applicationSuspend]; +} + +- (void)applicationWillEnterForeground:(UIApplication *)application { + [_view applicationResume]; +} + +- (void)didRotate:(NSNotification *)notification { + UIDeviceOrientation screenOrientation = [[UIDevice currentDevice] orientation]; + [_view deviceOrientationChanged:screenOrientation]; +} + +@end + +const char *iOS7_getDocumentsDir() { + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *documentsDirectory = [paths objectAtIndex:0]; + return [documentsDirectory UTF8String]; +} diff --git a/backends/platform/ios7/iOS7MainApplication.h b/backends/platform/ios7/iOS7MainApplication.h deleted file mode 100644 index a47f5da9ce..0000000000 --- a/backends/platform/ios7/iOS7MainApplication.h +++ /dev/null @@ -1,39 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - - -#import - -@class iOS7ScummVMViewController; -@class iPhoneView; - -@interface iOS7MainApplication : UIApplication { - UIWindow *_window; - iOS7ScummVMViewController *_controller; - iPhoneView *_view; -} - -- (void)mainLoop:(id)param; -- (iPhoneView *)getView; -- (UIWindow *)getWindow; -- (void)didRotate:(NSNotification *)notification; -@end diff --git a/backends/platform/ios7/iOS7MainApplication.mm b/backends/platform/ios7/iOS7MainApplication.mm deleted file mode 100644 index c21c017174..0000000000 --- a/backends/platform/ios7/iOS7MainApplication.mm +++ /dev/null @@ -1,121 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - - -#import "iOS7MainApplication.h" -#import "iOS7ScummVMViewController.h" - -#define FORBIDDEN_SYMBOL_ALLOW_ALL -#import "ios7_common.h" -#import "ios7_video.h" - - -@implementation iOS7MainApplication - --(id)init { - [super init]; - _window = nil; - _view = nil; - return self; -} - -- (void)mainLoop:(id)param { - @autoreleasepool { - iOS7_main(iOS7_argc, iOS7_argv); - } - - exit(0); -} - -- (iPhoneView *)getView { - return _view; -} - -- (void)applicationDidFinishLaunching:(UIApplication *)application { - CGRect rect = [[UIScreen mainScreen] bounds]; - - // Create the directory for savegames -#ifdef IPHONE_OFFICIAL - NSFileManager *fm = [NSFileManager defaultManager]; - NSString *documentPath = [NSString stringWithUTF8String:iOS7_getDocumentsDir()]; - NSString *savePath = [documentPath stringByAppendingPathComponent:@"Savegames"]; - if (![fm fileExistsAtPath:savePath]) { - [fm createDirectoryAtPath:savePath withIntermediateDirectories:YES attributes:nil error:nil]; - } -#endif - - _window = [[UIWindow alloc] initWithFrame:rect]; - [_window retain]; - - _controller = [[iOS7ScummVMViewController alloc] init]; - - _view = [[iPhoneView alloc] initWithFrame:rect]; - _view.multipleTouchEnabled = YES; - _controller.view = _view; - - [_window setRootViewController:_controller]; - [_window makeKeyAndVisible]; - - [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(didRotate:) - name:@"UIDeviceOrientationDidChangeNotification" - object:nil]; - - [NSThread detachNewThreadSelector:@selector(mainLoop:) toTarget:self withObject:nil]; -} - -- (void)applicationDidResume { -} - -- (void)applicationWillSuspend { -} - -- (void)applicationWillTerminate { -} - -- (void)applicationSuspend:(struct __GSEvent *)event { - //[self setApplicationBadge:NSLocalizedString(@"ON", nil)]; - [_view applicationSuspend]; -} - -- (void)applicationResume:(struct __GSEvent *)event { - [_view applicationResume]; -} - -- (void)didRotate:(NSNotification *)notification { - UIDeviceOrientation screenOrientation = [[UIDevice currentDevice] orientation]; - [_view deviceOrientationChanged:screenOrientation]; -} - -- (UIWindow*) getWindow { - return _window; -} - -@end - - -const char *iOS7_getDocumentsDir() { - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *documentsDirectory = [paths objectAtIndex:0]; - return [documentsDirectory UTF8String]; -} diff --git a/backends/platform/ios7/ios7_main.mm b/backends/platform/ios7/ios7_main.mm index c6ca14d490..96f41f4c02 100644 --- a/backends/platform/ios7/ios7_main.mm +++ b/backends/platform/ios7/ios7_main.mm @@ -39,7 +39,7 @@ int main(int argc, char **argv) { iOS7_argc = argc; iOS7_argv = argv; - returnCode = UIApplicationMain(argc, argv, @"iOS7MainApplication", @"iOS7MainApplication"); + returnCode = UIApplicationMain(argc, argv, @"UIApplication", @"iOS7AppDelegate"); } return returnCode; diff --git a/backends/platform/ios7/ios7_osys_events.cpp b/backends/platform/ios7/ios7_osys_events.cpp index da44983b03..7e805f34b7 100644 --- a/backends/platform/ios7/ios7_osys_events.cpp +++ b/backends/platform/ios7/ios7_osys_events.cpp @@ -68,12 +68,14 @@ bool OSystem_iOS7::pollEvent(Common::Event &event) { case kInputOrientationChanged: handleEvent_orientationChanged(internalEvent.value1); return false; - break; case kInputApplicationSuspended: - suspendLoop(); + handleEvent_applicationSuspended(); + return false; + + case kInputApplicationResumed: + handleEvent_applicationResumed(); return false; - break; case kInputMouseSecondDragged: if (!handleEvent_mouseSecondDragged(event, internalEvent.value1, internalEvent.value2)) @@ -353,16 +355,28 @@ void OSystem_iOS7::handleEvent_orientationChanged(int orientation) { return; } - if (_screenOrientation != newOrientation) { _screenOrientation = newOrientation; - updateOutputSurface(); + rebuildSurface(); + } +} - dirtyFullScreen(); - if (_videoContext->overlayVisible) +void OSystem_iOS7::rebuildSurface() { + updateOutputSurface(); + + dirtyFullScreen(); + if (_videoContext->overlayVisible) { dirtyFullOverlayScreen(); - updateScreen(); - } + } + updateScreen(); +} + +void OSystem_iOS7::handleEvent_applicationSuspended() { + suspendLoop(); +} + +void OSystem_iOS7::handleEvent_applicationResumed() { + rebuildSurface(); } void OSystem_iOS7::handleEvent_keyPressed(Common::Event &event, int keyPressed) { diff --git a/backends/platform/ios7/ios7_osys_main.cpp b/backends/platform/ios7/ios7_osys_main.cpp index 84ddff26df..a58aa10340 100644 --- a/backends/platform/ios7/ios7_osys_main.cpp +++ b/backends/platform/ios7/ios7_osys_main.cpp @@ -339,6 +339,6 @@ void iOS7_main(int argc, char **argv) { assert(g_system); // Invoke the actual ScummVM main entry point: - scummvm_main(argc, argv); + scummvm_main(argc, (const char *const *) argv); g_system->quit(); // TODO: Consider removing / replacing this! } diff --git a/backends/platform/ios7/ios7_osys_main.h b/backends/platform/ios7/ios7_osys_main.h index 50114a9112..26b147e2a1 100644 --- a/backends/platform/ios7/ios7_osys_main.h +++ b/backends/platform/ios7/ios7_osys_main.h @@ -210,6 +210,8 @@ protected: bool handleEvent_tap(Common::Event &event, UIViewTapDescription type, int touches); void handleEvent_keyPressed(Common::Event &event, int keyPressed); void handleEvent_orientationChanged(int orientation); + void handleEvent_applicationSuspended(); + void handleEvent_applicationResumed(); bool handleEvent_mouseDown(Common::Event &event, int x, int y); bool handleEvent_mouseUp(Common::Event &event, int x, int y); @@ -219,6 +221,8 @@ protected: bool handleEvent_mouseDragged(Common::Event &event, int x, int y); bool handleEvent_mouseSecondDragged(Common::Event &event, int x, int y); + + void rebuildSurface(); }; #endif diff --git a/backends/platform/ios7/module.mk b/backends/platform/ios7/module.mk index fad69d715e..5ee4c7a601 100644 --- a/backends/platform/ios7/module.mk +++ b/backends/platform/ios7/module.mk @@ -9,7 +9,7 @@ MODULE_OBJS := \ ios7_video.o \ ios7_keyboard.o \ iOS7ScummVMViewController.o \ - iOS7MainApplication.o + iOS7AppDelegate.o # We don't use rules.mk but rather manually update OBJS and MODULE_DIRS. MODULE_OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) -- cgit v1.2.3