Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/story_entities/world.cc @ 3734

Last change on this file since 3734 was 3734, checked in by patrick, 19 years ago

orxonox/trunk: SimpleAnimation: the NEG_EXP function now gets scaled in a very smooth manner.

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