Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 225 was 225, checked in by landauf, 13 years ago

added ++it operator to the Iterator (because its faster than it++)

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