Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/parenting: took out the test-curve, because it resulted in a seg-fault while chanching the Level, and because it was only for temporary testing

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