Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3557 was 3557, checked in by chris, 19 years ago

orxonox/branches/levelloader: Rolling toward bug-free-ness

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