Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/orxonox.cc @ 434

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

added a config-file-parser and a makro ( SetConfigValue(variable, defaultvalue) ) to get user-modified values from the config-file (or to write the defaultvalue into it if the variable isn't yet in the file).

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