From 15a826571c8f4809023c2f3ca014705feb5492bf Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 22 Oct 2015 17:31:09 -0700 Subject: Added setting for CADisplayLink on iOS, so you no longer need to recompile to change it --- platform/iphone/app_delegate.mm | 2 + platform/iphone/gl_view.h | 9 ++-- platform/iphone/gl_view.mm | 75 +++++++++++++++-------------- platform/iphone/globals/global_defaults.cpp | 1 + 4 files changed, 45 insertions(+), 42 deletions(-) mode change 100644 => 100755 platform/iphone/globals/global_defaults.cpp (limited to 'platform/iphone') diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm index d5764b2b5c..647bf1a2d1 100644 --- a/platform/iphone/app_delegate.mm +++ b/platform/iphone/app_delegate.mm @@ -236,6 +236,8 @@ static int frame_count = 0; view_controller.view = glView; window.rootViewController = view_controller; + glView.useCADisplayLink = bool(GLOBAL_DEF("display.iOS/use_cadisplaylink",true)) ? YES : NO; + printf("cadisaplylink: %d", glView.useCADisplayLink); glView.animationInterval = 1.0 / kRenderingFrequency; [glView startAnimation]; diff --git a/platform/iphone/gl_view.h b/platform/iphone/gl_view.h index cda75394db..ca2d1d25ae 100755 --- a/platform/iphone/gl_view.h +++ b/platform/iphone/gl_view.h @@ -34,8 +34,6 @@ #import #import -#define USE_CADISPLAYLINK 0 //iOS version 3.1+ is required - @protocol GLViewDelegate; @interface GLView : UIView @@ -53,13 +51,13 @@ // OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) GLuint depthRenderbuffer; -#if USE_CADISPLAYLINK + BOOL useCADisplayLink; // CADisplayLink available on 3.1+ synchronizes the animation timer & drawing with the refresh rate of the display, only supports animation intervals of 1/60 1/30 & 1/15 CADisplayLink *displayLink; -#else + // An animation timer that, when animation is started, will periodically call -drawView at the given rate. + // Only used if CADisplayLink is not NSTimer *animationTimer; -#endif NSTimeInterval animationInterval; @@ -104,6 +102,7 @@ - (void)audioRouteChangeListenerCallback:(NSNotification*)notification; @property NSTimeInterval animationInterval; +@property(nonatomic, assign) BOOL useCADisplayLink; @end diff --git a/platform/iphone/gl_view.mm b/platform/iphone/gl_view.mm index 4d5d1b81e3..279fbdafa8 100755 --- a/platform/iphone/gl_view.mm +++ b/platform/iphone/gl_view.mm @@ -334,13 +334,15 @@ static void clear_touches() { delegateSetup = ![delegate respondsToSelector:@selector(setupView:)]; } +@synthesize useCADisplayLink; + // If our view is resized, we'll be asked to layout subviews. // This is the perfect opportunity to also update the framebuffer so that it is // the same size as our display area. -(void)layoutSubviews { - printf("HERE\n"); + //printf("HERE\n"); [EAGLContext setCurrentContext:context]; [self destroyFramebuffer]; [self createFramebuffer]; @@ -418,19 +420,21 @@ static void clear_touches() { return; active = TRUE; printf("start animation!\n"); -#if USE_CADISPLAYLINK - // Approximate frame rate - // assumes device refreshes at 60 fps - int frameInterval = (int) floor(animationInterval * 60.0f); - - displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView)]; - [displayLink setFrameInterval:frameInterval]; - - // Setup DisplayLink in main thread - [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; -#else - animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES]; -#endif + if (useCADisplayLink) { + + // Approximate frame rate + // assumes device refreshes at 60 fps + int frameInterval = (int) floor(animationInterval * 60.0f); + + displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView)]; + [displayLink setFrameInterval:frameInterval]; + + // Setup DisplayLink in main thread + [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; + } + else { + animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES]; + } if (video_playing) { @@ -444,13 +448,16 @@ static void clear_touches() { return; active = FALSE; printf("******** stop animation!\n"); -#if USE_CADISPLAYLINK - [displayLink invalidate]; - displayLink = nil; -#else - [animationTimer invalidate]; - animationTimer = nil; -#endif + + if (useCADisplayLink) { + [displayLink invalidate]; + displayLink = nil; + } + else { + [animationTimer invalidate]; + animationTimer = nil; + } + clear_touches(); if (video_playing) @@ -462,13 +469,7 @@ static void clear_touches() { - (void)setAnimationInterval:(NSTimeInterval)interval { animationInterval = interval; - -#if USE_CADISPLAYLINK - if(displayLink) -#else - if(animationTimer) -#endif - { + if ( (useCADisplayLink && displayLink) || ( !useCADisplayLink && animationTimer ) ) { [self stopAnimation]; [self startAnimation]; } @@ -477,16 +478,16 @@ static void clear_touches() { // Updates the OpenGL view when the timer fires - (void)drawView { -#if USE_CADISPLAYLINK - // Pause the CADisplayLink to avoid recursion - [displayLink setPaused: YES]; + if (useCADisplayLink) { + // Pause the CADisplayLink to avoid recursion + [displayLink setPaused: YES]; - // Process all input events - while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource); + // Process all input events + while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource); - // We are good to go, resume the CADisplayLink - [displayLink setPaused: NO]; -#endif + // We are good to go, resume the CADisplayLink + [displayLink setPaused: NO]; + } if (!active) { printf("draw view not active!\n"); @@ -632,7 +633,7 @@ static void clear_touches() { case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: NSLog(@"AVAudioSessionRouteChangeReasonOldDeviceUnavailable"); NSLog(@"Headphone/Line was pulled. Resuming video play...."); - if (_is_video_playing) { + if (_is_video_playing()) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [_instance.avPlayer play]; // NOTE: change this line according your current player implementation diff --git a/platform/iphone/globals/global_defaults.cpp b/platform/iphone/globals/global_defaults.cpp old mode 100644 new mode 100755 index a4929c57dc..18a51a5b4e --- a/platform/iphone/globals/global_defaults.cpp +++ b/platform/iphone/globals/global_defaults.cpp @@ -9,4 +9,5 @@ void register_iphone_global_defaults() { GLOBAL_DEF("rasterizer.iOS/fp16_framebuffer",false); GLOBAL_DEF("display.iOS/driver","GLES2"); Globals::get_singleton()->set_custom_property_info("display.iOS/driver",PropertyInfo(Variant::STRING,"display.iOS/driver",PROPERTY_HINT_ENUM,"GLES1,GLES2")); + GLOBAL_DEF("display.iOS/use_cadisplaylink",true); } -- cgit v1.2.3 From 402c24ec8baf10d6445213f1552cbeaaf0b55643 Mon Sep 17 00:00:00 2001 From: Aren Villanueva Date: Mon, 16 Nov 2015 11:07:21 +1100 Subject: iOS compile fixes. --- platform/iphone/app_delegate.mm | 2 ++ platform/iphone/game_center.mm | 2 +- platform/iphone/gl_view.mm | 10 +++++++++- platform/iphone/godot_iphone.cpp | 2 ++ platform/iphone/icloud.mm | 2 -- platform/iphone/sem_iphone.cpp | 5 +++++ platform/iphone/view_controller.mm | 3 +++ 7 files changed, 22 insertions(+), 4 deletions(-) (limited to 'platform/iphone') diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm index 647bf1a2d1..e5bd7a96b4 100644 --- a/platform/iphone/app_delegate.mm +++ b/platform/iphone/app_delegate.mm @@ -56,6 +56,8 @@ #import "Appirater.h" #endif +Error _shell_open(String); + Error _shell_open(String p_uri) { NSString* url = [[NSString alloc] initWithUTF8String:p_uri.utf8().get_data()]; diff --git a/platform/iphone/game_center.mm b/platform/iphone/game_center.mm index 79c056776d..1e46d9f014 100644 --- a/platform/iphone/game_center.mm +++ b/platform/iphone/game_center.mm @@ -30,8 +30,8 @@ #include "game_center.h" -extern "C" { #import +extern "C" { #import "app_delegate.h" }; diff --git a/platform/iphone/gl_view.mm b/platform/iphone/gl_view.mm index 279fbdafa8..f19e16f3f6 100755 --- a/platform/iphone/gl_view.mm +++ b/platform/iphone/gl_view.mm @@ -54,6 +54,14 @@ static bool video_playing = false; static float video_previous_volume = 0.0f; static CMTime video_current_time; +void _show_keyboard(String); +void _hide_keyboard(); +bool _play_video(String, float, String, String); +bool _is_video_playing(); +void _focus_out_video(); +void _unpause_video(); +void _stop_video(); + void _show_keyboard(String p_existing) { keyboard_text = p_existing; printf("instance on show is %p\n", _instance); @@ -618,7 +626,7 @@ static void clear_touches() { - (void)audioRouteChangeListenerCallback:(NSNotification*)notification { - printf("*********** route changed!%i\n"); + printf("*********** route changed!\n"); NSDictionary *interuptionDict = notification.userInfo; NSInteger routeChangeReason = [[interuptionDict valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue]; diff --git a/platform/iphone/godot_iphone.cpp b/platform/iphone/godot_iphone.cpp index b7b9b747b4..f0cb929429 100644 --- a/platform/iphone/godot_iphone.cpp +++ b/platform/iphone/godot_iphone.cpp @@ -40,6 +40,8 @@ int add_path(int p_argc, char** p_args); int add_cmdline(int p_argc, char** p_args); }; +int iphone_main(int, int, int, char**); + int iphone_main(int width, int height, int argc, char** argv) { int len = strlen(argv[0]); diff --git a/platform/iphone/icloud.mm b/platform/iphone/icloud.mm index 2dc2f7d9c1..a35d8ecd69 100644 --- a/platform/iphone/icloud.mm +++ b/platform/iphone/icloud.mm @@ -30,10 +30,8 @@ #include "icloud.h" -extern "C" { #import #import "app_delegate.h" -}; ICloud* ICloud::instance = NULL; diff --git a/platform/iphone/sem_iphone.cpp b/platform/iphone/sem_iphone.cpp index 5afaa7b308..36baa40427 100644 --- a/platform/iphone/sem_iphone.cpp +++ b/platform/iphone/sem_iphone.cpp @@ -31,6 +31,11 @@ #include #include +void cgsem_init(cgsem_t*); +void cgsem_post(cgsem_t*); +void cgsem_wait(cgsem_t*); +void cgsem_destroy(cgsem_t*); + void cgsem_init(cgsem_t *cgsem) { int flags, fd, i; diff --git a/platform/iphone/view_controller.mm b/platform/iphone/view_controller.mm index 6a9c3ac9ec..f98fb7c355 100644 --- a/platform/iphone/view_controller.mm +++ b/platform/iphone/view_controller.mm @@ -32,6 +32,9 @@ extern "C" { +int add_path(int, char**); +int add_cmdline(int, char**); + int add_path(int p_argc, char** p_args) { NSString* str = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_path"]; -- cgit v1.2.3 From e68c2c6c2a14c32e7c07ab3158fc459b104212d3 Mon Sep 17 00:00:00 2001 From: Aren Villanueva Date: Mon, 16 Nov 2015 12:31:44 +1100 Subject: Use macros to determine which iOS SDK we have in order to be backwards compatible with older SDKs when fixing template compilation issues. --- platform/iphone/game_center.mm | 10 ++++++++++ platform/iphone/icloud.mm | 8 ++++++++ 2 files changed, 18 insertions(+) (limited to 'platform/iphone') diff --git a/platform/iphone/game_center.mm b/platform/iphone/game_center.mm index 1e46d9f014..4cb7a20a7f 100644 --- a/platform/iphone/game_center.mm +++ b/platform/iphone/game_center.mm @@ -30,8 +30,18 @@ #include "game_center.h" +#ifdef __IPHONE_9_0 + #import extern "C" { + +#else + +extern "C" { +#import + +#endif + #import "app_delegate.h" }; diff --git a/platform/iphone/icloud.mm b/platform/iphone/icloud.mm index a35d8ecd69..518385992d 100644 --- a/platform/iphone/icloud.mm +++ b/platform/iphone/icloud.mm @@ -30,9 +30,17 @@ #include "icloud.h" +#ifndef __IPHONE_9_0 +extern "C" { +#endif + #import #import "app_delegate.h" +#ifndef __IPHONE_9_0 +}; +#endif + ICloud* ICloud::instance = NULL; void ICloud::_bind_methods() { -- cgit v1.2.3