Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/trackManager/src/story_entities/world.cc @ 3516

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

orxonox/branches/trackManager: now nearest works… this was rather strange
what is important is, that the nearest node is not too far from the center (if there is a 3-fork :)

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