From 309096419b10d0029e015a5476efc3f85c7d1b89 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Fri, 7 Feb 2014 11:15:51 -0500 Subject: [PATCH 1/4] removing useless line with our use of GLKViewController --- ios/MBXViewController.mm | 1 - 1 file changed, 1 deletion(-) diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index 580f36853..d700fb9b2 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -73,7 +73,6 @@ class MBXMapView GLKView *view = (GLKView *)self.view; view.context = self.context; view.drawableStencilFormat = GLKViewDrawableStencilFormat8; - self.preferredFramesPerSecond = 60; [view bindDrawable]; [EAGLContext setCurrentContext:self.context]; From ad104ee03e8ac4d5cc214aaeb7484de51c45e9dd Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Fri, 7 Feb 2014 11:26:39 -0500 Subject: [PATCH 2/4] refs #43: only render on iOS when we need to --- ios/MBXViewController.mm | 64 ++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index d700fb9b2..2034f5ff7 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -16,6 +16,8 @@ #include #include +NSString *const MBXNeedsRenderNotification = @"MBXNeedsRenderNotification"; + @interface MBXViewController () @property (nonatomic) EAGLContext *context; @@ -77,9 +79,6 @@ class MBXMapView [EAGLContext setCurrentContext:self.context]; - displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(render:)]; - [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; - mapView->init(); UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; @@ -112,6 +111,25 @@ class MBXMapView UILongPressGestureRecognizer *threeFingerLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleThreeFingerLongPressGesture:)]; threeFingerLongPress.numberOfTouchesRequired = 3; [self.view addGestureRecognizer:threeFingerLongPress]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startRender) name:MBXNeedsRenderNotification object:nil]; + + displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(render:)]; + [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; +} + +- (void)startRender +{ + [NSObject cancelPreviousPerformRequestsWithTarget:self]; + + displayLink.paused = NO; + + [self performSelector:@selector(stopRender) withObject:nil afterDelay:3.0]; +} + +- (void)stopRender +{ + displayLink.paused = YES; } - (void)render:(id)sender @@ -162,6 +180,8 @@ class MBXMapView mapView->map.moveBy(finalCenter.x - self.center.x, finalCenter.y - self.center.y, duration); } + + [self startRender]; } - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch @@ -188,6 +208,8 @@ class MBXMapView mapView->map.scaleBy(powf(2, newZoom) / mapView->map.getScale(), [pinch locationInView:pinch.view].x, [pinch locationInView:pinch.view].y); } + + [self startRender]; } - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate @@ -200,30 +222,40 @@ class MBXMapView { mapView->map.setAngle(self.angle + rotate.rotation, [rotate locationInView:rotate.view].x, [rotate locationInView:rotate.view].y); } + + [self startRender]; } - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap { if (doubleTap.state == UIGestureRecognizerStateEnded) mapView->map.scaleBy(2, [doubleTap locationInView:doubleTap.view].x, [doubleTap locationInView:doubleTap.view].y, 0.5); + + [self startRender]; } - (void)handleTwoFingerTapGesture:(UITapGestureRecognizer *)twoFingerTap { if (twoFingerTap.state == UIGestureRecognizerStateEnded) mapView->map.scaleBy(0.5, [twoFingerTap locationInView:twoFingerTap.view].x, [twoFingerTap locationInView:twoFingerTap.view].y, 0.5); + + [self startRender]; } - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)longPress { if (longPress.state == UIGestureRecognizerStateBegan) mapView->map.resetNorth(); + + [self startRender]; } - (void)handleTwoFingerLongPressGesture:(UILongPressGestureRecognizer *)twoFingerLongPress { if (twoFingerLongPress.state == UIGestureRecognizerStateBegan) mapView->map.resetPosition(); + + [self startRender]; } - (void)handleThreeFingerLongPressGesture:(UILongPressGestureRecognizer *)threeFingerLongPress @@ -234,6 +266,8 @@ class MBXMapView self.debug = ! self.debug; } + + [self startRender]; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer @@ -291,7 +325,9 @@ namespace llmr func(res); } - }]; + + [[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil]; + }]; } void request_http(std::string url, std::function func, std::function cb) @@ -302,18 +338,20 @@ namespace llmr queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { - Response res; + Response res; - if (error == nil) - { - res.code = [(NSHTTPURLResponse *)response statusCode]; - res.body = { (const char *)[data bytes], [data length] }; - } + if (error == nil) + { + res.code = [(NSHTTPURLResponse *)response statusCode]; + res.body = { (const char *)[data bytes], [data length] }; + } - func(res); + func(res); - cb(); - }]; + cb(); + + [[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil]; + }]; } double time() From b17698579125cacaddb9b16e7cab4226b8f24094 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Fri, 7 Feb 2014 11:33:07 -0500 Subject: [PATCH 3/4] fix some indentation --- ios/MBXViewController.mm | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index 2034f5ff7..865ad00fc 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -309,25 +309,25 @@ namespace llmr [NSURLConnection sendAsynchronousRequest:urlRequest queue:[NSOperationQueue mainQueue] completionHandler: ^(NSURLResponse *response, NSData *data, NSError *error) - { - if ( ! error) - { - Response res; + { + if ( ! error) + { + Response res; - res.code = [(NSHTTPURLResponse *)response statusCode]; - res.body = { (const char *)[data bytes], [data length] }; + res.code = [(NSHTTPURLResponse *)response statusCode]; + res.body = { (const char *)[data bytes], [data length] }; - func(res); - } - else - { - Response res; + func(res); + } + else + { + Response res; - func(res); - } + func(res); + } - [[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil]; - }]; + [[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil]; + }]; } void request_http(std::string url, std::function func, std::function cb) @@ -351,7 +351,7 @@ namespace llmr cb(); [[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil]; - }]; + }]; } double time() From daac03f5269b0c000ca06db56e65118238b92bd7 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Fri, 7 Feb 2014 11:40:15 -0500 Subject: [PATCH 4/4] fixes #43: fix tile renders on OS X --- macosx/main.mm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/macosx/main.mm b/macosx/main.mm index 1c12b7f3c..b8f333ba2 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -7,6 +7,8 @@ #include +NSString *const MBXNeedsRenderNotification = @"MBXNeedsRenderNotification"; + class MapView { public: MapView() : @@ -53,6 +55,14 @@ public: glfwSetScrollCallback(window, scroll); glfwSetCharCallback(window, character); glfwSetKeyCallback(window, key); + + [[NSNotificationCenter defaultCenter] addObserverForName:MBXNeedsRenderNotification + object:nil + queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *notification) + { + dirty = true; + }]; } static void character(GLFWwindow *window, unsigned int codepoint) { @@ -241,6 +251,7 @@ void request_http(std::string url, std::function func) { Response res; func(res); } + [[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil]; }]; } @@ -263,6 +274,7 @@ void request_http(std::string url, std::function func, std::fun func(res); cb(); + [[NSNotificationCenter defaultCenter] postNotificationName:MBXNeedsRenderNotification object:nil]; }]; }