Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 219 was 219, checked in by landauf, 12 years ago
  • removed the "ClassHierarchy" manager-class and put its sole feature (bIsCreatingClassHierarchy_) directly into the Identifier.
  • added a dynamic_cast from OrxonoxClass to BaseObject to the Factory. OrxonoxClass is needed because several classes use Interfaces, but all classes are derived at least from BaseObject, so the cast will work.
File size: 25.7 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      }
530
531      ~OrxApplication()
532      {
533        mInputManager->destroyInputObject(mKeyboard);
534        OIS::InputManager::destroyInputSystem(mInputManager);
535
536        delete mRenderer;
537        delete mSystem;
538
539        delete mListener;
540        delete mRoot;
541      }
542
543    private:
544      Ogre::Root *mRoot;
545      OIS::Keyboard *mKeyboard;
546      OIS::Mouse *mMouse;
547      OIS::InputManager *mInputManager;
548      CEGUI::OgreCEGUIRenderer *mRenderer;
549      CEGUI::System *mSystem;
550      OrxExitListener *mListener;
551
552      void createRoot()
553      {
554#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
555        mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg");
556#else
557        mRoot = new Ogre::Root();
558#endif
559      }
560
561      void defineResources()
562      {
563        Ogre::String secName, typeName, archName;
564        Ogre::ConfigFile cf;
565#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
566        cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");
567#else
568        cf.load("resources.cfg");
569#endif
570
571        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
572        while (seci.hasMoreElements())
573        {
574          secName = seci.peekNextKey();
575          Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
576          Ogre::ConfigFile::SettingsMultiMap::iterator i;
577          for (i = settings->begin(); i != settings->end(); ++i)
578          {
579            typeName = i->first;
580            archName = i->second;
581#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
582            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName);
583#else
584            Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
585#endif
586          }
587        }
588      }
589
590      void setupRenderSystem()
591      {
592        if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())
593          throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");
594      }
595
596      void createRenderWindow()
597      {
598        mRoot->initialise(true, "Ogre Render Window");
599      }
600
601      void initializeResourceGroups()
602      {
603        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
604        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
605      }
606
607      void setupScene()
608      {
609        Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager");
610        Ogre::Camera *cam = mgr->createCamera("Camera");
611        Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
612      }
613
614      void setupInputSystem()
615      {
616        size_t windowHnd = 0;
617        std::ostringstream windowHndStr;
618        OIS::ParamList pl;
619        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
620
621        win->getCustomAttribute("WINDOW", &windowHnd);
622        windowHndStr << windowHnd;
623        pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
624        mInputManager = OIS::InputManager::createInputSystem(pl);
625
626        try
627        {
628          mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));
629          mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));
630        }
631        catch (const OIS::Exception &e)
632        {
633          throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem");
634        }
635      }
636
637      void setupCEGUI()
638      {
639        Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");
640        Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();
641
642        // CEGUI setup
643        mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr);
644        mSystem = new CEGUI::System(mRenderer);
645
646        // Other CEGUI setup here.
647      }
648
649      void createFrameListener()
650      {
651        mListener = new OrxExitListener(mKeyboard);
652        mRoot->addFrameListener(mListener);
653      }
654
655      void startRenderLoop()
656      {
657        mRoot->startRendering();
658      }
659  };
660}
661
662using namespace Ogre;
663
664#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
665#define WIN32_LEAN_AND_MEAN
666#include "windows.h"
667
668             INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
669#else
670             int main(int argc, char **argv)
671#endif
672{
673  try
674  {
675    orxonox::OrxApplication orxonox;
676    orxonox.go();
677  }
678  catch(Exception& e)
679  {
680#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
681    MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
682#else
683    fprintf(stderr, "An exception has occurred: %s\n",
684            e.getFullDescription().c_str());
685#endif
686  }
687
688  return 0;
689}
Note: See TracBrowser for help on using the repository browser.