Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 221 was 221, checked in by landauf, 13 years ago
  • made ObjectList double-linked to allow forward- and backward-iterating. its now a LI(F/L)O list.
  • added an iterator to iterate through object-lists. you can iterate forwards and backwards.

iterating forwards is easy: you get "0 1 2 … last"
iterating backwards is a bit tricky: you still get "0" first, but then "last … 2 1".
thats caused by the structure of the for-loop: you get the first element before the iterator knows if you'll increase or decrease it

File size: 27.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#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* test9_01 = Class(A1B2);
531        Identifier* test9_02 = Class(A2);
532        Identifier* test9_03 = Class(A3B1C1);
533
534
535        BaseObject* test9_04 = test9_01->fabricate();
536        BaseObject* test9_05 = test9_02->fabricate();
537        BaseObject* test9_06 = test9_03->fabricate();
538
539        BaseObject* test9_07;
540        for (int i = 0; i < 10; i++)
541            test9_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* test9_08;
572        for (int i = 0; i < 10; i++)
573        {
574            test9_08 = Factory("A2B1C1");
575            test9_08->name_ = "A2B1C1#";
576            test9_08->name_ += ('0' + i);
577        }
578
579        for (Iterator<A2B1C1> it; it; it++)
580            std::cout << "Name: " << it->name_ << "\n";
581
582        std::cout << "3\n";
583        for (Iterator<A2B1C1> it; it; it--)
584            std::cout << "Name: " << it->name_ << "\n";
585
586        std::cout << "4\n";
587
588      }
589
590      ~OrxApplication()
591      {
592        mInputManager->destroyInputObject(mKeyboard);
593        OIS::InputManager::destroyInputSystem(mInputManager);
594
595        delete mRenderer;
596        delete mSystem;
597
598        delete mListener;
599        delete mRoot;
600      }
601
602    private:
603      Ogre::Root *mRoot;
604      OIS::Keyboard *mKeyboard;
605      OIS::Mouse *mMouse;
606      OIS::InputManager *mInputManager;
607      CEGUI::OgreCEGUIRenderer *mRenderer;
608      CEGUI::System *mSystem;
609      OrxExitListener *mListener;
610
611      void createRoot()
612      {
613#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
614        mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg");
615#else
616        mRoot = new Ogre::Root();
617#endif
618      }
619
620      void defineResources()
621      {
622        Ogre::String secName, typeName, archName;
623        Ogre::ConfigFile cf;
624#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
625        cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");
626#else
627        cf.load("resources.cfg");
628#endif
629
630        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
631        while (seci.hasMoreElements())
632        {
633          secName = seci.peekNextKey();
634          Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
635          Ogre::ConfigFile::SettingsMultiMap::iterator i;
636          for (i = settings->begin(); i != settings->end(); ++i)
637          {
638            typeName = i->first;
639            archName = i->second;
640#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
641            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName);
642#else
643            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
644#endif
645          }
646        }
647      }
648
649      void setupRenderSystem()
650      {
651        if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())
652          throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");
653      }
654
655      void createRenderWindow()
656      {
657        mRoot->initialise(true, "Ogre Render Window");
658      }
659
660      void initializeResourceGroups()
661      {
662        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
663        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
664      }
665
666      void setupScene()
667      {
668        Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager");
669        Ogre::Camera *cam = mgr->createCamera("Camera");
670        Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
671      }
672
673      void setupInputSystem()
674      {
675        size_t windowHnd = 0;
676        std::ostringstream windowHndStr;
677        OIS::ParamList pl;
678        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
679
680        win->getCustomAttribute("WINDOW", &windowHnd);
681        windowHndStr << windowHnd;
682        pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
683        mInputManager = OIS::InputManager::createInputSystem(pl);
684
685        try
686        {
687          mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));
688          mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));
689        }
690        catch (const OIS::Exception &e)
691        {
692          throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem");
693        }
694      }
695
696      void setupCEGUI()
697      {
698        Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");
699        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
700
701        // CEGUI setup
702        mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr);
703        mSystem = new CEGUI::System(mRenderer);
704
705        // Other CEGUI setup here.
706      }
707
708      void createFrameListener()
709      {
710        mListener = new OrxExitListener(mKeyboard);
711        mRoot->addFrameListener(mListener);
712      }
713
714      void startRenderLoop()
715      {
716        mRoot->startRendering();
717      }
718  };
719}
720
721using namespace Ogre;
722
723#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
724#define WIN32_LEAN_AND_MEAN
725#include "windows.h"
726
727             INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
728#else
729             int main(int argc, char **argv)
730#endif
731{
732  try
733  {
734    orxonox::OrxApplication orxonox;
735    orxonox.go();
736  }
737  catch(Exception& e)
738  {
739#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
740    MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
741#else
742    fprintf(stderr, "An exception has occurred: %s\n",
743            e.getFullDescription().c_str());
744#endif
745  }
746
747  return 0;
748}
Note: See TracBrowser for help on using the repository browser.