Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: renamed all timing functions to tick() - cleanede up world

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