Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchie/src/orxonox.cc @ 174

Last change on this file since 174 was 172, checked in by landauf, 17 years ago

some features work perfectly,
some features are fucked up,
some features arent yet implemented.

x3n→hair→brightness++;

theres still a lot to do, but i can see the light on the end of the tunnel.
templates, makros, operator overloading, function pointers… the beauty of the beast. i'm in love and still dying piece by piece with every line of code i'm writing.
</film noir>

File size: 22.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software: you can redistribute it and/or modify
8 *   it under the terms of the GNU General Public License as published by
9 *   the Free Software Foundation, either version 3 of the License, or
10 *   (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 *
20 *
21 *   Author:
22 *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include <Ogre.h>
29#include <OIS/OIS.h>
30#include <CEGUI/CEGUI.h>
31#include <OgreCEGUIRenderer.h>
32
33#include "BaseObject.h"
34#include "Test.h"
35
36#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
37#include <CoreFoundation/CoreFoundation.h>
38
39// This function will locate the path to our application on OS X,
40// unlike windows you can not rely on the curent working directory
41// for locating your configuration files and resources.
42std::string macBundlePath()
43{
44  char path[1024];
45  CFBundleRef mainBundle = CFBundleGetMainBundle();
46  assert(mainBundle);
47
48  CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
49  assert(mainBundleURL);
50
51  CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
52  assert(cfStringRef);
53
54  CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
55
56  CFRelease(mainBundleURL);
57  CFRelease(cfStringRef);
58
59  return std::string(path);
60}
61#endif
62
63namespace orxonox
64{
65  class OrxExitListener : public Ogre::FrameListener
66  {
67    public:
68      OrxExitListener(OIS::Keyboard *keyboard)
69    : mKeyboard(keyboard)
70      {
71      }
72
73      bool frameStarted(const Ogre::FrameEvent& evt)
74      {
75        mKeyboard->capture();
76        return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
77      }
78
79    private:
80      OIS::Keyboard *mKeyboard;
81  };
82
83  class OrxApplication
84  {
85    public:
86      void go()
87      {
88/*
89        createRoot();
90        defineResources();
91        setupRenderSystem();
92        createRenderWindow();
93        initializeResourceGroups();
94        setupScene();
95        setupInputSystem();
96        setupCEGUI();
97        createFrameListener();
98        startRenderLoop();
99*/
100/*
101        std::cout << "Test 1\n";
102        BaseObject* test1;
103        test1 = new BaseObject();
104        test1 = new BaseObject();
105        test1 = new BaseObject();
106
107        std::cout << "Test 2\n";
108        A1* test2;
109        test2 = new A1();
110        test2 = new A1();
111        test2 = new A1();
112
113        std::cout << "Test 3\n";
114        BaseObject* test3;
115        test3 = new BaseObject();
116        test3 = new BaseObject();
117        test3 = new BaseObject();
118
119        std::cout << "Test 4\n";
120        A3* test4;
121        test4 = new A3();
122        test4 = new A3();
123        test4 = new A3();
124*/
125/*
126        std::cout << "Test 5\n";
127        A1* test5_01 = new A1();
128        A2* test5_02 = new A2();
129        A3* test5_03 = new A3();
130        A1B1* test5_04 = new A1B1();
131        A1B2* test5_05 = new A1B2();
132        A2B1* test5_06 = new A2B1();
133        A2B2* test5_07 = new A2B2();
134        A3B1* test5_08 = new A3B1();
135        A3B2* test5_09 = new A3B2();
136        A1B1C1* test5_10 = new A1B1C1();
137        A1B1C2* test5_11 = new A1B1C2();
138        A1B2C1* test5_12 = new A1B2C1();
139        A2B1C1* test5_13 = new A2B1C1();
140        A2B2C1* test5_14 = new A2B2C1();
141        A3B1C1* test5_15 = new A3B1C1();
142        A3B1C2* test5_16 = new A3B1C2();
143        A3B2C1* test5_17 = new A3B2C1();
144        A3B2C2* test5_18 = new A3B2C2();
145
146        OrxonoxClass* test5;
147        for (int i = 0; i <= 18; i++)
148        {
149          if (i == 0) test5 = test1;
150          if (i == 1) test5 = test5_01;
151          if (i == 2) test5 = test5_02;
152          if (i == 3) test5 = test5_03;
153          if (i == 4) test5 = test5_04;
154          if (i == 5) test5 = test5_05;
155          if (i == 6) test5 = test5_06;
156          if (i == 7) test5 = test5_07;
157          if (i == 8) test5 = test5_08;
158          if (i == 9) test5 = test5_09;
159          if (i == 10) test5 = test5_10;
160          if (i == 11) test5 = test5_11;
161          if (i == 12) test5 = test5_12;
162          if (i == 13) test5 = test5_13;
163          if (i == 14) test5 = test5_14;
164          if (i == 15) test5 = test5_15;
165          if (i == 16) test5 = test5_16;
166          if (i == 17) test5 = test5_17;
167          if (i == 18) test5 = test5_18;
168
169          std::cout << "\n";
170          std::cout << test5->getIdentifier()->getName() << ": directParents:  " << test5->getIdentifier()->getDirectParents()->toString() << "\n";
171          std::cout << test5->getIdentifier()->getName() << ": allParents:     " << test5->getIdentifier()->getAllParents()->toString() << "\n";
172          std::cout << test5->getIdentifier()->getName() << ": directChildren: " << test5->getIdentifier()->getDirectChildren()->toString() << "\n";
173          std::cout << test5->getIdentifier()->getName() << ": allChildren:    " << test5->getIdentifier()->getAllChildren()->toString() << "\n";
174        }
175*/
176/*
177        #define testandcout(code) \
178          std::cout << #code << " " << code << "\n"
179
180
181        std::cout << "\n";
182        std::cout << "isA(XYZ)-Test:\n";
183        std::cout << "test5_01 = A1, Erwartet: 1 0 0 1 0\n";
184        testandcout(test5_01->isA(Class(A1)));
185        testandcout(test5_01->isA(Class(A2)));
186        testandcout(test5_01->isA(Class(A1B1)));
187        testandcout(test5_01->isA(Class(BaseObject)));
188        testandcout(test5_01->isA(Class(Interface1)));
189
190        std::cout << "\n";
191        std::cout << "test5_02 = A2, Erwartet: 0 1 0 1 0\n";
192        testandcout(test5_02->isA(Class(A1)));
193        testandcout(test5_02->isA(Class(A2)));
194        testandcout(test5_02->isA(Class(A1B1)));
195        testandcout(test5_02->isA(Class(BaseObject)));
196        testandcout(test5_02->isA(Class(Interface1)));
197
198        std::cout << "\n";
199        std::cout << "test5_01 = A3, Erwartet: 0 0 0 1 1\n";
200        testandcout(test5_03->isA(Class(A1)));
201        testandcout(test5_03->isA(Class(A2)));
202        testandcout(test5_03->isA(Class(A1B1)));
203        testandcout(test5_03->isA(Class(BaseObject)));
204        testandcout(test5_03->isA(Class(Interface1)));
205
206
207        std::cout << "\n";
208        std::cout << "isDirectA(XYZ)-Test:\n";
209        std::cout << "test5_01 = A1, Erwartet: 1 0 0 0 0\n";
210        testandcout(test5_01->isDirectlyA(Class(A1)));
211        testandcout(test5_01->isDirectlyA(Class(A2)));
212        testandcout(test5_01->isDirectlyA(Class(A1B1)));
213        testandcout(test5_01->isDirectlyA(Class(BaseObject)));
214        testandcout(test5_01->isDirectlyA(Class(Interface1)));
215
216        std::cout << "\n";
217        std::cout << "test5_02 = A2, Erwartet: 0 1 0 0 0\n";
218        testandcout(test5_02->isDirectlyA(Class(A1)));
219        testandcout(test5_02->isDirectlyA(Class(A2)));
220        testandcout(test5_02->isDirectlyA(Class(A1B1)));
221        testandcout(test5_02->isDirectlyA(Class(BaseObject)));
222        testandcout(test5_02->isDirectlyA(Class(Interface1)));
223
224        std::cout << "\n";
225        std::cout << "test5_03 = A3, Erwartet: 0 0 0 0 0\n";
226        testandcout(test5_03->isDirectlyA(Class(A1)));
227        testandcout(test5_03->isDirectlyA(Class(A2)));
228        testandcout(test5_03->isDirectlyA(Class(A1B1)));
229        testandcout(test5_03->isDirectlyA(Class(BaseObject)));
230        testandcout(test5_03->isDirectlyA(Class(Interface1)));
231
232        std::cout << "\n";
233        std::cout << "isChildOf(XYZ)-Test:\n";
234        std::cout << "test5_04 = A1B1, Erwartet: 1 0 1 0 0 0 0\n";
235        testandcout(test5_04->isChildOf(Class(A1)));
236        testandcout(test5_04->isChildOf(Class(A2)));
237        testandcout(test5_04->isChildOf(Class(BaseObject)));
238        testandcout(test5_04->isChildOf(Class(Interface1)));
239        testandcout(test5_04->isChildOf(Class(Interface2)));
240        testandcout(test5_04->isChildOf(Class(A1B1C2)));
241        testandcout(test5_04->isChildOf(Class(A1B1)));
242
243        std::cout << "\n";
244        std::cout << "test5_06 = A2B1, Erwartet: 0 1 1 0 0 0 0\n";
245        testandcout(test5_06->isChildOf(Class(A1)));
246        testandcout(test5_06->isChildOf(Class(A2)));
247        testandcout(test5_06->isChildOf(Class(BaseObject)));
248        testandcout(test5_06->isChildOf(Class(Interface1)));
249        testandcout(test5_06->isChildOf(Class(Interface2)));
250        testandcout(test5_06->isChildOf(Class(A1B1C2)));
251        testandcout(test5_06->isChildOf(Class(A1B1)));
252
253        std::cout << "\n";
254        std::cout << "test5_07 = A2B2, Erwartet: 0 1 1 1 0 0\n";
255        testandcout(test5_07->isChildOf(Class(A1)));
256        testandcout(test5_07->isChildOf(Class(A2)));
257        testandcout(test5_07->isChildOf(Class(BaseObject)));
258        testandcout(test5_07->isChildOf(Class(Interface1)));
259        testandcout(test5_07->isChildOf(Class(Interface2)));
260        testandcout(test5_07->isChildOf(Class(A1B1C2)));
261
262        std::cout << "\n";
263        std::cout << "test5_08 = A3B1, Erwartet: 0 0 1 1 0 0\n";
264        testandcout(test5_08->isChildOf(Class(A1)));
265        testandcout(test5_08->isChildOf(Class(A2)));
266        testandcout(test5_08->isChildOf(Class(BaseObject)));
267        testandcout(test5_08->isChildOf(Class(Interface1)));
268        testandcout(test5_08->isChildOf(Class(Interface2)));
269        testandcout(test5_08->isChildOf(Class(A1B1C2)));
270
271        std::cout << "\n";
272        std::cout << "test5_09 = A3B2, Erwartet: 0 0 1 1 1 0\n";
273        testandcout(test5_09->isChildOf(Class(A1)));
274        testandcout(test5_09->isChildOf(Class(A2)));
275        testandcout(test5_09->isChildOf(Class(BaseObject)));
276        testandcout(test5_09->isChildOf(Class(Interface1)));
277        testandcout(test5_09->isChildOf(Class(Interface2)));
278        testandcout(test5_09->isChildOf(Class(A1B1C2)));
279
280        std::cout << "\n";
281        std::cout << "isDirectChildOf(XYZ)-Test:\n";
282        std::cout << "test5_04 = A1B1, Erwartet: 1 0 0 0 0 0 0\n";
283        testandcout(test5_04->isDirectChildOf(Class(A1)));
284        testandcout(test5_04->isDirectChildOf(Class(A2)));
285        testandcout(test5_04->isDirectChildOf(Class(BaseObject)));
286        testandcout(test5_04->isDirectChildOf(Class(Interface1)));
287        testandcout(test5_04->isDirectChildOf(Class(Interface2)));
288        testandcout(test5_04->isDirectChildOf(Class(A1B1C2)));
289        testandcout(test5_04->isDirectChildOf(Class(A1B1)));
290
291        std::cout << "\n";
292        std::cout << "test5_06 = A2B1, Erwartet: 0 1 0 0 0 0 0\n";
293        testandcout(test5_06->isDirectChildOf(Class(A1)));
294        testandcout(test5_06->isDirectChildOf(Class(A2)));
295        testandcout(test5_06->isDirectChildOf(Class(BaseObject)));
296        testandcout(test5_06->isDirectChildOf(Class(Interface1)));
297        testandcout(test5_06->isDirectChildOf(Class(Interface2)));
298        testandcout(test5_06->isDirectChildOf(Class(A1B1C2)));
299        testandcout(test5_06->isDirectChildOf(Class(A1B1)));
300
301        std::cout << "\n";
302        std::cout << "test5_07 = A2B2, Erwartet: 0 1 0 1 0 0\n";
303        testandcout(test5_07->isDirectChildOf(Class(A1)));
304        testandcout(test5_07->isDirectChildOf(Class(A2)));
305        testandcout(test5_07->isDirectChildOf(Class(BaseObject)));
306        testandcout(test5_07->isDirectChildOf(Class(Interface1)));
307        testandcout(test5_07->isDirectChildOf(Class(Interface2)));
308        testandcout(test5_07->isDirectChildOf(Class(A1B1C2)));
309
310        std::cout << "\n";
311        std::cout << "test5_08 = A3B1, Erwartet: 0 0 0 0 0 0\n";
312        testandcout(test5_08->isDirectChildOf(Class(A1)));
313        testandcout(test5_08->isDirectChildOf(Class(A2)));
314        testandcout(test5_08->isDirectChildOf(Class(BaseObject)));
315        testandcout(test5_08->isDirectChildOf(Class(Interface1)));
316        testandcout(test5_08->isDirectChildOf(Class(Interface2)));
317        testandcout(test5_08->isDirectChildOf(Class(A1B1C2)));
318
319        std::cout << "\n";
320        std::cout << "test5_09 = A3B2, Erwartet: 0 0 0 0 1 0\n";
321        testandcout(test5_09->isDirectChildOf(Class(A1)));
322        testandcout(test5_09->isDirectChildOf(Class(A2)));
323        testandcout(test5_09->isDirectChildOf(Class(BaseObject)));
324        testandcout(test5_09->isDirectChildOf(Class(Interface1)));
325        testandcout(test5_09->isDirectChildOf(Class(Interface2)));
326        testandcout(test5_09->isDirectChildOf(Class(A1B1C2)));
327
328        std::cout << "\n";
329        std::cout << "isParentOf(XYZ)-Test:\n";
330        std::cout << "test1 = BaseObject, Erwartet: 0 0 1 1 1 1 1\n";
331        testandcout(test1->isParentOf(Class(BaseObject)));
332        testandcout(test1->isParentOf(Class(Interface1)));
333        testandcout(test1->isParentOf(Class(A1)));
334        testandcout(test1->isParentOf(Class(A2)));
335        testandcout(test1->isParentOf(Class(A1B1)));
336        testandcout(test1->isParentOf(Class(A2B2)));
337        testandcout(test1->isParentOf(Class(A3B1C2)));
338
339        std::cout << "\n";
340        std::cout << "test5_01 = A1, Erwartet: 0 0 0 0 1 0 0\n";
341        testandcout(test5_01->isParentOf(Class(BaseObject)));
342        testandcout(test5_01->isParentOf(Class(Interface1)));
343        testandcout(test5_01->isParentOf(Class(A1)));
344        testandcout(test5_01->isParentOf(Class(A2)));
345        testandcout(test5_01->isParentOf(Class(A1B1)));
346        testandcout(test5_01->isParentOf(Class(A2B2)));
347        testandcout(test5_01->isParentOf(Class(A3B1C2)));
348
349        std::cout << "\n";
350        std::cout << "Interface1, Erwartet: 0 0 0 0 0 1 1\n";
351        testandcout(Class(Interface1)->isParentOf(Class(BaseObject)));
352        testandcout(Class(Interface1)->isParentOf(Class(Interface1)));
353        testandcout(Class(Interface1)->isParentOf(Class(A1)));
354        testandcout(Class(Interface1)->isParentOf(Class(A2)));
355        testandcout(Class(Interface1)->isParentOf(Class(A1B1)));
356        testandcout(Class(Interface1)->isParentOf(Class(A2B2)));
357        testandcout(Class(Interface1)->isParentOf(Class(A3B1C2)));
358
359        std::cout << "\n";
360        std::cout << "isDirectParentOf(XYZ)-Test:\n";
361        std::cout << "test1 = BaseObject, Erwartet: 0 0 1 1 0 0 0\n";
362        testandcout(test1->isDirectParentOf(Class(BaseObject)));
363        testandcout(test1->isDirectParentOf(Class(Interface1)));
364        testandcout(test1->isDirectParentOf(Class(A1)));
365        testandcout(test1->isDirectParentOf(Class(A2)));
366        testandcout(test1->isDirectParentOf(Class(A1B1)));
367        testandcout(test1->isDirectParentOf(Class(A2B2)));
368        testandcout(test1->isDirectParentOf(Class(A3B1C2)));
369
370        std::cout << "\n";
371        std::cout << "test5_01 = A1, Erwartet: 0 0 0 0 1 0 0\n";
372        testandcout(test5_01->isDirectParentOf(Class(BaseObject)));
373        testandcout(test5_01->isDirectParentOf(Class(Interface1)));
374        testandcout(test5_01->isDirectParentOf(Class(A1)));
375        testandcout(test5_01->isDirectParentOf(Class(A2)));
376        testandcout(test5_01->isDirectParentOf(Class(A1B1)));
377        testandcout(test5_01->isDirectParentOf(Class(A2B2)));
378        testandcout(test5_01->isDirectParentOf(Class(A3B1C2)));
379
380        std::cout << "\n";
381        std::cout << "Interface1, Erwartet: 0 0 0 0 0 1 0\n";
382        testandcout(Class(Interface1)->isDirectParentOf(Class(BaseObject)));
383        testandcout(Class(Interface1)->isDirectParentOf(Class(Interface1)));
384        testandcout(Class(Interface1)->isDirectParentOf(Class(A1)));
385        testandcout(Class(Interface1)->isDirectParentOf(Class(A2)));
386        testandcout(Class(Interface1)->isDirectParentOf(Class(A1B1)));
387        testandcout(Class(Interface1)->isDirectParentOf(Class(A2B2)));
388        testandcout(Class(Interface1)->isDirectParentOf(Class(A3B1C2)));
389*/
390/*
391        std::cout << "Test 6\n";
392        std::cout << "1:\n";
393        Identifier* test6_01 = Class(A1B1);
394        std::cout << "2:\n";
395        Identifier* test6_02 = Class(A1B1);
396        std::cout << "3:\n";
397        Identifier* test6_03 = Class(A1);
398        std::cout << "4:\n";
399        Identifier* test6_04 = Class(A1B1C1);
400        std::cout << "5:\n";
401        Identifier* test6_05 = Class(A1B1);
402        std::cout << "6:\n";
403        Identifier* test6_06 = Class(A1B1C1);
404*/
405/*
406        std::cout << "\n";
407        std::cout << "BaseObject: directParents:  " << Class(BaseObject)->getDirectParents()->toString() << "\n";
408        std::cout << "BaseObject: allParents:     " << Class(BaseObject)->getAllParents()->toString() << "\n";
409        std::cout << "BaseObject: directChildren: " << Class(BaseObject)->getDirectChildren()->toString() << "\n";
410        std::cout << "BaseObject: allChildren:    " << Class(BaseObject)->getAllChildren()->toString() << "\n";
411
412        std::cout << "\n";
413        std::cout << "A1: directParents:  " << Class(A1)->getDirectParents()->toString() << "\n";
414        std::cout << "A1: allParents:     " << Class(A1)->getAllParents()->toString() << "\n";
415        std::cout << "A1: directChildren: " << Class(A1)->getDirectChildren()->toString() << "\n";
416        std::cout << "A1: allChildren:    " << Class(A1)->getAllChildren()->toString() << "\n";
417
418        std::cout << "\n";
419        std::cout << "A1B1: directParents:  " << Class(A1B1)->getDirectParents()->toString() << "\n";
420        std::cout << "A1B1: allParents:     " << Class(A1B1)->getAllParents()->toString() << "\n";
421        std::cout << "A1B1: directChildren: " << Class(A1B1)->getDirectChildren()->toString() << "\n";
422        std::cout << "A1B1: allChildren:    " << Class(A1B1)->getAllChildren()->toString() << "\n";
423
424        std::cout << "\n";
425        std::cout << "A1B1C1: directParents:  " << Class(A1B1C1)->getDirectParents()->toString() << "\n";
426        std::cout << "A1B1C1: allParents:     " << Class(A1B1C1)->getAllParents()->toString() << "\n";
427        std::cout << "A1B1C1: directChildren: " << Class(A1B1C1)->getDirectChildren()->toString() << "\n";
428        std::cout << "A1B1C1: allChildren:    " << Class(A1B1C1)->getAllChildren()->toString() << "\n";
429
430        std::cout << "\n";
431        std::cout << "A3B1C1 child of A3:  " << Class(A3B1C1)->isChildOf(Class(A3)) << "\n";
432        std::cout << "\n";
433        std::cout << "A2 parent of A2B1C1: " << Class(A2)->isParentOf(Class(A2B1C1)) << "\n";
434*/
435
436      }
437
438      ~OrxApplication()
439      {
440        mInputManager->destroyInputObject(mKeyboard);
441        OIS::InputManager::destroyInputSystem(mInputManager);
442
443        delete mRenderer;
444        delete mSystem;
445
446        delete mListener;
447        delete mRoot;
448      }
449
450    private:
451      Ogre::Root *mRoot;
452      OIS::Keyboard *mKeyboard;
453      OIS::Mouse *mMouse;
454      OIS::InputManager *mInputManager;
455      CEGUI::OgreCEGUIRenderer *mRenderer;
456      CEGUI::System *mSystem;
457      OrxExitListener *mListener;
458
459      void createRoot()
460      {
461#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
462        mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg");
463#else
464        mRoot = new Ogre::Root();
465#endif
466      }
467
468      void defineResources()
469      {
470        Ogre::String secName, typeName, archName;
471        Ogre::ConfigFile cf;
472#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
473        cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");
474#else
475        cf.load("resources.cfg");
476#endif
477
478        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
479        while (seci.hasMoreElements())
480        {
481          secName = seci.peekNextKey();
482          Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
483          Ogre::ConfigFile::SettingsMultiMap::iterator i;
484          for (i = settings->begin(); i != settings->end(); ++i)
485          {
486            typeName = i->first;
487            archName = i->second;
488#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
489            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName);
490#else
491            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
492#endif
493          }
494        }
495      }
496
497      void setupRenderSystem()
498      {
499        if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())
500          throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");
501      }
502
503      void createRenderWindow()
504      {
505        mRoot->initialise(true, "Ogre Render Window");
506      }
507
508      void initializeResourceGroups()
509      {
510        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
511        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
512      }
513
514      void setupScene()
515      {
516        Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager");
517        Ogre::Camera *cam = mgr->createCamera("Camera");
518        Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
519      }
520
521      void setupInputSystem()
522      {
523        size_t windowHnd = 0;
524        std::ostringstream windowHndStr;
525        OIS::ParamList pl;
526        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
527
528        win->getCustomAttribute("WINDOW", &windowHnd);
529        windowHndStr << windowHnd;
530        pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
531        mInputManager = OIS::InputManager::createInputSystem(pl);
532
533        try
534        {
535          mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));
536          mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));
537        }
538        catch (const OIS::Exception &e)
539        {
540          throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem");
541        }
542      }
543
544      void setupCEGUI()
545      {
546        Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");
547        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
548
549        // CEGUI setup
550        mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr);
551        mSystem = new CEGUI::System(mRenderer);
552
553        // Other CEGUI setup here.
554      }
555
556      void createFrameListener()
557      {
558        mListener = new OrxExitListener(mKeyboard);
559        mRoot->addFrameListener(mListener);
560      }
561
562      void startRenderLoop()
563      {
564        mRoot->startRendering();
565      }
566  };
567}
568
569using namespace Ogre;
570
571#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
572#define WIN32_LEAN_AND_MEAN
573#include "windows.h"
574
575             INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
576#else
577             int main(int argc, char **argv)
578#endif
579{
580  try
581  {
582    orxonox::OrxApplication orxonox;
583    orxonox.go();
584  }
585  catch(Exception& e)
586  {
587#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
588    MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
589#else
590    fprintf(stderr, "An exception has occurred: %s\n",
591            e.getFullDescription().c_str());
592#endif
593  }
594
595  return 0;
596}
Note: See TracBrowser for help on using the repository browser.