Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: resolved a list deleting problem in tlist.h.

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