summaryrefslogtreecommitdiff
path: root/platform/iphone
diff options
context:
space:
mode:
authorBastiaanOlij <mux213@gmail.com>2017-04-09 21:22:40 +1000
committerBastiaanOlij <mux213@gmail.com>2017-04-09 21:22:40 +1000
commit5c2ddb299ba1385bae19e16590bd6207e493ace6 (patch)
tree217b35aad58f0909e9915ba9fcdaf0ea6be5694d /platform/iphone
parent21727657ff6df8ebbf5860547ecd3c48f22eefe5 (diff)
Formatting of mm files
Diffstat (limited to 'platform/iphone')
-rw-r--r--platform/iphone/app_delegate.mm336
-rw-r--r--platform/iphone/game_center.mm81
-rwxr-xr-xplatform/iphone/gl_view.mm213
-rw-r--r--platform/iphone/icloud.mm101
-rw-r--r--platform/iphone/in_app_store.mm180
-rw-r--r--platform/iphone/ios.mm13
-rw-r--r--platform/iphone/main.m3
-rw-r--r--platform/iphone/view_controller.mm81
8 files changed, 463 insertions, 545 deletions
diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm
index 4c36942ff8..5060fae0ea 100644
--- a/platform/iphone/app_delegate.mm
+++ b/platform/iphone/app_delegate.mm
@@ -59,10 +59,10 @@ void _set_keep_screen_on(bool p_enabled);
Error _shell_open(String p_uri) {
NSString* url = [[NSString alloc] initWithUTF8String:p_uri.utf8().get_data()];
- if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:url]])
- return ERR_CANT_OPEN;
+ if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:url]])
+ return ERR_CANT_OPEN;
- printf("opening url %ls\n", p_uri.c_str());
+ printf("opening url %ls\n", p_uri.c_str());
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
[url release];
return OK;
@@ -85,8 +85,7 @@ CMMotionManager *motionManager;
bool motionInitialised;
static ViewController* mainViewController = nil;
-+ (ViewController*) getViewController
-{
++ (ViewController*) getViewController {
return mainViewController;
}
@@ -94,156 +93,153 @@ static int frame_count = 0;
- (void)drawView:(GLView*)view; {
switch (frame_count) {
-
- case 0: {
- int backingWidth;
- int backingHeight;
- glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
- glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
-
-
- OS::VideoMode vm;
- vm.fullscreen = true;
- vm.width = backingWidth;
- vm.height = backingHeight;
- vm.resizable = false;
- OS::get_singleton()->set_video_mode(vm);
-
- if (!OS::get_singleton()) {
- exit(0);
- };
- ++frame_count;
-
- NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- //NSString *documentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
- OSIPhone::get_singleton()->set_data_dir(String::utf8([documentsDirectory UTF8String]));
-
- NSString *locale_code = [[[NSLocale preferredLanguages] objectAtIndex:0] substringToIndex:2];
- OSIPhone::get_singleton()->set_locale(String::utf8([locale_code UTF8String]));
-
- NSString* uuid;
- if ([[UIDevice currentDevice]respondsToSelector:@selector(identifierForVendor)]) {
- uuid = [UIDevice currentDevice].identifierForVendor.UUIDString;
- }else{
-
- // before iOS 6, so just generate an identifier and store it
- uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"identiferForVendor"];
- if( !uuid ) {
- CFUUIDRef cfuuid = CFUUIDCreate(NULL);
- uuid = (__bridge_transfer NSString*)CFUUIDCreateString(NULL, cfuuid);
- CFRelease(cfuuid);
- [[NSUserDefaults standardUserDefaults] setObject:uuid forKey:@"identifierForVendor"];
+ case 0: {
+ int backingWidth;
+ int backingHeight;
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
+
+ OS::VideoMode vm;
+ vm.fullscreen = true;
+ vm.width = backingWidth;
+ vm.height = backingHeight;
+ vm.resizable = false;
+ OS::get_singleton()->set_video_mode(vm);
+
+ if (!OS::get_singleton()) {
+ exit(0);
+ };
+ ++frame_count;
+
+ NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ NSString *documentsDirectory = [paths objectAtIndex:0];
+ //NSString *documentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
+ OSIPhone::get_singleton()->set_data_dir(String::utf8([documentsDirectory UTF8String]));
+
+ NSString *locale_code = [[[NSLocale preferredLanguages] objectAtIndex:0] substringToIndex:2];
+ OSIPhone::get_singleton()->set_locale(String::utf8([locale_code UTF8String]));
+
+ NSString* uuid;
+ if ([[UIDevice currentDevice]respondsToSelector:@selector(identifierForVendor)]) {
+ uuid = [UIDevice currentDevice].identifierForVendor.UUIDString;
+ } else {
+ // before iOS 6, so just generate an identifier and store it
+ uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"identiferForVendor"];
+ if( !uuid ) {
+ CFUUIDRef cfuuid = CFUUIDCreate(NULL);
+ uuid = (__bridge_transfer NSString*)CFUUIDCreateString(NULL, cfuuid);
+ CFRelease(cfuuid);
+ [[NSUserDefaults standardUserDefaults] setObject:uuid forKey:@"identifierForVendor"];
+ }
}
- }
- OSIPhone::get_singleton()->set_unique_ID(String::utf8([uuid UTF8String]));
+ OSIPhone::get_singleton()->set_unique_ID(String::utf8([uuid UTF8String]));
- }; break;
+ }; break;
/*
- case 1: {
- ++frame_count;
- } break;
+ case 1: {
+ ++frame_count;
+ }; break;
*/
- case 1: {
+ case 1: {
- Main::setup2();
- ++frame_count;
+ Main::setup2();
+ ++frame_count;
- // this might be necessary before here
- NSDictionary* dict = [[NSBundle mainBundle] infoDictionary];
- for (NSString* key in dict) {
- NSObject* value = [dict objectForKey:key];
- String ukey = String::utf8([key UTF8String]);
+ // this might be necessary before here
+ NSDictionary* dict = [[NSBundle mainBundle] infoDictionary];
+ for (NSString* key in dict) {
+ NSObject* value = [dict objectForKey:key];
+ String ukey = String::utf8([key UTF8String]);
- // we need a NSObject to Variant conversor
+ // we need a NSObject to Variant conversor
- if ([value isKindOfClass:[NSString class]]) {
- NSString* str = (NSString*)value;
- String uval = String::utf8([str UTF8String]);
+ if ([value isKindOfClass:[NSString class]]) {
+ NSString* str = (NSString*)value;
+ String uval = String::utf8([str UTF8String]);
- GlobalConfig::get_singleton()->set("Info.plist/"+ukey, uval);
+ GlobalConfig::get_singleton()->set("Info.plist/"+ukey, uval);
- } else if ([value isKindOfClass:[NSNumber class]]) {
+ } else if ([value isKindOfClass:[NSNumber class]]) {
- NSNumber* n = (NSNumber*)value;
- double dval = [n doubleValue];
+ NSNumber* n = (NSNumber*)value;
+ double dval = [n doubleValue];
- GlobalConfig::get_singleton()->set("Info.plist/"+ukey, dval);
- };
- // do stuff
- }
+ GlobalConfig::get_singleton()->set("Info.plist/"+ukey, dval);
+ };
+ // do stuff
+ }
- } break;
+ }; break;
/*
- case 3: {
- ++frame_count;
- } break;
+ case 3: {
+ ++frame_count;
+ }; break;
*/
- case 2: {
+ case 2: {
- Main::start();
- ++frame_count;
+ Main::start();
+ ++frame_count;
- }; break; // no fallthrough
+ }; break; // no fallthrough
- default: {
- if (OSIPhone::get_singleton()) {
+ default: {
+ if (OSIPhone::get_singleton()) {
// OSIPhone::get_singleton()->update_accelerometer(accel[0], accel[1], accel[2]);
- if (motionInitialised) {
- // Just using polling approach for now, we can set this up so it sends data to us in intervals, might be better.
- // See Apple reference pages for more details:
- // https://developer.apple.com/reference/coremotion/cmmotionmanager?language=objc
-
- // Apple splits our accelerometer date into a gravity and user movement component. We add them back together
- CMAcceleration gravity = motionManager.deviceMotion.gravity;
- CMAcceleration acceleration = motionManager.deviceMotion.userAcceleration;
-
- ///@TODO We don't seem to be getting data here, is my device broken or is this code incorrect?
- CMMagneticField magnetic = motionManager.deviceMotion.magneticField.field;
-
- ///@TODO we can access rotationRate as a CMRotationRate variable (processed date) or CMGyroData (raw data), have to see what works best
- CMRotationRate rotation = motionManager.deviceMotion.rotationRate;
-
- // Adjust for screen orientation.
- // [[UIDevice currentDevice] orientation] changes even if we've fixed our orientation which is not
- // a good thing when you're trying to get your user to move the screen in all directions and want consistent output
-
- ///@TODO Using [[UIApplication sharedApplication] statusBarOrientation] is a bit of a hack. Godot obviously knows the orientation so maybe we
- // can use that instead? (note that left and right seem swapped)
-
- switch ([[UIApplication sharedApplication] statusBarOrientation]) {
- case UIDeviceOrientationLandscapeLeft: {
- OSIPhone::get_singleton()->update_gravity(-gravity.y, gravity.x, gravity.z);
- OSIPhone::get_singleton()->update_accelerometer(-(acceleration.y + gravity.y), (acceleration.x + gravity.x), acceleration.z + gravity.z);
- OSIPhone::get_singleton()->update_magnetometer(-magnetic.y, magnetic.x, magnetic.z);
- OSIPhone::get_singleton()->update_gyroscope(-rotation.y, rotation.x, rotation.z);
- }; break;
- case UIDeviceOrientationLandscapeRight: {
- OSIPhone::get_singleton()->update_gravity(gravity.y, -gravity.x, gravity.z);
- OSIPhone::get_singleton()->update_accelerometer((acceleration.y + gravity.y), -(acceleration.x + gravity.x), acceleration.z + gravity.z);
- OSIPhone::get_singleton()->update_magnetometer(magnetic.y, -magnetic.x, magnetic.z);
- OSIPhone::get_singleton()->update_gyroscope(rotation.y, -rotation.x, rotation.z);
- }; break;
- case UIDeviceOrientationPortraitUpsideDown: {
- OSIPhone::get_singleton()->update_gravity(-gravity.x, gravity.y, gravity.z);
- OSIPhone::get_singleton()->update_accelerometer(-(acceleration.x + gravity.x), (acceleration.y + gravity.y), acceleration.z + gravity.z);
- OSIPhone::get_singleton()->update_magnetometer(-magnetic.x, magnetic.y, magnetic.z);
- OSIPhone::get_singleton()->update_gyroscope(-rotation.x, rotation.y, rotation.z);
- }; break;
- default: { // assume portrait
- OSIPhone::get_singleton()->update_gravity(gravity.x, gravity.y, gravity.z);
- OSIPhone::get_singleton()->update_accelerometer(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z);
- OSIPhone::get_singleton()->update_magnetometer(magnetic.x, magnetic.y, magnetic.z);
- OSIPhone::get_singleton()->update_gyroscope(rotation.x, rotation.y, rotation.z);
- }; break;
- };
- }
-
- bool quit_request = OSIPhone::get_singleton()->iterate();
- };
+ if (motionInitialised) {
+ // Just using polling approach for now, we can set this up so it sends data to us in intervals, might be better.
+ // See Apple reference pages for more details:
+ // https://developer.apple.com/reference/coremotion/cmmotionmanager?language=objc
+
+ // Apple splits our accelerometer date into a gravity and user movement component. We add them back together
+ CMAcceleration gravity = motionManager.deviceMotion.gravity;
+ CMAcceleration acceleration = motionManager.deviceMotion.userAcceleration;
+
+ ///@TODO We don't seem to be getting data here, is my device broken or is this code incorrect?
+ CMMagneticField magnetic = motionManager.deviceMotion.magneticField.field;
+
+ ///@TODO we can access rotationRate as a CMRotationRate variable (processed date) or CMGyroData (raw data), have to see what works best
+ CMRotationRate rotation = motionManager.deviceMotion.rotationRate;
+
+ // Adjust for screen orientation.
+ // [[UIDevice currentDevice] orientation] changes even if we've fixed our orientation which is not
+ // a good thing when you're trying to get your user to move the screen in all directions and want consistent output
+
+ ///@TODO Using [[UIApplication sharedApplication] statusBarOrientation] is a bit of a hack. Godot obviously knows the orientation so maybe we
+ // can use that instead? (note that left and right seem swapped)
+
+ switch ([[UIApplication sharedApplication] statusBarOrientation]) {
+ case UIDeviceOrientationLandscapeLeft: {
+ OSIPhone::get_singleton()->update_gravity(-gravity.y, gravity.x, gravity.z);
+ OSIPhone::get_singleton()->update_accelerometer(-(acceleration.y + gravity.y), (acceleration.x + gravity.x), acceleration.z + gravity.z);
+ OSIPhone::get_singleton()->update_magnetometer(-magnetic.y, magnetic.x, magnetic.z);
+ OSIPhone::get_singleton()->update_gyroscope(-rotation.y, rotation.x, rotation.z);
+ }; break;
+ case UIDeviceOrientationLandscapeRight: {
+ OSIPhone::get_singleton()->update_gravity(gravity.y, -gravity.x, gravity.z);
+ OSIPhone::get_singleton()->update_accelerometer((acceleration.y + gravity.y), -(acceleration.x + gravity.x), acceleration.z + gravity.z);
+ OSIPhone::get_singleton()->update_magnetometer(magnetic.y, -magnetic.x, magnetic.z);
+ OSIPhone::get_singleton()->update_gyroscope(rotation.y, -rotation.x, rotation.z);
+ }; break;
+ case UIDeviceOrientationPortraitUpsideDown: {
+ OSIPhone::get_singleton()->update_gravity(-gravity.x, gravity.y, gravity.z);
+ OSIPhone::get_singleton()->update_accelerometer(-(acceleration.x + gravity.x), (acceleration.y + gravity.y), acceleration.z + gravity.z);
+ OSIPhone::get_singleton()->update_magnetometer(-magnetic.x, magnetic.y, magnetic.z);
+ OSIPhone::get_singleton()->update_gyroscope(-rotation.x, rotation.y, rotation.z);
+ }; break;
+ default: { // assume portrait
+ OSIPhone::get_singleton()->update_gravity(gravity.x, gravity.y, gravity.z);
+ OSIPhone::get_singleton()->update_accelerometer(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z);
+ OSIPhone::get_singleton()->update_magnetometer(magnetic.x, magnetic.y, magnetic.z);
+ OSIPhone::get_singleton()->update_gyroscope(rotation.x, rotation.y, rotation.z);
+ }; break;
+ };
+ }
+
+ bool quit_request = OSIPhone::get_singleton()->iterate();
+ };
- };
+ }; break;
};
};
@@ -301,7 +297,7 @@ static int frame_count = 0;
motionManager = [[CMMotionManager alloc] init];
if (motionManager.deviceMotionAvailable) {
motionManager.deviceMotionUpdateInterval = 1.0/70.0;
- [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXMagneticNorthZVertical];
+ [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXMagneticNorthZVertical];
motionInitialised = YES;
};
};
@@ -312,30 +308,27 @@ static int frame_count = 0;
mainViewController = view_controller;
#ifdef MODULE_GAME_ANALYTICS_ENABLED
- printf("********************* didFinishLaunchingWithOptions\n");
- if(!GlobalConfig::get_singleton()->has("mobileapptracker/advertiser_id"))
- {
- return;
- }
- if(!GlobalConfig::get_singleton()->has("mobileapptracker/conversion_key"))
- {
- return;
- }
-
- String adid = GLOBAL_DEF("mobileapptracker/advertiser_id","");
- String convkey = GLOBAL_DEF("mobileapptracker/conversion_key","");
-
- NSString * advertiser_id = [NSString stringWithUTF8String:adid.utf8().get_data()];
- NSString * conversion_key = [NSString stringWithUTF8String:convkey.utf8().get_data()];
-
- // Account Configuration info - must be set
- [MobileAppTracker initializeWithMATAdvertiserId:advertiser_id
- MATConversionKey:conversion_key];
-
- // Used to pass us the IFA, enables highly accurate 1-to-1 attribution.
- // Required for many advertising networks.
- [MobileAppTracker setAppleAdvertisingIdentifier:[[ASIdentifierManager sharedManager] advertisingIdentifier]
- advertisingTrackingEnabled:[[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]];
+ printf("********************* didFinishLaunchingWithOptions\n");
+ if (!GlobalConfig::get_singleton()->has("mobileapptracker/advertiser_id")) {
+ return;
+ }
+ if (!GlobalConfig::get_singleton()->has("mobileapptracker/conversion_key")) {
+ return;
+ }
+
+ String adid = GLOBAL_DEF("mobileapptracker/advertiser_id","");
+ String convkey = GLOBAL_DEF("mobileapptracker/conversion_key","");
+
+ NSString * advertiser_id = [NSString stringWithUTF8String:adid.utf8().get_data()];
+ NSString * conversion_key = [NSString stringWithUTF8String:convkey.utf8().get_data()];
+
+ // Account Configuration info - must be set
+ [MobileAppTracker initializeWithMATAdvertiserId:advertiser_id MATConversionKey:conversion_key];
+
+ // Used to pass us the IFA, enables highly accurate 1-to-1 attribution.
+ // Required for many advertising networks.
+ [MobileAppTracker setAppleAdvertisingIdentifier:[[ASIdentifierManager sharedManager] advertisingIdentifier]
+ advertisingTrackingEnabled:[[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]];
#endif
@@ -356,42 +349,40 @@ static int frame_count = 0;
iphone_finish();
};
-- (void)applicationDidEnterBackground:(UIApplication *)application
-{
+- (void)applicationDidEnterBackground:(UIApplication *)application {
printf("********************* did enter background\n");
///@TODO maybe add pause motionManager? and where would we unpause it?
if (OS::get_singleton()->get_main_loop())
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
+
[view_controller.view stopAnimation];
if (OS::get_singleton()->native_video_is_playing()) {
OSIPhone::get_singleton()->native_video_focus_out();
};
}
-- (void)applicationWillEnterForeground:(UIApplication *)application
-{
+- (void)applicationWillEnterForeground:(UIApplication *)application {
printf("********************* did enter foreground\n");
//OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
[view_controller.view startAnimation];
}
-- (void) applicationWillResignActive:(UIApplication *)application
-{
+- (void) applicationWillResignActive:(UIApplication *)application {
printf("********************* will resign active\n");
//OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
[view_controller.view stopAnimation]; // FIXME: pause seems to be recommended elsewhere
}
-- (void) applicationDidBecomeActive:(UIApplication *)application
-{
+- (void) applicationDidBecomeActive:(UIApplication *)application {
printf("********************* did become active\n");
#ifdef MODULE_GAME_ANALYTICS_ENABLED
- printf("********************* mobile app tracker found\n");
+ printf("********************* mobile app tracker found\n");
[MobileAppTracker measureSession];
#endif
if (OS::get_singleton()->get_main_loop())
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
+
[view_controller.view startAnimation]; // FIXME: resume seems to be recommended elsewhere
if (OSIPhone::get_singleton()->native_video_is_playing()) {
OSIPhone::get_singleton()->native_video_unpause();
@@ -411,9 +402,9 @@ static int frame_count = 0;
#ifdef MODULE_PARSE_ENABLED
NSLog(@"Handling application openURL");
return [[FBSDKApplicationDelegate sharedInstance] application:application
- openURL:url
- sourceApplication:sourceApplication
- annotation:annotation];
+ openURL:url
+ sourceApplication:sourceApplication
+ annotation:annotation];
#endif
@@ -450,8 +441,7 @@ static int frame_count = 0;
#endif
}
-- (void)dealloc
-{
+- (void)dealloc {
[window release];
[super dealloc];
}
diff --git a/platform/iphone/game_center.mm b/platform/iphone/game_center.mm
index 2593134512..729d9f61a5 100644
--- a/platform/iphone/game_center.mm
+++ b/platform/iphone/game_center.mm
@@ -49,18 +49,18 @@ extern "C" {
GameCenter* GameCenter::instance = NULL;
void GameCenter::_bind_methods() {
- ClassDB::bind_method(D_METHOD("connect"),&GameCenter::connect);
- ClassDB::bind_method(D_METHOD("is_connected"),&GameCenter::is_connected);
-
- ClassDB::bind_method(D_METHOD("post_score"),&GameCenter::post_score);
- ClassDB::bind_method(D_METHOD("award_achievement"),&GameCenter::award_achievement);
- ClassDB::bind_method(D_METHOD("reset_achievements"),&GameCenter::reset_achievements);
- ClassDB::bind_method(D_METHOD("request_achievements"),&GameCenter::request_achievements);
- ClassDB::bind_method(D_METHOD("request_achievement_descriptions"),&GameCenter::request_achievement_descriptions);
- ClassDB::bind_method(D_METHOD("show_game_center"),&GameCenter::show_game_center);
-
- ClassDB::bind_method(D_METHOD("get_pending_event_count"),&GameCenter::get_pending_event_count);
- ClassDB::bind_method(D_METHOD("pop_pending_event"),&GameCenter::pop_pending_event);
+ ClassDB::bind_method(D_METHOD("connect"), &GameCenter::connect);
+ ClassDB::bind_method(D_METHOD("is_connected"), &GameCenter::is_connected);
+
+ ClassDB::bind_method(D_METHOD("post_score"), &GameCenter::post_score);
+ ClassDB::bind_method(D_METHOD("award_achievement"), &GameCenter::award_achievement);
+ ClassDB::bind_method(D_METHOD("reset_achievements"), &GameCenter::reset_achievements);
+ ClassDB::bind_method(D_METHOD("request_achievements"), &GameCenter::request_achievements);
+ ClassDB::bind_method(D_METHOD("request_achievement_descriptions"), &GameCenter::request_achievement_descriptions);
+ ClassDB::bind_method(D_METHOD("show_game_center"), &GameCenter::show_game_center);
+
+ ClassDB::bind_method(D_METHOD("get_pending_event_count"), &GameCenter::get_pending_event_count);
+ ClassDB::bind_method(D_METHOD("pop_pending_event"), &GameCenter::pop_pending_event);
};
@@ -78,27 +78,25 @@ Error GameCenter::connect() {
ViewController *root_controller=(ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
ERR_FAIL_COND_V(!root_controller, FAILED);
- //this handler is called serveral times. first when the view needs to be shown, then again after the view is cancelled or the user logs in. or if the user's already logged in, it's called just once to confirm they're authenticated. This is why no result needs to be specified in the presentViewController phase. in this case, more calls to this function will follow.
+ //this handler is called serveral times. first when the view needs to be shown, then again after the view is cancelled or the user logs in. or if the user's already logged in, it's called just once to confirm they're authenticated. This is why no result needs to be specified in the presentViewController phase. in this case, more calls to this function will follow.
player.authenticateHandler = (^(UIViewController *controller, NSError *error) {
- if (controller) {
- [root_controller presentViewController:controller animated:YES completion:nil];
- }
- else {
- Dictionary ret;
- ret["type"] = "authentication";
- if (player.isAuthenticated) {
- ret["result"] = "ok";
- GameCenter::get_singleton()->connected = true;
- } else {
- ret["result"] = "error";
- ret["error_code"] = error.code;
- ret["error_description"] = [error.localizedDescription UTF8String];
- GameCenter::get_singleton()->connected = false;
- };
-
- pending_events.push_back(ret);
- };
-
+ if (controller) {
+ [root_controller presentViewController:controller animated:YES completion:nil];
+ } else {
+ Dictionary ret;
+ ret["type"] = "authentication";
+ if (player.isAuthenticated) {
+ ret["result"] = "ok";
+ GameCenter::get_singleton()->connected = true;
+ } else {
+ ret["result"] = "error";
+ ret["error_code"] = error.code;
+ ret["error_description"] = [error.localizedDescription UTF8String];
+ GameCenter::get_singleton()->connected = false;
+ };
+
+ pending_events.push_back(ret);
+ };
});
return OK;
@@ -191,7 +189,7 @@ void GameCenter::request_achievement_descriptions() {
Array hidden;
Array replayable;
- for (int i=0; i<[descriptions count]; i++) {
+ for (int i = 0; i < [descriptions count]; i++) {
GKAchievementDescription* description = [descriptions objectAtIndex:i];
@@ -266,8 +264,7 @@ void GameCenter::request_achievements() {
void GameCenter::reset_achievements() {
- [GKAchievement resetAchievementsWithCompletionHandler:^(NSError *error)
- {
+ [GKAchievement resetAchievementsWithCompletionHandler:^(NSError *error) {
Dictionary ret;
ret["type"] = "reset_achievements";
if (error == nil) {
@@ -292,17 +289,13 @@ Error GameCenter::show_game_center(Variant p_params) {
String view_name = params["view"];
if (view_name == "default") {
view_state = GKGameCenterViewControllerStateDefault;
- }
- else if (view_name == "leaderboards") {
+ } else if (view_name == "leaderboards") {
view_state = GKGameCenterViewControllerStateLeaderboards;
- }
- else if (view_name == "achievements") {
+ } else if (view_name == "achievements") {
view_state = GKGameCenterViewControllerStateAchievements;
- }
- else if (view_name == "challenges") {
+ } else if (view_name == "challenges") {
view_state = GKGameCenterViewControllerStateChallenges;
- }
- else {
+ } else {
return ERR_INVALID_PARAMETER;
}
}
@@ -332,7 +325,7 @@ Error GameCenter::show_game_center(Variant p_params) {
void GameCenter::game_center_closed() {
Dictionary ret;
- ret["type"] = "show_game_center";
+ ret["type"] = "show_game_center";
ret["result"] = "ok";
pending_events.push_back(ret);
}
diff --git a/platform/iphone/gl_view.mm b/platform/iphone/gl_view.mm
index 735235e73d..bbad775b9e 100755
--- a/platform/iphone/gl_view.mm
+++ b/platform/iphone/gl_view.mm
@@ -91,9 +91,9 @@ bool _play_video(String p_path, float p_volume, String p_audio_track, String p_s
[_instance.avPlayer addObserver:_instance forKeyPath:@"status" options:0 context:nil];
[[NSNotificationCenter defaultCenter] addObserver:_instance
- selector:@selector(playerItemDidReachEnd:)
- name:AVPlayerItemDidPlayToEndTimeNotification
- object:[_instance.avPlayer currentItem]];
+ selector:@selector(playerItemDidReachEnd:)
+ name:AVPlayerItemDidPlayToEndTimeNotification
+ object:[_instance.avPlayer currentItem]];
[_instance.avPlayer addObserver:_instance forKeyPath:@"rate" options:NSKeyValueObservingOptionNew context:0];
@@ -104,13 +104,11 @@ bool _play_video(String p_path, float p_volume, String p_audio_track, String p_s
AVMediaSelectionGroup *audioGroup = [_instance.avAsset mediaSelectionGroupForMediaCharacteristic: AVMediaCharacteristicAudible];
NSMutableArray *allAudioParams = [NSMutableArray array];
- for (id track in audioGroup.options)
- {
+ for (id track in audioGroup.options) {
NSString* language = [[track locale] localeIdentifier];
NSLog(@"subtitle lang: %@", language);
- if ([language isEqualToString:[NSString stringWithUTF8String:p_audio_track.utf8()]])
- {
+ if ([language isEqualToString:[NSString stringWithUTF8String:p_audio_track.utf8()]]) {
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
[audioInputParams setVolume:p_volume atTime:kCMTimeZero];
[audioInputParams setTrackID:[track trackID]];
@@ -122,23 +120,21 @@ bool _play_video(String p_path, float p_volume, String p_audio_track, String p_s
[_instance.avPlayer.currentItem selectMediaOption:track inMediaSelectionGroup: audioGroup];
[_instance.avPlayer.currentItem setAudioMix:audioMix];
- break;
- }
+ break;
+ }
}
AVMediaSelectionGroup *subtitlesGroup = [_instance.avAsset mediaSelectionGroupForMediaCharacteristic: AVMediaCharacteristicLegible];
NSArray *useableTracks = [AVMediaSelectionGroup mediaSelectionOptionsFromArray:subtitlesGroup.options withoutMediaCharacteristics:[NSArray arrayWithObject:AVMediaCharacteristicContainsOnlyForcedSubtitles]];
- for (id track in useableTracks)
- {
+ for (id track in useableTracks) {
NSString* language = [[track locale] localeIdentifier];
NSLog(@"subtitle lang: %@", language);
- if ([language isEqualToString:[NSString stringWithUTF8String:p_subtitle_track.utf8()]])
- {
- [_instance.avPlayer.currentItem selectMediaOption:track inMediaSelectionGroup: subtitlesGroup];
- break;
- }
+ if ([language isEqualToString:[NSString stringWithUTF8String:p_subtitle_track.utf8()]]) {
+ [_instance.avPlayer.currentItem selectMediaOption:track inMediaSelectionGroup: subtitlesGroup];
+ break;
+ }
}
video_playing = true;
@@ -246,14 +242,12 @@ static void clear_touches() {
// Implement this to override the default layer class (which is [CALayer class]).
// We do this so that our view will be backed by a layer that is capable of OpenGL ES rendering.
-+ (Class) layerClass
-{
++ (Class) layerClass {
return [CAEAGLLayer class];
}
//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
-- (id)initWithCoder:(NSCoder*)coder
-{
+- (id)initWithCoder:(NSCoder*)coder {
active = FALSE;
if((self = [super initWithCoder:coder]))
{
@@ -262,8 +256,7 @@ static void clear_touches() {
return self;
}
--(id)initGLES
-{
+-(id)initGLES {
// Get our backing layer
CAEAGLLayer *eaglLayer = (CAEAGLLayer*) self.layer;
@@ -277,8 +270,7 @@ static void clear_touches() {
// Create our EAGLContext, and if successful make it current and create our framebuffer.
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
- if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer])
- {
+ if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer]) {
[self release];
return nil;
}
@@ -288,14 +280,12 @@ static void clear_touches() {
return self;
}
--(id<GLViewDelegate>)delegate
-{
+-(id<GLViewDelegate>)delegate {
return delegate;
}
// Update the delegate, and if it needs a -setupView: call, set our internal flag so that it will be called.
--(void)setDelegate:(id<GLViewDelegate>)d
-{
+-(void)setDelegate:(id<GLViewDelegate>)d {
delegate = d;
delegateSetup = ![delegate respondsToSelector:@selector(setupView:)];
}
@@ -306,8 +296,7 @@ static void clear_touches() {
// This is the perfect opportunity to also update the framebuffer so that it is
// the same size as our display area.
--(void)layoutSubviews
-{
+-(void)layoutSubviews {
//printf("HERE\n");
[EAGLContext setCurrentContext:context];
[self destroyFramebuffer];
@@ -317,8 +306,7 @@ static void clear_touches() {
}
-- (BOOL)createFramebuffer
-{
+- (BOOL)createFramebuffer {
// Generate IDs for a framebuffer object and a color renderbuffer
UIScreen* mainscr = [UIScreen mainScreen];
printf("******** screen size %i, %i\n", (int)mainscr.currentMode.size.width, (int)mainscr.currentMode.size.height);
@@ -345,8 +333,7 @@ static void clear_touches() {
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
- if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
- {
+ if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}
@@ -366,8 +353,7 @@ static void clear_touches() {
}
// Clean up any buffers we have allocated.
-- (void)destroyFramebuffer
-{
+- (void)destroyFramebuffer {
glDeleteFramebuffersOES(1, &viewFramebuffer);
viewFramebuffer = 0;
glDeleteRenderbuffersOES(1, &viewRenderbuffer);
@@ -380,8 +366,7 @@ static void clear_touches() {
}
}
-- (void)startAnimation
-{
+- (void)startAnimation {
if (active)
return;
active = TRUE;
@@ -397,19 +382,16 @@ static void clear_touches() {
// Setup DisplayLink in main thread
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
- }
- else {
+ } else {
animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES];
}
- if (video_playing)
- {
+ if (video_playing) {
_unpause_video();
}
}
-- (void)stopAnimation
-{
+- (void)stopAnimation {
if (!active)
return;
active = FALSE;
@@ -418,22 +400,19 @@ static void clear_touches() {
if (useCADisplayLink) {
[displayLink invalidate];
displayLink = nil;
- }
- else {
+ } else {
[animationTimer invalidate];
animationTimer = nil;
}
clear_touches();
- if (video_playing)
- {
+ if (video_playing) {
// save position
}
}
-- (void)setAnimationInterval:(NSTimeInterval)interval
-{
+- (void)setAnimationInterval:(NSTimeInterval)interval {
animationInterval = interval;
if ( (useCADisplayLink && displayLink) || ( !useCADisplayLink && animationTimer ) ) {
[self stopAnimation];
@@ -442,8 +421,7 @@ static void clear_touches() {
}
// Updates the OpenGL view when the timer fires
-- (void)drawView
-{
+- (void)drawView {
if (useCADisplayLink) {
// Pause the CADisplayLink to avoid recursion
[displayLink setPaused: YES];
@@ -464,8 +442,7 @@ static void clear_touches() {
[EAGLContext setCurrentContext:context];
// If our drawing delegate needs to have the view setup, then call -setupView: and flag that it won't need to be called again.
- if(!delegateSetup)
- {
+ if(!delegateSetup) {
[delegate setupView:self];
delegateSetup = YES;
}
@@ -484,8 +461,7 @@ static void clear_touches() {
#endif
}
-- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-{
+- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray* tlist = [[event allTouches] allObjects];
for (unsigned int i=0; i< [tlist count]; i++) {
@@ -502,8 +478,7 @@ static void clear_touches() {
};
}
-- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
-{
+- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray* tlist = [[event allTouches] allObjects];
for (unsigned int i=0; i< [tlist count]; i++) {
@@ -524,8 +499,7 @@ static void clear_touches() {
}
-- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
-{
+- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray* tlist = [[event allTouches] allObjects];
for (unsigned int i=0; i< [tlist count]; i++) {
@@ -582,8 +556,7 @@ static void clear_touches() {
printf("inserting text with character %i\n", character[0]);
};
-- (void)audioRouteChangeListenerCallback:(NSNotification*)notification
-{
+- (void)audioRouteChangeListenerCallback:(NSNotification*)notification {
printf("*********** route changed!\n");
NSDictionary *interuptionDict = notification.userInfo;
@@ -591,12 +564,12 @@ static void clear_touches() {
switch (routeChangeReason) {
- case AVAudioSessionRouteChangeReasonNewDeviceAvailable:
+ case AVAudioSessionRouteChangeReasonNewDeviceAvailable: {
NSLog(@"AVAudioSessionRouteChangeReasonNewDeviceAvailable");
NSLog(@"Headphone/Line plugged in");
- break;
+ }; break;
- case AVAudioSessionRouteChangeReasonOldDeviceUnavailable:
+ case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: {
NSLog(@"AVAudioSessionRouteChangeReasonOldDeviceUnavailable");
NSLog(@"Headphone/Line was pulled. Resuming video play....");
if (_is_video_playing()) {
@@ -606,19 +579,18 @@ static void clear_touches() {
NSLog(@"resumed play");
});
};
- break;
+ }; break;
- case AVAudioSessionRouteChangeReasonCategoryChange:
+ case AVAudioSessionRouteChangeReasonCategoryChange: {
// called at start - also when other audio wants to play
NSLog(@"AVAudioSessionRouteChangeReasonCategoryChange");
- break;
+ }; break;
}
}
// When created via code however, we get initWithFrame
--(id)initWithFrame:(CGRect)frame
-{
+-(id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
_instance = self;
printf("after init super %p\n", self);
@@ -633,7 +605,7 @@ static void clear_touches() {
printf("******** adding observer for sound routing changes\n");
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioRouteChangeListenerCallback:)
name:AVAudioSessionRouteChangeNotification
- object:nil];
+ object:nil];
//self.autoresizesSubviews = YES;
//[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
@@ -641,21 +613,19 @@ static void clear_touches() {
return self;
}
-// -(BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers {
-// return YES;
-// }
+//- (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers {
+// return YES;
+//}
-// - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
-// return YES;
-// }
+//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
+// return YES;
+//}
// Stop animating and release resources when they are no longer needed.
-- (void)dealloc
-{
+- (void)dealloc {
[self stopAnimation];
- if([EAGLContext currentContext] == context)
- {
+ if([EAGLContext currentContext] == context) {
[EAGLContext setCurrentContext:nil];
}
@@ -665,25 +635,24 @@ static void clear_touches() {
[super dealloc];
}
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
- change:(NSDictionary *)change context:(void *)context {
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == _instance.avPlayerItem && [keyPath isEqualToString:@"status"]) {
- if (_instance.avPlayerItem.status == AVPlayerStatusFailed || _instance.avPlayer.status == AVPlayerStatusFailed) {
- _stop_video();
- video_found_error = true;
- }
+ if (_instance.avPlayerItem.status == AVPlayerStatusFailed || _instance.avPlayer.status == AVPlayerStatusFailed) {
+ _stop_video();
+ video_found_error = true;
+ }
- if(_instance.avPlayer.status == AVPlayerStatusReadyToPlay &&
- _instance.avPlayerItem.status == AVPlayerItemStatusReadyToPlay &&
- CMTIME_COMPARE_INLINE(video_current_time, ==, kCMTimeZero)) {
+ if(_instance.avPlayer.status == AVPlayerStatusReadyToPlay &&
+ _instance.avPlayerItem.status == AVPlayerItemStatusReadyToPlay &&
+ CMTIME_COMPARE_INLINE(video_current_time, ==, kCMTimeZero)) {
- //NSLog(@"time: %@", video_current_time);
+ //NSLog(@"time: %@", video_current_time);
- [_instance.avPlayer seekToTime:video_current_time];
- video_current_time = kCMTimeZero;
+ [_instance.avPlayer seekToTime:video_current_time];
+ video_current_time = kCMTimeZero;
}
- }
+ }
if (object == _instance.avPlayer && [keyPath isEqualToString:@"rate"]) {
NSLog(@"Player playback rate changed: %.5f", _instance.avPlayer.rate);
@@ -699,40 +668,40 @@ static void clear_touches() {
}
- (void)playerItemDidReachEnd:(NSNotification *)notification {
- _stop_video();
+ _stop_video();
}
/*
- (void)moviePlayBackDidFinish:(NSNotification*)notification {
- NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
- switch ([reason intValue]) {
- case MPMovieFinishReasonPlaybackEnded:
- //NSLog(@"Playback Ended");
- break;
- case MPMovieFinishReasonPlaybackError:
- //NSLog(@"Playback Error");
- video_found_error = true;
- break;
- case MPMovieFinishReasonUserExited:
- //NSLog(@"User Exited");
- video_found_error = true;
- break;
- default:
- //NSLog(@"Unsupported reason!");
- break;
- }
-
- MPMoviePlayerController *player = [notification object];
-
- [[NSNotificationCenter defaultCenter]
- removeObserver:self
- name:MPMoviePlayerPlaybackDidFinishNotification
- object:player];
-
- [_instance.moviePlayerController stop];
- [_instance.moviePlayerController.view removeFromSuperview];
+ NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
+ switch ([reason intValue]) {
+ case MPMovieFinishReasonPlaybackEnded:
+ //NSLog(@"Playback Ended");
+ break;
+ case MPMovieFinishReasonPlaybackError:
+ //NSLog(@"Playback Error");
+ video_found_error = true;
+ break;
+ case MPMovieFinishReasonUserExited:
+ //NSLog(@"User Exited");
+ video_found_error = true;
+ break;
+ default:
+ //NSLog(@"Unsupported reason!");
+ break;
+ }
+
+ MPMoviePlayerController *player = [notification object];
+
+ [[NSNotificationCenter defaultCenter]
+ removeObserver:self
+ name:MPMoviePlayerPlaybackDidFinishNotification
+ object:player];
+
+ [_instance.moviePlayerController stop];
+ [_instance.moviePlayerController.view removeFromSuperview];
//[[MPMusicPlayerController applicationMusicPlayer] setVolume: video_previous_volume];
video_playing = false;
diff --git a/platform/iphone/icloud.mm b/platform/iphone/icloud.mm
index 180e38ba81..11c04d39c6 100644
--- a/platform/iphone/icloud.mm
+++ b/platform/iphone/icloud.mm
@@ -45,14 +45,14 @@ extern "C" {
ICloud* ICloud::instance = NULL;
void ICloud::_bind_methods() {
- ClassDB::bind_method(D_METHOD("remove_key"),&ICloud::remove_key);
- ClassDB::bind_method(D_METHOD("set_key_values"),&ICloud::set_key_values);
- ClassDB::bind_method(D_METHOD("get_key_value"),&ICloud::get_key_value);
- ClassDB::bind_method(D_METHOD("synchronize_key_values"),&ICloud::synchronize_key_values);
- ClassDB::bind_method(D_METHOD("get_all_key_values"),&ICloud::get_all_key_values);
-
- ClassDB::bind_method(D_METHOD("get_pending_event_count"),&ICloud::get_pending_event_count);
- ClassDB::bind_method(D_METHOD("pop_pending_event"),&ICloud::pop_pending_event);
+ ClassDB::bind_method(D_METHOD("remove_key"), &ICloud::remove_key);
+ ClassDB::bind_method(D_METHOD("set_key_values"), &ICloud::set_key_values);
+ ClassDB::bind_method(D_METHOD("get_key_value"), &ICloud::get_key_value);
+ ClassDB::bind_method(D_METHOD("synchronize_key_values"), &ICloud::synchronize_key_values);
+ ClassDB::bind_method(D_METHOD("get_all_key_values"), &ICloud::get_all_key_values);
+
+ ClassDB::bind_method(D_METHOD("get_pending_event_count"), &ICloud::get_pending_event_count);
+ ClassDB::bind_method(D_METHOD("pop_pending_event"), &ICloud::pop_pending_event);
};
int ICloud::get_pending_event_count() {
@@ -77,8 +77,7 @@ Variant nsobject_to_variant(NSObject* object) {
if ([object isKindOfClass:[NSString class]]) {
const char* str = [(NSString*)object UTF8String];
return String::utf8(str != NULL ? str : "");
- }
- else if ([object isKindOfClass:[NSData class]]) {
+ } else if ([object isKindOfClass:[NSData class]]) {
PoolByteArray ret;
NSData* data = (NSData*)object;
if ([data length] > 0) {
@@ -89,8 +88,7 @@ Variant nsobject_to_variant(NSObject* object) {
}
}
return ret;
- }
- else if ([object isKindOfClass:[NSArray class]]) {
+ } else if ([object isKindOfClass:[NSArray class]]) {
Array result;
NSArray* array = (NSArray*)object;
for (unsigned int i = 0; i < [array count]; ++i) {
@@ -98,8 +96,7 @@ Variant nsobject_to_variant(NSObject* object) {
result.push_back(nsobject_to_variant(value));
}
return result;
- }
- else if ([object isKindOfClass:[NSDictionary class]]) {
+ } else if ([object isKindOfClass:[NSDictionary class]]) {
Dictionary result;
NSDictionary* dic = (NSDictionary*)object;
@@ -113,8 +110,7 @@ Variant nsobject_to_variant(NSObject* object) {
result[nsobject_to_variant(k)] = nsobject_to_variant(v);
}
return result;
- }
- else if ([object isKindOfClass:[NSNumber class]]) {
+ } else if ([object isKindOfClass:[NSNumber class]]) {
//Every type except numbers can reliably identify its type. The following is comparing to the *internal* representation, which isn't guaranteed to match the type that was used to create it, and is not advised, particularly when dealing with potential platform differences (ie, 32/64 bit)
//To avoid errors, we'll cast as broadly as possible, and only return int or float.
//bool, char, int, uint, longlong -> int
@@ -122,37 +118,28 @@ Variant nsobject_to_variant(NSObject* object) {
NSNumber* num = (NSNumber*)object;
if(strcmp([num objCType], @encode(BOOL)) == 0) {
return Variant((int)[num boolValue]);
- }
- else if(strcmp([num objCType], @encode(char)) == 0) {
+ } else if(strcmp([num objCType], @encode(char)) == 0) {
return Variant((int)[num charValue]);
- }
- else if(strcmp([num objCType], @encode(int)) == 0) {
+ } else if(strcmp([num objCType], @encode(int)) == 0) {
return Variant([num intValue]);
- }
- else if(strcmp([num objCType], @encode(unsigned int)) == 0) {
+ } else if(strcmp([num objCType], @encode(unsigned int)) == 0) {
return Variant((int)[num unsignedIntValue]);
- }
- else if(strcmp([num objCType], @encode(long long)) == 0) {
+ } else if(strcmp([num objCType], @encode(long long)) == 0) {
return Variant((int)[num longValue]);
- }
- else if(strcmp([num objCType], @encode(float)) == 0) {
+ } else if(strcmp([num objCType], @encode(float)) == 0) {
return Variant([num floatValue]);
- }
- else if(strcmp([num objCType], @encode(double)) == 0) {
+ } else if(strcmp([num objCType], @encode(double)) == 0) {
return Variant((float)[num doubleValue]);
}
- }
- else if ([object isKindOfClass:[NSDate class]]) {
+ } else if ([object isKindOfClass:[NSDate class]]) {
//this is a type that icloud supports...but how did you submit it in the first place?
//I guess this is a type that *might* show up, if you were, say, trying to make your game
//compatible with existing cloud data written by another engine's version of your game
WARN_PRINT("NSDate unsupported, returning null Variant")
return Variant();
- }
- else if ([object isKindOfClass:[NSNull class]] or object == nil) {
+ } else if ([object isKindOfClass:[NSNull class]] or object == nil) {
return Variant();
- }
- else {
+ } else {
WARN_PRINT("Trying to convert unknown NSObject type to Variant");
return Variant();
}
@@ -161,17 +148,13 @@ Variant nsobject_to_variant(NSObject* object) {
NSObject* variant_to_nsobject(Variant v) {
if (v.get_type() == Variant::STRING) {
return [[[NSString alloc] initWithUTF8String:((String)v).utf8().get_data()] autorelease];
- }
- else if (v.get_type() == Variant::REAL) {
+ } else if (v.get_type() == Variant::REAL) {
return [NSNumber numberWithDouble:(double)v];
- }
- else if (v.get_type() == Variant::INT) {
+ } else if (v.get_type() == Variant::INT) {
return [NSNumber numberWithLongLong:(long)(int)v];
- }
- else if (v.get_type() == Variant::BOOL) {
+ } else if (v.get_type() == Variant::BOOL) {
return [NSNumber numberWithBool:BOOL((bool)v)];
- }
- else if (v.get_type() == Variant::DICTIONARY) {
+ } else if (v.get_type() == Variant::DICTIONARY) {
NSMutableDictionary* result = [[[NSMutableDictionary alloc] init] autorelease];
Dictionary dic = v;
Array keys = dic.keys();
@@ -186,8 +169,7 @@ NSObject* variant_to_nsobject(Variant v) {
[result setObject:value forKey:key];
}
return result;
- }
- else if (v.get_type() == Variant::ARRAY) {
+ } else if (v.get_type() == Variant::ARRAY) {
NSMutableArray* result = [[[NSMutableArray alloc] init] autorelease];
Array arr = v;
for (unsigned int i = 0; i < arr.size(); ++i) {
@@ -199,8 +181,7 @@ NSObject* variant_to_nsobject(Variant v) {
[result addObject:value];
}
return result;
- }
- else if (v.get_type() == Variant::POOL_BYTE_ARRAY) {
+ } else if (v.get_type() == Variant::POOL_BYTE_ARRAY) {
PoolByteArray arr = v;
PoolByteArray::Read r = arr.read();
NSData* result = [NSData dataWithBytes:r.ptr() length:arr.size()];
@@ -297,8 +278,7 @@ Error ICloud::synchronize_key_values() {
BOOL result = [store synchronize];
if (result == YES) {
return OK;
- }
- else {
+ } else {
return FAILED;
}
}
@@ -307,14 +287,14 @@ Error ICloud::initial_sync() {
//you sometimes have to write something to the store to get it to download new data. go apple!
NSUbiquitousKeyValueStore *store = [NSUbiquitousKeyValueStore defaultStore];
if ([store boolForKey:@"isb"])
- {
- [store setBool:NO forKey:@"isb"];
- }
- else
- {
- [store setBool:YES forKey:@"isb"];
- }
- return synchronize();
+ {
+ [store setBool:NO forKey:@"isb"];
+ }
+ else
+ {
+ [store setBool:YES forKey:@"isb"];
+ }
+ return synchronize();
}
*/
ICloud::ICloud() {
@@ -341,14 +321,11 @@ ICloud::ICloud() {
if (change == NSUbiquitousKeyValueStoreServerChange) {
reason = "server";
- }
- else if (change == NSUbiquitousKeyValueStoreInitialSyncChange) {
+ } else if (change == NSUbiquitousKeyValueStoreInitialSyncChange) {
reason = "initial_sync";
- }
- else if (change == NSUbiquitousKeyValueStoreQuotaViolationChange) {
+ } else if (change == NSUbiquitousKeyValueStoreQuotaViolationChange) {
reason = "quota_violation";
- }
- else if (change == NSUbiquitousKeyValueStoreAccountChange) {
+ } else if (change == NSUbiquitousKeyValueStoreAccountChange) {
reason = "account";
}
diff --git a/platform/iphone/in_app_store.mm b/platform/iphone/in_app_store.mm
index 6f4d0f927c..ed26d59235 100644
--- a/platform/iphone/in_app_store.mm
+++ b/platform/iphone/in_app_store.mm
@@ -51,8 +51,7 @@ NSMutableDictionary* pending_transactions = [NSMutableDictionary dictionary];
// SKProduct extension
//----------------------------------//
@implementation SKProduct (LocalizedPrice)
-- (NSString *)localizedPrice
-{
+- (NSString *)localizedPrice {
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
@@ -165,95 +164,90 @@ Error InAppStore::request_product_info(Variant p_params) {
- (void)paymentQueue:(SKPaymentQueue*)queue updatedTransactions:(NSArray*) transactions {
- printf("transactions updated!\n");
+ printf("transactions updated!\n");
for (SKPaymentTransaction* transaction in transactions) {
switch (transaction.transactionState) {
+ case SKPaymentTransactionStatePurchased: {
+ printf("status purchased!\n");
+ String pid = String::utf8([transaction.payment.productIdentifier UTF8String]);
+ String transactionId = String::utf8([transaction.transactionIdentifier UTF8String]);
+ InAppStore::get_singleton()->_record_purchase(pid);
+ Dictionary ret;
+ ret["type"] = "purchase";
+ ret["result"] = "ok";
+ ret["product_id"] = pid;
+ ret["transaction_id"] = transactionId;
+
+ NSData* receipt = nil;
+ int sdk_version = 6;
+
+ if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){
+
+ NSURL *receiptFileURL = nil;
+ NSBundle *bundle = [NSBundle mainBundle];
+ if ([bundle respondsToSelector:@selector(appStoreReceiptURL)]) {
+
+ // Get the transaction receipt file path location in the app bundle.
+ receiptFileURL = [bundle appStoreReceiptURL];
+
+ // Read in the contents of the transaction file.
+ receipt = [NSData dataWithContentsOfURL:receiptFileURL];
+ sdk_version = 7;
+
+ } else {
+ // Fall back to deprecated transaction receipt,
+ // which is still available in iOS 7.
+
+ // Use SKPaymentTransaction's transactionReceipt.
+ receipt = transaction.transactionReceipt;
+ }
+
+ } else {
+ receipt = transaction.transactionReceipt;
+ }
+
+ NSString* receipt_to_send = nil;
+ if (receipt != nil) {
+ receipt_to_send = [receipt description];
+ }
+ Dictionary receipt_ret;
+ receipt_ret["receipt"] = String::utf8(receipt_to_send != nil ? [receipt_to_send UTF8String] : "");
+ receipt_ret["sdk"] = sdk_version;
+ ret["receipt"] = receipt_ret;
+
+ InAppStore::get_singleton()->_post_event(ret);
+
+ if (auto_finish_transactions){
+ [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
+ } else{
+ [pending_transactions setObject:transaction forKey:transaction.payment.productIdentifier];
+ }
- case SKPaymentTransactionStatePurchased: {
- printf("status purchased!\n");
- String pid = String::utf8([transaction.payment.productIdentifier UTF8String]);
- String transactionId = String::utf8([transaction.transactionIdentifier UTF8String]);
- InAppStore::get_singleton()->_record_purchase(pid);
- Dictionary ret;
- ret["type"] = "purchase";
- ret["result"] = "ok";
- ret["product_id"] = pid;
- ret["transaction_id"] = transactionId;
-
- NSData* receipt = nil;
- int sdk_version = 6;
-
- if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){
-
- NSURL *receiptFileURL = nil;
- NSBundle *bundle = [NSBundle mainBundle];
- if ([bundle respondsToSelector:@selector(appStoreReceiptURL)]) {
-
- // Get the transaction receipt file path location in the app bundle.
- receiptFileURL = [bundle appStoreReceiptURL];
-
- // Read in the contents of the transaction file.
- receipt = [NSData dataWithContentsOfURL:receiptFileURL];
- sdk_version = 7;
-
- } else {
- // Fall back to deprecated transaction receipt,
- // which is still available in iOS 7.
-
- // Use SKPaymentTransaction's transactionReceipt.
- receipt = transaction.transactionReceipt;
- }
-
- }else{
- receipt = transaction.transactionReceipt;
- }
-
- NSString* receipt_to_send = nil;
- if (receipt != nil)
- {
- receipt_to_send = [receipt description];
- }
- Dictionary receipt_ret;
- receipt_ret["receipt"] = String::utf8(receipt_to_send != nil ? [receipt_to_send UTF8String] : "");
- receipt_ret["sdk"] = sdk_version;
- ret["receipt"] = receipt_ret;
-
- InAppStore::get_singleton()->_post_event(ret);
-
- if (auto_finish_transactions){
- [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
- }
- else{
- [pending_transactions setObject:transaction forKey:transaction.payment.productIdentifier];
- }
-
- #ifdef MODULE_FUSEBOXX_ENABLED
- printf("Registering transaction on Fuseboxx!\n");
- [FuseSDK registerInAppPurchase: transaction];
- #endif
- } break;
- case SKPaymentTransactionStateFailed: {
- printf("status transaction failed!\n");
- String pid = String::utf8([transaction.payment.productIdentifier UTF8String]);
- Dictionary ret;
- ret["type"] = "purchase";
- ret["result"] = "error";
- ret["product_id"] = pid;
- InAppStore::get_singleton()->_post_event(ret);
- [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
- } break;
- case SKPaymentTransactionStateRestored: {
- printf("status transaction restored!\n");
- String pid = String::utf8([transaction.originalTransaction.payment.productIdentifier UTF8String]);
- InAppStore::get_singleton()->_record_purchase(pid);
- [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
- } break;
-
- default:
- printf("status default %i!\n", (int)transaction.transactionState);
-
- break;
+#ifdef MODULE_FUSEBOXX_ENABLED
+ printf("Registering transaction on Fuseboxx!\n");
+ [FuseSDK registerInAppPurchase: transaction];
+#endif
+ }; break;
+ case SKPaymentTransactionStateFailed: {
+ printf("status transaction failed!\n");
+ String pid = String::utf8([transaction.payment.productIdentifier UTF8String]);
+ Dictionary ret;
+ ret["type"] = "purchase";
+ ret["result"] = "error";
+ ret["product_id"] = pid;
+ InAppStore::get_singleton()->_post_event(ret);
+ [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
+ } break;
+ case SKPaymentTransactionStateRestored: {
+ printf("status transaction restored!\n");
+ String pid = String::utf8([transaction.originalTransaction.payment.productIdentifier UTF8String]);
+ InAppStore::get_singleton()->_record_purchase(pid);
+ [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
+ } break;
+ default: {
+ printf("status default %i!\n", (int)transaction.transactionState);
+ }; break;
};
};
};
@@ -267,7 +261,7 @@ Error InAppStore::purchase(Variant p_params) {
if (![SKPaymentQueue canMakePayments])
return ERR_UNAVAILABLE;
- printf("purchasing!\n");
+ printf("purchasing!\n");
Dictionary params = p_params;
ERR_FAIL_COND_V(!params.has("product_id"), ERR_INVALID_PARAMETER);
@@ -275,7 +269,7 @@ Error InAppStore::purchase(Variant p_params) {
SKPayment *payment = [SKPayment paymentWithProductIdentifier:pid];
SKPaymentQueue* defq = [SKPaymentQueue defaultQueue];
[defq addPayment:payment];
- printf("purchase sent!\n");
+ printf("purchase sent!\n");
return OK;
};
@@ -318,20 +312,20 @@ InAppStore::InAppStore() {
TransObserver* observer = [[TransObserver alloc] init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];
- //pending_transactions = [NSMutableDictionary dictionary];
+ //pending_transactions = [NSMutableDictionary dictionary];
};
void InAppStore::finish_transaction(String product_id){
- NSString* prod_id = [NSString stringWithCString:product_id.utf8().get_data() encoding:NSUTF8StringEncoding];
+ NSString* prod_id = [NSString stringWithCString:product_id.utf8().get_data() encoding:NSUTF8StringEncoding];
if ([pending_transactions objectForKey:prod_id]){
[[SKPaymentQueue defaultQueue] finishTransaction:[pending_transactions objectForKey:prod_id]];
- [pending_transactions removeObjectForKey:prod_id];
+ [pending_transactions removeObjectForKey:prod_id];
}
};
void InAppStore::set_auto_finish_transaction(bool b){
- auto_finish_transactions = b;
+ auto_finish_transactions = b;
}
InAppStore::~InAppStore() {
diff --git a/platform/iphone/ios.mm b/platform/iphone/ios.mm
index fe8412d5fd..91e1e20fba 100644
--- a/platform/iphone/ios.mm
+++ b/platform/iphone/ios.mm
@@ -33,7 +33,7 @@
void iOS::_bind_methods() {
- ClassDB::bind_method(D_METHOD("get_rate_url","app_id"),&iOS::get_rate_url);
+ ClassDB::bind_method(D_METHOD("get_rate_url","app_id"), &iOS::get_rate_url);
};
String iOS::get_rate_url(int p_app_id) const {
@@ -44,14 +44,11 @@ String iOS::get_rate_url(int p_app_id) const {
//ios7 before
String ret = templ;
- // iOS 7 needs a different templateReviewURL @see https://github.com/arashpayan/appirater/issues/131
- if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 7.1)
- {
+ if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 7.1) {
+ // iOS 7 needs a different templateReviewURL @see https://github.com/arashpayan/appirater/issues/131
ret = templ_iOS7;
- }
- // iOS 8 needs a different templateReviewURL also @see https://github.com/arashpayan/appirater/issues/182
- else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
- {
+ } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
+ // iOS 8 needs a different templateReviewURL also @see https://github.com/arashpayan/appirater/issues/182
ret = templ_iOS8;
}
diff --git a/platform/iphone/main.m b/platform/iphone/main.m
index 43c3c8c8cc..cdcbacbd4f 100644
--- a/platform/iphone/main.m
+++ b/platform/iphone/main.m
@@ -34,8 +34,7 @@
int gargc;
char** gargv;
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
printf("*********** main.m\n");
gargc = argc;
gargv = argv;
diff --git a/platform/iphone/view_controller.mm b/platform/iphone/view_controller.mm
index 773ca62d2e..2b9027e042 100644
--- a/platform/iphone/view_controller.mm
+++ b/platform/iphone/view_controller.mm
@@ -33,42 +33,42 @@
extern "C" {
-int add_path(int, char**);
-int add_cmdline(int, char**);
+ int add_path(int, char**);
+ int add_cmdline(int, char**);
-int add_path(int p_argc, char** p_args) {
+ int add_path(int p_argc, char** p_args) {
- NSString* str = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_path"];
- if (!str)
- return p_argc;
+ NSString* str = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_path"];
+ if (!str)
+ return p_argc;
- p_args[p_argc++] = "-path";
- [str retain]; // memory leak lol (maybe make it static here and delete it in ViewController destructor? @todo
- p_args[p_argc++] = (char*)[str cString];
- p_args[p_argc] = NULL;
+ p_args[p_argc++] = "-path";
+ [str retain]; // memory leak lol (maybe make it static here and delete it in ViewController destructor? @todo
+ p_args[p_argc++] = (char*)[str cString];
+ p_args[p_argc] = NULL;
- return p_argc;
-};
+ return p_argc;
+ };
-int add_cmdline(int p_argc, char** p_args) {
+ int add_cmdline(int p_argc, char** p_args) {
- NSArray* arr = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_cmdline"];
- if (!arr)
- return p_argc;
+ NSArray* arr = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_cmdline"];
+ if (!arr)
+ return p_argc;
- for (int i=0; i < [arr count]; i++) {
+ for (int i=0; i < [arr count]; i++) {
- NSString* str = [arr objectAtIndex:i];
- if (!str)
- continue;
- [str retain]; // @todo delete these at some point
- p_args[p_argc++] = (char*)[str cString];
- };
+ NSString* str = [arr objectAtIndex:i];
+ if (!str)
+ continue;
+ [str retain]; // @todo delete these at some point
+ p_args[p_argc++] = (char*)[str cString];
+ };
- p_args[p_argc] = NULL;
+ p_args[p_argc] = NULL;
- return p_argc;
-};
+ return p_argc;
+ };
};
@@ -91,20 +91,20 @@ int add_cmdline(int p_argc, char** p_args) {
NSArray* arr = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"];
switch(p_orientation) {
- case UIInterfaceOrientationLandscapeLeft:
- return [arr indexOfObject:@"UIInterfaceOrientationLandscapeLeft"] != NSNotFound ? YES : NO;
+ case UIInterfaceOrientationLandscapeLeft:
+ return [arr indexOfObject:@"UIInterfaceOrientationLandscapeLeft"] != NSNotFound ? YES : NO;
- case UIInterfaceOrientationLandscapeRight:
- return [arr indexOfObject:@"UIInterfaceOrientationLandscapeRight"] != NSNotFound ? YES : NO;
+ case UIInterfaceOrientationLandscapeRight:
+ return [arr indexOfObject:@"UIInterfaceOrientationLandscapeRight"] != NSNotFound ? YES : NO;
- case UIInterfaceOrientationPortrait:
- return [arr indexOfObject:@"UIInterfaceOrientationPortrait"] != NSNotFound ? YES : NO;
+ case UIInterfaceOrientationPortrait:
+ return [arr indexOfObject:@"UIInterfaceOrientationPortrait"] != NSNotFound ? YES : NO;
- case UIInterfaceOrientationPortraitUpsideDown:
- return [arr indexOfObject:@"UIInterfaceOrientationPortraitUpsideDown"] != NSNotFound ? YES : NO;
+ case UIInterfaceOrientationPortraitUpsideDown:
+ return [arr indexOfObject:@"UIInterfaceOrientationPortraitUpsideDown"] != NSNotFound ? YES : NO;
- default:
- return NO;
+ default:
+ return NO;
}
};
@@ -128,16 +128,15 @@ int add_cmdline(int p_argc, char** p_args) {
}
};
-- (BOOL)prefersStatusBarHidden
-{
+- (BOOL)prefersStatusBarHidden {
return YES;
}
#ifdef GAME_CENTER_ENABLED
- (void) gameCenterViewControllerDidFinish:(GKGameCenterViewController*) gameCenterViewController {
- //[gameCenterViewController dismissViewControllerAnimated:YES completion:^{GameCenter::get_singleton()->game_center_closed();}];//version for signaling when overlay is completely gone
- GameCenter::get_singleton()->game_center_closed();
- [gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
+ //[gameCenterViewController dismissViewControllerAnimated:YES completion:^{GameCenter::get_singleton()->game_center_closed();}];//version for signaling when overlay is completely gone
+ GameCenter::get_singleton()->game_center_closed();
+ [gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
}
#endif