Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/convention/src/story_entities/world.cc @ 3756

Last change on this file since 3756 was 3756, checked in by bensch, 19 years ago

orxonox/branches: added new branche convention for some showing stuff at the convention

File size: 26.0 KB
RevLine 
[1853]1
2/*
3   orxonox - the future of 3D-vertical-scrollers
4
5   Copyright (C) 2004 orx
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 2, or (at your option)
10   any later version.
[1855]11
12   ### File Specific:
13   main-programmer: Patrick Boenzli
[2190]14   co-programmer: Christian Meyer
[1853]15*/
16
[3590]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
18
[2190]19#include "world.h"
[3608]20
21#include "orxonox.h"
[3620]22
[3608]23#include "p_node.h"
24#include "null_parent.h"
25#include "helper_parent.h"
26#include "track_node.h"
[2190]27#include "world_entity.h"
[2036]28#include "player.h"
[2190]29#include "camera.h"
[2816]30#include "environment.h"
[3419]31#include "skysphere.h"
[3750]32#include "satellite.h"
[3608]33#include "terrain.h"
[3436]34#include "light.h"
[3620]35
[3646]36#include "track_manager.h"
37#include "garbage_collector.h"
[3729]38#include "simple_animation.h"
[3646]39
[3608]40#include "command_node.h"
41#include "glmenu_imagescreen.h"
[3475]42#include "fontset.h"
[3756]43#include "test_mat.h"
[3608]44#include "list.h"
[2036]45
[3608]46
47
[1856]48using namespace std;
[1853]49
50
[3620]51WorldInterface* WorldInterface::singletonRef = 0;
52
53
54/**
55   \brief private constructor because of singleton
56*/
57WorldInterface::WorldInterface()
58{
59  this->worldIsInitialized = false;
60  this->worldReference = NULL;
61}
62
63/**
64   \brief public deconstructor
65*/
66WorldInterface::~WorldInterface()
67{
68  this->singletonRef = NULL;
69  this->worldIsInitialized = false;
70  this->worldReference = NULL;
71}
72
73/**
74   \brief gets the singleton instance
75   \returns singleton instance
76*/
77WorldInterface* WorldInterface::getInstance()
78{
79  if( singletonRef == NULL)
80    singletonRef = new WorldInterface();
81  return singletonRef;
82}
83
84
85/**
86   \brief initializes the interface
87   \param reference to the world
88
89   if the worldinterface is not initilizes, there wont be any
90   useable interface
91*/
92void WorldInterface::init(World* world)
93{
94  this->worldReference = world;
[3629]95  if( world != NULL)
[3620]96    {
97      this->worldIsInitialized = true;
98      PRINTF(3)("WorldInterface up and running\n");
99    }
100}
101
102
103/**
104   \brief gets the entity list from the world
105   \return entity list
106*/
107tList<WorldEntity>* WorldInterface::getEntityList()
108{
109  if( this->worldIsInitialized)
110    return this->worldReference->getEntities();
111  PRINT(1)("Someone tried to use the WorldInterface before it has been initizlized! this can result in SEGFAULTs!\n");
112  return NULL;
113}
114
115
116
[1858]117/**
[2551]118    \brief create a new World
119   
120    This creates a new empty world!
[1858]121*/
[2636]122World::World (char* name)
[1855]123{
[3526]124  this->init(name, -1);
[3573]125  //NullParent* np = NullParent::getInstance();
[1855]126}
127
[3449]128/**
129   \brief creates a new World...
130   \param worldID with this ID
131*/
[2636]132World::World (int worldID)
133{
[3526]134  this->init(NULL, worldID);
[2636]135}
136
[1858]137/**
[2551]138    \brief remove the World from memory
[3365]139   
140    delete everything explicitly, that isn't contained in the parenting tree!
141    things contained in the tree are deleted automaticaly
[1858]142*/
[2190]143World::~World ()
[1872]144{
[3546]145  PRINTF(3)("World::~World() - deleting current world\n");
[3226]146  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
[3220]147  cn->unbind(this->localPlayer);
148  cn->reset();
[3677]149
[3676]150  ResourceManager::getInstance()->debug();
[3672]151  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
[3677]152  ResourceManager::getInstance()->debug();
[3660]153
[3620]154  delete WorldInterface::getInstance();
155
[3529]156  delete this->nullParent;
[3553]157  delete this->entities;
[3597]158  delete this->lightMan;
[3566]159  delete this->trackManager;
[3729]160
[3752]161  delete this->simpleAnimation;
[3729]162  //delete garbagecollecor
163  //delete animator
[1872]164}
[1858]165
[3526]166/**
[3629]167   \brief initializes the world.
168
169   set all stuff here that is world generic and does not use to much memory
170   because the real init() function StoryEntity::init() will be called
171   shortly before start of the game. 
172   since all worlds are initiated/referenced before they will be started.
173   NO LEVEL LOADING HERE - NEVER!
[3526]174*/
175void World::init(char* name, int worldID)
176{
177  this->setClassName ("World");
[2636]178
[3631]179  this->worldName = name;
[3526]180  this->debugWorldNr = worldID;
181  this->entities = new tList<WorldEntity>();
[3756]182
183  this->testMat = NULL;
[3629]184}
[3526]185
[3629]186
187/**
188   \brief this is executed before load
189
190   since the load function sometimes needs data, that has been init before
191   the load and after the proceeding storyentity has finished
192*/
193ErrorMessage World::preLoad()
194{
[3620]195  /* init the world interface */
196  WorldInterface* wi = WorldInterface::getInstance();
197  wi->init(this);
[3646]198  this->garbageCollector = GarbageCollector::getInstance();
[3729]199  this->simpleAnimation = SimpleAnimation::getInstance();
[3526]200}
201
202
[3449]203/**
204   \brief loads the World by initializing all resources, and set their default values.
205*/
[3459]206ErrorMessage World::load()
[2636]207{
[3365]208  //  BezierCurve* tmpCurve = new BezierCurve();
[2636]209  if(this->debugWorldNr != -1)
210    {
[3455]211      // initializing Font
[3456]212      testFont = new FontSet();
213      testFont->buildFont("../data/pictures/font.tga");
[3675]214      this->glmis->step();
[3455]215
216      // initializing the TrackManager
[3365]217      trackManager = TrackManager::getInstance();
[3686]218      //trackManager->addPoint(Vector(0,0,0));
219      trackManager->addPoint(Vector(150, -35, 5));
220      trackManager->addPoint(Vector(200,-35, 5));
221      trackManager->addPoint(Vector(250, -35, 5));
[3567]222      trackManager->addPoint(Vector(320,-33,-.55));
[3686]223      trackManager->setDuration(2);
[3567]224      trackManager->setSavePoint();
[3686]225
[3567]226      trackManager->addPoint(Vector(410, 0, 0));
227      trackManager->addPoint(Vector(510, 20, -10));
228      trackManager->addPoint(Vector(550, 20, -10));
229      trackManager->addPoint(Vector(570, 20, -10));
[3634]230      trackManager->setDuration(5);
[3567]231     
232      int fork11, fork12;
233      trackManager->fork(2, &fork11, &fork12);
234      trackManager->workOn(fork11);
235      trackManager->addPoint(Vector(640, 25, -30));
236      trackManager->addPoint(Vector(700, 40, -120));
237      trackManager->addPoint(Vector(800, 50, -150));
238      trackManager->addPoint(Vector(900, 60, -100));
239      trackManager->addPoint(Vector(900, 60, -70));
240      trackManager->addPoint(Vector(990, 65, -15));
241      trackManager->addPoint(Vector(1050, 65, -10));
242      trackManager->addPoint(Vector(1100, 65, -20));
[3634]243      trackManager->setDuration(10);
[3567]244
[3365]245      trackManager->workOn(fork12);
[3567]246      trackManager->addPoint(Vector(640, 25, 20));
247      trackManager->addPoint(Vector(670, 50, 120));
248      trackManager->addPoint(Vector(700, 70, 80));
249      trackManager->addPoint(Vector(800, 70, 65));
250      trackManager->addPoint(Vector(850, 65, 65));
251      trackManager->addPoint(Vector(920, 35, 40));
252      trackManager->addPoint(Vector(945, 40, 40));
253      trackManager->addPoint(Vector(970, 24, 40));
254      trackManager->addPoint(Vector(1000, 40, -7));
[3634]255      trackManager->setDuration(10);
[3567]256     
[3522]257
[3567]258      trackManager->join(2, fork11, fork12);
259
[3522]260      trackManager->workOn(5);
[3567]261      trackManager->addPoint(Vector(1200, 60, -50));
262      trackManager->addPoint(Vector(1300, 50, -50));
263      trackManager->addPoint(Vector(1400, 40, -50));
264      trackManager->addPoint(Vector(1500, 40, -60));
265      trackManager->addPoint(Vector(1600, 35, -55));
266      trackManager->addPoint(Vector(1700, 45, -40));
267      trackManager->addPoint(Vector(1750, 60, -40));
268      trackManager->addPoint(Vector(1770, 80, -40));
269      trackManager->addPoint(Vector(1800, 100, -40));
[3634]270      trackManager->setDuration(10);
[3522]271
[3433]272      trackManager->finalize();
[3522]273
[3433]274     
[3368]275      /*monitor progress*/
276      this->glmis->step();
277
[3602]278      // LIGHT initialisation
279      lightMan = LightManager::getInstance();
280      lightMan->setAmbientColor(.1,.1,.1);
281      lightMan->addLight();
[3603]282      //      lightMan->setAttenuation(1.0, .01, 0.0);
[3602]283      //      lightMan->setDiffuseColor(1,1,1);
284      //  lightMan->addLight(1);
285      //  lightMan->setPosition(20, 10, -20);
286      //  lightMan->setDiffuseColor(0,0,0);
287      lightMan->debug();
288
[2636]289      switch(this->debugWorldNr)
290        {
[3225]291          /*
292            this loads the hard-coded debug world. this only for simplicity and will be
293            removed by a reald world-loader, which interprets a world-file.
294            if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and
295            make whatever you want...
296           */
[2636]297        case DEBUG_WORLD_0:
298          {
[3602]299            lightMan->setPosition(-5.0, 10.0, -40.0);
[3365]300            this->nullParent = NullParent::getInstance ();
301            this->nullParent->setName ("NullParent");
302
[3194]303            // !\todo old track-system has to be removed
304
[3365]305            //create helper for player
[3586]306            //HelperParent* hp = new HelperParent ();
[3365]307            /* the player has to be added to this helper */
308
[2636]309            // create a player
[3586]310            this->localPlayer = new Player ();
311            this->localPlayer->setName ("player");
312            this->spawn (this->localPlayer);
[3368]313            /*monitor progress*/
[3675]314            //this->glmis->step();         
315            this->glmis->step();
[3368]316
[2636]317            // bind input
[3365]318            Orxonox *orx = Orxonox::getInstance ();
[3586]319            orx->getLocalInput()->bind (this->localPlayer);
[2636]320           
321            // bind camera
[3635]322            this->localCamera = new Camera();
[3365]323            this->localCamera->setName ("camera");
[3635]324            this->localCamera->lookAt(this->localPlayer);
[3643]325            this->localCamera->setParent(this->localPlayer);
[3637]326           
[3507]327            /*monitor progress*/
[3675]328            this->glmis->step();
[2816]329
[3419]330            // Create SkySphere
[3545]331            this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
332            this->skySphere->setName("SkySphere");
[3527]333            this->localCamera->addChild(this->skySphere);
[3565]334            this->skySphere->setMode(PNODE_MOVEMENT);
[3419]335
[3368]336            /*monitor progress*/
337            this->glmis->step();
338
[3521]339           
340            WorldEntity* env = new Environment();
341            env->setName ("env");
342            this->spawn(env);
343
[3586]344           
[3670]345            /*
[3587]346            Vector* es = new Vector (10, 5, 0);
347            Quaternion* qs = new Quaternion ();
[3614]348            WorldEntity* pr = new Primitive(P_CYLINDER);
[3587]349            pr->setName("primitive");
350            this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT);
[3670]351            */
[3521]352
[3368]353            /*monitor progress*/
354            this->glmis->step();
[2816]355
[3535]356            //      trackManager->setBindSlave(env);
[3556]357            PNode* tn = trackManager->getTrackNode();
[3586]358            tn->addChild(this->localPlayer);
[3539]359
[3537]360            //localCamera->setParent(TrackNode::getInstance());
[3643]361            tn->addChild(this->localCamera);
362            //      localCamera->lookAt(tn);
[3710]363            this->localPlayer->setMode(PNODE_ALL);
[3538]364            //Vector* cameraOffset = new Vector (0, 5, -10);
[3596]365            trackManager->condition(2, LEFTRIGHT, this->localPlayer);
[3675]366            this->glmis->step();
[3522]367
[2636]368            break;
369          }
370        case DEBUG_WORLD_1:
371          {
[3756]372            this->testMat = new TestMat();
[3602]373            lightMan->setPosition(.0, .0, .0);
[3603]374            lightMan->setAttenuation(1.0, .01, 0.0);
375            lightMan->setSpecularColor(1,0,0);
[3365]376            this->nullParent = NullParent::getInstance ();
377            this->nullParent->setName ("NullParent");
378
[2636]379            // create a player
[2644]380            WorldEntity* myPlayer = new Player();
[3365]381            myPlayer->setName ("player");
[2644]382            this->spawn(myPlayer);
[3194]383            this->localPlayer = myPlayer;           
[2636]384           
385            // bind input
386            Orxonox *orx = Orxonox::getInstance();
[3226]387            orx->getLocalInput()->bind (myPlayer);
[2636]388           
389            // bind camera
[3635]390            this->localCamera = new Camera ();
[3365]391            this->localCamera->setName ("camera");
[3637]392            this->localCamera->lookAt(LightManager::getInstance()->getLight(0));
393            this->localCamera->setParent(this->localPlayer);
[3429]394
395            // Create SkySphere
396            skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
[3502]397            this->localPlayer->addChild(this->skySphere);
[3429]398
[3586]399            Vector* es = new Vector (20, 0, 0);
400            Quaternion* qs = new Quaternion ();
401
[3602]402            lightMan->getLight(0)->setParent(trackManager->getTrackNode());
[2636]403            break;
404          }
[3727]405        case DEBUG_WORLD_2:
406          {
[3729]407            lightMan->setAmbientColor(.1,.1,.1);
408            lightMan->addLight();
[3727]409            lightMan->setPosition(-5.0, 10.0, -40.0);
410            this->nullParent = NullParent::getInstance ();
411            this->nullParent->setName ("NullParent");
[3756]412           
[3727]413            // !\todo old track-system has to be removed
414
415            //create helper for player
416            //HelperParent* hp = new HelperParent ();
417            /* the player has to be added to this helper */
418
419            // create a player
420            this->localPlayer = new Player ();
421            this->localPlayer->setName ("player");
422            this->spawn (this->localPlayer);
423            /*monitor progress*/
424            //this->glmis->step();         
425            this->glmis->step();
426
427            // bind input
428            Orxonox *orx = Orxonox::getInstance ();
429            orx->getLocalInput()->bind (this->localPlayer);
430           
431            // bind camera
432            this->localCamera = new Camera();
433            this->localCamera->setName ("camera");
434            this->localCamera->lookAt(this->localPlayer);
435            this->localCamera->setParent(this->localPlayer);
436           
437            /*monitor progress*/
438            this->glmis->step();
439
440            // Create SkySphere
441            this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
442            this->skySphere->setName("SkySphere");
443            this->localCamera->addChild(this->skySphere);
444            this->skySphere->setMode(PNODE_MOVEMENT);
445
446            /*monitor progress*/
447            this->glmis->step();
448
449
[3750]450            WorldEntity* baseNode = new Satellite(Vector(1,0,1), 1.2);
451            this->localPlayer->addChild(baseNode);
452            baseNode->setRelCoor(new Vector(10.0, 2.0, 1.0));
453            this->spawn(baseNode);
[3730]454
[3752]455            WorldEntity* secondNode = new Satellite(Vector(0,0,1), 2.0);
[3750]456            baseNode->addChild(secondNode);
[3752]457            secondNode->setRelCoor(new Vector(0.0, 0.0, 3.0));
[3750]458            this->spawn(secondNode);
[3729]459
[3750]460
[3752]461            WorldEntity* thirdNode = new Satellite(Vector(0,0,1), 1.0);
[3750]462            secondNode->addChild(thirdNode);
463            thirdNode->setRelCoor(new Vector(2.0, 0.0, 0.0));
464            this->spawn(thirdNode);
465
466
[3752]467           
468           
[3750]469
[3729]470            WorldEntity* b = new Environment();
471            this->localPlayer->addChild(b);
[3730]472            b->setRelCoor(new Vector(10.0, 1.0, 1.0));
[3729]473            this->spawn(b);
[3730]474
[3745]475           
[3730]476            WorldEntity* c = new Environment();
477            this->localPlayer->addChild(c);
478            c->setRelCoor(new Vector(10.0, 2.0, -1.0));
479            this->spawn(c);
[3745]480           
[3727]481           
[3729]482            KeyFrame* f1 = new KeyFrame;
[3739]483            f1->position = new Vector(-1.1, 0.0, 2.6);
[3729]484            f1->direction = new Quaternion();
[3739]485            f1->time = 1.0;
[3733]486            f1->mode = NEG_EXP;
[3729]487
488
489            KeyFrame* f2 = new KeyFrame;
[3739]490            f2->position = new Vector(-2.1, 0.0, 2.6);
[3729]491            f2->direction = new Quaternion();
[3739]492            f2->time = 0.1;
[3733]493            f2->mode = NEG_EXP;
[3729]494
[3731]495            KeyFrame* f3 = new KeyFrame;
[3745]496            f3->position = new Vector(10.0, 2.0, -1.0);
[3731]497            f3->direction = new Quaternion();
[3739]498            f3->time = 0.2;
[3733]499            f3->mode = NEG_EXP;
[3731]500
[3745]501            KeyFrame* f4 = new KeyFrame;
502            f4->position = new Vector(10.0, 5.0, -1.0);
503            f4->direction = new Quaternion();
504            f4->time = 1.0;
505            f4->mode = NEG_EXP;
[3731]506
[3745]507
[3752]508
[3729]509            this->simpleAnimation->animatorBegin();
510            this->simpleAnimation->selectObject(b);
[3752]511            this->simpleAnimation->setAnimationMode(SINGLE);
[3729]512            this->simpleAnimation->addKeyFrame(f1);
513            this->simpleAnimation->addKeyFrame(f2);
[3744]514            this->simpleAnimation->start();
[3745]515            this->simpleAnimation->selectObject(c);
516            this->simpleAnimation->addKeyFrame(f3);
517            this->simpleAnimation->addKeyFrame(f4);
518            this->simpleAnimation->start();
[3729]519            this->simpleAnimation->animatorEnd();
520
521
522            /*
[3727]523            Vector* es = new Vector (10, 5, 0);
524            Quaternion* qs = new Quaternion ();
525            WorldEntity* pr = new Primitive(P_CYLINDER);
526            pr->setName("primitive");
527            this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT);
528            */
529
530            /*monitor progress*/
531            this->glmis->step();
532
533            //      trackManager->setBindSlave(env);
534            PNode* tn = trackManager->getTrackNode();
535            tn->addChild(this->localPlayer);
536
537            //localCamera->setParent(TrackNode::getInstance());
538            tn->addChild(this->localCamera);
539            //      localCamera->lookAt(tn);
540            this->localPlayer->setMode(PNODE_ALL);
541            //Vector* cameraOffset = new Vector (0, 5, -10);
542            trackManager->condition(2, LEFTRIGHT, this->localPlayer);
543            this->glmis->step();
544
545            break;
546          }
[2636]547        default:
548          printf("World::load() - no world with ID %i found", this->debugWorldNr );
549        }
550    }
551  else if(this->worldName != NULL)
552    {
553
554    }
[2731]555
556  // initialize debug coord system
557  objectList = glGenLists(1);
558  glNewList (objectList, GL_COMPILE);
[3559]559 
[3365]560  trackManager->drawGraph(.01);
561  trackManager->debug(2);
[2731]562  glEndList();
[3526]563
[3567]564  terrain = new Terrain("../data/worlds/newGround.obj");
[3568]565  terrain->setRelCoor(new Vector(0,-10,0));
[3559]566  this->spawn(terrain);
[3455]567
[2636]568}
569
[3629]570
[3459]571/**
[3629]572   \brief initializes a new World shortly before start
573
574   this is the function, that will be loaded shortly before the world is
575   started
[3459]576*/
577ErrorMessage World::init()
578{
579  this->bPause = false;
580  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
581  cn->addToWorld(this);
582  cn->enable(true);
583}
584
585
586/**
587   \brief starts the World
588*/
589ErrorMessage World::start()
590{
[3546]591  PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr);
[3459]592  this->bQuitOrxonox = false;
593  this->bQuitCurrentGame = false;
594  this->mainLoop();
595}
596
597/**
598   \brief stops the world.
599
600   This happens, when the player decides to end the Level.
601*/
602ErrorMessage World::stop()
603{
[3546]604  PRINTF(3)("World::stop() - got stop signal\n");
[3459]605  this->bQuitCurrentGame = true;
606}
607
608/**
609   \brief pauses the Game
610*/
611ErrorMessage World::pause()
612{
613  this->isPaused = true;
614}
615
616/**
617   \brief ends the pause Phase
618*/
619ErrorMessage World::resume()
620{
621  this->isPaused = false;
622}
623
624/**
625   \brief destroys the World
626*/
627ErrorMessage World::destroy()
628{
[3566]629
[3459]630}
631
632/**
633   \brief shows the loading screen
634*/
635void World::displayLoadScreen ()
636{
[3546]637  PRINTF(3)("World::displayLoadScreen - start\n"); 
[3459]638 
639  //GLMenuImageScreen*
640  this->glmis = GLMenuImageScreen::getInstance();
641  this->glmis->init();
[3675]642  this->glmis->setMaximum(8);
[3459]643  this->glmis->draw();
644 
[3546]645  PRINTF(3)("World::displayLoadScreen - end\n"); 
[3459]646}
647
648/**
649   \brief removes the loadscreen, and changes over to the game
650
651   \todo take out the delay
652*/
653void World::releaseLoadScreen ()
654{
[3546]655  PRINTF(3)("World::releaseLoadScreen - start\n"); 
[3459]656  this->glmis->setValue(this->glmis->getMaximum());
[3675]657  //SDL_Delay(500);
[3546]658  PRINTF(3)("World::releaseLoadScreen - end\n"); 
[3459]659}
660
661
[3620]662/**
663   \brief gets the list of entities from the world
664   \returns entity list
665*/
666tList<WorldEntity>* World::getEntities()
667{
668  return this->entities;
669}
670
671
[3646]672/**
673   \brief this returns the current game time
674   \returns elapsed game time
675*/
676double World::getGameTime()
677{
678  return this->gameTime;
679}
680
681
[2636]682/**
[2551]683    \brief checks for collisions
684   
685    This method runs through all WorldEntities known to the world and checks for collisions
686    between them. In case of collisions the collide() method of the corresponding entities
687    is called.
[1858]688*/
[2190]689void World::collide ()
[1858]690{
[2816]691  /*
692  List *a, *b;
[2551]693  WorldEntity *aobj, *bobj;
[2816]694   
695  a = entities;
[2551]696 
697  while( a != NULL)
698    {
[2816]699      aobj = a->nextElement();
[2551]700      if( aobj->bCollide && aobj->collisioncluster != NULL)
[2190]701        {
[2816]702          b = a->nextElement();
[2551]703          while( b != NULL )
704            {
[2816]705              bobj = b->nextElement();
[2551]706              if( bobj->bCollide && bobj->collisioncluster != NULL )
[2190]707                {
[2551]708                  unsigned long ahitflg, bhitflg;
709                  if( check_collision ( &aobj->place, aobj->collisioncluster,
710                                        &ahitflg, &bobj->place, bobj->collisioncluster,
711                                        &bhitflg) );
712                  {
713                    aobj->collide (bobj, ahitflg, bhitflg);
714                    bobj->collide (aobj, bhitflg, ahitflg);
715                  }
[2190]716                }
[2816]717              b = b->nextElement();
[2551]718            }
[2190]719        }
[2816]720      a = a->enumerate();
[2551]721    }
[2816]722  */
[1858]723}
724
725/**
[2551]726    \brief runs through all entities calling their draw() methods
[1931]727*/
[2190]728void World::draw ()
[2077]729{
[3462]730  /* draw entities */
[2551]731  WorldEntity* entity;
[3526]732  glLoadIdentity();
733
[3653]734  //entity = this->entities->enumerate();
735  tIterator<WorldEntity>* iterator = this->entities->getIterator();
736  entity = iterator->nextElement();
[2816]737  while( entity != NULL ) 
[2551]738    { 
[2822]739      if( entity->bDraw ) entity->draw();
[3653]740      //entity = this->entities->nextElement();
741      entity = iterator->nextElement();
742    }
743  delete iterator;
[3756]744
745  if (this->testMat)
746    this->testMat->draw();
747
[2731]748  glCallList (objectList);
[3419]749  //! \todo skysphere is a WorldEntity and should be inside of the world-entity-list.
750  skySphere->draw();
751
[3456]752  testFont->printText(0, 0, 1, "orxonox_" PACKAGE_VERSION);
[3455]753
[3602]754  lightMan->draw(); // must be at the end of the drawing procedure, otherwise Light cannot be handled as PNodes //
[1931]755}
756
[2816]757
[2190]758/**
[3225]759   \brief function to put your own debug stuff into it. it can display informations about
760   the current class/procedure
761*/
[2640]762void World::debug()
763{
[3546]764  PRINTF(2)("debug() - starting debug\n");
[3365]765  PNode* p1 = NullParent::getInstance ();
766  PNode* p2 = new PNode (new Vector(2, 2, 2), p1);
767  PNode* p3 = new PNode (new Vector(4, 4, 4), p1);
768  PNode* p4 = new PNode (new Vector(6, 6, 6), p2);
769
770  p1->debug ();
771  p2->debug ();
772  p3->debug ();
773  p4->debug ();
774
775  p1->shiftCoor (new Vector(-1, -1, -1));
776
777  printf("World::debug() - shift\n");
778  p1->debug ();
779  p2->debug ();
780  p3->debug ();
781  p4->debug ();
782 
[3644]783  p1->update (0);
[3365]784
785  printf ("World::debug() - update\n");
786  p1->debug ();
787  p2->debug ();
788  p3->debug ();
789  p4->debug ();
790
791  p2->shiftCoor (new Vector(-1, -1, -1));
[3644]792  p1->update (0);
[3365]793
794  p1->debug ();
795  p2->debug ();
796  p3->debug ();
797  p4->debug ();
798
799  p2->setAbsCoor (new Vector(1,2,3));
800
801
[3644]802 p1->update (0);
[3365]803
804  p1->debug ();
805  p2->debug ();
806  p3->debug ();
807  p4->debug ();
808
[3544]809  delete p1;
[3365]810 
811 
812  /*
[2640]813  WorldEntity* entity;
814  printf("counting all entities\n");
[2816]815  printf("World::debug() - enumerate()\n");
816  entity = entities->enumerate(); 
817  while( entity != NULL )
[2640]818    {
819      if( entity->bDraw ) printf("got an entity\n");
[2816]820      entity = entities->nextElement();
[2640]821    }
[3365]822  */
[2640]823}
[2636]824
[2640]825
[3449]826/**
[3225]827  \brief main loop of the world: executing all world relevant function
828
829  in this loop we synchronize (if networked), handle input events, give the heart-beat to
830  all other member-entities of the world (tick to player, enemies etc.), checking for
831  collisions drawing everything to the screen.
832*/
[2636]833void World::mainLoop()
834{
[3365]835  this->lastFrame = SDL_GetTicks ();
[3546]836  PRINTF(3)("World::mainLoop() - Entering main loop\n");
[3215]837  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */
[2551]838    {
[3546]839      PRINTF(3)("World::mainloop() - number of entities: %i\n", this->entities->getSize());
[2636]840      // Network
[3365]841      this->synchronize ();
[2636]842      // Process input
[3365]843      this->handleInput ();
[3215]844      if( this->bQuitCurrentGame || this->bQuitOrxonox)
845          break;
[2636]846      // Process time
[3551]847      this->tick ();
848      // Update the state
849      this->update ();     
[2636]850      // Process collision
[3459]851      this->collide ();
[2636]852      // Draw
[3365]853      this->display ();
[3548]854
[3565]855      //      for( int i = 0; i < 5000000; i++) {}
[3365]856      /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/
[2551]857    }
[3546]858  PRINTF(3)("World::mainLoop() - Exiting the main loop\n");
[1899]859}
860
[3459]861
[2190]862/**
[2636]863   \brief synchronize local data with remote data
[1855]864*/
[2636]865void World::synchronize ()
[1855]866{
[2636]867  // Get remote input
868  // Update synchronizables
[1855]869}
[2636]870
[3459]871
[2636]872/**
873   \brief run all input processing
[3225]874
875   the command node is the central input event dispatcher. the node uses the even-queue from
876   sdl and has its own event-passing-queue.
[2636]877*/
[3225]878void World::handleInput ()
[2636]879{
880  // localinput
[3225]881  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
[3216]882  cn->process();
[2636]883  // remoteinput
884}
885
[3459]886
[2636]887/**
888   \brief advance the timeline
[3225]889
890   this calculates the time used to process one frame (with all input handling, drawing, etc)
891   the time is mesured in ms and passed to all world-entities and other classes that need
892   a heart-beat.
[2636]893*/
[3551]894void World::tick ()
[2636]895{
896  Uint32 currentFrame = SDL_GetTicks();
897  if(!this->bPause)
898    {
[3644]899      this->dt = currentFrame - this->lastFrame;
[2816]900     
[3646]901      if( this->dt > 0)
[2636]902        {
903          float fps = 1000/dt;
[3546]904          PRINTF(3)("fps = %f\n", fps);
[2636]905        }
906      else
907        {
[3225]908          /* the frame-rate is limited to 100 frames per second, all other things are for
909             nothing.
910          */
[3546]911          PRINTF(2)("fps = 1000 - frame rate is adjusted\n");
[3194]912          SDL_Delay(10);
[3646]913          this->dt = 10;
[2636]914        }
[3459]915      //this->timeSlice (dt);
916     
917      /* function to let all entities tick (iterate through list) */
[3646]918      float seconds = this->dt / 1000.0;     
919      this->gameTime += seconds;
[3654]920      //entity = entities->enumerate();
921      tIterator<WorldEntity>* iterator = this->entities->getIterator();
922      WorldEntity* entity = iterator->nextElement();
[3459]923      while( entity != NULL) 
924        { 
925          entity->tick (seconds);
[3654]926          entity = iterator->nextElement();
[3459]927        }
[3654]928      delete iterator;
[3502]929      //skySphere->updatePosition(localCamera->absCoordinate);
[3459]930     
931      /* update tick the rest */
[3646]932      this->trackManager->tick(this->dt);
933      this->localCamera->tick(this->dt);
934      this->garbageCollector->tick(seconds);
[3729]935      this->simpleAnimation->tick(seconds);
[2636]936    }
937  this->lastFrame = currentFrame;
938}
939
[3216]940
[2636]941/**
[3551]942   \brief this function gives the world a consistant state
943
944   after ticking (updating the world state) this will give a constistant
945   state to the whole system.
946*/
947void World::update()
948{
[3646]949  this->garbageCollector->update();
[3644]950  this->nullParent->update (dt);
[3551]951}
952
953
954/**
[3225]955   \brief render the current frame
956   
957   clear all buffers and draw the world
[2636]958*/
959void World::display ()
960{
961  // clear buffer
962  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
963  // set camera
964  this->localCamera->apply ();
965  // draw world
966  this->draw();
967  // draw HUD
[3365]968  /* \todo draw HUD */
[2636]969  // flip buffers
970  SDL_GL_SwapBuffers();
[3365]971  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
972  //SDL_Flip (screen);
[2636]973}
974
[2644]975
[3225]976/**
977   \brief add and spawn a new entity to this world
978   \param entity to be added
979*/
[2644]980void World::spawn(WorldEntity* entity)
981{
[3365]982  this->entities->add (entity);
[3233]983  entity->postSpawn ();
[2816]984}
985
986
[3225]987/**
988   \brief add and spawn a new entity to this world
989   \param entity to be added
[3449]990   \param absCoor At what coordinates to add this entity.
991   \param absDir In which direction should it look.
[3225]992*/
[3365]993void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
[2816]994{
[3529]995  this->entities->add (entity);
996
[3365]997  entity->setAbsCoor (absCoor);
998  entity->setAbsDir (absDir);
999
[3233]1000  entity->postSpawn ();
[2644]1001}
[2816]1002
1003
[3521]1004/**
1005   \brief add and spawn a new entity to this world
1006   \param entity to be added
1007   \param entity to be added to (PNode)
1008   \param At what relative  coordinates to add this entity.
1009   \param In which relative direction should it look.
1010*/
1011void World::spawn(WorldEntity* entity, PNode* parentNode, 
1012                  Vector* relCoor, Quaternion* relDir, 
[3565]1013                  int parentingMode)
[3521]1014{
[3551]1015  this->nullParent = NullParent::getInstance();
[3529]1016  if( parentNode != NULL)
[3521]1017    {
1018      parentNode->addChild (entity);
1019     
1020      entity->setRelCoor (relCoor);
1021      entity->setRelDir (relDir);
[3586]1022      entity->setMode(parentingMode);
[3521]1023     
1024      this->entities->add (entity);
1025     
1026      entity->postSpawn ();
1027    }
1028}
1029
1030
1031
[3449]1032/**
[3225]1033  \brief commands that the world must catch
1034  \returns false if not used by the world
1035*/
[3216]1036bool World::command(Command* cmd)
1037{
[3640]1038  if( !strcmp( cmd->cmd, "view0")) this->localCamera->setViewMode(VIEW_NORMAL);
1039  else if( !strcmp( cmd->cmd, "view1")) this->localCamera->setViewMode(VIEW_BEHIND);
1040  else if( !strcmp( cmd->cmd, "view2")) this->localCamera->setViewMode(VIEW_FRONT);
1041  else if( !strcmp( cmd->cmd, "view3")) this->localCamera->setViewMode(VIEW_LEFT);
1042  else if( !strcmp( cmd->cmd, "view4")) this->localCamera->setViewMode(VIEW_RIGHT);
[3643]1043  else if( !strcmp( cmd->cmd, "view5")) this->localCamera->setViewMode(VIEW_TOP);
[3640]1044 
[3216]1045  return false;
1046}
[3365]1047
Note: See TracBrowser for help on using the repository browser.