1 //|||||||||||||||||||||||||||||||||||||||||||||||
2
3 #include "DemoApp.h"
4
5 //|||||||||||||||||||||||||||||||||||||||||||||||
6
7 #ifdef OGRE_STATIC_LIB
8 # define OGRE_STATIC_GL
9 # if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
10 # define OGRE_STATIC_Direct3D9
11 // dx10 will only work on vista, so be careful about statically linking
12 # if OGRE_USE_D3D11
13 # define OGRE_STATIC_Direct3D11
14 # endif
15 # endif
16 # define OGRE_STATIC_BSPSceneManager
17 # define OGRE_STATIC_ParticleFX
18 # define OGRE_STATIC_CgProgramManager
19 # ifdef OGRE_USE_PCZ
20 # define OGRE_STATIC_PCZSceneManager
21 # define OGRE_STATIC_OctreeZone
22 # else
23 # define OGRE_STATIC_OctreeSceneManager
24 # endif
25 # if OGRE_PLATFORM == OGRE_PLATFORM_IPHONE
26 # undef OGRE_STATIC_CgProgramManager
27 # undef OGRE_STATIC_GL
28 # define OGRE_STATIC_GLES 1
29 # ifdef __OBJC__
30 # import <UIKit/UIKit.h>
31 # endif
32 # endif
33 # include "OgreStaticPluginLoader.h"
34 #endif
35
36 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_IPHONE
37 #include "macUtils.h"
38 #endif
39
40 #if OGRE_PLATFORM == OGRE_PLATFORM_IPHONE
41 #include <UIKit/UIKit.h>
42 #endif
43
44 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
45 #define WIN32_LEAN_AND_MEAN
46 #include "windows.h"
47
48 //|||||||||||||||||||||||||||||||||||||||||||||||
49
WinMain(HINSTANCE hInst,HINSTANCE,LPSTR strCmdLine,INT)50 INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
51 #else
52 int main(int argc, char **argv)
53 #endif
54 {
55 #if OGRE_PLATFORM == OGRE_PLATFORM_IPHONE
56 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
57 int retVal = UIApplicationMain(argc, argv, @"UIApplication", @"AppDelegate");
58 [pool release];
59 return retVal;
60 #else
61 try
62 {
63 DemoApp demo;
64 demo.startDemo();
65 }
66 catch(Ogre::Exception& e)
67 {
68 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
69 MessageBoxA(NULL, e.what(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
70 #else
71 fprintf(stderr, "An exception has occurred: %s\n", e.what());
72 #endif
73 }
74
75 return 0;
76 #endif
77 }
78
79 //|||||||||||||||||||||||||||||||||||||||||||||||
80
81 #if OGRE_PLATFORM == OGRE_PLATFORM_IPHONE
82 # ifdef __OBJC__
83 @interface AppDelegate : NSObject <UIApplicationDelegate>
84 {
85 DemoApp demo;
86 NSTimer *mTimer;
87 double timeSinceLastFrame;
88 double startTime;
89 }
90
91 - (void)go;
92 - (void)renderOneFrame:(id)sender;
93
94 @property (retain) NSTimer *mTimer;
95
96 @end
97
98 @implementation AppDelegate
99
100 @synthesize mTimer;
101
102 - (void)go {
103 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
104 try {
105 timeSinceLastFrame = 0;
106 startTime = 0;
107
108 new OgreFramework();
109 if(!OgreFramework::getSingletonPtr()->initOgre("DemoApp v1.0", &demo, 0))
110 return;
111
112 demo.setShutdown(false);
113
114 OgreFramework::getSingletonPtr()->m_pLog->logMessage("Demo initialized!");
115
116 demo.setupDemoScene();
117 OgreFramework::getSingletonPtr()->m_pRenderWnd->resetStatistics();
118
119 mTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)(1.0f / 60.0f)
120 target:self
121 selector:@selector(renderOneFrame:)
122 userInfo:nil
123 repeats:YES];
124 } catch( Ogre::Exception& e ) {
125 std::cerr << "An exception has occurred: " <<
126 e.getFullDescription().c_str() << std::endl;
127 }
128
129 [pool release];
130 }
131
132 - (void)renderOneFrame:(id)sender
133 {
134 #pragma unused(sender)
135 if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isActive())
136 {
137 startTime = OgreFramework::getSingletonPtr()->m_pTimer->getMillisecondsCPU();
138
139 OgreFramework::getSingletonPtr()->m_pMouse->capture();
140
141 OgreFramework::getSingletonPtr()->updateOgre(timeSinceLastFrame);
142 OgreFramework::getSingletonPtr()->m_pRoot->renderOneFrame();
143
144 timeSinceLastFrame = OgreFramework::getSingletonPtr()->m_pTimer->getMillisecondsCPU() - startTime;
145 }
146 }
147
148 - (void)applicationDidFinishLaunching:(UIApplication *)application {
149 #pragma unused(application)
150 // Hide the status bar
151 [[UIApplication sharedApplication] setStatusBarHidden:YES];
152
153 // Create a window
154 UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
155
156 // Create an image view
157 UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
158 [window addSubview:imageView];
159
160 // Create an indeterminate status indicator
161 UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
162 [indicator setFrame:CGRectMake(150, 280, 20, 20)];
163 [indicator startAnimating];
164 [window addSubview:indicator];
165
166 // Display our window
167 [window makeKeyAndVisible];
168
169 // Clean up
170 [imageView release];
171 [indicator release];
172
173 [self go];
174
175 [window release];
176 }
177
178 - (void)applicationWillTerminate:(UIApplication *)application {
179 #pragma unused(application)
180 Ogre::Root::getSingleton().queueEndRendering();
181 }
182
183 //- (void)applicationWillResignActive:(UIApplication *)application
184 //{
185 // // Pause FrameListeners and rendering
186 //}
187 //
188 //- (void)applicationDidBecomeActive:(UIApplication *)application
189 //{
190 // // Resume FrameListeners and rendering
191 //}
192
193 - (void)dealloc {
194 [super dealloc];
195 }
196
197 @end
198 # endif
199 #endif
200