cmd/ebitenmobile: Add suspendGame/resumeGame to the ViewController

Updates #894
This commit is contained in:
Hajime Hoshi 2019-09-13 02:41:43 +09:00
parent 71b28b6211
commit 16337bb6bf
3 changed files with 50 additions and 2 deletions

View File

@ -122,6 +122,8 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
@implementation {{.PrefixUpper}}EbitenViewController { @implementation {{.PrefixUpper}}EbitenViewController {
GLKView* glkView_; GLKView* glkView_;
bool started_;
bool active_;
bool error_; bool error_;
} }
@ -136,6 +138,13 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
if (!started_) {
@synchronized(self) {
active_ = true;
}
started_ = true;
}
self.glkView.delegate = (id<GLKViewDelegate>)(self); self.glkView.delegate = (id<GLKViewDelegate>)(self);
[self.view addSubview: self.glkView]; [self.view addSubview: self.glkView];
@ -174,6 +183,13 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
if (error_) { if (error_) {
return; return;
} }
@synchronized(self) {
if (!active_) {
return;
}
}
NSError* err = nil; NSError* err = nil;
EbitenmobileviewUpdate(&err); EbitenmobileviewUpdate(&err);
if (err != nil) { if (err != nil) {
@ -214,6 +230,24 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
[self updateTouches:touches]; [self updateTouches:touches];
} }
- (void)suspendGame
{
NSAssert(started_, @"suspendGame msut not be called before viewDidLoad is called");
@synchronized(self) {
active_ = false;
}
}
- (void)resumeGame
{
NSAssert(started_, @"resumeGame msut not be called before viewDidLoad is called");
@synchronized(self) {
active_ = true;
}
}
@end @end
` `

File diff suppressed because one or more lines are too long

View File

@ -214,7 +214,21 @@ const objcH = `// Code generated by ebitenmobile. DO NOT EDIT.
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@interface {{.PrefixUpper}}EbitenViewController : UIViewController @interface {{.PrefixUpper}}EbitenViewController : UIViewController
// onErrorOnGameUpdate is called on the main thread when an error happens when updating a game.
// You can define your own error handler, e.g., using Crashlytics, by overwriting this method.
- (void)onErrorOnGameUpdate:(NSError*)err; - (void)onErrorOnGameUpdate:(NSError*)err;
// suspendGame suspends the game.
// It is recommended to call this when the application is being suspended e.g.,
// UIApplicationDelegate's applicationWillResignActive is called.
- (void)suspendGame;
// resumeGame resumes the game.
// It is recommended to call this when the application is being resumed e.g.,
// UIApplicationDelegate's applicationDidBecomeActive is called.
- (void)resumeGame;
@end @end
` `