Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/parenting/src/world.cc @ 3283

Last change on this file since 3283 was 3277, checked in by patrick, 20 years ago

orxonox/branches/parenting: worldentity is now derived from parentnode, pNode added into the world class, not yet used activly.. this will be a mess…

File size: 19.2 KB
RevLine 
[1853]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.
[1855]11
12   ### File Specific:
13   main-programmer: Patrick Boenzli
[2190]14   co-programmer: Christian Meyer
[1853]15*/
16
[2190]17#include "world.h"
18#include "world_entity.h"
19#include "collision.h"
20#include "track.h"
[2036]21#include "player.h"
[2190]22#include "command_node.h"
23#include "camera.h"
[2816]24#include "environment.h"
[3265]25#include "p_node.h"
[3276]26#include "null_parent.h"
[2036]27
[1856]28using namespace std;
[1853]29
30
[1858]31/**
[2551]32    \brief create a new World
33   
34    This creates a new empty world!
[1858]35*/
[2636]36World::World (char* name)
[1855]37{
[2636]38  this->worldName = name;
39  this->debugWorldNr = -1;
[2822]40  this->entities = new tList<WorldEntity>();
[1855]41}
42
[2636]43World::World (int worldID)
44{
45  this->debugWorldNr = worldID;
46  this->worldName = NULL;
[2822]47  this->entities = new tList<WorldEntity>();
[2636]48}
49
[1858]50/**
[2551]51    \brief remove the World from memory
[1858]52*/
[2190]53World::~World ()
[1872]54{
[3220]55  printf("World::~World() - deleting current world\n");
[3226]56  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
[3220]57  cn->unbind(this->localPlayer);
58  cn->reset();
59  this->localCamera->destroy();
60
61  WorldEntity* entity = entities->enumerate(); 
62  while( entity != NULL ) 
63    { 
64      entity->destroy();
65      entity = entities->nextElement();
66    }
67  this->entities->destroy();
68
[3277]69  /* FIX the parent list has to be cleared - not possible if we got the old list also*/
70  //this->nullParent->destroy ();
71
[2644]72  delete this->entities;
73  delete this->localCamera;
[3220]74  /* this->localPlayer hasn't to be deleted explicitly, it is
75     contained in entities*/
[1872]76}
[1858]77
[2636]78
[3222]79ErrorMessage World::init()
[2636]80{
81  this->bPause = false;
[3226]82  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
[3216]83  cn->addToWorld(this);
84  cn->enable(true);
[3265]85
86  /* this is only for test purposes */
[3277]87  this->debug ();
[2636]88}
89
[3222]90ErrorMessage World::start()
[2636]91{
[3220]92  printf("World::start() - starting current World: nr %i\n", this->debugWorldNr);
93  this->bQuitOrxonox = false;
94  this->bQuitCurrentGame = false;
[2636]95  this->mainLoop();
96}
97
[3222]98ErrorMessage World::stop()
[2636]99{
[3220]100  printf("World::stop() - got stop signal\n");
[2636]101  this->bQuitCurrentGame = true;
102}
103
[3222]104ErrorMessage World::pause()
[2636]105{
106  this->isPaused = true;
107}
108
[3222]109ErrorMessage World::resume()
[2636]110{
111  this->isPaused = false;
112}
113
[3221]114void World::destroy()
115{
116
117}
118
[2636]119void World::load()
120{
121  if(this->debugWorldNr != -1)
122    {
123      switch(this->debugWorldNr)
124        {
[3225]125          /*
126            this loads the hard-coded debug world. this only for simplicity and will be
127            removed by a reald world-loader, which interprets a world-file.
128            if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and
129            make whatever you want...
130           */
[2636]131        case DEBUG_WORLD_0:
132          {
[3277]133            this->nullParent = new NullParent ();
134
[2636]135            // create some path nodes
136            this->pathnodes = new Vector[6];
137            this->pathnodes[0] = Vector(0, 0, 0);
[2792]138            this->pathnodes[1] = Vector(1000, 0, 0);
139            //      this->pathnodes[2] = Vector(-100, 140, 0);
140            //      this->pathnodes[3] = Vector(0, 180, 0);
141            //      this->pathnodes[4] = Vector(100, 140, 0);
142            //      this->pathnodes[5] = Vector(100, 40, 0);
[2636]143           
144            // create the tracks
[2816]145            this->tracklen = 2;
146            this->track = new Track[2];
[2636]147            for( int i = 0; i < this->tracklen; i++)
148              {
149                this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]);
150              }
[3194]151            // !\todo old track-system has to be removed
152
[2636]153            // create a player
[2644]154            WorldEntity* myPlayer = new Player();
155            this->spawn(myPlayer);
[2640]156            this->localPlayer = myPlayer;           
157
[2636]158            // bind input
159            Orxonox *orx = Orxonox::getInstance();
[3226]160            orx->getLocalInput()->bind (myPlayer);
[2636]161           
162            // bind camera
163            this->localCamera = new Camera(this);
164            this->getCamera()->bind (myPlayer); 
[3277]165           
166            /*
[2816]167            Placement* plc = new Placement;
168            plc->r = Vector(100, 10, 10);
169            plc->w = Quaternion();
170            WorldEntity* env = new Environment();
171            this->spawn(env, plc);
[3277]172            */
[2816]173
[2636]174            break;
175          }
176        case DEBUG_WORLD_1:
177          {
[3277]178            this->nullParent = new NullParent ();
179
[2636]180            // create some path nodes
181            this->pathnodes = new Vector[6];
182            this->pathnodes[0] = Vector(0, 0, 0);
183            this->pathnodes[1] = Vector(20, 10, 10);
184            this->pathnodes[2] = Vector(40, 0, 10);
185            this->pathnodes[3] = Vector(60, 10, 0);
186            this->pathnodes[4] = Vector(80, 20, 10);
187            this->pathnodes[5] = Vector(30, 50, 0);
188           
189            // create the tracks
190            this->tracklen = 6;
191            this->track = new Track[6];
192            for( int i = 0; i < this->tracklen; i++)
193              {
194                this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]);
195              }
[3194]196
[2636]197            // create a player
[2644]198            WorldEntity* myPlayer = new Player();
199            this->spawn(myPlayer);
[3194]200            this->localPlayer = myPlayer;           
[2636]201           
202            // bind input
203            Orxonox *orx = Orxonox::getInstance();
[3226]204            orx->getLocalInput()->bind (myPlayer);
[2636]205           
206            // bind camera
207            this->localCamera = new Camera(this);
208            this->getCamera()->bind (myPlayer); 
209            break;
210          }
211        default:
212          printf("World::load() - no world with ID %i found", this->debugWorldNr );
213        }
214    }
215  else if(this->worldName != NULL)
216    {
217
218    }
[2731]219
220  // initialize debug coord system
221  objectList = glGenLists(1);
222  glNewList (objectList, GL_COMPILE);
223  glLoadIdentity();
[2792]224  glColor3f(1.0,0,0);
[2817]225  glBegin(GL_QUADS);
[3200]226
227  int sizeX = 100;
228  int sizeY = 80;
229  float length = 1000;
230  float width = 200;
231  float widthX = float (length /sizeX);
232  float widthY = float (width /sizeY);
[3199]233 
[3200]234  float height [sizeX][sizeY];
235  Vector normal_vectors[sizeX][sizeY];
[3199]236 
[3200]237 
238  for ( int i = 0; i<sizeX-1; i+=1)
239    for (int j = 0; j<sizeY-1;j+=1)
240      //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
[3199]241#ifdef __WIN32__
[3200]242      height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5;
[3199]243#else
[3200]244      height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;
[3199]245#endif
[3200]246
[3199]247  //Die Hügel ein wenig glätten
248  for (int h=1; h<2;h++)
[3200]249    for (int i=1;i<sizeX-2 ;i+=1 )
250      for(int j=1;j<sizeY-2;j+=1)
[3199]251        height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
252 
253  //Berechnung von normalen Vektoren
[3200]254
255  for(int i=1;i<sizeX-2;i+=1)
256    for(int j=1;j<sizeY-2 ;j+=1)
[2792]257      {
[3200]258        Vector v1 = Vector (widthX*(1),      widthY*(j)  ,      height[i][j]);
259        Vector v2 = Vector (widthX*(i-1),    widthY*(j)  ,      height[i-1][j]);
260        Vector v3 = Vector (widthX*(i),      widthY*(j+1),      height[i][j+1]);
261        Vector v4 = Vector (widthX*(i+1),    widthY*(j),        height[i+1][j]);
262        Vector v5 = Vector (widthX*(i),      widthY*(j-1),      height[i][j-1]);
[3199]263       
[3200]264        Vector c1 = v2 - v1;
265        Vector c2 = v3 - v1;
266        Vector c3=  v4 - v1;
267        Vector c4 = v5 - v1;
268        Vector zero = Vector (0,0,0);
269        normal_vectors[i][j]=c1.cross(v4-v2)+c2.cross(v1-v3)+c3.cross(v2-v4)+c4.cross(v3-v1);
[3199]270        normal_vectors[i][j].normalize();
[3200]271      }
272
273  int snowheight=3;
274  for ( int i = 0; i<sizeX; i+=1)
275    for (int j = 0; j<sizeY;j+=1)
276      {   
277        Vector v1 = Vector (widthX*(i),      widthY*(j)  -width/2,      height[i][j]-20 );
278        Vector v2 = Vector (widthX*(i+1),    widthY*(j)  -width/2,      height[i+1][j]-20);
279        Vector v3 = Vector (widthX*(i+1),    widthY*(j+1)-width/2,    height[i+1][j+1]-20);
280        Vector v4 = Vector (widthX*(i),      widthY*(j+1)-width/2,    height[i][j+1]-20);
281        float a[3];
282        if(height[i][j]<snowheight){
283          a[0]=0;
284          a[1]=1.0-height[i][j]/10-.3;
285          a[2]=0;
286          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
[3199]287        }
[3200]288        else{
[3199]289            a[0]=1.0;
290            a[1]=1.0;
291            a[2]=1.0;
292            glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
[2817]293           
[3199]294        }
[3200]295        glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);
296        glVertex3f(v1.x, v1.y, v1.z);
297        if(height[i+1][j]<snowheight){
298          a[0]=0;
299          a[1] =1.0-height[i+1][j]/10-.3;
300          a[2]=0;
301          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
302        }
303        else{
304          a[0]=1.0;
305          a[1]=1.0;
306          a[2]=1.0;
307          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
308         
309        }
310        glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);
311        glVertex3f(v2.x, v2.y, v2.z);
312        if(height[i+1][j+1]<snowheight){
313          a[0]=0;
314          a[1] =1.0-height[i+1][j+1]/10-.3;
315          a[2]=0;
316          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
317        }
318        else{
319          a[0]=1.0;
320          a[1]=1.0;
321          a[2]=1.0;
322          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
323         
324         
325        }
326        glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);
327        glVertex3f(v3.x, v3.y, v3.z);
328        if(height[i][j+1]<snowheight){
329          a[0]=0;
330          a[1] =1.0-height[i+1][j+1]/10-.3;
331          a[2]=0;
332          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
333        }
334        else{
335          a[0]=1.0;
336          a[1]=1.0;
337          a[2]=1.0;
338          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
339        }
340        glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);
341        glVertex3f(v4.x, v4.y, v4.z);
342       
343      }
[3199]344  glEnd();
345  /* 
[2792]346  glBegin(GL_LINES);
[2731]347  for( float x = -128.0; x < 128.0; x += 25.0)
348    {
349      for( float y = -128.0; y < 128.0; y += 25.0)
350        {
351          glColor3f(1,0,0);
352          glVertex3f(x,y,-128.0);
353          glVertex3f(x,y,0.0);
354          glColor3f(0.5,0,0);
355          glVertex3f(x,y,0.0);
356          glVertex3f(x,y,128.0);
357        }
358    }
359  for( float y = -128.0; y < 128.0; y += 25.0)
360    {
361      for( float z = -128.0; z < 128.0; z += 25.0)
362        {
363          glColor3f(0,1,0);
364          glVertex3f(-128.0,y,z);
365          glVertex3f(0.0,y,z);
366          glColor3f(0,0.5,0);
367          glVertex3f(0.0,y,z);
368          glVertex3f(128.0,y,z);
369        }
370    }
371  for( float x = -128.0; x < 128.0; x += 25.0)
372    {
373      for( float z = -128.0; z < 128.0; z += 25.0)
374        {
375          glColor3f(0,0,1);
376          glVertex3f(x,-128.0,z);
377          glVertex3f(x,0.0,z);
378          glColor3f(0,0,0.5);
379          glVertex3f(x,0.0,z);
380          glVertex3f(x,128.0,z);
381        }
382     
383    }
[2792]384  */ 
[2731]385  //draw track
[2792]386  glBegin(GL_LINES);
[2731]387  glColor3f(0,1,1);
388  for( int i = 0; i < tracklen; i++)
389    {
390      glVertex3f(pathnodes[i].x,pathnodes[i].y,pathnodes[i].z);
391      glVertex3f(pathnodes[(i+1)%tracklen].x,pathnodes[(i+1)%tracklen].y,pathnodes[(i+1)%tracklen].z);
392    }
393  glEnd();
394  glEndList();
[2636]395}
396
397
398/**
[2551]399    \brief checks for collisions
400   
401    This method runs through all WorldEntities known to the world and checks for collisions
402    between them. In case of collisions the collide() method of the corresponding entities
403    is called.
[1858]404*/
[2190]405void World::collide ()
[1858]406{
[2816]407  /*
408  List *a, *b;
[2551]409  WorldEntity *aobj, *bobj;
[2816]410   
411  a = entities;
[2551]412 
413  while( a != NULL)
414    {
[2816]415      aobj = a->nextElement();
[2551]416      if( aobj->bCollide && aobj->collisioncluster != NULL)
[2190]417        {
[2816]418          b = a->nextElement();
[2551]419          while( b != NULL )
420            {
[2816]421              bobj = b->nextElement();
[2551]422              if( bobj->bCollide && bobj->collisioncluster != NULL )
[2190]423                {
[2551]424                  unsigned long ahitflg, bhitflg;
425                  if( check_collision ( &aobj->place, aobj->collisioncluster,
426                                        &ahitflg, &bobj->place, bobj->collisioncluster,
427                                        &bhitflg) );
428                  {
429                    aobj->collide (bobj, ahitflg, bhitflg);
430                    bobj->collide (aobj, bhitflg, ahitflg);
431                  }
[2190]432                }
[2816]433              b = b->nextElement();
[2551]434            }
[2190]435        }
[2816]436      a = a->enumerate();
[2551]437    }
[2816]438  */
[1858]439}
440
441/**
[2551]442    \brief runs through all entities calling their draw() methods
[1931]443*/
[2190]444void World::draw ()
[2077]445{
[2551]446  // draw geometry
447 
448  // draw entities
449  WorldEntity* entity;
450 
[2822]451  entity = this->entities->enumerate();
[2816]452  while( entity != NULL ) 
[2551]453    { 
[2822]454      if( entity->bDraw ) entity->draw();
455      entity = this->entities->nextElement();
[2551]456    }
457 
458 
459  // draw debug coord system
[2731]460  glCallList (objectList);
[2551]461
[2731]462
[1931]463}
464
465/**
[2551]466    \brief updates Placements and notifies entities when they left the
467    world
468   
469    This runs trough all WorldEntities and maps Locations to Placements
470    if they are bound, checks whether they left the level boundaries
471    and calls appropriate functions.
[1883]472*/
[2190]473void World::update ()
[1883]474{
[2816]475  //List<WorldEntity> *l;
[2551]476  WorldEntity* entity;
477  Location* loc;
478  Placement* plc;
479  Uint32 t;
480 
[2816]481  //  l = entities->enumerate();
482  entity = this->entities->enumerate();
483  while( entity != NULL ) 
[2551]484    { 
[2816]485
[2551]486     
487      if( !entity->isFree() )
488        {
[3233]489          loc = entity->getLocation();
490          plc = entity->getPlacement();
[2551]491          t = loc->part;
492         
493          /* check if entity has still a legal track-id */
494          if( t >= tracklen )
495            {
496              printf("An entity is out of the game area\n");
[3233]497              entity->leftWorld ();
[2551]498            }
499          else
500            {
[3233]501              while( track[t].mapCoords( loc, plc) )
[2190]502                {
[3233]503                  track[t].postLeave (entity);
[2551]504                  if( loc->part >= tracklen )
505                    {
506                      printf("An entity has left the game area\n");
[3233]507                      entity->leftWorld ();
[2551]508                      break;
509                    }
[3233]510                  track[loc->part].postEnter (entity);
[2190]511                }
[2551]512            }
[2190]513        }
[2551]514      else
515        {
[3225]516          /* \todo: implement check whether this particular free entity
[2551]517             is out of the game area
[3225]518             \todo: call function to notify the entity that it left
[2551]519             the game area
520          */
521        }
522     
[2816]523      entity = entities->nextElement();
[2551]524    }
525 
[1883]526}
527
[2077]528/**
[2551]529    \brief relays the passed time since the last frame to entities and Track parts
530    \param deltaT: the time passed since the last frame in milliseconds
[2077]531*/
[3225]532void World::timeSlice (Uint32 deltaT)
[2077]533{
[2816]534  //List<WorldEntity> *l;
[2551]535  WorldEntity* entity;
[3175]536  float seconds = deltaT / 1000.0;
[2551]537 
[2816]538  entity = entities->enumerate(); 
539  while( entity != NULL) 
[2551]540    { 
541      entity->tick (seconds);
[2816]542      entity = entities->nextElement();
[2551]543    }
[2816]544
[3209]545  //for( int i = 0; i < tracklen; i++) track[i].tick (seconds);
[2077]546}
[1883]547
[2190]548/**
[2551]549   \brief removes level data from memory
[1858]550*/
[2190]551void World::unload()
[1858]552{
[2551]553  if( pathnodes) delete []pathnodes;
554  if( track) delete []pathnodes;
[1883]555}
[1879]556
[2636]557
558
[2190]559/**
[2636]560   \brief calls the correct mapping function to convert a given "look at"-Location to a
561   Camera Placement
[1858]562*/
[3225]563void World::calcCameraPos (Location* loc, Placement* plc)
[1858]564{
[3233]565  track[loc->part].mapCamera (loc, plc);
[2636]566}
567
568
569void World::setTrackLen(Uint32 len)
570{
571  this->tracklen = len;
572}
573
574int World::getTrackLen()
575{
576  return this->tracklen;
577}
578
[3225]579
580
581/**
582   \brief function to put your own debug stuff into it. it can display informations about
583   the current class/procedure
584*/
[2640]585void World::debug()
586{
[3269]587  printf ("World::debug() - starting debug\n");
[3276]588  PNode* p1 = new NullParent ();
[3265]589  PNode* p2 = new PNode (new Vector(2, 2, 2), p1);
590  PNode* p3 = new PNode (new Vector(4, 4, 4), p1);
591  PNode* p4 = new PNode (new Vector(6, 6, 6), p2);
592
593  p1->debug ();
594  p2->debug ();
595  p3->debug ();
596  p4->debug ();
597
598  p1->shiftCoor (new Vector(-1, -1, -1));
599
600  printf("World::debug() - shift\n");
601  p1->debug ();
602  p2->debug ();
603  p3->debug ();
604  p4->debug ();
605 
606  p1->update (1);
607
[3269]608  printf ("World::debug() - update\n");
[3265]609  p1->debug ();
610  p2->debug ();
611  p3->debug ();
612  p4->debug ();
613
[3269]614  p2->shiftCoor (new Vector(-1, -1, -1));
615  p1->update (2);
[3265]616
[3269]617  p1->debug ();
618  p2->debug ();
619  p3->debug ();
620  p4->debug ();
621
622  p2->setAbsCoor (new Vector(1,2,3));
623
624
625 p1->update (2);
626
627  p1->debug ();
628  p2->debug ();
629  p3->debug ();
630  p4->debug ();
[3277]631
632  p1->destroy ();
633 
634 
[3265]635  /*
[2640]636  WorldEntity* entity;
637  printf("counting all entities\n");
[2816]638  printf("World::debug() - enumerate()\n");
639  entity = entities->enumerate(); 
640  while( entity != NULL )
[2640]641    {
642      if( entity->bDraw ) printf("got an entity\n");
[2816]643      entity = entities->nextElement();
[2640]644    }
[3265]645  */
[2640]646}
[2636]647
[2640]648
[3225]649/*
650  \brief main loop of the world: executing all world relevant function
651
652  in this loop we synchronize (if networked), handle input events, give the heart-beat to
653  all other member-entities of the world (tick to player, enemies etc.), checking for
654  collisions drawing everything to the screen.
655*/
[2636]656void World::mainLoop()
657{
658  this->lastFrame = SDL_GetTicks();
[3220]659  printf("World::mainLoop() - Entering main loop\n");
[3215]660  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */
[2551]661    {
[2636]662      // Network
663      synchronize();
664      // Process input
[3226]665      handleInput();
[3215]666      if( this->bQuitCurrentGame || this->bQuitOrxonox)
667        {
668          printf("World::mainLoop() - leaving loop earlier...\n");
669          break;
670        }
[2636]671      // Process time
[3225]672      timeSlice();
[2636]673      // Process collision
674      collision();
675      // Draw
676      display();
[2816]677 
[3210]678      for(int i = 0; i < 10000000; i++) {}
[2551]679    }
[3215]680  printf("World::mainLoop() - Exiting the main loop\n");
[1899]681}
682
[2190]683/**
[2636]684   \brief synchronize local data with remote data
[1855]685*/
[2636]686void World::synchronize ()
[1855]687{
[2636]688  // Get remote input
689  // Update synchronizables
[1855]690}
[2636]691
692/**
693   \brief run all input processing
[3225]694
695   the command node is the central input event dispatcher. the node uses the even-queue from
696   sdl and has its own event-passing-queue.
[2636]697*/
[3225]698void World::handleInput ()
[2636]699{
700  // localinput
[3225]701  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
[3216]702  cn->process();
[2636]703  // remoteinput
704}
705
706/**
707   \brief advance the timeline
[3225]708
709   this calculates the time used to process one frame (with all input handling, drawing, etc)
710   the time is mesured in ms and passed to all world-entities and other classes that need
711   a heart-beat.
[2636]712*/
[3225]713void World::timeSlice ()
[2636]714{
715  Uint32 currentFrame = SDL_GetTicks();
716  if(!this->bPause)
717    {
718      Uint32 dt = currentFrame - this->lastFrame;
[2816]719     
[2636]720      if(dt > 0)
721        {
722          float fps = 1000/dt;
723          printf("fps = %f\n", fps);
724        }
725      else
726        {
[3225]727          /* the frame-rate is limited to 100 frames per second, all other things are for
728             nothing.
729          */
[3194]730          printf("fps = 1000 - frame rate is adjusted\n");
731          SDL_Delay(10);
732          dt = 10;
[2636]733        }
[3225]734      this->timeSlice (dt);
[2636]735      this->update ();
[3225]736      this->localCamera->timeSlice(dt);
[2636]737    }
738  this->lastFrame = currentFrame;
739}
740
[3216]741
[2636]742/**
743   \brief compute collision detection
744*/
745void World::collision ()
746{
747  this->collide ();
748}
749
750
751/**
[3225]752   \brief render the current frame
753   
754   clear all buffers and draw the world
[2636]755*/
756void World::display ()
757{
758  // clear buffer
759  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
760  // set camera
761  this->localCamera->apply ();
762  // draw world
763  this->draw();
764  // draw HUD
765  // flip buffers
766  SDL_GL_SwapBuffers();
767}
768
[3225]769/**
770   \brief give back active camera
771   
772   this passes back the actualy active camera
773   \todo ability to define more than one camera or camera-places
774*/
[2636]775Camera* World::getCamera()
776{
777  return this->localCamera;
778}
[2644]779
780
[3225]781/**
782   \brief add and spawn a new entity to this world
783   \param entity to be added
784*/
[2644]785void World::spawn(WorldEntity* entity)
786{
787  Location zeroloc;
788  Location* loc = NULL;
789  WorldEntity* owner;
[2816]790
[3277]791  if( this->nullParent != NULL)
792    this->nullParent->addChild (entity);
793
[2816]794  entities->add (entity);
795  zeroloc.dist = 0;
796  zeroloc.part = 0;
797  zeroloc.pos = Vector();
798  zeroloc.rot = Quaternion();
799  loc = &zeroloc;
[2644]800  entity->init (loc, owner);
801  if (entity->bFree)
802    {
[3233]803      this->track[loc->part].mapCoords( loc, entity->getPlacement());
[2644]804    }
[3233]805  entity->postSpawn ();
[2816]806}
807
808
[3225]809/**
810   \brief add and spawn a new entity to this world
811   \param entity to be added
812   \param location where to add
813*/
[2816]814void World::spawn(WorldEntity* entity, Location* loc)
815{
[3277]816  if( this->nullParent != NULL)
817    this->nullParent->addChild (entity);
818
[2816]819  Location zeroLoc;
820  WorldEntity* owner;
821  this->entities->add (entity);
822  if( loc == NULL)
823    {
824      zeroLoc.dist = 0;
825      zeroLoc.part = 0;
826      zeroLoc.pos = Vector();
827      zeroLoc.rot = Quaternion();
828      loc = &zeroLoc;
829    }
830  entity->init (loc, owner);
831  if (entity->bFree)
832    {
[3233]833      this->track[loc->part].mapCoords( loc, entity->getPlacement());
[2816]834    }
[3233]835  entity->postSpawn ();
[2644]836  //return entity;
837}
[2816]838
839
[3225]840/**
841   \brief add and spawn a new entity to this world
842   \param entity to be added
843   \param place where to be added
844*/
[2816]845void World::spawn(WorldEntity* entity, Placement* plc)
846{
[3277]847  if( this->nullParent != NULL)
848    this->nullParent->addChild (entity);
849
[2816]850  Placement zeroPlc;
851  WorldEntity* owner;
852  if( plc == NULL)
853    {
854      zeroPlc.r = Vector();
855      zeroPlc.w = Quaternion();
856      plc = &zeroPlc;
857    }
858  this->entities->add (entity);
859  entity->init (plc, owner);
[3233]860  entity->postSpawn ();
[2816]861  //return entity;
862}
[3216]863
864
[3225]865/*
866  \brief commands that the world must catch
867  \returns false if not used by the world
868*/
[3216]869bool World::command(Command* cmd)
870{
871  return false;
872}
[3265]873
Note: See TracBrowser for help on using the repository browser.