Skip to content

Commit

Permalink
Improved iOS 6 compatibility and fixed initial display bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Anderson authored and Ross Anderson committed Jun 17, 2012
1 parent 09a590d commit 3ed0234
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 102 deletions.
4 changes: 2 additions & 2 deletions EarthViewExample-Info.plist
Expand Up @@ -41,8 +41,8 @@
<array>
<string>armv7</string>
</array>
<key>UIStatusBarHidden</key>
<true/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackTranslucent</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
Binary file not shown.
18 changes: 7 additions & 11 deletions Source/RASceneGraphController.m
Expand Up @@ -143,14 +143,14 @@ - (void)viewDidLoad

// setup auxillary context for threaded texture loading operations
if ( _pager && ! _pager.auxilliaryContext ) _pager.auxilliaryContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:[_context sharegroup]];
[_pager setupGL];

// register for notifications
if ( _camera ) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(displayNotification:) name:RACameraStateChangedNotification object:_camera];
if ( _pager ) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(displayNotification:) name:RATilePagerContentChangedNotification object:_pager];

_needsUpdate = YES;
_needsDisplay = YES;
[self setupGL];
[self update];
}

- (void)viewDidUnload
Expand Down Expand Up @@ -245,7 +245,6 @@ - (IBAction)flyToLocationFrom:(id)sender {
#pragma mark - UITextFieldDelegate

- (BOOL)textFieldShouldClear:(UITextField *)textField {
NSLog(@"Clear!");
return YES;
}

Expand Down Expand Up @@ -273,6 +272,7 @@ - (RANode *)createSceneGraphForPager:(RATilePager *)pager
- (void)setupGL
{
[EAGLContext setCurrentContext:_context];
[glView bindDrawable];

glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
Expand Down Expand Up @@ -302,10 +302,7 @@ - (void)setupGL
[_renderVisitor setupGL];
}

[self update];

_needsUpdate = YES;
_needsDisplay = YES;
[_pager setupGL];
}

- (void)tearDownGL
Expand All @@ -329,11 +326,11 @@ - (void)update
_renderVisitor.lightPosition = lightEcef;
}

self.camera.viewport = self.view.bounds;
self.camera.viewport = self.glView.bounds;
[_camera calculateProjectionForBounds: self.sceneRoot.bound];

// update skybox projection
float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
float aspect = fabsf(self.glView.bounds.size.width / self.glView.bounds.size.height);
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(_camera.fieldOfView), aspect, 10, 50);
_skybox.transform.projectionMatrix = projectionMatrix;
_skybox.transform.modelviewMatrix = self.camera.modelViewMatrix;
Expand Down Expand Up @@ -376,8 +373,7 @@ - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
[RAGeometry cleanupAll:NO];

// show stats
if ( statsLabel )
[statsLabel setText:_renderVisitor.statsString];
[statsLabel setText:_renderVisitor.statsString];
}

@end
69 changes: 41 additions & 28 deletions Source/RATilePager.m
Expand Up @@ -336,13 +336,22 @@ - (void)requestPage:(RAPage *)page {
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

if ( error ) {
// attempt to reload if the connection timed out
if ( [[error domain] isEqualToString:NSURLErrorDomain] && [error code] == NSURLErrorTimedOut ) {
page.imageryState = NotLoaded;
return;
// catch common errors
if ( [[error domain] isEqualToString:NSURLErrorDomain] ) {
switch( [error code] ) {
case NSURLErrorTimedOut:
// attempt to reload if the connection timed out
page.imageryState = NotLoaded;
return;
case NSURLErrorNotConnectedToInternet: // !!! catch other common errors here
// give up if net access is unavailable
page.imageryState = Failed;
return;
default: break;
}
}
NSLog(@"URL loading error): %@", error);

NSLog(@"URL loading error: %@", error);
page.imageryState = Failed;
return;
} else if ( [[response MIMEType] isEqualToString:@"text/html"] ) {
Expand Down Expand Up @@ -399,13 +408,22 @@ - (void)requestPage:(RAPage *)page {
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

if ( error ) {
// attempt to reload if the connection timed out
if ( [[error domain] isEqualToString:NSURLErrorDomain] && [error code] == NSURLErrorTimedOut ) {
page.terrainState = NotLoaded;
return;
// catch common errors
if ( [[error domain] isEqualToString:NSURLErrorDomain] ) {
switch( [error code] ) {
case NSURLErrorTimedOut:
// attempt to reload if the connection timed out
page.terrainState = NotLoaded;
return;
case NSURLErrorNotConnectedToInternet: // !!! catch other common errors here
// give up if net access is unavailable
page.terrainState = Failed;
return;
default: break;
}
}
NSLog(@"URL Error loading (%@): %@", url, error);

NSLog(@"URL loading error: %@", error);
page.terrainState = Failed;
return;
} else if ( [[response MIMEType] isEqualToString:@"text/html"] ) {
Expand Down Expand Up @@ -509,28 +527,23 @@ - (void)requestUpdate {
return;
}

[self update];
}

- (void)update {

NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];

// capture self to avoid a retain cycle
__block RATilePager *mySelf = self;

[_updateQueue addOperationWithBlock:^{
[mySelf traverse];
}];
}

- (void)traverse {
NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];

do {
// traverse pages gathering ones that are active and should be displayed
[mySelf->rootPages enumerateObjectsUsingBlock:^(RAPage *page, BOOL *stop) {
[mySelf traversePage:page withTimestamp:currentTime];
[rootPages enumerateObjectsUsingBlock:^(RAPage *page, BOOL *stop) {
[self traversePage:page withTimestamp:currentTime];
}];

// update again if changes were made during traverse
if ( mySelf->_updateAgain ) {
mySelf->_updateAgain = NO;
[mySelf update];
}
}];
} while( _updateAgain ); // update again if changes were made
}

@end

0 comments on commit 3ed0234

Please sign in to comment.