Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/textEngine/src/story_entities/world.cc @ 3786

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

orxonox/branches/textEngine: amimate: rewind works

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#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
18
19#include "world.h"
20
21#include "orxonox.h"
22
23#include "p_node.h"
24#include "null_parent.h"
25#include "helper_parent.h"
26#include "track_node.h"
27#include "world_entity.h"
28#include "player.h"
29#include "camera.h"
30#include "environment.h"
31#include "skysphere.h"
32#include "terrain.h"
33#include "light.h"
34#include "text_engine.h"
35
36#include "track_manager.h"
37#include "garbage_collector.h"
38
39#include "command_node.h"
40#include "glmenu_imagescreen.h"
41#include "list.h"
42
43#include "animation.h"
44
45using namespace std;
46
47
48WorldInterface* WorldInterface::singletonRef = 0;
49
50
51/**
52   \brief private constructor because of singleton
53*/
54WorldInterface::WorldInterface()
55{
56  this->worldIsInitialized = false;
57  this->worldReference = NULL;
58}
59
60/**
61   \brief public deconstructor
62*/
63WorldInterface::~WorldInterface()
64{
65  this->singletonRef = NULL;
66  this->worldIsInitialized = false;
67  this->worldReference = NULL;
68}
69
70/**
71   \brief gets the singleton instance
72   \returns singleton instance
73*/
74WorldInterface* WorldInterface::getInstance()
75{
76  if( singletonRef == NULL)
77    singletonRef = new WorldInterface();
78  return singletonRef;
79}
80
81
82/**
83   \brief initializes the interface
84   \param reference to the world
85
86   if the worldinterface is not initilizes, there wont be any
87   useable interface
88*/
89void WorldInterface::init(World* world)
90{
91  this->worldReference = world;
92  if( world != NULL)
93    {
94      this->worldIsInitialized = true;
95      PRINTF(3)("WorldInterface up and running\n");
96    }
97}
98
99
100/**
101   \brief gets the entity list from the world
102   \return entity list
103*/
104tList<WorldEntity>* WorldInterface::getEntityList()
105{
106  if( this->worldIsInitialized)
107    return this->worldReference->getEntities();
108  PRINT(1)("Someone tried to use the WorldInterface before it has been initizlized! this can result in SEGFAULTs!\n");
109  return NULL;
110}
111
112
113
114/**
115    \brief create a new World
116   
117    This creates a new empty world!
118*/
119World::World (char* name)
120{
121  this->init(name, -1);
122  //NullParent* np = NullParent::getInstance();
123}
124
125/**
126   \brief creates a new World...
127   \param worldID with this ID
128*/
129World::World (int worldID)
130{
131  this->init(NULL, worldID);
132}
133
134/**
135    \brief remove the World from memory
136   
137    delete everything explicitly, that isn't contained in the parenting tree!
138    things contained in the tree are deleted automaticaly
139*/
140World::~World ()
141{
142  PRINTF(3)("World::~World() - deleting current world\n");
143  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
144  cn->unbind(this->localPlayer);
145  cn->reset();
146
147  ResourceManager::getInstance()->debug();
148  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
149  ResourceManager::getInstance()->debug();
150
151  delete WorldInterface::getInstance();
152
153  delete this->nullParent;
154  delete this->entities;
155  delete this->lightMan;
156  delete this->trackManager;
157
158  TextEngine::getInstance()->flush();
159}
160
161/**
162   \brief initializes the world.
163
164   set all stuff here that is world generic and does not use to much memory
165   because the real init() function StoryEntity::init() will be called
166   shortly before start of the game. 
167   since all worlds are initiated/referenced before they will be started.
168   NO LEVEL LOADING HERE - NEVER!
169*/
170void World::init(char* name, int worldID)
171{
172  this->setClassName ("World");
173
174  this->worldName = name;
175  this->debugWorldNr = worldID;
176  this->entities = new tList<WorldEntity>();
177}
178
179
180/**
181   \brief this is executed before load
182
183   since the load function sometimes needs data, that has been init before
184   the load and after the proceeding storyentity has finished
185*/
186ErrorMessage World::preLoad()
187{
188  /* init the world interface */
189  WorldInterface* wi = WorldInterface::getInstance();
190  wi->init(this);
191  this->garbageCollector = GarbageCollector::getInstance();
192}
193
194
195/**
196   \brief loads the World by initializing all resources, and set their default values.
197*/
198ErrorMessage World::load()
199{
200  //  BezierCurve* tmpCurve = new BezierCurve();
201  if(this->debugWorldNr != -1)
202    {
203      // initializing Font
204      this->glmis->step();
205      // initializing the TrackManager
206      trackManager = TrackManager::getInstance();
207      trackManager->addPoint(Vector(0,0,0));
208      trackManager->addPoint(Vector(100, -40, 5));
209      trackManager->addPoint(Vector(200,-40,-8));
210      trackManager->addPoint(Vector(250, -35, -2));
211      trackManager->addPoint(Vector(320,-33,-.55));
212      trackManager->setDuration(3);
213      trackManager->setSavePoint();
214      trackManager->addPoint(Vector(410, 0, 0));
215      trackManager->addPoint(Vector(510, 20, -10));
216      trackManager->addPoint(Vector(550, 20, -10));
217      trackManager->addPoint(Vector(570, 20, -10));
218      trackManager->setDuration(5);
219     
220      int fork11, fork12;
221      trackManager->fork(2, &fork11, &fork12);
222      trackManager->workOn(fork11);
223      trackManager->addPoint(Vector(640, 25, -30));
224      trackManager->addPoint(Vector(700, 40, -120));
225      trackManager->addPoint(Vector(800, 50, -150));
226      trackManager->addPoint(Vector(900, 60, -100));
227      trackManager->addPoint(Vector(900, 60, -70));
228      trackManager->addPoint(Vector(990, 65, -15));
229      trackManager->addPoint(Vector(1050, 65, -10));
230      trackManager->addPoint(Vector(1100, 65, -20));
231      trackManager->setDuration(10);
232
233      trackManager->workOn(fork12);
234      trackManager->addPoint(Vector(640, 25, 20));
235      trackManager->addPoint(Vector(670, 50, 120));
236      trackManager->addPoint(Vector(700, 70, 80));
237      trackManager->addPoint(Vector(800, 70, 65));
238      trackManager->addPoint(Vector(850, 65, 65));
239      trackManager->addPoint(Vector(920, 35, 40));
240      trackManager->addPoint(Vector(945, 40, 40));
241      trackManager->addPoint(Vector(970, 24, 40));
242      trackManager->addPoint(Vector(1000, 40, -7));
243      trackManager->setDuration(10);
244     
245
246      trackManager->join(2, fork11, fork12);
247
248      trackManager->workOn(5);
249      trackManager->addPoint(Vector(1200, 60, -50));
250      trackManager->addPoint(Vector(1300, 50, -50));
251      trackManager->addPoint(Vector(1400, 40, -50));
252      trackManager->addPoint(Vector(1500, 40, -60));
253      trackManager->addPoint(Vector(1600, 35, -55));
254      trackManager->addPoint(Vector(1700, 45, -40));
255      trackManager->addPoint(Vector(1750, 60, -40));
256      trackManager->addPoint(Vector(1770, 80, -40));
257      trackManager->addPoint(Vector(1800, 100, -40));
258      trackManager->setDuration(10);
259
260      trackManager->finalize();
261
262     
263      /*monitor progress*/
264      this->glmis->step();
265
266      // LIGHT initialisation
267      lightMan = LightManager::getInstance();
268      lightMan->setAmbientColor(.1,.1,.1);
269      lightMan->addLight();
270      //      lightMan->setAttenuation(1.0, .01, 0.0);
271      //      lightMan->setDiffuseColor(1,1,1);
272      //  lightMan->addLight(1);
273      //  lightMan->setPosition(20, 10, -20);
274      //  lightMan->setDiffuseColor(0,0,0);
275      lightMan->debug();
276
277      switch(this->debugWorldNr)
278        {
279          /*
280            this loads the hard-coded debug world. this only for simplicity and will be
281            removed by a reald world-loader, which interprets a world-file.
282            if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and
283            make whatever you want...
284           */
285        case DEBUG_WORLD_0:
286          {
287            lightMan->setPosition(-5.0, 10.0, -40.0);
288            this->nullParent = NullParent::getInstance ();
289            this->nullParent->setName ("NullParent");
290
291            // !\todo old track-system has to be removed
292
293            //create helper for player
294            //HelperParent* hp = new HelperParent ();
295            /* the player has to be added to this helper */
296
297            // create a player
298            this->localPlayer = new Player ();
299            this->localPlayer->setName ("player");
300            this->spawn (this->localPlayer);
301            /*monitor progress*/
302            //this->glmis->step();
303            this->glmis->step();
304
305            // bind input
306            Orxonox *orx = Orxonox::getInstance ();
307            orx->getLocalInput()->bind (this->localPlayer);
308           
309            // bind camera
310            this->localCamera = new Camera();
311            this->localCamera->setName ("camera");
312            this->localCamera->lookAt(this->localPlayer);
313            this->localCamera->setParent(this->localPlayer);
314           
315            /*monitor progress*/
316            this->glmis->step();
317
318            // Create SkySphere
319            this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
320            this->skySphere->setName("SkySphere");
321            this->localCamera->addChild(this->skySphere);
322            this->skySphere->setMode(PNODE_MOVEMENT);
323
324            /*monitor progress*/
325            this->glmis->step();
326
327           
328            WorldEntity* env = new Environment();
329            env->setName ("env");
330            this->spawn(env);
331
332           
333            /*
334            Vector* es = new Vector (10, 5, 0);
335            Quaternion* qs = new Quaternion ();
336            WorldEntity* pr = new Primitive(P_CYLINDER);
337            pr->setName("primitive");
338            this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT);
339            */
340
341            /*monitor progress*/
342            this->glmis->step();
343
344            //      trackManager->setBindSlave(env);
345            PNode* tn = trackManager->getTrackNode();
346            tn->addChild(this->localPlayer);
347
348            //localCamera->setParent(TrackNode::getInstance());
349            tn->addChild(this->localCamera);
350            //      localCamera->lookAt(tn);
351            this->localPlayer->setMode(PNODE_ALL);
352            //Vector* cameraOffset = new Vector (0, 5, -10);
353            trackManager->condition(2, LEFTRIGHT, this->localPlayer);
354            this->glmis->step();
355
356            this->testText = TextEngine::getInstance()->createText("fonts/earth.ttf", 30, TEXT_DYNAMIC, 0, 255, 0);
357            testText->setText("TEXT  rocks");
358            testText->setBlending(1.0);
359            testText->setBindNode(tn);
360
361           
362            tmpAnim = new Animation<Text>(testText, &Text::setBlending);
363            tmpAnim->addKeyFrame(0.0, 1.0, ANIM_LINEAR);
364            tmpAnim->addKeyFrame(1.0, 1.0, ANIM_LINEAR);
365            tmpAnim->addKeyFrame(0.0, 1.0, ANIM_LINEAR);
366            tmpAnim->addKeyFrame(1.0, 1.0, ANIM_LINEAR);
367            break;
368          }
369        case DEBUG_WORLD_1:
370          {
371            lightMan->setPosition(.0, .0, .0);
372            lightMan->setAttenuation(1.0, .01, 0.0);
373            lightMan->setSpecularColor(1,0,0);
374            this->nullParent = NullParent::getInstance ();
375            this->nullParent->setName ("NullParent");
376
377            // create a player
378            WorldEntity* myPlayer = new Player();
379            myPlayer->setName ("player");
380            this->spawn(myPlayer);
381            this->localPlayer = myPlayer;           
382           
383            // bind input
384            Orxonox *orx = Orxonox::getInstance();
385            orx->getLocalInput()->bind (myPlayer);
386           
387            // bind camera
388            this->localCamera = new Camera ();
389            this->localCamera->setName ("camera");
390            this->localCamera->lookAt(LightManager::getInstance()->getLight(0));
391            this->localCamera->setParent(this->localPlayer);
392
393            // Create SkySphere
394            skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
395            this->localPlayer->addChild(this->skySphere);
396
397            Vector* es = new Vector (20, 0, 0);
398            Quaternion* qs = new Quaternion ();
399
400            lightMan->getLight(0)->setParent(trackManager->getTrackNode());
401            break;
402          }
403        default:
404          printf("World::load() - no world with ID %i found", this->debugWorldNr );
405        }
406    }
407  else if(this->worldName != NULL)
408    {
409
410    }
411
412  // initialize debug coord system
413  objectList = glGenLists(1);
414  glNewList (objectList, GL_COMPILE);
415 
416  //  trackManager->drawGraph(.01);
417  trackManager->debug(2);
418  glEndList();
419
420  terrain = new Terrain("../data/worlds/newGround.obj");
421  terrain->setRelCoor(new Vector(0,-10,0));
422  this->spawn(terrain);
423
424}
425
426
427/**
428   \brief initializes a new World shortly before start
429
430   this is the function, that will be loaded shortly before the world is
431   started
432*/
433ErrorMessage World::init()
434{
435  this->bPause = false;
436  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
437  cn->addToWorld(this);
438  cn->enable(true);
439}
440
441
442/**
443   \brief starts the World
444*/
445ErrorMessage World::start()
446{
447  PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr);
448  this->bQuitOrxonox = false;
449  this->bQuitCurrentGame = false;
450  this->mainLoop();
451}
452
453/**
454   \brief stops the world.
455
456   This happens, when the player decides to end the Level.
457*/
458ErrorMessage World::stop()
459{
460  PRINTF(3)("World::stop() - got stop signal\n");
461  this->bQuitCurrentGame = true;
462}
463
464/**
465   \brief pauses the Game
466*/
467ErrorMessage World::pause()
468{
469  this->isPaused = true;
470}
471
472/**
473   \brief ends the pause Phase
474*/
475ErrorMessage World::resume()
476{
477  this->isPaused = false;
478}
479
480/**
481   \brief destroys the World
482*/
483ErrorMessage World::destroy()
484{
485
486}
487
488/**
489   \brief shows the loading screen
490*/
491void World::displayLoadScreen ()
492{
493  PRINTF(3)("World::displayLoadScreen - start\n"); 
494 
495  //GLMenuImageScreen*
496  this->glmis = GLMenuImageScreen::getInstance();
497  this->glmis->init();
498  this->glmis->setMaximum(8);
499  this->glmis->draw();
500 
501  PRINTF(3)("World::displayLoadScreen - end\n"); 
502}
503
504/**
505   \brief removes the loadscreen, and changes over to the game
506
507   \todo take out the delay
508*/
509void World::releaseLoadScreen ()
510{
511  PRINTF(3)("World::releaseLoadScreen - start\n"); 
512  this->glmis->setValue(this->glmis->getMaximum());
513  //SDL_Delay(500);
514  PRINTF(3)("World::releaseLoadScreen - end\n"); 
515}
516
517
518/**
519   \brief gets the list of entities from the world
520   \returns entity list
521*/
522tList<WorldEntity>* World::getEntities()
523{
524  return this->entities;
525}
526
527
528/**
529   \brief this returns the current game time
530   \returns elapsed game time
531*/
532double World::getGameTime()
533{
534  return this->gameTime;
535}
536
537
538/**
539    \brief checks for collisions
540   
541    This method runs through all WorldEntities known to the world and checks for collisions
542    between them. In case of collisions the collide() method of the corresponding entities
543    is called.
544*/
545void World::collide ()
546{
547  /*
548  List *a, *b;
549  WorldEntity *aobj, *bobj;
550   
551  a = entities;
552 
553  while( a != NULL)
554    {
555      aobj = a->nextElement();
556      if( aobj->bCollide && aobj->collisioncluster != NULL)
557        {
558          b = a->nextElement();
559          while( b != NULL )
560            {
561              bobj = b->nextElement();
562              if( bobj->bCollide && bobj->collisioncluster != NULL )
563                {
564                  unsigned long ahitflg, bhitflg;
565                  if( check_collision ( &aobj->place, aobj->collisioncluster,
566                                        &ahitflg, &bobj->place, bobj->collisioncluster,
567                                        &bhitflg) );
568                  {
569                    aobj->collide (bobj, ahitflg, bhitflg);
570                    bobj->collide (aobj, bhitflg, ahitflg);
571                  }
572                }
573              b = b->nextElement();
574            }
575        }
576      a = a->enumerate();
577    }
578  */
579}
580
581/**
582    \brief runs through all entities calling their draw() methods
583*/
584void World::draw ()
585{
586  /* draw entities */
587  WorldEntity* entity;
588  glLoadIdentity();
589
590  //entity = this->entities->enumerate();
591  tIterator<WorldEntity>* iterator = this->entities->getIterator();
592  entity = iterator->nextElement();
593  while( entity != NULL ) 
594    { 
595      if( entity->bDraw ) entity->draw();
596      //entity = this->entities->nextElement();
597      entity = iterator->nextElement();
598    }
599  delete iterator;
600 
601  glCallList (objectList);
602  //! \todo skysphere is a WorldEntity and should be inside of the world-entity-list.
603  skySphere->draw();
604
605  TextEngine::getInstance()->draw();
606  lightMan->draw(); // must be at the end of the drawing procedure, otherwise Light cannot be handled as PNodes //
607}
608
609
610/**
611   \brief function to put your own debug stuff into it. it can display informations about
612   the current class/procedure
613*/
614void World::debug()
615{
616  PRINTF(2)("debug() - starting debug\n");
617  PNode* p1 = NullParent::getInstance ();
618  PNode* p2 = new PNode (new Vector(2, 2, 2), p1);
619  PNode* p3 = new PNode (new Vector(4, 4, 4), p1);
620  PNode* p4 = new PNode (new Vector(6, 6, 6), p2);
621
622  p1->debug ();
623  p2->debug ();
624  p3->debug ();
625  p4->debug ();
626
627  p1->shiftCoor (new Vector(-1, -1, -1));
628
629  printf("World::debug() - shift\n");
630  p1->debug ();
631  p2->debug ();
632  p3->debug ();
633  p4->debug ();
634 
635  p1->update (0);
636
637  printf ("World::debug() - update\n");
638  p1->debug ();
639  p2->debug ();
640  p3->debug ();
641  p4->debug ();
642
643  p2->shiftCoor (new Vector(-1, -1, -1));
644  p1->update (0);
645
646  p1->debug ();
647  p2->debug ();
648  p3->debug ();
649  p4->debug ();
650
651  p2->setAbsCoor (new Vector(1,2,3));
652
653
654 p1->update (0);
655
656  p1->debug ();
657  p2->debug ();
658  p3->debug ();
659  p4->debug ();
660
661  delete p1;
662 
663 
664  /*
665  WorldEntity* entity;
666  printf("counting all entities\n");
667  printf("World::debug() - enumerate()\n");
668  entity = entities->enumerate(); 
669  while( entity != NULL )
670    {
671      if( entity->bDraw ) printf("got an entity\n");
672      entity = entities->nextElement();
673    }
674  */
675}
676
677
678/**
679  \brief main loop of the world: executing all world relevant function
680
681  in this loop we synchronize (if networked), handle input events, give the heart-beat to
682  all other member-entities of the world (tick to player, enemies etc.), checking for
683  collisions drawing everything to the screen.
684*/
685void World::mainLoop()
686{
687  this->lastFrame = SDL_GetTicks ();
688  PRINTF(3)("World::mainLoop() - Entering main loop\n");
689  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */
690    {
691      PRINTF(3)("World::mainloop() - number of entities: %i\n", this->entities->getSize());
692      // Network
693      this->synchronize ();
694      // Process input
695      this->handleInput ();
696      if( this->bQuitCurrentGame || this->bQuitOrxonox)
697          break;
698      // Process time
699      this->tick ();
700      // Update the state
701      this->update ();     
702      // Process collision
703      this->collide ();
704      // Draw
705      this->display ();
706
707      //      for( int i = 0; i < 5000000; i++) {}
708      /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/
709    }
710  PRINTF(3)("World::mainLoop() - Exiting the main loop\n");
711}
712
713
714/**
715   \brief synchronize local data with remote data
716*/
717void World::synchronize ()
718{
719  // Get remote input
720  // Update synchronizables
721}
722
723
724/**
725   \brief run all input processing
726
727   the command node is the central input event dispatcher. the node uses the even-queue from
728   sdl and has its own event-passing-queue.
729*/
730void World::handleInput ()
731{
732  // localinput
733  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
734  cn->process();
735  // remoteinput
736}
737
738
739/**
740   \brief advance the timeline
741
742   this calculates the time used to process one frame (with all input handling, drawing, etc)
743   the time is mesured in ms and passed to all world-entities and other classes that need
744   a heart-beat.
745*/
746void World::tick ()
747{
748  Uint32 currentFrame = SDL_GetTicks();
749  if(!this->bPause)
750    {
751      this->dt = currentFrame - this->lastFrame;
752     
753      if( this->dt > 0)
754        {
755          float fps = 1000/dt;
756
757          // temporary, only for showing how fast the text-engine is
758          char tmpChar[20];
759          sprintf(tmpChar, "fps: %4.0f", fps);
760        }
761      else
762        {
763          /* the frame-rate is limited to 100 frames per second, all other things are for
764             nothing.
765          */
766          PRINTF(2)("fps = 1000 - frame rate is adjusted\n");
767          SDL_Delay(10);
768          this->dt = 10;
769        }
770      //this->timeSlice (dt);
771     
772      /* function to let all entities tick (iterate through list) */
773      float seconds = this->dt / 1000.0;     
774      this->gameTime += seconds;
775      //entity = entities->enumerate();
776      tIterator<WorldEntity>* iterator = this->entities->getIterator();
777      WorldEntity* entity = iterator->nextElement();
778      while( entity != NULL) 
779        { 
780          entity->tick (seconds);
781          entity = iterator->nextElement();
782        }
783      delete iterator;
784      //skySphere->updatePosition(localCamera->absCoordinate);
785     
786      /* update tick the rest */
787      this->trackManager->tick(this->dt);
788      this->localCamera->tick(this->dt);
789      this->garbageCollector->tick(seconds);
790      tmpAnim->tick(seconds);
791    }
792  this->lastFrame = currentFrame;
793}
794
795
796/**
797   \brief this function gives the world a consistant state
798
799   after ticking (updating the world state) this will give a constistant
800   state to the whole system.
801*/
802void World::update()
803{
804  this->garbageCollector->update();
805  this->nullParent->update (dt);
806}
807
808
809/**
810   \brief render the current frame
811   
812   clear all buffers and draw the world
813*/
814void World::display ()
815{
816  // clear buffer
817  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
818  // set camera
819  this->localCamera->apply ();
820  // draw world
821  this->draw();
822  // draw HUD
823  /* \todo draw HUD */
824  // flip buffers
825  SDL_GL_SwapBuffers();
826  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
827  //SDL_Flip (screen);
828}
829
830
831/**
832   \brief add and spawn a new entity to this world
833   \param entity to be added
834*/
835void World::spawn(WorldEntity* entity)
836{
837  this->entities->add (entity);
838  entity->postSpawn ();
839}
840
841
842/**
843   \brief add and spawn a new entity to this world
844   \param entity to be added
845   \param absCoor At what coordinates to add this entity.
846   \param absDir In which direction should it look.
847*/
848void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
849{
850  this->entities->add (entity);
851
852  entity->setAbsCoor (absCoor);
853  entity->setAbsDir (absDir);
854
855  entity->postSpawn ();
856}
857
858
859/**
860   \brief add and spawn a new entity to this world
861   \param entity to be added
862   \param entity to be added to (PNode)
863   \param At what relative  coordinates to add this entity.
864   \param In which relative direction should it look.
865*/
866void World::spawn(WorldEntity* entity, PNode* parentNode, 
867                  Vector* relCoor, Quaternion* relDir, 
868                  int parentingMode)
869{
870  this->nullParent = NullParent::getInstance();
871  if( parentNode != NULL)
872    {
873      parentNode->addChild (entity);
874     
875      entity->setRelCoor (relCoor);
876      entity->setRelDir (relDir);
877      entity->setMode(parentingMode);
878     
879      this->entities->add (entity);
880     
881      entity->postSpawn ();
882    }
883}
884
885
886
887/**
888  \brief commands that the world must catch
889  \returns false if not used by the world
890*/
891bool World::command(Command* cmd)
892{
893  if( !strcmp( cmd->cmd, "view0")) this->localCamera->setViewMode(VIEW_NORMAL);
894  else if( !strcmp( cmd->cmd, "view1")) this->localCamera->setViewMode(VIEW_BEHIND);
895  else if( !strcmp( cmd->cmd, "view2")) this->localCamera->setViewMode(VIEW_FRONT);
896  else if( !strcmp( cmd->cmd, "view3")) this->localCamera->setViewMode(VIEW_LEFT);
897  else if( !strcmp( cmd->cmd, "view4")) this->localCamera->setViewMode(VIEW_RIGHT);
898  else if( !strcmp( cmd->cmd, "view5")) this->localCamera->setViewMode(VIEW_TOP);
899 
900  return false;
901}
902
Note: See TracBrowser for help on using the repository browser.