Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 244 was 244, checked in by landauf, 12 years ago

reimplementation of the factory and parts of the class-hierarchy-generating-algorithm. interfaces with protected constructors are now allowed.

File size: 23.2 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 "IdentifierIncludes.h"
34#include "BaseObject.h"
35#include "Test.h"
36#include "test1.h"
37#include "test2.h"
38#include "test3.h"
39
40#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
41#include <CoreFoundation/CoreFoundation.h>
42
43// This function will locate the path to our application on OS X,
44// unlike windows you can not rely on the curent working directory
45// for locating your configuration files and resources.
46std::string macBundlePath()
47{
48  char path[1024];
49  CFBundleRef mainBundle = CFBundleGetMainBundle();
50  assert(mainBundle);
51
52  CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
53  assert(mainBundleURL);
54
55  CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
56  assert(cfStringRef);
57
58  CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
59
60  CFRelease(mainBundleURL);
61  CFRelease(cfStringRef);
62
63  return std::string(path);
64}
65#endif
66
67namespace orxonox
68{
69  class OrxExitListener : public Ogre::FrameListener
70  {
71    public:
72      OrxExitListener(OIS::Keyboard *keyboard)
73    : mKeyboard(keyboard)
74      {
75      }
76
77      bool frameStarted(const Ogre::FrameEvent& evt)
78      {
79        mKeyboard->capture();
80        return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
81      }
82
83    private:
84      OIS::Keyboard *mKeyboard;
85  };
86
87  class OrxApplication
88  {
89    public:
90      void go()
91      {
92/*
93        createRoot();
94        defineResources();
95        setupRenderSystem();
96        createRenderWindow();
97        initializeResourceGroups();
98        setupScene();
99        setupInputSystem();
100        setupCEGUI();
101        createFrameListener();
102        startRenderLoop();
103*/
104
105        #define testandcout(code) \
106          std::cout << #code << " " << code << "\n"
107
108/*
109        std::cout << "Test 1\n";
110        BaseObject* test1;
111        test1 = new BaseObject();
112        test1 = new BaseObject();
113        test1 = new BaseObject();
114
115        std::cout << "Test 2\n";
116        A1* test2;
117        test2 = new A1();
118        test2 = new A1();
119        test2 = new A1();
120
121        std::cout << "Test 3\n";
122        BaseObject* test3;
123        test3 = new BaseObject();
124        test3 = new BaseObject();
125        test3 = new BaseObject();
126
127        std::cout << "Test 4\n";
128        A3* test4;
129        test4 = new A3();
130        test4 = new A3();
131        test4 = new A3();
132*/
133/*
134        std::cout << "Test 5\n";
135        A1* test5_01 = new A1();
136        A2* test5_02 = new A2();
137        A3* test5_03 = new A3();
138        A1B1* test5_04 = new A1B1();
139        A1B2* test5_05 = new A1B2();
140        A2B1* test5_06 = new A2B1();
141        A2B2* test5_07 = new A2B2();
142        A3B1* test5_08 = new A3B1();
143        A3B2* test5_09 = new A3B2();
144        A1B1C1* test5_10 = new A1B1C1();
145        A1B1C2* test5_11 = new A1B1C2();
146        A1B2C1* test5_12 = new A1B2C1();
147        A2B1C1* test5_13 = new A2B1C1();
148        A2B2C1* test5_14 = new A2B2C1();
149        A3B1C1* test5_15 = new A3B1C1();
150        A3B1C2* test5_16 = new A3B1C2();
151        A3B2C1* test5_17 = new A3B2C1();
152        A3B2C2* test5_18 = new A3B2C2();
153
154        OrxonoxClass* test5;
155        for (int i = 0; i <= 18; i++)
156        {
157          if (i == 0) test5 = new BaseObject;
158          if (i == 1) test5 = test5_01;
159          if (i == 2) test5 = test5_02;
160          if (i == 3) test5 = test5_03;
161          if (i == 4) test5 = test5_04;
162          if (i == 5) test5 = test5_05;
163          if (i == 6) test5 = test5_06;
164          if (i == 7) test5 = test5_07;
165          if (i == 8) test5 = test5_08;
166          if (i == 9) test5 = test5_09;
167          if (i == 10) test5 = test5_10;
168          if (i == 11) test5 = test5_11;
169          if (i == 12) test5 = test5_12;
170          if (i == 13) test5 = test5_13;
171          if (i == 14) test5 = test5_14;
172          if (i == 15) test5 = test5_15;
173          if (i == 16) test5 = test5_16;
174          if (i == 17) test5 = test5_17;
175          if (i == 18) test5 = test5_18;
176
177          std::cout << "\n";
178          std::cout << test5->getIdentifier()->getName() << ": parents:     " << test5->getIdentifier()->getParents().toString() << "\n";
179          std::cout << test5->getIdentifier()->getName() << ": children:    " << test5->getIdentifier()->getChildren().toString() << "\n";
180        }
181*/
182/*
183        std::cout << "\n";
184        std::cout << "isA(XYZ)-Test:\n";
185        std::cout << "test5_01 = A1, Erwartet: 1 0 0 1 0\n";
186        testandcout(test5_01->isA(Class(A1)));
187        testandcout(test5_01->isA(Class(A2)));
188        testandcout(test5_01->isA(Class(A1B1)));
189        testandcout(test5_01->isA(Class(BaseObject)));
190        testandcout(test5_01->isA(Class(Interface1)));
191
192        std::cout << "\n";
193        std::cout << "test5_02 = A2, Erwartet: 0 1 0 1 0\n";
194        testandcout(test5_02->isA(Class(A1)));
195        testandcout(test5_02->isA(Class(A2)));
196        testandcout(test5_02->isA(Class(A1B1)));
197        testandcout(test5_02->isA(Class(BaseObject)));
198        testandcout(test5_02->isA(Class(Interface1)));
199
200        std::cout << "\n";
201        std::cout << "test5_01 = A3, Erwartet: 0 0 0 1 1\n";
202        testandcout(test5_03->isA(Class(A1)));
203        testandcout(test5_03->isA(Class(A2)));
204        testandcout(test5_03->isA(Class(A1B1)));
205        testandcout(test5_03->isA(Class(BaseObject)));
206        testandcout(test5_03->isA(Class(Interface1)));
207
208        std::cout << "\n";
209        std::cout << "isDirectA(XYZ)-Test:\n";
210        std::cout << "test5_01 = A1, Erwartet: 1 0 0 0 0\n";
211        testandcout(test5_01->isDirectlyA(Class(A1)));
212        testandcout(test5_01->isDirectlyA(Class(A2)));
213        testandcout(test5_01->isDirectlyA(Class(A1B1)));
214        testandcout(test5_01->isDirectlyA(Class(BaseObject)));
215        testandcout(test5_01->isDirectlyA(Class(Interface1)));
216
217        std::cout << "\n";
218        std::cout << "test5_02 = A2, Erwartet: 0 1 0 0 0\n";
219        testandcout(test5_02->isDirectlyA(Class(A1)));
220        testandcout(test5_02->isDirectlyA(Class(A2)));
221        testandcout(test5_02->isDirectlyA(Class(A1B1)));
222        testandcout(test5_02->isDirectlyA(Class(BaseObject)));
223        testandcout(test5_02->isDirectlyA(Class(Interface1)));
224
225        std::cout << "\n";
226        std::cout << "test5_03 = A3, Erwartet: 0 0 0 0 0\n";
227        testandcout(test5_03->isDirectlyA(Class(A1)));
228        testandcout(test5_03->isDirectlyA(Class(A2)));
229        testandcout(test5_03->isDirectlyA(Class(A1B1)));
230        testandcout(test5_03->isDirectlyA(Class(BaseObject)));
231        testandcout(test5_03->isDirectlyA(Class(Interface1)));
232
233        std::cout << "\n";
234        std::cout << "isChildOf(XYZ)-Test:\n";
235        std::cout << "test5_04 = A1B1, Erwartet: 1 0 1 0 0 0 0\n";
236        testandcout(test5_04->isChildOf(Class(A1)));
237        testandcout(test5_04->isChildOf(Class(A2)));
238        testandcout(test5_04->isChildOf(Class(BaseObject)));
239        testandcout(test5_04->isChildOf(Class(Interface1)));
240        testandcout(test5_04->isChildOf(Class(Interface2)));
241        testandcout(test5_04->isChildOf(Class(A1B1C2)));
242        testandcout(test5_04->isChildOf(Class(A1B1)));
243
244        std::cout << "\n";
245        std::cout << "test5_06 = A2B1, Erwartet: 0 1 1 0 0 0 0\n";
246        testandcout(test5_06->isChildOf(Class(A1)));
247        testandcout(test5_06->isChildOf(Class(A2)));
248        testandcout(test5_06->isChildOf(Class(BaseObject)));
249        testandcout(test5_06->isChildOf(Class(Interface1)));
250        testandcout(test5_06->isChildOf(Class(Interface2)));
251        testandcout(test5_06->isChildOf(Class(A1B1C2)));
252        testandcout(test5_06->isChildOf(Class(A1B1)));
253
254        std::cout << "\n";
255        std::cout << "test5_07 = A2B2, Erwartet: 0 1 1 1 0 0\n";
256        testandcout(test5_07->isChildOf(Class(A1)));
257        testandcout(test5_07->isChildOf(Class(A2)));
258        testandcout(test5_07->isChildOf(Class(BaseObject)));
259        testandcout(test5_07->isChildOf(Class(Interface1)));
260        testandcout(test5_07->isChildOf(Class(Interface2)));
261        testandcout(test5_07->isChildOf(Class(A1B1C2)));
262
263        std::cout << "\n";
264        std::cout << "test5_08 = A3B1, Erwartet: 0 0 1 1 0 0\n";
265        testandcout(test5_08->isChildOf(Class(A1)));
266        testandcout(test5_08->isChildOf(Class(A2)));
267        testandcout(test5_08->isChildOf(Class(BaseObject)));
268        testandcout(test5_08->isChildOf(Class(Interface1)));
269        testandcout(test5_08->isChildOf(Class(Interface2)));
270        testandcout(test5_08->isChildOf(Class(A1B1C2)));
271
272        std::cout << "\n";
273        std::cout << "test5_09 = A3B2, Erwartet: 0 0 1 1 1 0\n";
274        testandcout(test5_09->isChildOf(Class(A1)));
275        testandcout(test5_09->isChildOf(Class(A2)));
276        testandcout(test5_09->isChildOf(Class(BaseObject)));
277        testandcout(test5_09->isChildOf(Class(Interface1)));
278        testandcout(test5_09->isChildOf(Class(Interface2)));
279        testandcout(test5_09->isChildOf(Class(A1B1C2)));
280
281        std::cout << "\n";
282        std::cout << "isParentOf(XYZ)-Test:\n";
283        std::cout << "test1 = BaseObject, Erwartet: 0 0 1 1 1 1 1\n";
284        testandcout(test1->isParentOf(Class(BaseObject)));
285        testandcout(test1->isParentOf(Class(Interface1)));
286        testandcout(test1->isParentOf(Class(A1)));
287        testandcout(test1->isParentOf(Class(A2)));
288        testandcout(test1->isParentOf(Class(A1B1)));
289        testandcout(test1->isParentOf(Class(A2B2)));
290        testandcout(test1->isParentOf(Class(A3B1C2)));
291
292        std::cout << "\n";
293        std::cout << "test5_01 = A1, Erwartet: 0 0 0 0 1 0 0\n";
294        testandcout(test5_01->isParentOf(Class(BaseObject)));
295        testandcout(test5_01->isParentOf(Class(Interface1)));
296        testandcout(test5_01->isParentOf(Class(A1)));
297        testandcout(test5_01->isParentOf(Class(A2)));
298        testandcout(test5_01->isParentOf(Class(A1B1)));
299        testandcout(test5_01->isParentOf(Class(A2B2)));
300        testandcout(test5_01->isParentOf(Class(A3B1C2)));
301
302        std::cout << "\n";
303        std::cout << "Interface1, Erwartet: 0 0 0 0 0 1 1\n";
304        testandcout(Class(Interface1)->isParentOf(Class(BaseObject)));
305        testandcout(Class(Interface1)->isParentOf(Class(Interface1)));
306        testandcout(Class(Interface1)->isParentOf(Class(A1)));
307        testandcout(Class(Interface1)->isParentOf(Class(A2)));
308        testandcout(Class(Interface1)->isParentOf(Class(A1B1)));
309        testandcout(Class(Interface1)->isParentOf(Class(A2B2)));
310        testandcout(Class(Interface1)->isParentOf(Class(A3B1C2)));
311*/
312/*
313        std::cout << "Test 6\n";
314        std::cout << "1:\n";
315        Identifier* test6_01 = Class(A1B1);
316        std::cout << "2:\n";
317        Identifier* test6_02 = Class(A1B1);
318        std::cout << "3:\n";
319        Identifier* test6_03 = Class(A1);
320        std::cout << "4:\n";
321        Identifier* test6_04 = Class(A1B1C1);
322        std::cout << "5:\n";
323        Identifier* test6_05 = Class(A1B1);
324        std::cout << "6:\n";
325        Identifier* test6_06 = Class(A1B1C1);
326
327        std::cout << "\n";
328        std::cout << "BaseObject: parents:     " << Class(BaseObject)->getParents().toString() << "\n";
329        std::cout << "BaseObject: children:    " << Class(BaseObject)->getChildren().toString() << "\n";
330
331        std::cout << "\n";
332        std::cout << "A1: parents:     " << Class(A1)->getParents().toString() << "\n";
333        std::cout << "A1: children:    " << Class(A1)->getChildren().toString() << "\n";
334
335        std::cout << "\n";
336        std::cout << "A1B1: parents:     " << Class(A1B1)->getParents().toString() << "\n";
337        std::cout << "A1B1: children:    " << Class(A1B1)->getChildren().toString() << "\n";
338
339        std::cout << "\n";
340        std::cout << "A1B1C1: parents:     " << Class(A1B1C1)->getParents().toString() << "\n";
341        std::cout << "A1B1C1: children:    " << Class(A1B1C1)->getChildren().toString() << "\n";
342
343        std::cout << "\n";
344        std::cout << "A3B1C1 child of A3:  " << Class(A3B1C1)->isChildOf(Class(A3)) << "\n";
345        std::cout << "\n";
346        std::cout << "A2 parent of A2B1C1: " << Class(A2)->isParentOf(Class(A2B1C1)) << "\n";
347*/
348/*
349        std::cout << "Test 7\n";
350        std::cout << "1\n";
351        SubclassIdentifier<A1B1> test7_01;
352        test7_01 = Class(A1B1C1);
353
354        SubclassIdentifier<A1B1> test7_02;
355        test7_02 = Class(A1B1);
356
357        std::cout << test7_01->getName() << "\n";
358        std::cout << test7_02->getName() << "\n";
359*/
360/*
361        std::cout << "2\n";
362
363        SubclassIdentifier<A1B1> test7_03;
364        test7_03 = Class(A1);
365
366        SubclassIdentifier<A1B1> test7_04;
367        test7_04 = Class(A1B2);
368
369        SubclassIdentifier<A1B1> test7_05;
370        test7_05 = Class(A2);
371*/
372/*
373        std::cout << "Test 8\n";
374
375        std::cout << "1\n";
376        Test1* test8_01 = new Test1;
377        Test3* test8_03 = new Test3;
378        test8_03->usefullClassesIsATest(test8_01);
379
380        std::cout << "2\n";
381        Test2* test8_02 = new Test2;
382        test8_03->usefullClassesIsATest(test8_02);
383
384        std::cout << "3\n";
385        test8_01->setUsefullClass1(Class(Test1));
386        test8_01->setUsefullClass1(test8_02->getIdentifier());
387        test8_01->setUsefullClass2(Class(Test2));
388        test8_01->setUsefullClassOfTypeTest3(Class(Test3));
389        test8_01->setUsefullClassOfTypeTest3(test8_03->getIdentifier());
390
391
392        testandcout(test8_01->isA(Class(Test1)));
393        testandcout(test8_01->isA(Class(Test2)));
394        testandcout(test8_01->isA(Class(Test3)));
395
396        Test2* test8_04 = new Test2;
397        testandcout(test8_02->isA(Class(Test1)));
398        testandcout(test8_02->isA(Class(Test2)));
399        testandcout(test8_02->isA(Class(Test3)));
400
401        Test3* test8_05 = new Test3;
402        testandcout(test8_03->isA(Class(Test1)));
403        testandcout(test8_03->isA(Class(Test2)));
404        testandcout(test8_03->isA(Class(Test3)));
405
406        delete test8_01;
407        delete test8_02;
408        delete test8_03;
409*/
410/*
411        std::cout << "Test 9\n";
412        std::cout << "1\n";
413        Identifier* test9_01 = Class(A3);
414        BaseObject* test9_02 = test9_01->fabricate();
415        std::cout << test9_02->getIdentifier()->getName() << "\n";
416
417        std::cout << "\n2\n";
418        BaseObject* test9_03 = Class(A1B2)->fabricate();
419        std::cout << test9_03->getIdentifier()->getName() << "\n";
420
421        std::cout << "\n3\n";
422        SubclassIdentifier<A1> test9_04;
423        test9_04 = Class(A1B1C1);
424        A1* test9_05 = test9_04.fabricate();
425        std::cout << test9_05->getIdentifier()->getName() << "\n";
426
427        std::cout << "\n4\n";
428        BaseObject* test9_06 = ID("A2B2")->fabricate();
429        std::cout << test9_06->getIdentifier()->getName() << "\n";
430
431        std::cout << "\n5\n";
432        delete test9_02;
433        delete test9_03;
434        delete test9_05;
435        delete test9_06;
436*/
437/*
438        std::cout << "Test 10\n";
439        Identifier* test10_01 = Class(A1B2);
440        Identifier* test10_02 = Class(A2);
441        Identifier* test10_03 = Class(A3B1C1);
442
443
444        BaseObject* test10_04 = test10_01->fabricate();
445        BaseObject* test10_05 = test10_02->fabricate();
446        BaseObject* test10_06 = test10_03->fabricate();
447
448        BaseObject* test10_07;
449        for (int i = 0; i < 10; i++)
450            test10_07 = ID("A1B1C1")->fabricate();
451
452        std::cout << "1\n";
453        int count = 0;
454        for (Iterator<BaseObject> it; it != 0; ++it)
455            count++;
456        std::cout << "Anzahl BaseObjects: " << count << "\n";
457
458        count = 0;
459        for (Iterator<A1> it; it != 0; ++it)
460            count++;
461        std::cout << "Anzahl A1: " << count << "\n";
462
463        count = 0;
464        for (Iterator<A1B1> it; it; ++it)
465            count++;
466        std::cout << "Anzahl A1B1: " << count << "\n";
467
468        count = 0;
469        for (Iterator<A1B1C1> it; it; ++it)
470            count++;
471        std::cout << "Anzahl A1B1C1: " << count << "\n";
472
473        count = 0;
474        for (Iterator<A2> it; it; ++it)
475            count++;
476        std::cout << "Anzahl A2: " << count << "\n";
477
478
479        std::cout << "2\n";
480        BaseObject* test10_08;
481        BaseObject* test10_09;
482        BaseObject* test10_10;
483        for (int i = 0; i < 10; i++)
484        {
485            test10_08 = ID("A2B1C1")->fabricate();
486            test10_08->name_ = "A2B1C1#";
487            test10_08->name_ += ('0' + i);
488
489            if (i == 0)
490                test10_09 = test10_08;
491
492            if (i == 5)
493                test10_10 = test10_08;
494        }
495
496        for (Iterator<A2B1C1> it; it; ++it)
497            std::cout << "Name: " << it->name_ << "\n";
498
499        std::cout << "3\n";
500        for (Iterator<A2B1C1> it; it; --it)
501            std::cout << "Name: " << it->name_ << "\n";
502
503        std::cout << "4\n";
504        delete test10_08;
505
506        std::cout << "5\n";
507        for (Iterator<A2B1C1> it; it; ++it)
508            std::cout << "Name: " << it->name_ << "\n";
509
510        std::cout << "6\n";
511        for (Iterator<A2B1C1> it; it; --it)
512            std::cout << "Name: " << it->name_ << "\n";
513
514        std::cout << "7\n";
515        delete test10_09;
516
517        std::cout << "8\n";
518        for (Iterator<A2B1C1> it; it; ++it)
519            std::cout << "Name: " << it->name_ << "\n";
520
521        std::cout << "9\n";
522        for (Iterator<A2B1C1> it; it; --it)
523            std::cout << "Name: " << it->name_ << "\n";
524
525        std::cout << "10\n";
526        delete test10_10;
527
528        std::cout << "11\n";
529        for (Iterator<A2B1C1> it; it; ++it)
530            std::cout << "Name: " << it->name_ << "\n";
531
532        std::cout << "12\n";
533        for (Iterator<A2B1C1> it; it; --it)
534            std::cout << "Name: " << it->name_ << "\n";
535*/
536
537      }
538
539      ~OrxApplication()
540      {
541        mInputManager->destroyInputObject(mKeyboard);
542        OIS::InputManager::destroyInputSystem(mInputManager);
543
544        delete mRenderer;
545        delete mSystem;
546
547        delete mListener;
548        delete mRoot;
549      }
550
551    private:
552      Ogre::Root *mRoot;
553      OIS::Keyboard *mKeyboard;
554      OIS::Mouse *mMouse;
555      OIS::InputManager *mInputManager;
556      CEGUI::OgreCEGUIRenderer *mRenderer;
557      CEGUI::System *mSystem;
558      OrxExitListener *mListener;
559
560      void createRoot()
561      {
562#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
563        mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg");
564#else
565        mRoot = new Ogre::Root();
566#endif
567      }
568
569      void defineResources()
570      {
571        Ogre::String secName, typeName, archName;
572        Ogre::ConfigFile cf;
573#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
574        cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");
575#else
576        cf.load("resources.cfg");
577#endif
578
579        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
580        while (seci.hasMoreElements())
581        {
582          secName = seci.peekNextKey();
583          Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
584          Ogre::ConfigFile::SettingsMultiMap::iterator i;
585          for (i = settings->begin(); i != settings->end(); ++i)
586          {
587            typeName = i->first;
588            archName = i->second;
589#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
590            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName);
591#else
592            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
593#endif
594          }
595        }
596      }
597
598      void setupRenderSystem()
599      {
600        if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())
601          throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");
602      }
603
604      void createRenderWindow()
605      {
606        mRoot->initialise(true, "Ogre Render Window");
607      }
608
609      void initializeResourceGroups()
610      {
611        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
612        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
613      }
614
615      void setupScene()
616      {
617        Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager");
618        Ogre::Camera *cam = mgr->createCamera("Camera");
619        Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
620      }
621
622      void setupInputSystem()
623      {
624        size_t windowHnd = 0;
625        std::ostringstream windowHndStr;
626        OIS::ParamList pl;
627        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
628
629        win->getCustomAttribute("WINDOW", &windowHnd);
630        windowHndStr << windowHnd;
631        pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
632        mInputManager = OIS::InputManager::createInputSystem(pl);
633
634        try
635        {
636          mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));
637          mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));
638        }
639        catch (const OIS::Exception &e)
640        {
641          throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem");
642        }
643      }
644
645      void setupCEGUI()
646      {
647        Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");
648        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
649
650        // CEGUI setup
651        mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr);
652        mSystem = new CEGUI::System(mRenderer);
653
654        // Other CEGUI setup here.
655      }
656
657      void createFrameListener()
658      {
659        mListener = new OrxExitListener(mKeyboard);
660        mRoot->addFrameListener(mListener);
661      }
662
663      void startRenderLoop()
664      {
665        mRoot->startRendering();
666      }
667  };
668}
669
670using namespace Ogre;
671
672#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
673#define WIN32_LEAN_AND_MEAN
674#include "windows.h"
675
676             INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
677#else
678             int main(int argc, char **argv)
679#endif
680{
681  try
682  {
683    orxonox::OrxApplication orxonox;
684    orxonox.go();
685  }
686  catch(Exception& e)
687  {
688#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
689    MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
690#else
691    fprintf(stderr, "An exception has occurred: %s\n",
692            e.getFullDescription().c_str());
693#endif
694  }
695
696  return 0;
697}
Note: See TracBrowser for help on using the repository browser.