Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: now the delete-process is as inteded by c++
virtual ~ClassName extends deletion and deletes also the MasterClass

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