Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added NetworkID

File size: 28.4 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/BaseObject.h"
46#include "objects/Test.h"
47#include "objects/test1.h"
48#include "objects/test2.h"
49#include "objects/test3.h"
50
51
52// some tests to see if enet works without includsion
53//#include <enet/enet.h>
54//#include <enet/protocol.h>
55
56#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
57#include <CoreFoundation/CoreFoundation.h>
58
59// This function will locate the path to our application on OS X,
60// unlike windows you can not rely on the curent working directory
61// for locating your configuration files and resources.
62std::string macBundlePath()
63{
64  char path[1024];
65  CFBundleRef mainBundle = CFBundleGetMainBundle();
66  assert(mainBundle);
67
68  CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
69  assert(mainBundleURL);
70
71  CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
72  assert(cfStringRef);
73
74  CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
75
76  CFRelease(mainBundleURL);
77  CFRelease(cfStringRef);
78
79  return std::string(path);
80}
81#endif
82
83namespace orxonox
84{
85  class OrxExitListener : public Ogre::FrameListener
86  {
87    public:
88      OrxExitListener(OIS::Keyboard *keyboard)
89    : mKeyboard(keyboard)
90      {
91      }
92
93      bool frameStarted(const Ogre::FrameEvent& evt)
94      {
95        mKeyboard->capture();
96        return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
97      }
98
99    private:
100      OIS::Keyboard *mKeyboard;
101  };
102
103  class OrxApplication
104  {
105    public:
106      void go()
107      {
108/*
109        createRoot();
110        defineResources();
111        setupRenderSystem();
112        createRenderWindow();
113        initializeResourceGroups();
114        createScene();
115        setupScene();
116        setupInputSystem();
117        setupCEGUI();
118        createFrameListener();
119        startRenderLoop();
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            test10_08->name_ = "A2B1C1#";
512            test10_08->name_ += ('0' + i);
513
514            if (i == 0)
515                test10_09 = test10_08;
516
517            if (i == 5)
518                test10_10 = test10_08;
519        }
520
521        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
522        std::cout << "Anzahl BaseObjects: " << count << "\n";
523        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
524        std::cout << "Anzahl A1: " << count << "\n";
525        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
526        std::cout << "Anzahl A1B1: " << count << "\n";
527        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; }
528        std::cout << "Anzahl A1B1C1: " << count << "\n";
529        count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; }
530        std::cout << "Anzahl A2: " << count << "\n";
531
532        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
533            std::cout << "Name: " << it->name_ << "\n";
534
535        std::cout << "3\n";
536        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
537            std::cout << "Name: " << it->name_ << "\n";
538
539        std::cout << "4\n";
540        delete test10_08;
541
542        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
543        std::cout << "Anzahl BaseObjects: " << count << "\n";
544        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
545        std::cout << "Anzahl A1: " << count << "\n";
546        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
547        std::cout << "Anzahl A1B1: " << count << "\n";
548        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; }
549        std::cout << "Anzahl A1B1C1: " << count << "\n";
550        count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; }
551        std::cout << "Anzahl A2: " << count << "\n";
552
553        std::cout << "5\n";
554        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
555            std::cout << "Name: " << it->name_ << "\n";
556
557        std::cout << "6\n";
558        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
559            std::cout << "Name: " << it->name_ << "\n";
560
561        std::cout << "7\n";
562        delete test10_09;
563
564        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::end(); it != 0; --it) { count++; }
565        std::cout << "Anzahl BaseObjects: " << count << "\n";
566        count = 0; for (Iterator<A1> it = ObjectList<A1>::end(); it != 0; --it) { count++; }
567        std::cout << "Anzahl A1: " << count << "\n";
568        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::end(); it; --it) { count++; }
569        std::cout << "Anzahl A1B1: " << count << "\n";
570        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::end(); it; --it) { count++; }
571        std::cout << "Anzahl A1B1C1: " << count << "\n";
572        count = 0; for (Iterator<A2> it = ObjectList<A2>::end(); it; --it) { count++; }
573        std::cout << "Anzahl A2: " << count << "\n";
574
575        std::cout << "8\n";
576        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
577            std::cout << "Name: " << it->name_ << "\n";
578
579        std::cout << "9\n";
580        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
581            std::cout << "Name: " << it->name_ << "\n";
582
583        std::cout << "10\n";
584        delete test10_10;
585
586        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
587        std::cout << "Anzahl BaseObjects: " << count << "\n";
588        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
589        std::cout << "Anzahl A1: " << count << "\n";
590        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
591        std::cout << "Anzahl A1B1: " << count << "\n";
592        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; }
593        std::cout << "Anzahl A1B1C1: " << count << "\n";
594        count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; }
595        std::cout << "Anzahl A2: " << count << "\n";
596
597        std::cout << "11\n";
598        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
599            std::cout << "Name: " << it->name_ << "\n";
600
601        std::cout << "12\n";
602        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
603            std::cout << "Name: " << it->name_ << "\n";
604
605        std::cout << "13\n";
606*/
607      }
608
609      ~OrxApplication()
610      {
611        mInputManager->destroyInputObject(mKeyboard);
612        OIS::InputManager::destroyInputSystem(mInputManager);
613
614//        delete mRenderer;
615//        delete mSystem;
616
617        delete mListener;
618        delete mRoot;
619      }
620
621    private:
622      Ogre::Root *mRoot;
623      OIS::Keyboard *mKeyboard;
624      OIS::Mouse *mMouse;
625      OIS::InputManager *mInputManager;
626      CEGUI::OgreCEGUIRenderer *mRenderer;
627      CEGUI::System *mSystem;
628      OrxExitListener *mListener;
629
630      void createRoot()
631      {
632#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
633        mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg");
634#else
635        mRoot = new Ogre::Root();
636#endif
637      }
638
639      void defineResources()
640      {
641        Ogre::String secName, typeName, archName;
642        Ogre::ConfigFile cf;
643#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
644        cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");
645#else
646        cf.load("resources.cfg");
647#endif
648
649        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
650        while (seci.hasMoreElements())
651        {
652          secName = seci.peekNextKey();
653          Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
654          Ogre::ConfigFile::SettingsMultiMap::iterator i;
655          for (i = settings->begin(); i != settings->end(); ++i)
656          {
657            typeName = i->first;
658            archName = i->second;
659#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
660            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName);
661#else
662            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
663#endif
664          }
665        }
666      }
667
668      void setupRenderSystem()
669      {
670        if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())
671          throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");
672      }
673
674      void createRenderWindow()
675      {
676        mRoot->initialise(true, "Ogre Render Window");
677      }
678
679      void initializeResourceGroups()
680      {
681        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
682        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
683      }
684
685      void createScene(void)
686      {
687
688        string levelFile = "sp_level_moonstation.oxw";
689        loader::LevelLoader* loader = new loader::LevelLoader(levelFile);
690      }
691
692      void setupScene()
693      {
694        Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager");
695        Ogre::Camera *cam = mgr->createCamera("Camera");
696        Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
697      }
698
699      void setupInputSystem()
700      {
701        size_t windowHnd = 0;
702        std::ostringstream windowHndStr;
703        OIS::ParamList pl;
704        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
705
706        win->getCustomAttribute("WINDOW", &windowHnd);
707        windowHndStr << windowHnd;
708        pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
709        mInputManager = OIS::InputManager::createInputSystem(pl);
710
711        try
712        {
713          mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));
714          mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));
715        }
716        catch (const OIS::Exception &e)
717        {
718          throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem");
719        }
720      }
721
722      void setupCEGUI()
723      {
724        Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");
725        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
726
727        // CEGUI setup
728//        mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr);
729//        mSystem = new CEGUI::System(mRenderer);
730
731        // Other CEGUI setup here.
732      }
733
734      void createFrameListener()
735      {
736        mListener = new OrxExitListener(mKeyboard);
737        mRoot->addFrameListener(mListener);
738      }
739
740      void startRenderLoop()
741      {
742        mRoot->startRendering();
743      }
744  };
745}
746
747using namespace Ogre;
748
749#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
750#define WIN32_LEAN_AND_MEAN
751#include "windows.h"
752
753             INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
754#else
755             int main(int argc, char **argv)
756#endif
757{
758  try
759  {
760    orxonox::OrxApplication orxonox;
761    orxonox.go();
762  }
763  catch(Exception& e)
764  {
765#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
766    MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
767#else
768    fprintf(stderr, "An exception has occurred: %s\n",
769            e.getFullDescription().c_str());
770#endif
771  }
772
773  return 0;
774}
775
Note: See TracBrowser for help on using the repository browser.