diff --git a/game/ht.h b/game/ht.h index 19b9591..0a58ce8 100644 --- a/game/ht.h +++ b/game/ht.h @@ -8808,6 +8808,7 @@ void HostSleep(dword ct) secHost; void HostSetGameThread(base::Thread *thread); base::Thread& HostGetGameThread(); base::Thread *HostGetGameThreadPointer(); +void HostAppStop(); const int knKeyboardAskDefault = 0; const int knKeyboardAskURL = 1; diff --git a/game/sdl/host.cpp b/game/sdl/host.cpp index ead79a0..d138063 100644 --- a/game/sdl/host.cpp +++ b/game/sdl/host.cpp @@ -789,4 +789,12 @@ base::Thread *HostGetGameThreadPointer() { return gpgt; } +void HostAppStop() { + // Only use this function for when you can't post an appStopEvent + + ggame.SaveReinitializeGame(); + gevm.SetAppStopping(); + ggame.AskResignGame(); +} + } // namespace wi diff --git a/game/sdl/ios/SDL_uikitappdelegate.h b/game/sdl/ios/SDL_uikitappdelegate.h new file mode 100644 index 0000000..1879f0b --- /dev/null +++ b/game/sdl/ios/SDL_uikitappdelegate.h @@ -0,0 +1,41 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2016 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#import + +@interface SDLLaunchScreenController : UIViewController + +- (instancetype)init; +- (void)loadView; +- (NSUInteger)supportedInterfaceOrientations; + +@end + +@interface SDLUIKitDelegate : NSObject + ++ (id)sharedAppDelegate; ++ (NSString *)getAppDelegateClassName; + +- (void)hideLaunchScreen; + +@end + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/game/sdl/ios/hosthelpers.mm b/game/sdl/ios/hosthelpers.mm index 3d2e5e1..cf446cc 100644 --- a/game/sdl/ios/hosthelpers.mm +++ b/game/sdl/ios/hosthelpers.mm @@ -53,7 +53,7 @@ bool HostHelpers::Init() { gphttp = (HttpService *)new IPhoneHttpService(); // iPhone controller - iphone = [[IPhone alloc] init]; + iphone = [IPhone sharedAppDelegate]; [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; [iphone forceDeviceIntoLandscape]; diff --git a/game/sdl/ios/iphone.h b/game/sdl/ios/iphone.h index 4929f33..7268dd2 100644 --- a/game/sdl/ios/iphone.h +++ b/game/sdl/ios/iphone.h @@ -1,11 +1,13 @@ #import #import +#import "game/sdl/ios/SDL_uikitappdelegate.h" + @class Webview; @class InputController; @class ChatView; -@interface IPhone : NSObject +@interface IPhone : SDLUIKitDelegate @property (strong, nonatomic) Webview *webView; @property (strong, nonatomic) InputController *inputController; @property (strong, nonatomic) ChatView *chatView; diff --git a/game/sdl/ios/iphone.mm b/game/sdl/ios/iphone.mm index aa4108a..f7b0268 100644 --- a/game/sdl/ios/iphone.mm +++ b/game/sdl/ios/iphone.mm @@ -1,3 +1,19 @@ +#import "game/sdl/ios/SDL_uikitappdelegate.h" + +// Catigorize the SDLUIKitDelegate class and override the method that +// loads the SDL_AppDelegate to load the subclassed IPhone class instead. + +@implementation SDLUIKitDelegate (LoadIPhoneAppDelegate) + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation" ++ (NSString *)getAppDelegateClassName { + return @"IPhone"; +} +#pragma clang diagnostic pop + +@end + #include #include #include @@ -24,6 +40,9 @@ @implementation IPhone - (id)init { + if (![super init]) + return NULL; + m_pchat = NULL; self.webView = [[Webview alloc] init]; @@ -33,6 +52,15 @@ return self; } ++ (NSString *)getAppDelegateClassName { + return @"IPhoneAppDelegate"; +} + +- (void)applicationWillTerminate:(UIApplication *)application { + [super applicationWillTerminate:application]; + wi::HostAppStop(); +} + + (void)presentViewController:(UIViewController* )viewController animated:(BOOL)animated completion:(void (^)(void))completion { // When this is done, the ViewController isn't in the window's hierarchy. Only use this method // if you cannot use [self presentView:] (i.e. for this only for UIAlertControllers)