Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core/src/orxonox/Orxonox.cc @ 804

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

added code for testing

File size: 37.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
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (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, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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 Class
31 */
32
33// Precompiled Headers
34#include "OrxonoxStableHeaders.h"
35
36//****** OGRE ******
37#include <OgreException.h>
38#include <OgreRoot.h>
39#include <OgreFrameListener.h>
40#include <OgreRenderWindow.h>
41#include <OgreTextureManager.h>
42#include <OgreResourceGroupManager.h>
43#include <OgreConfigFile.h>
44#include <OgreOverlay.h>
45#include <OgreOverlayManager.h>
46
47//****** OIS *******
48#include <OIS/OIS.h>
49
50//****** STD *******
51#include <iostream>
52#include <exception>
53
54//***** ORXONOX ****
55//misc
56#include "util/Sleep.h"
57
58// loader and audio
59//#include "loader/LevelLoader.h"
60//#include "audio/AudioManager.h"
61
62// network
63//#include "network/Server.h"
64//#include "network/Client.h"
65//#include "network/NetworkFrameListener.h"
66
67// objects
68#include "objects/Tickable.h"
69#include "tools/Timer.h"
70//#include "objects/NPC.h"
71#include "core/ArgReader.h"
72#include "core/Factory.h"
73#include "core/Debug.h"
74//#include "hud/HUD.h"
75//#include "objects/weapon/BulletManager.h"
76#include "GraphicsEngine.h"
77
78#include "core/ClassTreeMask.h"
79#include "objects/WorldEntity.h"
80#include "core/BaseObject.h"
81#include "objects/Test.h"
82#include "objects/test1.h"
83#include "objects/test2.h"
84#include "objects/test3.h"
85
86#include "Orxonox.h"
87
88namespace orxonox
89{
90   // put this in a seperate Class or solve the problem in another fashion
91  class OrxListener : public Ogre::FrameListener
92  {
93    public:
94      OrxListener(OIS::Keyboard *keyboard/*, audio::AudioManager*  auMan*/, gameMode mode)
95      {
96        mKeyboard = keyboard;
97        mode_=mode;
98//        auMan_ = auMan;
99      }
100
101      bool frameStarted(const Ogre::FrameEvent& evt)
102      {
103//        auMan_->update();
104        updateAI();
105
106/*        if(mode_ == PRESENTATION)
107          server_g->tick(evt.timeSinceLastFrame);
108        else if(mode_ == CLIENT)
109          client_g->tick(evt.timeSinceLastFrame);
110*/
111        usleep(10);
112
113        mKeyboard->capture();
114        return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
115      }
116
117      void updateAI()
118      {/*
119        for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it)
120        {
121          it->update();
122        }*/
123      }
124
125    private:
126      gameMode mode_;
127      OIS::Keyboard *mKeyboard;
128//      audio::AudioManager*  auMan_;
129  };
130
131  // init static singleton reference of Orxonox
132  Orxonox* Orxonox::singletonRef_ = NULL;
133
134  /**
135   * create a new instance of Orxonox
136   */
137  Orxonox::Orxonox()
138  {
139    this->ogre_ = new GraphicsEngine();
140    this->dataPath_ = "";
141//    this->loader_ = 0;
142//    this->auMan_ = 0;
143    this->singletonRef_ = 0;
144    this->keyboard_ = 0;
145    this->mouse_ = 0;
146    this->inputManager_ = 0;
147    this->frameListener_ = 0;
148    this->root_ = 0;
149  }
150
151  /**
152   * destruct Orxonox
153   */
154  Orxonox::~Orxonox()
155  {
156    // nothing to delete as for now
157  }
158
159  /**
160   * initialization of Orxonox object
161   * @param argc argument counter
162   * @param argv list of arguments
163   * @param path path to config (in home dir or something)
164   */
165  void Orxonox::init(int argc, char **argv, std::string path)
166  {
167    //TODO: find config file (assuming executable directory)
168    //TODO: read config file
169    //TODO: give config file to Ogre
170    std::string mode;
171//     if(argc>=2)
172//       mode = std::string(argv[1]);
173//     else
174//       mode = "";
175    ArgReader ar = ArgReader(argc, argv);
176    ar.checkArgument("mode", mode, false);
177    ar.checkArgument("data", this->dataPath_, false);
178    ar.checkArgument("ip", serverIp_, false);
179    //mode = "presentation";
180    if(ar.errorHandling()) die();
181    if(mode == std::string("server"))
182    {
183      serverInit(path);
184      mode_ = SERVER;
185    }
186    else if(mode == std::string("client"))
187    {
188      clientInit(path);
189      mode_ = CLIENT;
190    }
191    else if(mode == std::string("presentation"))
192    {
193      serverInit(path);
194      mode_ = PRESENTATION;
195    }
196    else{
197      standaloneInit(path);
198      mode_ = STANDALONE;
199    }
200  }
201
202  /**
203   * start modules
204   */
205  void Orxonox::start()
206  {
207    //TODO: start modules
208    ogre_->startRender();
209    //TODO: run engine
210    Factory::createClassHierarchy();
211    createScene();
212    setupScene();
213    setupInputSystem();
214    if(mode_!=CLIENT){ // remove this in future ---- presentation hack
215    }
216    else
217      std::cout << "client here" << std::endl;
218    createFrameListener();
219    switch(mode_){
220    case PRESENTATION:
221      //ogre_->getRoot()->addFrameListener(new network::ServerFrameListener());
222      //std::cout << "could not add framelistener" << std::endl;
223//      server_g->open();
224      break;
225    case CLIENT:
226//      client_g->establishConnection();
227      break;
228    case SERVER:
229    case STANDALONE:
230    default:
231      break;
232    }
233
234        #define testandcout(code) \
235          std::cout << #code << " " << code << "\n"
236
237/*
238        std::cout << "Test 1\n";
239        BaseObject* test1;
240        test1 = new BaseObject();
241        test1 = new BaseObject();
242        test1 = new BaseObject();
243
244        std::cout << "Test 2\n";
245        A1* test2;
246        test2 = new A1();
247        test2 = new A1();
248        test2 = new A1();
249
250        std::cout << "Test 3\n";
251        BaseObject* test3;
252        test3 = new BaseObject();
253        test3 = new BaseObject();
254        test3 = new BaseObject();
255
256        std::cout << "Test 4\n";
257        A3* test4;
258        test4 = new A3();
259        test4 = new A3();
260        test4 = new A3();
261*/
262/*
263        std::cout << "Test 5\n";
264        A1* test5_01 = new A1();
265        A2* test5_02 = new A2();
266        A3* test5_03 = new A3();
267        A1B1* test5_04 = new A1B1();
268        A1B2* test5_05 = new A1B2();
269        A2B1* test5_06 = new A2B1();
270        A2B2* test5_07 = new A2B2();
271        A3B1* test5_08 = new A3B1();
272        A3B2* test5_09 = new A3B2();
273        A1B1C1* test5_10 = new A1B1C1();
274        A1B1C2* test5_11 = new A1B1C2();
275        A1B2C1* test5_12 = new A1B2C1();
276        A2B1C1* test5_13 = new A2B1C1();
277        A2B2C1* test5_14 = new A2B2C1();
278        A3B1C1* test5_15 = new A3B1C1();
279        A3B1C2* test5_16 = new A3B1C2();
280        A3B2C1* test5_17 = new A3B2C1();
281        A3B2C2* test5_18 = new A3B2C2();
282
283        OrxonoxClass* test5;
284        for (int i = 0; i <= 18; i++)
285        {
286          if (i == 0) test5 = new BaseObject;
287          if (i == 1) test5 = test5_01;
288          if (i == 2) test5 = test5_02;
289          if (i == 3) test5 = test5_03;
290          if (i == 4) test5 = test5_04;
291          if (i == 5) test5 = test5_05;
292          if (i == 6) test5 = test5_06;
293          if (i == 7) test5 = test5_07;
294          if (i == 8) test5 = test5_08;
295          if (i == 9) test5 = test5_09;
296          if (i == 10) test5 = test5_10;
297          if (i == 11) test5 = test5_11;
298          if (i == 12) test5 = test5_12;
299          if (i == 13) test5 = test5_13;
300          if (i == 14) test5 = test5_14;
301          if (i == 15) test5 = test5_15;
302          if (i == 16) test5 = test5_16;
303          if (i == 17) test5 = test5_17;
304          if (i == 18) test5 = test5_18;
305
306          std::cout << "\n";
307          std::cout << test5->getIdentifier()->getName() << " (" << test5->getIdentifier()->getNetworkID() << "): parents:     " << test5->getIdentifier()->getParents().toString() << "\n";
308          std::cout << test5->getIdentifier()->getName() << " (" << test5->getIdentifier()->getNetworkID() << "): children:    " << test5->getIdentifier()->getChildren().toString() << "\n";
309        }
310
311        std::cout << "Class with ID 0: " << ID(0) << " " << ID(0)->getName() << "\n";
312        std::cout << "Class with ID 1: " << ID(1) << " " << ID(1)->getName() << "\n";
313        std::cout << "Class with ID 2: " << ID(2) << " " << ID(2)->getName() << "\n";
314        std::cout << "Class with ID 3: " << ID(3) << " " << ID(3)->getName() << "\n";
315        std::cout << "Class with ID 4: " << ID(4) << " " << ID(4)->getName() << "\n";
316        std::cout << "Class with ID 100: " << ID(100) << "\n";
317        std::cout << "ID of BaseObject: " << Class(BaseObject)->getNetworkID() << "\n";
318
319        std::cout << "\nChange ID of BaseObject to 100\n";
320        Class(BaseObject)->setNetworkID(100);
321        std::cout << "Class with ID 100: " << ID(100) << "\n";
322        std::cout << "Class with ID 1: " << ID(1) << "\n";
323        std::cout << "ID of BaseObject: " << Class(BaseObject)->getNetworkID() << "\n";
324
325        std::cout << "\nChange ID of BaseObject to 3\n";
326        Class(BaseObject)->setNetworkID(3);
327        std::cout << "Class with ID 100: " << ID(100) << "\n";
328        std::cout << "Class with ID 1: " << ID(1) << "\n";
329        std::cout << "Class with ID 3: " << ID(3) << "\n";
330        std::cout << "ID of BaseObject: " << Class(BaseObject)->getNetworkID() << "\n";
331        std::cout << "ID of Test1: " << Class(Test1)->getNetworkID() << "\n";
332*/
333/*
334        std::cout << "\n";
335        std::cout << "isA(XYZ)-Test:\n";
336        std::cout << "test5_01 = A1, Erwartet: 1 0 0 1 0\n";
337        testandcout(test5_01->isA(Class(A1)));
338        testandcout(test5_01->isA(Class(A2)));
339        testandcout(test5_01->isA(Class(A1B1)));
340        testandcout(test5_01->isA(Class(BaseObject)));
341        testandcout(test5_01->isA(Class(Interface1)));
342
343        std::cout << "\n";
344        std::cout << "test5_02 = A2, Erwartet: 0 1 0 1 0\n";
345        testandcout(test5_02->isA(Class(A1)));
346        testandcout(test5_02->isA(Class(A2)));
347        testandcout(test5_02->isA(Class(A1B1)));
348        testandcout(test5_02->isA(Class(BaseObject)));
349        testandcout(test5_02->isA(Class(Interface1)));
350
351        std::cout << "\n";
352        std::cout << "test5_01 = A3, Erwartet: 0 0 0 1 1\n";
353        testandcout(test5_03->isA(Class(A1)));
354        testandcout(test5_03->isA(Class(A2)));
355        testandcout(test5_03->isA(Class(A1B1)));
356        testandcout(test5_03->isA(Class(BaseObject)));
357        testandcout(test5_03->isA(Class(Interface1)));
358
359        std::cout << "\n";
360        std::cout << "isDirectA(XYZ)-Test:\n";
361        std::cout << "test5_01 = A1, Erwartet: 1 0 0 0 0\n";
362        testandcout(test5_01->isDirectlyA(Class(A1)));
363        testandcout(test5_01->isDirectlyA(Class(A2)));
364        testandcout(test5_01->isDirectlyA(Class(A1B1)));
365        testandcout(test5_01->isDirectlyA(Class(BaseObject)));
366        testandcout(test5_01->isDirectlyA(Class(Interface1)));
367
368        std::cout << "\n";
369        std::cout << "test5_02 = A2, Erwartet: 0 1 0 0 0\n";
370        testandcout(test5_02->isDirectlyA(Class(A1)));
371        testandcout(test5_02->isDirectlyA(Class(A2)));
372        testandcout(test5_02->isDirectlyA(Class(A1B1)));
373        testandcout(test5_02->isDirectlyA(Class(BaseObject)));
374        testandcout(test5_02->isDirectlyA(Class(Interface1)));
375
376        std::cout << "\n";
377        std::cout << "test5_03 = A3, Erwartet: 0 0 0 0 0\n";
378        testandcout(test5_03->isDirectlyA(Class(A1)));
379        testandcout(test5_03->isDirectlyA(Class(A2)));
380        testandcout(test5_03->isDirectlyA(Class(A1B1)));
381        testandcout(test5_03->isDirectlyA(Class(BaseObject)));
382        testandcout(test5_03->isDirectlyA(Class(Interface1)));
383
384        std::cout << "\n";
385        std::cout << "isChildOf(XYZ)-Test:\n";
386        std::cout << "test5_04 = A1B1, Erwartet: 1 0 1 0 0 0 0\n";
387        testandcout(test5_04->isChildOf(Class(A1)));
388        testandcout(test5_04->isChildOf(Class(A2)));
389        testandcout(test5_04->isChildOf(Class(BaseObject)));
390        testandcout(test5_04->isChildOf(Class(Interface1)));
391        testandcout(test5_04->isChildOf(Class(Interface2)));
392        testandcout(test5_04->isChildOf(Class(A1B1C2)));
393        testandcout(test5_04->isChildOf(Class(A1B1)));
394
395        std::cout << "\n";
396        std::cout << "test5_06 = A2B1, Erwartet: 0 1 1 0 0 0 0\n";
397        testandcout(test5_06->isChildOf(Class(A1)));
398        testandcout(test5_06->isChildOf(Class(A2)));
399        testandcout(test5_06->isChildOf(Class(BaseObject)));
400        testandcout(test5_06->isChildOf(Class(Interface1)));
401        testandcout(test5_06->isChildOf(Class(Interface2)));
402        testandcout(test5_06->isChildOf(Class(A1B1C2)));
403        testandcout(test5_06->isChildOf(Class(A1B1)));
404
405        std::cout << "\n";
406        std::cout << "test5_07 = A2B2, Erwartet: 0 1 1 1 0 0\n";
407        testandcout(test5_07->isChildOf(Class(A1)));
408        testandcout(test5_07->isChildOf(Class(A2)));
409        testandcout(test5_07->isChildOf(Class(BaseObject)));
410        testandcout(test5_07->isChildOf(Class(Interface1)));
411        testandcout(test5_07->isChildOf(Class(Interface2)));
412        testandcout(test5_07->isChildOf(Class(A1B1C2)));
413
414        std::cout << "\n";
415        std::cout << "test5_08 = A3B1, Erwartet: 0 0 1 1 0 0\n";
416        testandcout(test5_08->isChildOf(Class(A1)));
417        testandcout(test5_08->isChildOf(Class(A2)));
418        testandcout(test5_08->isChildOf(Class(BaseObject)));
419        testandcout(test5_08->isChildOf(Class(Interface1)));
420        testandcout(test5_08->isChildOf(Class(Interface2)));
421        testandcout(test5_08->isChildOf(Class(A1B1C2)));
422
423        std::cout << "\n";
424        std::cout << "test5_09 = A3B2, Erwartet: 0 0 1 1 1 0\n";
425        testandcout(test5_09->isChildOf(Class(A1)));
426        testandcout(test5_09->isChildOf(Class(A2)));
427        testandcout(test5_09->isChildOf(Class(BaseObject)));
428        testandcout(test5_09->isChildOf(Class(Interface1)));
429        testandcout(test5_09->isChildOf(Class(Interface2)));
430        testandcout(test5_09->isChildOf(Class(A1B1C2)));
431
432        std::cout << "\n";
433        std::cout << "isParentOf(XYZ)-Test:\n";
434        std::cout << "test1 = BaseObject, Erwartet: 0 0 1 1 1 1 1\n";
435        testandcout(test1->isParentOf(Class(BaseObject)));
436        testandcout(test1->isParentOf(Class(Interface1)));
437        testandcout(test1->isParentOf(Class(A1)));
438        testandcout(test1->isParentOf(Class(A2)));
439        testandcout(test1->isParentOf(Class(A1B1)));
440        testandcout(test1->isParentOf(Class(A2B2)));
441        testandcout(test1->isParentOf(Class(A3B1C2)));
442
443        std::cout << "\n";
444        std::cout << "test5_01 = A1, Erwartet: 0 0 0 0 1 0 0\n";
445        testandcout(test5_01->isParentOf(Class(BaseObject)));
446        testandcout(test5_01->isParentOf(Class(Interface1)));
447        testandcout(test5_01->isParentOf(Class(A1)));
448        testandcout(test5_01->isParentOf(Class(A2)));
449        testandcout(test5_01->isParentOf(Class(A1B1)));
450        testandcout(test5_01->isParentOf(Class(A2B2)));
451        testandcout(test5_01->isParentOf(Class(A3B1C2)));
452
453        std::cout << "\n";
454        std::cout << "Interface1, Erwartet: 0 0 0 0 0 1 1\n";
455        testandcout(Class(Interface1)->isParentOf(Class(BaseObject)));
456        testandcout(Class(Interface1)->isParentOf(Class(Interface1)));
457        testandcout(Class(Interface1)->isParentOf(Class(A1)));
458        testandcout(Class(Interface1)->isParentOf(Class(A2)));
459        testandcout(Class(Interface1)->isParentOf(Class(A1B1)));
460        testandcout(Class(Interface1)->isParentOf(Class(A2B2)));
461        testandcout(Class(Interface1)->isParentOf(Class(A3B1C2)));
462*/
463/*
464        std::cout << "Test 6\n";
465        std::cout << "1:\n";
466        Identifier* test6_01 = Class(A1B1);
467        std::cout << "2:\n";
468        Identifier* test6_02 = Class(A1B1);
469        std::cout << "3:\n";
470        Identifier* test6_03 = Class(A1);
471        std::cout << "4:\n";
472        Identifier* test6_04 = Class(A1B1C1);
473        std::cout << "5:\n";
474        Identifier* test6_05 = Class(A1B1);
475        std::cout << "6:\n";
476        Identifier* test6_06 = Class(A1B1C1);
477
478        std::cout << "\n";
479        std::cout << "BaseObject: parents:     " << Class(BaseObject)->getParents().toString() << "\n";
480        std::cout << "BaseObject: children:    " << Class(BaseObject)->getChildren().toString() << "\n";
481
482        std::cout << "\n";
483        std::cout << "A1: parents:     " << Class(A1)->getParents().toString() << "\n";
484        std::cout << "A1: children:    " << Class(A1)->getChildren().toString() << "\n";
485
486        std::cout << "\n";
487        std::cout << "A1B1: parents:     " << Class(A1B1)->getParents().toString() << "\n";
488        std::cout << "A1B1: children:    " << Class(A1B1)->getChildren().toString() << "\n";
489
490        std::cout << "\n";
491        std::cout << "A1B1C1: parents:     " << Class(A1B1C1)->getParents().toString() << "\n";
492        std::cout << "A1B1C1: children:    " << Class(A1B1C1)->getChildren().toString() << "\n";
493
494        std::cout << "\n";
495        std::cout << "A3B1C1 child of A3:  " << Class(A3B1C1)->isChildOf(Class(A3)) << "\n";
496        std::cout << "\n";
497        std::cout << "A2 parent of A2B1C1: " << Class(A2)->isParentOf(Class(A2B1C1)) << "\n";
498*/
499/*
500        std::cout << "Test 7\n";
501        std::cout << "1\n";
502        SubclassIdentifier<A1B1> test7_01;
503        test7_01 = Class(A1B1C1);
504
505        SubclassIdentifier<A1B1> test7_02;
506        test7_02 = Class(A1B1);
507
508        std::cout << test7_01->getName() << "\n";
509        std::cout << test7_02->getName() << "\n";
510*/
511/*
512        std::cout << "2\n";
513
514        SubclassIdentifier<A1B1> test7_03;
515        test7_03 = Class(A1);
516
517        SubclassIdentifier<A1B1> test7_04;
518        test7_04 = Class(A1B2);
519
520        SubclassIdentifier<A1B1> test7_05;
521        test7_05 = Class(A2);
522*/
523/*
524        std::cout << "Test 8\n";
525
526        std::cout << "1\n";
527        Test1* test8_01 = new Test1;
528        Test3* test8_03 = new Test3;
529        test8_03->usefullClassesIsATest(test8_01);
530
531        std::cout << "2\n";
532        Test2* test8_02 = new Test2;
533        test8_03->usefullClassesIsATest(test8_02);
534
535        std::cout << "3\n";
536        test8_01->setUsefullClass1(Class(Test1));
537        test8_01->setUsefullClass1(test8_02->getIdentifier());
538        test8_01->setUsefullClass2(Class(Test2));
539        test8_01->setUsefullClassOfTypeTest3(Class(Test3));
540        test8_01->setUsefullClassOfTypeTest3(test8_03->getIdentifier());
541
542
543        testandcout(test8_01->isA(Class(Test1)));
544        testandcout(test8_01->isA(Class(Test2)));
545        testandcout(test8_01->isA(Class(Test3)));
546
547        Test2* test8_04 = new Test2;
548        testandcout(test8_02->isA(Class(Test1)));
549        testandcout(test8_02->isA(Class(Test2)));
550        testandcout(test8_02->isA(Class(Test3)));
551
552        Test3* test8_05 = new Test3;
553        testandcout(test8_03->isA(Class(Test1)));
554        testandcout(test8_03->isA(Class(Test2)));
555        testandcout(test8_03->isA(Class(Test3)));
556
557        delete test8_01;
558        delete test8_02;
559        delete test8_03;
560
561
562        std::cout << "Test 9\n";
563        std::cout << "1\n";
564        Identifier* test9_01 = Class(A3);
565        BaseObject* test9_02 = test9_01->fabricate();
566        std::cout << test9_02->getIdentifier()->getName() << "\n";
567
568        std::cout << "\n2\n";
569        BaseObject* test9_03 = Class(A1B2)->fabricate();
570        std::cout << test9_03->getIdentifier()->getName() << "\n";
571
572        std::cout << "\n3\n";
573        SubclassIdentifier<A1> test9_04;
574        test9_04 = Class(A1B1C1);
575        A1* test9_05 = test9_04.fabricate();
576        std::cout << test9_05->getIdentifier()->getName() << "\n";
577
578        std::cout << "\n4\n";
579        BaseObject* test9_06 = ID("A2B2")->fabricate();
580        std::cout << test9_06->getIdentifier()->getName() << "\n";
581
582        std::cout << "\n5\n";
583        delete test9_02;
584        delete test9_03;
585        delete test9_05;
586        delete test9_06;
587*/
588/*
589        std::cout << "Test 10\n";
590        Identifier* test10_01 = Class(A1B2);
591        Identifier* test10_02 = Class(A2);
592        Identifier* test10_03 = Class(A3B1C1);
593
594        BaseObject* test10_04 = test10_01->fabricate();
595        BaseObject* test10_05 = test10_02->fabricate();
596        BaseObject* test10_06 = test10_03->fabricate();
597
598        BaseObject* test10_07;
599        for (int i = 0; i < 10; i++)
600            test10_07 = ID("A1B1C1")->fabricate();
601
602        std::cout << "1\n";
603        int count;
604
605        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
606        std::cout << "Anzahl BaseObjects: " << count << "\n";
607        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
608        std::cout << "Anzahl A1: " << count << "\n";
609        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
610        std::cout << "Anzahl A1B1: " << count << "\n";
611        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; }
612        std::cout << "Anzahl A1B1C1: " << count << "\n";
613        count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; }
614        std::cout << "Anzahl A2: " << count << "\n";
615
616        std::cout << "2\n";
617        BaseObject* test10_08;
618        BaseObject* test10_09;
619        BaseObject* test10_10;
620        for (int i = 0; i < 10; i++)
621        {
622            test10_08 = ID("A2B1C1")->fabricate();
623            std::string objName = "A2B1C1#";
624            objName += '0' + i;
625            test10_08->setName(objName);
626
627            if (i == 0)
628                test10_09 = test10_08;
629
630            if (i == 5)
631                test10_10 = test10_08;
632        }
633
634        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
635        std::cout << "Anzahl BaseObjects: " << count << "\n";
636        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
637        std::cout << "Anzahl A1: " << count << "\n";
638        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
639        std::cout << "Anzahl A1B1: " << count << "\n";
640        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; }
641        std::cout << "Anzahl A1B1C1: " << count << "\n";
642        count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; }
643        std::cout << "Anzahl A2: " << count << "\n";
644
645        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
646            std::cout << "Name: " << it->getName() << "\n";
647
648        std::cout << "3\n";
649        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
650            std::cout << "Name: " << it->getName() << "\n";
651
652        std::cout << "4\n";
653        delete test10_08;
654
655        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
656        std::cout << "Anzahl BaseObjects: " << count << "\n";
657        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
658        std::cout << "Anzahl A1: " << count << "\n";
659        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
660        std::cout << "Anzahl A1B1: " << count << "\n";
661        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; }
662        std::cout << "Anzahl A1B1C1: " << count << "\n";
663        count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; }
664        std::cout << "Anzahl A2: " << count << "\n";
665
666        std::cout << "5\n";
667        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
668            std::cout << "Name: " << it->getName() << "\n";
669
670        std::cout << "6\n";
671        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
672            std::cout << "Name: " << it->getName() << "\n";
673
674        std::cout << "7\n";
675        delete test10_09;
676
677        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::end(); it != 0; --it) { count++; }
678        std::cout << "Anzahl BaseObjects: " << count << "\n";
679        count = 0; for (Iterator<A1> it = ObjectList<A1>::end(); it != 0; --it) { count++; }
680        std::cout << "Anzahl A1: " << count << "\n";
681        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::end(); it; --it) { count++; }
682        std::cout << "Anzahl A1B1: " << count << "\n";
683        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::end(); it; --it) { count++; }
684        std::cout << "Anzahl A1B1C1: " << count << "\n";
685        count = 0; for (Iterator<A2> it = ObjectList<A2>::end(); it; --it) { count++; }
686        std::cout << "Anzahl A2: " << count << "\n";
687
688        std::cout << "8\n";
689        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
690            std::cout << "Name: " << it->getName() << "\n";
691
692        std::cout << "9\n";
693        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
694            std::cout << "Name: " << it->getName() << "\n";
695
696        std::cout << "10\n";
697        delete test10_10;
698
699        count = 0; for (Iterator<BaseObject> it = ObjectList<BaseObject>::start(); it != 0; ++it) { count++; }
700        std::cout << "Anzahl BaseObjects: " << count << "\n";
701        count = 0; for (Iterator<A1> it = ObjectList<A1>::start(); it != 0; ++it) { count++; }
702        std::cout << "Anzahl A1: " << count << "\n";
703        count = 0; for (Iterator<A1B1> it = ObjectList<A1B1>::start(); it; ++it) { count++; }
704        std::cout << "Anzahl A1B1: " << count << "\n";
705        count = 0; for (Iterator<A1B1C1> it = ObjectList<A1B1C1>::start(); it; ++it) { count++; }
706        std::cout << "Anzahl A1B1C1: " << count << "\n";
707        count = 0; for (Iterator<A2> it = ObjectList<A2>::start(); it; ++it) { count++; }
708        std::cout << "Anzahl A2: " << count << "\n";
709
710        std::cout << "11\n";
711        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::start(); it; ++it)
712            std::cout << "Name: " << it->getName() << "\n";
713
714        std::cout << "12\n";
715        for (Iterator<A2B1C1> it = ObjectList<A2B1C1>::end(); it; --it)
716            std::cout << "Name: " << it->getName() << "\n";
717
718        std::cout << "13\n";
719*/
720/*
721        std::cout << "Test 11\n";
722        std::cout << "1\n";
723        count = 0; for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) { count++; }
724        std::cout << "AnzahlTickable: " << count << "\n";
725
726        Test1* test11_1;
727        for (int i = 0; i < 3; i++)
728            test11_1 = new Test1;
729
730        count = 0; for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) { count++; }
731        std::cout << "AnzahlTickable: " << count << "\n";
732
733        for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
734            it->tick(0);
735
736        std::cout << "2\n";
737        Test2* test11_2 = new Test2;
738*/
739/*
740        std::cout << "3\n";
741        Test3* test11_3 = new Test3;
742        test11_3->configOutput();
743
744        std::cout << "4\n";
745*/
746/*
747        std::cout << "Test 12\n";
748        std::cout << "1\n";
749
750        WorldEntity* test12_1 = new WorldEntity;
751
752        std::cout << sizeof(WorldEntity) << std::endl;
753
754        std::cout << "2\n";
755*/
756        std::cout << "Test 13\n";
757
758        #define BoolToYesNo(bool) \
759            if (bool) \
760                std::cout << "yes "; \
761            else \
762                std::cout << "no  "
763
764        #define TestClassTreeMask(mask) \
765            std::cout << "========== ClassTreeMask-Test ===========" << std::endl; \
766            std::cout << "                 "; \
767            BoolToYesNo(mask.isIncluded(Class(BaseObject))); \
768            std::cout << std::endl; \
769            \
770            std::cout << "     "; \
771            BoolToYesNo(mask.isIncluded(Class(A1))); \
772            std::cout << "        "; \
773            BoolToYesNo(mask.isIncluded(Class(A2))); \
774            std::cout << "           "; \
775            BoolToYesNo(mask.isIncluded(Class(A3))); \
776            std::cout << std::endl; \
777            \
778            std::cout << "  "; \
779            BoolToYesNo(mask.isIncluded(Class(A1B1))); \
780            std::cout << "  "; \
781            BoolToYesNo(mask.isIncluded(Class(A1B2))); \
782            std::cout << "  "; \
783            BoolToYesNo(mask.isIncluded(Class(A2B1))); \
784            std::cout << "  "; \
785            BoolToYesNo(mask.isIncluded(Class(A2B2))); \
786            std::cout << "    "; \
787            BoolToYesNo(mask.isIncluded(Class(A3B1))); \
788            std::cout << "    "; \
789            BoolToYesNo(mask.isIncluded(Class(A3B2))); \
790            std::cout << std::endl; \
791            \
792            BoolToYesNo(mask.isIncluded(Class(A1B1C1))); \
793            BoolToYesNo(mask.isIncluded(Class(A1B1C2))); \
794            BoolToYesNo(mask.isIncluded(Class(A1B2C1))); \
795            std::cout << "  "; \
796            BoolToYesNo(mask.isIncluded(Class(A2B1C1))); \
797            std::cout << "  "; \
798            BoolToYesNo(mask.isIncluded(Class(A2B2C1))); \
799            std::cout << "  "; \
800            BoolToYesNo(mask.isIncluded(Class(A3B1C1))); \
801            BoolToYesNo(mask.isIncluded(Class(A3B1C2))); \
802            BoolToYesNo(mask.isIncluded(Class(A3B2C1))); \
803            BoolToYesNo(mask.isIncluded(Class(A3B2C2))); \
804            std::cout << std::endl; \
805            std::cout << "=========================================" << std::endl
806
807        std::cout << "1\n";
808
809        ClassTreeMask test13_1;
810//        test13_1.include(Class(BaseObject));
811        test13_1.exclude(Class(A1B1));
812        test13_1.exclude(Class(A2));
813        test13_1.include(Class(A2B2));
814        test13_1.exclude(Class(A2B2C1));
815        test13_1.exclude(Class(A3B1));
816        test13_1.include(Class(A3B1C2));
817        test13_1.exclude(Class(A3B2C1));
818        test13_1.exclude(Class(A3B2C2));
819
820        ClassTreeMask test13_2;
821        test13_2.exclude(Class(BaseObject));
822        test13_2.include(Class(A1));
823        test13_2.exclude(Class(A1B2));
824        test13_2.exclude(Class(A1B1C2));
825        test13_2.include(Class(A2));
826        test13_2.exclude(Class(A2B2));
827        test13_2.include(Class(A3B1));
828        test13_2.include(Class(A3B2));
829        test13_2.exclude(Class(A3B2C2));
830
831//        TestClassTreeMask(test13_1);
832std::cout << "1_0: " << ClassIdentifier<BaseObject>::getIdentifier() << std::endl;
833
834        TestClassTreeMask(test13_2);
835
836        std::cout << "2\n";
837
838        std::cout << "3\n";
839
840//    startRenderLoop();
841  }
842
843  /**
844   * @return singleton object
845   */
846  Orxonox* Orxonox::getSingleton()
847  {
848    if (!singletonRef_)
849      singletonRef_ = new Orxonox();
850    return singletonRef_;
851  }
852
853  /**
854   * error kills orxonox
855   */
856  void Orxonox::die(/* some error code */)
857  {
858    //TODO: destroy and destruct everything and print nice error msg
859    delete this;
860  }
861
862  void Orxonox::standaloneInit(std::string path)
863  {
864    ogre_->setConfigPath(path);
865    ogre_->setup();
866    root_ = ogre_->getRoot();
867    if(!ogre_->load()) die(/* unable to load */);
868
869    //defineResources();
870    //setupRenderSystem();
871    //createRenderWindow();
872    //initializeResourceGroups();
873    /*createScene();
874    setupScene();
875    setupInputSystem();
876    createFrameListener();
877    Factory::createClassHierarchy();
878    startRenderLoop();*/
879  }
880
881  void Orxonox::playableServer(std::string path)
882  {
883    ogre_->setConfigPath(path);
884    ogre_->setup();
885    root_ = ogre_->getRoot();
886    defineResources();
887    setupRenderSystem();
888    createRenderWindow();
889    initializeResourceGroups();
890    setupInputSystem();
891    Factory::createClassHierarchy();
892    createScene();
893    setupScene();
894    createFrameListener();
895    try{
896//      server_g = new network::Server(); //!< add port and bindadress
897//      server_g->open(); //!< open server and create listener thread
898//      if(ogre_ && ogre_->getRoot())
899//        ogre_->getRoot()->addFrameListener(new network::ServerFrameListener()); // adds a framelistener for the server
900      COUT(3) << "Info: network framelistener added" << std::endl;
901    }
902    catch(...)
903    {
904      COUT(1) << "Error: There was a problem initialising the server :(" << std::endl;
905    }
906    startRenderLoop();
907  }
908
909  void Orxonox::standalone(){
910
911
912
913  }
914
915  void Orxonox::serverInit(std::string path)
916  {
917    COUT(2) << "initialising server" << std::endl;
918    ogre_->setConfigPath(path);
919    ogre_->setup();
920//    server_g = new network::Server(); // FIXME add some settings if wanted
921    if(!ogre_->load()) die(/* unable to load */);
922    // FIXME add network framelistener
923  }
924
925  void Orxonox::clientInit(std::string path)
926  {
927    COUT(2) << "initialising client" << std::endl;
928    ogre_->setConfigPath(path);
929    ogre_->setup();
930/*    if(serverIp_.compare("")==0)
931      client_g = new network::Client();
932    else
933      client_g = new network::Client(serverIp_, 55556);*/
934    if(!ogre_->load()) die(/* unable to load */);
935//    ogre_->getRoot()->addFrameListener(new network::ClientFrameListener());
936  }
937
938  void Orxonox::defineResources()
939  {
940    std::string secName, typeName, archName;
941    Ogre::ConfigFile cf;
942#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
943    cf.load(macBundlePath() + "/Contents/Resources/resources.cfg");
944#else
945    cf.load(dataPath_ + "resources.cfg");
946#endif
947
948    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
949    while (seci.hasMoreElements())
950    {
951      secName = seci.peekNextKey();
952      Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
953      Ogre::ConfigFile::SettingsMultiMap::iterator i;
954      for (i = settings->begin(); i != settings->end(); ++i)
955      {
956        typeName = i->first;
957        archName = i->second;
958#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
959        Ogre::ResourceGroupManager::getSingleton().addResourceLocation( std::string(macBundlePath() + "/" + archName), typeName, secName);
960#else
961        Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName);
962#endif
963      }
964    }
965  }
966
967  void Orxonox::setupRenderSystem()
968  {
969    if (!root_->restoreConfig() && !root_->showConfigDialog())
970      throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");
971  }
972
973  void Orxonox::createRenderWindow()
974  {
975    root_->initialise(true, "OrxonoxV2");
976  }
977
978  void Orxonox::initializeResourceGroups()
979  {
980    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
981    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
982  }
983
984  /**
985   *
986   * @param
987   */
988  void Orxonox::createScene(void)
989  {
990        // Init audio
991//    auMan_ = new audio::AudioManager();
992
993//    bulletMgr_ = new BulletManager();
994
995    // load this file from config
996//    loader_ = new loader::LevelLoader("sample.oxw");
997//    loader_->loadLevel();
998
999//    Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2");
1000//    HUD* orxonoxHud;
1001//    orxonoxHud = new HUD();
1002//    orxonoxHud->setEnergyValue(20);
1003//    orxonoxHud->setEnergyDistr(20,20,60);
1004//    hudOverlay->show();
1005
1006        /*
1007    auMan_->ambientAdd("a1");
1008    auMan_->ambientAdd("a2");
1009    auMan_->ambientAdd("a3");
1010                                //auMan->ambientAdd("ambient1");
1011    auMan_->ambientStart();*/
1012  }
1013
1014
1015  /**
1016   *
1017   */
1018  void Orxonox::setupScene()
1019  {
1020//    SceneManager *mgr = ogre_->getSceneManager();
1021
1022
1023//    SceneNode* node = (SceneNode*)mgr->getRootSceneNode()->getChild("OgreHeadNode");
1024//     SceneNode *node = mgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode", Vector3(0,0,0));
1025
1026
1027/*
1028    particle::ParticleInterface *e = new particle::ParticleInterface(mgr,"engine","Orxonox/strahl");
1029    e->particleSystem_->setParameter("local_space","true");
1030    e->setPositionOfEmitter(0, Vector3(0,-10,0));
1031    e->setDirection(Vector3(0,0,-1));
1032    e->addToSceneNode(node);
1033*/
1034  }
1035
1036
1037  void Orxonox::setupInputSystem()
1038  {
1039    size_t windowHnd = 0;
1040    std::ostringstream windowHndStr;
1041    OIS::ParamList pl;
1042
1043    // fixes auto repeat problem
1044    #if defined OIS_LINUX_PLATFORM
1045      pl.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
1046    #endif
1047
1048      Ogre::RenderWindow *win = ogre_->getRoot()->getAutoCreatedWindow();
1049    win->getCustomAttribute("WINDOW", &windowHnd);
1050    windowHndStr << windowHnd;
1051    pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
1052    inputManager_ = OIS::InputManager::createInputSystem(pl);
1053
1054    try
1055    {
1056      keyboard_ = static_cast<OIS::Keyboard*>(inputManager_->createInputObject(OIS::OISKeyboard, false));
1057      mouse_ = static_cast<OIS::Mouse*>(inputManager_->createInputObject(OIS::OISMouse, true));
1058    }
1059    catch (const OIS::Exception &e)
1060    {
1061      throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem");
1062    }
1063  }
1064
1065  // FIXME we actually want to do this differently...
1066  void Orxonox::createFrameListener()
1067  {
1068    TickFrameListener* TickFL = new TickFrameListener();
1069    ogre_->getRoot()->addFrameListener(TickFL);
1070
1071    TimerFrameListener* TimerFL = new TimerFrameListener();
1072    ogre_->getRoot()->addFrameListener(TimerFL);
1073
1074    //if(mode_!=CLIENT) // FIXME just a hack ------- remove this in future
1075      frameListener_ = new OrxListener(keyboard_/*, auMan_*/, mode_);
1076    ogre_->getRoot()->addFrameListener(frameListener_);
1077  }
1078
1079  void Orxonox::startRenderLoop()
1080  {
1081    // FIXME
1082    // this is a hack!!!
1083    // the call to reset the mouse clipping size should probably be somewhere
1084    // else, however this works for the moment.
1085    unsigned int width, height, depth;
1086    int left, top;
1087    ogre_->getRoot()->getAutoCreatedWindow()->getMetrics(width, height, depth, left, top);
1088
1089    if(mode_!=CLIENT){
1090      const OIS::MouseState &ms = mouse_->getMouseState();
1091      ms.width = width;
1092      ms.height = height;
1093    }
1094    ogre_->getRoot()->startRendering();
1095  }
1096}
Note: See TracBrowser for help on using the repository browser.