Save reinitialize game on SDL-iOS when app is terminated

This commit is contained in:
Nathan Fulton 2016-03-26 14:35:56 -04:00
parent 93d484864e
commit 31adbf1da0
6 changed files with 82 additions and 2 deletions

View File

@ -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;

View File

@ -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

View File

@ -0,0 +1,41 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
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 <UIKit/UIKit.h>
@interface SDLLaunchScreenController : UIViewController
- (instancetype)init;
- (void)loadView;
- (NSUInteger)supportedInterfaceOrientations;
@end
@interface SDLUIKitDelegate : NSObject<UIApplicationDelegate>
+ (id)sharedAppDelegate;
+ (NSString *)getAppDelegateClassName;
- (void)hideLaunchScreen;
@end
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -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];

View File

@ -1,11 +1,13 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "game/sdl/ios/SDL_uikitappdelegate.h"
@class Webview;
@class InputController;
@class ChatView;
@interface IPhone : NSObject <UIApplicationDelegate>
@interface IPhone : SDLUIKitDelegate
@property (strong, nonatomic) Webview *webView;
@property (strong, nonatomic) InputController *inputController;
@property (strong, nonatomic) ChatView *chatView;

View File

@ -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 <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
@ -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)