Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/story_entities/world.cc @ 3605

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

orxonox/trunk: merged trunk back to levelloader
merged with command:
svn merge -r 3499:HEAD trunk branches/levelloader

Conflicts in
C track_manager.h
C world_entities/player.cc
C world_entities/player.h
C world_entities/environment.h
C lib/coord/p_node.cc
C defs/debug.h
C track_manager.cc
C story_entities/campaign.h

solved in merge-favouring. It was quite easy because Chris only worked on the headers, and he didi it quite clean. Thats the spirit :)

Conflits in world.cc are a MESS: fix it

File size: 22.8 KB
Line 
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.
11
12   ### File Specific:
13   main-programmer: Patrick Boenzli
14   co-programmer: Christian Meyer
15*/
16
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
18
19#include "world.h"
20#include "world_entity.h"
21#include "track_manager.h"
22#include "player.h"
23#include "command_node.h"
24#include "camera.h"
25#include "environment.h"
26#include "primitive.h"
27#include "p_node.h"
28#include "null_parent.h"
29#include "helper_parent.h"
30#include "glmenu_imagescreen.h"
31#include "skysphere.h"
32#include "light.h"
33#include "fontset.h"
34#include "factory.h"
35#include "game_loader.h"
36#include "track_node.h"
37#include "terrain.h"
38
39using namespace std;
40
41CREATE_FACTORY(World);
42
43World::World( TiXmlElement* root)
44{
45        const char *string;
46        char *name;
47        int id;
48
49        PRINTF0("Creating a World\n");
50       
51        // identifier
52        string = grabParameter( root, "identifier");
53        if( string == NULL || sscanf(string, "%d", &id) != 1)
54        {
55                PRINTF0("World is missing a proper 'identifier'\n");
56                this->setStoryID( -1);
57        }
58        else setStoryID( id);
59       
60        // path
61        string = grabParameter( root, "path");
62        if( string == NULL)
63        {
64                PRINTF0("World is missing a proper 'path'\n");
65                this->setPath( NULL);
66        }
67        else
68        {
69                name = new char[strlen(string + 2)];
70                strcpy( name, string);
71                this->setPath( name);
72        }
73       
74        localPlayer = NULL;
75  this->entities = new tList<WorldEntity>();
76               
77}
78
79/**
80    \brief create a new World
81   
82    This creates a new empty world!
83*/
84World::World (char* name)
85{
86  this->init(name, -1);
87  //NullParent* np = NullParent::getInstance();
88}
89
90/**
91   \brief creates a new World...
92   \param worldID with this ID
93*/
94World::World (int worldID)
95{
96  this->init(NULL, worldID);
97}
98
99/**
100    \brief remove the World from memory
101   
102    delete everything explicitly, that isn't contained in the parenting tree!
103    things contained in the tree are deleted automaticaly
104*/
105World::~World ()
106{
107  PRINTF(3)("World::~World() - deleting current world\n");
108  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
109  cn->unbind(this->localPlayer);
110  cn->reset();
111
112  delete this->nullParent;
113  delete this->entities;
114  delete this->lightMan;
115  delete this->trackManager;
116}
117  if( this->worldName) delete this->worldName;
118  if( this->path) delete this->path;
119
120/**
121   \brief initializes a new World
122*/
123void World::init(char* name, int worldID)
124{
125  this->setClassName ("World");
126
127  this->worldName = name;
128  this->debugWorldNr = worldID;
129  this->entities = new tList<WorldEntity>();
130
131  // Enable default GL stuff
132  glEnable(GL_DEPTH_TEST);
133
134}
135
136
137/**
138   \brief loads the World by initializing all resources, and set their default values.
139*/
140ErrorMessage World::load()
141{
142<<<<<<< .working
143       
144        PRINTF0("> Loading world: '%s'\n", getPath());
145       
146        GameLoader* loader = GameLoader::getInstance();
147       
148  if( getPath() == NULL)
149  {
150                PRINTF0("World has no path specified for loading");
151                return (ErrorMessage){213,"Path not specified","World::load()"};
152  }
153 
154        TiXmlDocument* XMLDoc = new TiXmlDocument( path);
155        // load the campaign document
156        if( !XMLDoc->LoadFile())
157=======
158  //  BezierCurve* tmpCurve = new BezierCurve();
159  if(this->debugWorldNr != -1)
160    {
161      // initializing Font
162      testFont = new FontSet();
163      testFont->buildFont("../data/pictures/font.tga");
164
165      // initializing the TrackManager
166      trackManager = TrackManager::getInstance();
167      trackManager->addPoint(Vector(0,0,0));
168      trackManager->addPoint(Vector(100, -40, 5));
169      trackManager->addPoint(Vector(200,-40,-8));
170      trackManager->addPoint(Vector(250, -35, -2));
171      trackManager->addPoint(Vector(320,-33,-.55));
172      trackManager->setDuration(1);
173      trackManager->setSavePoint();
174      trackManager->addPoint(Vector(410, 0, 0));
175      trackManager->addPoint(Vector(510, 20, -10));
176      trackManager->addPoint(Vector(550, 20, -10));
177      trackManager->addPoint(Vector(570, 20, -10));
178      trackManager->setDuration(1);
179     
180      int fork11, fork12;
181      trackManager->fork(2, &fork11, &fork12);
182      trackManager->workOn(fork11);
183      trackManager->addPoint(Vector(640, 25, -30));
184      trackManager->addPoint(Vector(700, 40, -120));
185      trackManager->addPoint(Vector(800, 50, -150));
186      trackManager->addPoint(Vector(900, 60, -100));
187      trackManager->addPoint(Vector(900, 60, -70));
188      trackManager->addPoint(Vector(990, 65, -15));
189      trackManager->addPoint(Vector(1050, 65, -10));
190      trackManager->addPoint(Vector(1100, 65, -20));
191      trackManager->setDuration(4);
192
193      trackManager->workOn(fork12);
194      trackManager->addPoint(Vector(640, 25, 20));
195      trackManager->addPoint(Vector(670, 50, 120));
196      trackManager->addPoint(Vector(700, 70, 80));
197      trackManager->addPoint(Vector(800, 70, 65));
198      trackManager->addPoint(Vector(850, 65, 65));
199      trackManager->addPoint(Vector(920, 35, 40));
200      trackManager->addPoint(Vector(945, 40, 40));
201      trackManager->addPoint(Vector(970, 24, 40));
202      trackManager->addPoint(Vector(1000, 40, -7));
203      trackManager->setDuration(4);
204     
205
206      trackManager->join(2, fork11, fork12);
207
208      trackManager->workOn(5);
209      trackManager->addPoint(Vector(1200, 60, -50));
210      trackManager->addPoint(Vector(1300, 50, -50));
211      trackManager->addPoint(Vector(1400, 40, -50));
212      trackManager->addPoint(Vector(1500, 40, -60));
213      trackManager->addPoint(Vector(1600, 35, -55));
214      trackManager->addPoint(Vector(1700, 45, -40));
215      trackManager->addPoint(Vector(1750, 60, -40));
216      trackManager->addPoint(Vector(1770, 80, -40));
217      trackManager->addPoint(Vector(1800, 100, -40));
218      trackManager->setDuration(4);
219
220      trackManager->finalize();
221
222     
223      /*monitor progress*/
224      this->glmis->step();
225
226      // LIGHT initialisation
227      lightMan = LightManager::getInstance();
228      lightMan->setAmbientColor(.1,.1,.1);
229      lightMan->addLight();
230      //      lightMan->setAttenuation(1.0, .01, 0.0);
231      //      lightMan->setDiffuseColor(1,1,1);
232      //  lightMan->addLight(1);
233      //  lightMan->setPosition(20, 10, -20);
234      //  lightMan->setDiffuseColor(0,0,0);
235      lightMan->debug();
236
237      switch(this->debugWorldNr)
238>>>>>>> .merge-right.r3604
239        {
240<<<<<<< .working
241                // report an error
242                PRINTF0("Error loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
243                delete XMLDoc;
244                return (ErrorMessage){213,"XML File parsing error","World::load()"};
245        }
246       
247        // check basic validity
248        TiXmlElement* root = XMLDoc->RootElement();
249        assert( root != NULL);
250       
251        if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))
252        {
253                // report an error
254                PRINTF0("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
255                delete XMLDoc;
256                return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"};
257        }
258       
259        // load the parameters
260                // name
261        char* temp;
262        const char* string = grabParameter( root, "name");
263        if( string == NULL)
264        {
265                PRINTF0("World is missing a proper 'name'\n");
266                string = "Unknown";
267                temp = new char[strlen(string + 2)];
268                strcpy( temp, string);
269                this->worldName = temp;
270        }
271        else
272        {
273                temp = new char[strlen(string + 2)];
274                strcpy( temp, string);
275                this->worldName = temp;
276        }
277       
278       
279        // find WorldEntities
280  TiXmlElement* element = root->FirstChildElement( "WorldEntities");
281 
282  if( element == NULL)
283  {
284                PRINTF0("World is missing 'WorldEntities'\n");
285  }
286  else
287  {
288        element = element->FirstChildElement();
289          // load Players/Objects/Whatever
290                PRINTF0("Loading WorldEntities\n");
291                while( element != NULL)
292                {
293                        WorldEntity* created = (WorldEntity*) loader->fabricate( element);
294                        if( created != NULL) this->spawn( created);
295                                // if we load a 'Player' we use it as localPlayer
296                                //todo do this more elegant
297                         if( element->Value() != NULL && !strcmp( element->Value(), "Player")) localPlayer = (Player*) created;
298                        element = element->NextSiblingElement();
299                }
300                PRINTF0("Done loading WorldEntities\n");
301        }
302       
303        // find Track
304  element = root->FirstChildElement( "Track");
305  if( element == NULL)
306  {
307                PRINTF0("World is missing a 'Track'\n");
308  }
309  else
310  {     
311        //load track
312                PRINTF0("Loading Track\n");
313                trackManager = TrackManager::getInstance();
314        trackManager->loadTrack( element);
315        trackManager->finalize();
316                PRINTF0("Done loading Track\n");
317        }
318=======
319          /*
320            this loads the hard-coded debug world. this only for simplicity and will be
321            removed by a reald world-loader, which interprets a world-file.
322            if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and
323            make whatever you want...
324           */
325        case DEBUG_WORLD_0:
326          {
327            lightMan->setPosition(-5.0, 10.0, -40.0);
328            this->nullParent = NullParent::getInstance ();
329            this->nullParent->setName ("NullParent");
330>>>>>>> .merge-right.r3604
331
332       
333        // free the XML data
334        delete XMLDoc;
335       
336        // finalize world
337          // initialize Font
338          testFont = new FontSet();
339          testFont->buildFont("../data/pictures/font.tga");
340       
341                // create null parent
342    this->nullParent = NullParent::getInstance ();
343    this->nullParent->setName ("NullParent");
344   
345    // finalize myPlayer
346                if( localPlayer == NULL)
347                {
348                        PRINTF0("No Player specified in World '%s'\n", this->worldName);
349                        return (ErrorMessage){213,"No Player defined","World::load()"};
350                }
351               
352        // bind input
353    Orxonox *orx = Orxonox::getInstance ();
354    orx->getLocalInput()->bind (localPlayer);
355   
356        // bind camera
357    this->localCamera = new Camera(this);
358    this->localCamera->setName ("camera");
359    this->localCamera->bind (localPlayer);
360    this->localPlayer->addChild (this->localCamera);
361
362<<<<<<< .working
363       
364        // stuff beyond this point remains to be loaded properly
365       
366      /*monitor progress*/
367  //  this->glmis->step();
368=======
369            //create helper for player
370            //HelperParent* hp = new HelperParent ();
371            /* the player has to be added to this helper */
372>>>>>>> .merge-right.r3604
373
374<<<<<<< .working
375=======
376            // create a player
377            this->localPlayer = new Player ();
378            this->localPlayer->setName ("player");
379            this->spawn (this->localPlayer);
380            /*monitor progress*/
381            this->glmis->step();           
382
383            // bind input
384            Orxonox *orx = Orxonox::getInstance ();
385            orx->getLocalInput()->bind (this->localPlayer);
386           
387            // bind camera
388            this->localCamera = new Camera(this);
389            this->localCamera->setName ("camera");
390            this->localCamera->bind (this->localPlayer);
391            /*monitor progress*/
392            this->glmis->step();           
393
394>>>>>>> .merge-right.r3604
395            // Create SkySphere
396            this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
397            this->skySphere->setName("SkySphere");
398            this->localCamera->addChild(this->skySphere);
399            this->skySphere->setMode(PNODE_MOVEMENT);
400
401            /*monitor progress*/
402          //  this->glmis->step();
403         
404          //  trackManager->setBindSlave(env);
405
406<<<<<<< .working
407=======
408           
409            WorldEntity* env = new Environment();
410            env->setName ("env");
411            this->spawn(env);
412
413           
414            Vector* es = new Vector (10, 5, 0);
415            Quaternion* qs = new Quaternion ();
416            WorldEntity* pr = new Primitive(PSPHERE);
417            pr->setName("primitive");
418            this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT);
419           
420
421            /*monitor progress*/
422            this->glmis->step();
423
424            //      trackManager->setBindSlave(env);
425            PNode* tn = trackManager->getTrackNode();
426            tn->addChild(this->localPlayer);
427
428            //localCamera->setParent(TrackNode::getInstance());
429            tn->addChild (this->localCamera);
430            this->localPlayer->setMode(PNODE_ROTATE_AND_MOVE);
431            //Vector* cameraOffset = new Vector (0, 5, -10);
432            Vector* cameraOffset = new Vector (-10, 5, 0);
433            this->localCamera->setRelCoor (cameraOffset);
434            trackManager->condition(2, LEFTRIGHT, this->localPlayer);
435
436            break;
437          }
438        case DEBUG_WORLD_1:
439          {
440            lightMan->setPosition(.0, .0, .0);
441            lightMan->setAttenuation(1.0, .01, 0.0);
442            lightMan->setSpecularColor(1,0,0);
443            this->nullParent = NullParent::getInstance ();
444            this->nullParent->setName ("NullParent");
445
446            // create a player
447            WorldEntity* myPlayer = new Player();
448            myPlayer->setName ("player");
449            this->spawn(myPlayer);
450            this->localPlayer = myPlayer;           
451           
452            // bind input
453            Orxonox *orx = Orxonox::getInstance();
454            orx->getLocalInput()->bind (myPlayer);
455           
456            // bind camera
457            this->localCamera = new Camera (this);
458            this->localCamera->setName ("camera");
459            this->localCamera->bind (myPlayer); 
460            this->localPlayer->addChild (this->localCamera);
461
462            // Create SkySphere
463            skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
464            this->localPlayer->addChild(this->skySphere);
465
466            Vector* es = new Vector (20, 0, 0);
467            Quaternion* qs = new Quaternion ();
468            WorldEntity* pr = new Primitive(PSPHERE);
469            pr->setName("primitive");
470            this->spawn(pr, this->localPlayer, es, qs, PNODE_ROTATE_AND_MOVE);
471
472            lightMan->getLight(0)->setParent(trackManager->getTrackNode());
473            break;
474          }
475        default:
476          printf("World::load() - no world with ID %i found", this->debugWorldNr );
477        }
478    }
479  else if(this->worldName != NULL)
480    {
481
482    }
483
484>>>>>>> .merge-right.r3604
485  // initialize debug coord system
486  objectList = glGenLists(1);
487  glNewList (objectList, GL_COMPILE);
488 
489  trackManager->drawGraph(.01);
490  trackManager->debug(2);
491  glEndList();
492
493  terrain = new Terrain("../data/worlds/newGround.obj");
494  terrain->setRelCoor(new Vector(0,-10,0));
495  this->spawn(terrain);
496
497}
498
499/**
500   \brief initializes a new World
501*/
502ErrorMessage World::init()
503{
504  this->bPause = false;
505  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
506  cn->addToWorld(this);
507  cn->enable(true);
508
509PRINTF0("> Done Loading world: '%s'\n", getPath());
510}
511
512
513/**
514   \brief starts the World
515*/
516ErrorMessage World::start()
517{
518  PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr);
519  this->bQuitOrxonox = false;
520  this->bQuitCurrentGame = false;
521  this->mainLoop();
522}
523
524/**
525   \brief stops the world.
526
527   This happens, when the player decides to end the Level.
528*/
529ErrorMessage World::stop()
530{
531  PRINTF(3)("World::stop() - got stop signal\n");
532  this->bQuitCurrentGame = true;
533}
534
535/**
536   \brief pauses the Game
537*/
538ErrorMessage World::pause()
539{
540  this->isPaused = true;
541}
542
543/**
544   \brief ends the pause Phase
545*/
546ErrorMessage World::resume()
547{
548  this->isPaused = false;
549}
550
551/**
552   \brief destroys the World
553*/
554ErrorMessage World::destroy()
555{
556
557}
558
559/**
560   \brief shows the loading screen
561*/
562void World::displayLoadScreen ()
563{
564  PRINTF(3)("World::displayLoadScreen - start\n"); 
565 
566  //GLMenuImageScreen*
567  this->glmis = GLMenuImageScreen::getInstance();
568  this->glmis->init();
569  this->glmis->setMaximum(10);
570  this->glmis->draw();
571 
572  PRINTF(3)("World::displayLoadScreen - end\n"); 
573}
574
575/**
576   \brief removes the loadscreen, and changes over to the game
577
578   \todo take out the delay
579*/
580void World::releaseLoadScreen ()
581{
582  PRINTF(3)("World::releaseLoadScreen - start\n"); 
583  this->glmis->setValue(this->glmis->getMaximum());
584  SDL_Delay(500);
585  PRINTF(3)("World::releaseLoadScreen - end\n"); 
586}
587
588
589/**
590    \brief checks for collisions
591   
592    This method runs through all WorldEntities known to the world and checks for collisions
593    between them. In case of collisions the collide() method of the corresponding entities
594    is called.
595*/
596void World::collide ()
597{
598  /*
599  List *a, *b;
600  WorldEntity *aobj, *bobj;
601   
602  a = entities;
603 
604  while( a != NULL)
605    {
606      aobj = a->nextElement();
607      if( aobj->bCollide && aobj->collisioncluster != NULL)
608        {
609          b = a->nextElement();
610          while( b != NULL )
611            {
612              bobj = b->nextElement();
613              if( bobj->bCollide && bobj->collisioncluster != NULL )
614                {
615                  unsigned long ahitflg, bhitflg;
616                  if( check_collision ( &aobj->place, aobj->collisioncluster,
617                                        &ahitflg, &bobj->place, bobj->collisioncluster,
618                                        &bhitflg) );
619                  {
620                    aobj->collide (bobj, ahitflg, bhitflg);
621                    bobj->collide (aobj, bhitflg, ahitflg);
622                  }
623                }
624              b = b->nextElement();
625            }
626        }
627      a = a->enumerate();
628    }
629  */
630}
631
632/**
633    \brief runs through all entities calling their draw() methods
634*/
635void World::draw ()
636{
637  /* draw entities */
638  WorldEntity* entity;
639  glLoadIdentity();
640
641  entity = this->entities->enumerate();
642  while( entity != NULL ) 
643    { 
644      if( entity->bDraw ) entity->draw();
645      entity = this->entities->nextElement();
646    } 
647 
648  glCallList (objectList);
649  //! \todo skysphere is a WorldEntity and should be inside of the world-entity-list.
650  skySphere->draw();
651
652  testFont->printText(0, 0, 1, "orxonox_" PACKAGE_VERSION);
653
654  lightMan->draw(); // must be at the end of the drawing procedure, otherwise Light cannot be handled as PNodes //
655}
656
657
658/**
659   \brief function to put your own debug stuff into it. it can display informations about
660   the current class/procedure
661*/
662void World::debug()
663{
664  PRINTF(2)("debug() - starting debug\n");
665  PNode* p1 = NullParent::getInstance ();
666  PNode* p2 = new PNode (new Vector(2, 2, 2), p1);
667  PNode* p3 = new PNode (new Vector(4, 4, 4), p1);
668  PNode* p4 = new PNode (new Vector(6, 6, 6), p2);
669
670  p1->debug ();
671  p2->debug ();
672  p3->debug ();
673  p4->debug ();
674
675  p1->shiftCoor (new Vector(-1, -1, -1));
676
677  printf("World::debug() - shift\n");
678  p1->debug ();
679  p2->debug ();
680  p3->debug ();
681  p4->debug ();
682 
683  p1->update ();
684
685  printf ("World::debug() - update\n");
686  p1->debug ();
687  p2->debug ();
688  p3->debug ();
689  p4->debug ();
690
691  p2->shiftCoor (new Vector(-1, -1, -1));
692  p1->update ();
693
694  p1->debug ();
695  p2->debug ();
696  p3->debug ();
697  p4->debug ();
698
699  p2->setAbsCoor (new Vector(1,2,3));
700
701
702 p1->update ();
703
704  p1->debug ();
705  p2->debug ();
706  p3->debug ();
707  p4->debug ();
708
709  delete p1;
710 
711 
712  /*
713  WorldEntity* entity;
714  printf("counting all entities\n");
715  printf("World::debug() - enumerate()\n");
716  entity = entities->enumerate(); 
717  while( entity != NULL )
718    {
719      if( entity->bDraw ) printf("got an entity\n");
720      entity = entities->nextElement();
721    }
722  */
723}
724
725
726/**
727  \brief main loop of the world: executing all world relevant function
728
729  in this loop we synchronize (if networked), handle input events, give the heart-beat to
730  all other member-entities of the world (tick to player, enemies etc.), checking for
731  collisions drawing everything to the screen.
732*/
733void World::mainLoop()
734{
735  this->lastFrame = SDL_GetTicks ();
736  printf("World::mainLoop() - Entering main loop of '%s'\n", this->worldName);
737  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */
738    {
739      PRINTF(3)("World::mainloop() - number of entities: %i\n", this->entities->getSize());
740      // Network
741      this->synchronize ();
742      // Process input
743      this->handleInput ();
744      if( this->bQuitCurrentGame || this->bQuitOrxonox)
745          break;
746      // Process time
747      this->tick ();
748      // Update the state
749      this->update ();     
750      // Process collision
751     this->collide ();
752      // Draw
753     this->display ();
754
755      //      for( int i = 0; i < 5000000; i++) {}
756      /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/
757    }
758  PRINTF(3)("World::mainLoop() - Exiting the main loop\n");
759}
760
761
762/**
763   \brief synchronize local data with remote data
764*/
765void World::synchronize ()
766{
767  // Get remote input
768  // Update synchronizables
769}
770
771
772/**
773   \brief run all input processing
774
775   the command node is the central input event dispatcher. the node uses the even-queue from
776   sdl and has its own event-passing-queue.
777*/
778void World::handleInput ()
779{
780  // localinput
781  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
782  cn->process();
783  // remoteinput
784}
785
786
787/**
788   \brief advance the timeline
789
790   this calculates the time used to process one frame (with all input handling, drawing, etc)
791   the time is mesured in ms and passed to all world-entities and other classes that need
792   a heart-beat.
793*/
794void World::tick ()
795{
796  Uint32 currentFrame = SDL_GetTicks();
797  if(!this->bPause)
798    {
799      Uint32 dt = currentFrame - this->lastFrame;
800     
801      if(dt > 0)
802        {
803          float fps = 1000/dt;
804          PRINTF(3)("fps = %f\n", fps);
805        }
806      else
807        {
808          /* the frame-rate is limited to 100 frames per second, all other things are for
809             nothing.
810          */
811          PRINTF(2)("fps = 1000 - frame rate is adjusted\n");
812          SDL_Delay(10);
813          dt = 10;
814        }
815      //this->timeSlice (dt);
816     
817      /* function to let all entities tick (iterate through list) */
818      WorldEntity* entity;
819      float seconds = dt / 1000.0; 
820      assert( this->nullParent != NULL); 
821      entity = entities->enumerate(); 
822      while( entity != NULL) 
823        { 
824          entity->tick (seconds);
825          entity = entities->nextElement();
826        }
827      /* update tick the rest */
828      assert( this->localCamera != NULL); 
829      assert( this->trackManager != NULL); 
830      this->localCamera->tick(dt);
831
832      this->trackManager->tick(dt);
833    }
834  this->lastFrame = currentFrame;
835}
836
837
838/**
839   \brief this function gives the world a consistant state
840
841   after ticking (updating the world state) this will give a constistant
842   state to the whole system.
843*/
844void World::update()
845{
846  this->nullParent->update ();
847}
848
849
850/**
851   \brief render the current frame
852   
853   clear all buffers and draw the world
854*/
855void World::display ()
856{
857  // clear buffer
858  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
859  // set camera
860  this->localCamera->apply ();
861  // draw world
862  this->draw();
863  // draw HUD
864  /* \todo draw HUD */
865  // flip buffers
866  SDL_GL_SwapBuffers();
867  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
868  //SDL_Flip (screen);
869}
870
871
872/**
873   \brief add and spawn a new entity to this world
874   \param entity to be added
875*/
876void World::spawn(WorldEntity* entity)
877{
878  this->entities->add (entity);
879  entity->postSpawn ();
880}
881
882
883/**
884   \brief add and spawn a new entity to this world
885   \param entity to be added
886   \param absCoor At what coordinates to add this entity.
887   \param absDir In which direction should it look.
888*/
889void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
890{
891  this->entities->add (entity);
892
893  entity->setAbsCoor (absCoor);
894  entity->setAbsDir (absDir);
895
896  entity->postSpawn ();
897}
898
899
900/**
901   \brief add and spawn a new entity to this world
902   \param entity to be added
903   \param entity to be added to (PNode)
904   \param At what relative  coordinates to add this entity.
905   \param In which relative direction should it look.
906*/
907void World::spawn(WorldEntity* entity, PNode* parentNode, 
908                  Vector* relCoor, Quaternion* relDir, 
909                  int parentingMode)
910{
911  this->nullParent = NullParent::getInstance();
912  if( parentNode != NULL)
913    {
914      parentNode->addChild (entity);
915     
916      entity->setRelCoor (relCoor);
917      entity->setRelDir (relDir);
918      entity->setMode(parentingMode);
919     
920      this->entities->add (entity);
921     
922      entity->postSpawn ();
923    }
924}
925
926
927
928/**
929  \brief commands that the world must catch
930  \returns false if not used by the world
931*/
932bool World::command(Command* cmd)
933{
934  return false;
935}
936
937void World::setPath( char* name)
938{
939        path = name;
940}
941
942char* World::getPath()
943{
944        return path;
945}
Note: See TracBrowser for help on using the repository browser.