#import "QnDMaze_iPhoneAppDelegate.h" #import "EAGLView.h" #import "MazeController.h" @implementation QnDMaze_iPhoneAppDelegate #define STEP_INTERVAL (1.0 / 120.0) @synthesize window; @synthesize glView; - (void) applicationDidFinishLaunching: (UIApplication *) application { mazeController = [[MazeController alloc] init]; lastTime = [NSDate timeIntervalSinceReferenceDate]; slop = 0.0; glView.animationInterval = 1.0 / 60.0; [glView startAnimation]; } - (void) applicationWillResignActive: (UIApplication *) application { glView.animationInterval = 1.0 / 5.0; } - (void) applicationDidBecomeActive: (UIApplication *) application { glView.animationInterval = 1.0 / 60.0; } - (void) dealloc { [window release]; [glView release]; [super dealloc]; } - (void) drawScene { double currentTime, interval; if (mazeController == nil) return; currentTime = [NSDate timeIntervalSinceReferenceDate]; interval = (currentTime - lastTime) + slop; while (interval > STEP_INTERVAL) { [mazeController run]; interval -= STEP_INTERVAL; } slop = interval; lastTime = currentTime; [mazeController draw]; } - (void) rotateLeft { [mazeController rotateLeft]; } - (void) rotateRight { [mazeController rotateRight]; } - (void) rotateUp { [mazeController rotateUp]; } - (void) rotateDown { [mazeController rotateDown]; } - (void) moveForward { [mazeController moveForward]; } @end