#import "AppDelegate.h"
#import "OgreTest.h"

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
	// setup OGRE
	BOOL ok = setupOgre(YES, [[[NSBundle mainBundle] resourcePath] cString]);
	if(!ok) [NSApp terminate:nil];
	
	createOgreWorld();
	
	
	// create a timer that causes OGRE to render as fast as possible
	// for an application you might want to set the time interval to something slower (eg 0.05 -- 20fps)
	NSTimer *renderTimer = [NSTimer timerWithTimeInterval:0 target:self selector:@selector(renderFrame) userInfo:NULL repeats:YES];
	
	// add the timer to the required run loop modes
	[[NSRunLoop currentRunLoop] addTimer:renderTimer forMode:NSDefaultRunLoopMode];
	
	// if you want OGRE to pause during menus, window resizing, modal dialogs etc, comment these out
	[[NSRunLoop currentRunLoop] addTimer:renderTimer forMode:NSEventTrackingRunLoopMode];
	[[NSRunLoop currentRunLoop] addTimer:renderTimer forMode:NSModalPanelRunLoopMode];
	
}

- (void)renderFrame
{
	static BOOL firstFrame = YES;

	if(!renderOgreFrame())
		[NSApp terminate:nil];
	
	if(firstFrame)
	{
		resetStatistics();
		firstFrame = NO;
	}
}

- (void)applicationWillTerminate:(NSNotification *)notification
{
	endOgre();
}

@end