Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the important files of the trackManager to the trunk
It was not anymore possible to merge.

this is not so big a problem, as I only coded inside the track_manager, track_node files. But it will be if we try to merge other branches back to the trunk

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