Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 246 was 246, checked in by landauf, 16 years ago

added "MetaObjectList", containing the list-element of the ObjectList of all classes an object is registered in. this allowes much faster deleting of objects.

File size: 25.6 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        BaseObject* test10_04 = test10_01->fabricate();
444        BaseObject* test10_05 = test10_02->fabricate();
445        BaseObject* test10_06 = test10_03->fabricate();
446
447        BaseObject* test10_07;
448        for (int i = 0; i < 10; i++)
449            test10_07 = ID("A1B1C1")->fabricate();
450
451        std::cout << "1\n";
452        int count;
453        count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
454        std::cout << "Anzahl BaseObjects: " << count << "\n";
455        count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
456        std::cout << "Anzahl A1: " << count << "\n";
457        count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
458        std::cout << "Anzahl A1B1: " << count << "\n";
459        count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
460        std::cout << "Anzahl A1B1C1: " << count << "\n";
461        count = 0; for (Iterator<A2> it; it; ++it) { count++; }
462        std::cout << "Anzahl A2: " << count << "\n";
463
464        std::cout << "2\n";
465        BaseObject* test10_08;
466        BaseObject* test10_09;
467        BaseObject* test10_10;
468        for (int i = 0; i < 10; i++)
469        {
470            test10_08 = ID("A2B1C1")->fabricate();
471            test10_08->name_ = "A2B1C1#";
472            test10_08->name_ += ('0' + i);
473
474            if (i == 0)
475                test10_09 = test10_08;
476
477            if (i == 5)
478                test10_10 = test10_08;
479        }
480
481        count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
482        std::cout << "Anzahl BaseObjects: " << count << "\n";
483        count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
484        std::cout << "Anzahl A1: " << count << "\n";
485        count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
486        std::cout << "Anzahl A1B1: " << count << "\n";
487        count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
488        std::cout << "Anzahl A1B1C1: " << count << "\n";
489        count = 0; for (Iterator<A2> it; it; ++it) { count++; }
490        std::cout << "Anzahl A2: " << count << "\n";
491
492        for (Iterator<A2B1C1> it; it; ++it)
493            std::cout << "Name: " << it->name_ << "\n";
494
495        std::cout << "3\n";
496        for (Iterator<A2B1C1> it; it; --it)
497            std::cout << "Name: " << it->name_ << "\n";
498
499        std::cout << "4\n";
500        delete test10_08;
501
502        count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
503        std::cout << "Anzahl BaseObjects: " << count << "\n";
504        count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
505        std::cout << "Anzahl A1: " << count << "\n";
506        count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
507        std::cout << "Anzahl A1B1: " << count << "\n";
508        count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
509        std::cout << "Anzahl A1B1C1: " << count << "\n";
510        count = 0; for (Iterator<A2> it; it; ++it) { count++; }
511        std::cout << "Anzahl A2: " << count << "\n";
512
513        std::cout << "5\n";
514        for (Iterator<A2B1C1> it; it; ++it)
515            std::cout << "Name: " << it->name_ << "\n";
516
517        std::cout << "6\n";
518        for (Iterator<A2B1C1> it; it; --it)
519            std::cout << "Name: " << it->name_ << "\n";
520
521        std::cout << "7\n";
522        delete test10_09;
523
524        count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
525        std::cout << "Anzahl BaseObjects: " << count << "\n";
526        count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
527        std::cout << "Anzahl A1: " << count << "\n";
528        count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
529        std::cout << "Anzahl A1B1: " << count << "\n";
530        count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
531        std::cout << "Anzahl A1B1C1: " << count << "\n";
532        count = 0; for (Iterator<A2> it; it; ++it) { count++; }
533        std::cout << "Anzahl A2: " << count << "\n";
534
535        std::cout << "8\n";
536        for (Iterator<A2B1C1> it; it; ++it)
537            std::cout << "Name: " << it->name_ << "\n";
538
539        std::cout << "9\n";
540        for (Iterator<A2B1C1> it; it; --it)
541            std::cout << "Name: " << it->name_ << "\n";
542
543        std::cout << "10\n";
544        delete test10_10;
545
546        count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
547        std::cout << "Anzahl BaseObjects: " << count << "\n";
548        count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
549        std::cout << "Anzahl A1: " << count << "\n";
550        count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
551        std::cout << "Anzahl A1B1: " << count << "\n";
552        count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
553        std::cout << "Anzahl A1B1C1: " << count << "\n";
554        count = 0; for (Iterator<A2> it; it; ++it) { count++; }
555        std::cout << "Anzahl A2: " << count << "\n";
556
557        std::cout << "11\n";
558        for (Iterator<A2B1C1> it; it; ++it)
559            std::cout << "Name: " << it->name_ << "\n";
560
561        std::cout << "12\n";
562        for (Iterator<A2B1C1> it; it; --it)
563            std::cout << "Name: " << it->name_ << "\n";
564*/
565
566      }
567
568      ~OrxApplication()
569      {
570        mInputManager->destroyInputObject(mKeyboard);
571        OIS::InputManager::destroyInputSystem(mInputManager);
572
573        delete mRenderer;
574        delete mSystem;
575
576        delete mListener;
577        delete mRoot;
578      }
579
580    private:
581      Ogre::Root *mRoot;
582      OIS::Keyboard *mKeyboard;
583      OIS::Mouse *mMouse;
584      OIS::InputManager *mInputManager;
585      CEGUI::OgreCEGUIRenderer *mRenderer;
586      CEGUI::System *mSystem;
587      OrxExitListener *mListener;
588
589      void createRoot()
590      {
591#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
592        mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg");
593#else
594        mRoot = new Ogre::Root();
595#endif
596      }
597
598      void defineResources()
599      {
600        Ogre::String secName, typeName, archName;
601        Ogre::ConfigFile cf;
602#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
603        cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");
604#else
605        cf.load("resources.cfg");
606#endif
607
608        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
609        while (seci.hasMoreElements())
610        {
611          secName = seci.peekNextKey();
612          Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
613          Ogre::ConfigFile::SettingsMultiMap::iterator i;
614          for (i = settings->begin(); i != settings->end(); ++i)
615          {
616            typeName = i->first;
617            archName = i->second;
618#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
619            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName);
620#else
621            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
622#endif
623          }
624        }
625      }
626
627      void setupRenderSystem()
628      {
629        if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())
630          throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");
631      }
632
633      void createRenderWindow()
634      {
635        mRoot->initialise(true, "Ogre Render Window");
636      }
637
638      void initializeResourceGroups()
639      {
640        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
641        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
642      }
643
644      void setupScene()
645      {
646        Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager");
647        Ogre::Camera *cam = mgr->createCamera("Camera");
648        Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
649      }
650
651      void setupInputSystem()
652      {
653        size_t windowHnd = 0;
654        std::ostringstream windowHndStr;
655        OIS::ParamList pl;
656        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
657
658        win->getCustomAttribute("WINDOW", &windowHnd);
659        windowHndStr << windowHnd;
660        pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
661        mInputManager = OIS::InputManager::createInputSystem(pl);
662
663        try
664        {
665          mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));
666          mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));
667        }
668        catch (const OIS::Exception &e)
669        {
670          throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem");
671        }
672      }
673
674      void setupCEGUI()
675      {
676        Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");
677        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
678
679        // CEGUI setup
680        mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr);
681        mSystem = new CEGUI::System(mRenderer);
682
683        // Other CEGUI setup here.
684      }
685
686      void createFrameListener()
687      {
688        mListener = new OrxExitListener(mKeyboard);
689        mRoot->addFrameListener(mListener);
690      }
691
692      void startRenderLoop()
693      {
694        mRoot->startRendering();
695      }
696  };
697}
698
699using namespace Ogre;
700
701#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
702#define WIN32_LEAN_AND_MEAN
703#include "windows.h"
704
705             INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
706#else
707             int main(int argc, char **argv)
708#endif
709{
710  try
711  {
712    orxonox::OrxApplication orxonox;
713    orxonox.go();
714  }
715  catch(Exception& e)
716  {
717#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
718    MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
719#else
720    fprintf(stderr, "An exception has occurred: %s\n",
721            e.getFullDescription().c_str());
722#endif
723  }
724
725  return 0;
726}
Note: See TracBrowser for help on using the repository browser.