Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/textEngine: some better implementation for the Animation Class. it now sends around some FunctionPointers

File size: 22.0 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
364            //      tmpAnim->setFuncToAnim(testText, &Text::setBlending);
365            break;
366          }
367        case DEBUG_WORLD_1:
368          {
369            lightMan->setPosition(.0, .0, .0);
370            lightMan->setAttenuation(1.0, .01, 0.0);
371            lightMan->setSpecularColor(1,0,0);
372            this->nullParent = NullParent::getInstance ();
373            this->nullParent->setName ("NullParent");
374
375            // create a player
376            WorldEntity* myPlayer = new Player();
377            myPlayer->setName ("player");
378            this->spawn(myPlayer);
379            this->localPlayer = myPlayer;           
380           
381            // bind input
382            Orxonox *orx = Orxonox::getInstance();
383            orx->getLocalInput()->bind (myPlayer);
384           
385            // bind camera
386            this->localCamera = new Camera ();
387            this->localCamera->setName ("camera");
388            this->localCamera->lookAt(LightManager::getInstance()->getLight(0));
389            this->localCamera->setParent(this->localPlayer);
390
391            // Create SkySphere
392            skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
393            this->localPlayer->addChild(this->skySphere);
394
395            Vector* es = new Vector (20, 0, 0);
396            Quaternion* qs = new Quaternion ();
397
398            lightMan->getLight(0)->setParent(trackManager->getTrackNode());
399            break;
400          }
401        default:
402          printf("World::load() - no world with ID %i found", this->debugWorldNr );
403        }
404    }
405  else if(this->worldName != NULL)
406    {
407
408    }
409
410  // initialize debug coord system
411  objectList = glGenLists(1);
412  glNewList (objectList, GL_COMPILE);
413 
414  //  trackManager->drawGraph(.01);
415  trackManager->debug(2);
416  glEndList();
417
418  terrain = new Terrain("../data/worlds/newGround.obj");
419  terrain->setRelCoor(new Vector(0,-10,0));
420  this->spawn(terrain);
421
422}
423
424
425/**
426   \brief initializes a new World shortly before start
427
428   this is the function, that will be loaded shortly before the world is
429   started
430*/
431ErrorMessage World::init()
432{
433  this->bPause = false;
434  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
435  cn->addToWorld(this);
436  cn->enable(true);
437}
438
439
440/**
441   \brief starts the World
442*/
443ErrorMessage World::start()
444{
445  PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr);
446  this->bQuitOrxonox = false;
447  this->bQuitCurrentGame = false;
448  this->mainLoop();
449}
450
451/**
452   \brief stops the world.
453
454   This happens, when the player decides to end the Level.
455*/
456ErrorMessage World::stop()
457{
458  PRINTF(3)("World::stop() - got stop signal\n");
459  this->bQuitCurrentGame = true;
460}
461
462/**
463   \brief pauses the Game
464*/
465ErrorMessage World::pause()
466{
467  this->isPaused = true;
468}
469
470/**
471   \brief ends the pause Phase
472*/
473ErrorMessage World::resume()
474{
475  this->isPaused = false;
476}
477
478/**
479   \brief destroys the World
480*/
481ErrorMessage World::destroy()
482{
483
484}
485
486/**
487   \brief shows the loading screen
488*/
489void World::displayLoadScreen ()
490{
491  PRINTF(3)("World::displayLoadScreen - start\n"); 
492 
493  //GLMenuImageScreen*
494  this->glmis = GLMenuImageScreen::getInstance();
495  this->glmis->init();
496  this->glmis->setMaximum(8);
497  this->glmis->draw();
498 
499  PRINTF(3)("World::displayLoadScreen - end\n"); 
500}
501
502/**
503   \brief removes the loadscreen, and changes over to the game
504
505   \todo take out the delay
506*/
507void World::releaseLoadScreen ()
508{
509  PRINTF(3)("World::releaseLoadScreen - start\n"); 
510  this->glmis->setValue(this->glmis->getMaximum());
511  //SDL_Delay(500);
512  PRINTF(3)("World::releaseLoadScreen - end\n"); 
513}
514
515
516/**
517   \brief gets the list of entities from the world
518   \returns entity list
519*/
520tList<WorldEntity>* World::getEntities()
521{
522  return this->entities;
523}
524
525
526/**
527   \brief this returns the current game time
528   \returns elapsed game time
529*/
530double World::getGameTime()
531{
532  return this->gameTime;
533}
534
535
536/**
537    \brief checks for collisions
538   
539    This method runs through all WorldEntities known to the world and checks for collisions
540    between them. In case of collisions the collide() method of the corresponding entities
541    is called.
542*/
543void World::collide ()
544{
545  /*
546  List *a, *b;
547  WorldEntity *aobj, *bobj;
548   
549  a = entities;
550 
551  while( a != NULL)
552    {
553      aobj = a->nextElement();
554      if( aobj->bCollide && aobj->collisioncluster != NULL)
555        {
556          b = a->nextElement();
557          while( b != NULL )
558            {
559              bobj = b->nextElement();
560              if( bobj->bCollide && bobj->collisioncluster != NULL )
561                {
562                  unsigned long ahitflg, bhitflg;
563                  if( check_collision ( &aobj->place, aobj->collisioncluster,
564                                        &ahitflg, &bobj->place, bobj->collisioncluster,
565                                        &bhitflg) );
566                  {
567                    aobj->collide (bobj, ahitflg, bhitflg);
568                    bobj->collide (aobj, bhitflg, ahitflg);
569                  }
570                }
571              b = b->nextElement();
572            }
573        }
574      a = a->enumerate();
575    }
576  */
577}
578
579/**
580    \brief runs through all entities calling their draw() methods
581*/
582void World::draw ()
583{
584  /* draw entities */
585  WorldEntity* entity;
586  glLoadIdentity();
587
588  //entity = this->entities->enumerate();
589  tIterator<WorldEntity>* iterator = this->entities->getIterator();
590  entity = iterator->nextElement();
591  while( entity != NULL ) 
592    { 
593      if( entity->bDraw ) entity->draw();
594      //entity = this->entities->nextElement();
595      entity = iterator->nextElement();
596    }
597  delete iterator;
598 
599  glCallList (objectList);
600  //! \todo skysphere is a WorldEntity and should be inside of the world-entity-list.
601  skySphere->draw();
602
603  TextEngine::getInstance()->draw();
604  lightMan->draw(); // must be at the end of the drawing procedure, otherwise Light cannot be handled as PNodes //
605}
606
607
608/**
609   \brief function to put your own debug stuff into it. it can display informations about
610   the current class/procedure
611*/
612void World::debug()
613{
614  PRINTF(2)("debug() - starting debug\n");
615  PNode* p1 = NullParent::getInstance ();
616  PNode* p2 = new PNode (new Vector(2, 2, 2), p1);
617  PNode* p3 = new PNode (new Vector(4, 4, 4), p1);
618  PNode* p4 = new PNode (new Vector(6, 6, 6), p2);
619
620  p1->debug ();
621  p2->debug ();
622  p3->debug ();
623  p4->debug ();
624
625  p1->shiftCoor (new Vector(-1, -1, -1));
626
627  printf("World::debug() - shift\n");
628  p1->debug ();
629  p2->debug ();
630  p3->debug ();
631  p4->debug ();
632 
633  p1->update (0);
634
635  printf ("World::debug() - update\n");
636  p1->debug ();
637  p2->debug ();
638  p3->debug ();
639  p4->debug ();
640
641  p2->shiftCoor (new Vector(-1, -1, -1));
642  p1->update (0);
643
644  p1->debug ();
645  p2->debug ();
646  p3->debug ();
647  p4->debug ();
648
649  p2->setAbsCoor (new Vector(1,2,3));
650
651
652 p1->update (0);
653
654  p1->debug ();
655  p2->debug ();
656  p3->debug ();
657  p4->debug ();
658
659  delete p1;
660 
661 
662  /*
663  WorldEntity* entity;
664  printf("counting all entities\n");
665  printf("World::debug() - enumerate()\n");
666  entity = entities->enumerate(); 
667  while( entity != NULL )
668    {
669      if( entity->bDraw ) printf("got an entity\n");
670      entity = entities->nextElement();
671    }
672  */
673}
674
675
676/**
677  \brief main loop of the world: executing all world relevant function
678
679  in this loop we synchronize (if networked), handle input events, give the heart-beat to
680  all other member-entities of the world (tick to player, enemies etc.), checking for
681  collisions drawing everything to the screen.
682*/
683void World::mainLoop()
684{
685  this->lastFrame = SDL_GetTicks ();
686  PRINTF(3)("World::mainLoop() - Entering main loop\n");
687  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */
688    {
689      PRINTF(3)("World::mainloop() - number of entities: %i\n", this->entities->getSize());
690      // Network
691      this->synchronize ();
692      // Process input
693      this->handleInput ();
694      if( this->bQuitCurrentGame || this->bQuitOrxonox)
695          break;
696      // Process time
697      this->tick ();
698      // Update the state
699      this->update ();     
700      // Process collision
701      this->collide ();
702      // Draw
703      this->display ();
704
705      //      for( int i = 0; i < 5000000; i++) {}
706      /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/
707    }
708  PRINTF(3)("World::mainLoop() - Exiting the main loop\n");
709}
710
711
712/**
713   \brief synchronize local data with remote data
714*/
715void World::synchronize ()
716{
717  // Get remote input
718  // Update synchronizables
719}
720
721
722/**
723   \brief run all input processing
724
725   the command node is the central input event dispatcher. the node uses the even-queue from
726   sdl and has its own event-passing-queue.
727*/
728void World::handleInput ()
729{
730  // localinput
731  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
732  cn->process();
733  // remoteinput
734}
735
736
737/**
738   \brief advance the timeline
739
740   this calculates the time used to process one frame (with all input handling, drawing, etc)
741   the time is mesured in ms and passed to all world-entities and other classes that need
742   a heart-beat.
743*/
744void World::tick ()
745{
746  Uint32 currentFrame = SDL_GetTicks();
747  if(!this->bPause)
748    {
749      this->dt = currentFrame - this->lastFrame;
750     
751      if( this->dt > 0)
752        {
753          float fps = 1000/dt;
754
755          // temporary, only for showing how fast the text-engine is
756          char tmpChar[20];
757          sprintf(tmpChar, "fps: %4.0f", fps);
758        }
759      else
760        {
761          /* the frame-rate is limited to 100 frames per second, all other things are for
762             nothing.
763          */
764          PRINTF(2)("fps = 1000 - frame rate is adjusted\n");
765          SDL_Delay(10);
766          this->dt = 10;
767        }
768      //this->timeSlice (dt);
769     
770      /* function to let all entities tick (iterate through list) */
771      float seconds = this->dt / 1000.0;     
772      this->gameTime += seconds;
773      //entity = entities->enumerate();
774      tIterator<WorldEntity>* iterator = this->entities->getIterator();
775      WorldEntity* entity = iterator->nextElement();
776      while( entity != NULL) 
777        { 
778          entity->tick (seconds);
779          entity = iterator->nextElement();
780        }
781      delete iterator;
782      //skySphere->updatePosition(localCamera->absCoordinate);
783     
784      /* update tick the rest */
785      this->trackManager->tick(this->dt);
786      this->localCamera->tick(this->dt);
787      this->garbageCollector->tick(seconds);
788      tmpAnim->tick(this->dt);
789    }
790  this->lastFrame = currentFrame;
791}
792
793
794/**
795   \brief this function gives the world a consistant state
796
797   after ticking (updating the world state) this will give a constistant
798   state to the whole system.
799*/
800void World::update()
801{
802  this->garbageCollector->update();
803  this->nullParent->update (dt);
804}
805
806
807/**
808   \brief render the current frame
809   
810   clear all buffers and draw the world
811*/
812void World::display ()
813{
814  // clear buffer
815  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
816  // set camera
817  this->localCamera->apply ();
818  // draw world
819  this->draw();
820  // draw HUD
821  /* \todo draw HUD */
822  // flip buffers
823  SDL_GL_SwapBuffers();
824  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
825  //SDL_Flip (screen);
826}
827
828
829/**
830   \brief add and spawn a new entity to this world
831   \param entity to be added
832*/
833void World::spawn(WorldEntity* entity)
834{
835  this->entities->add (entity);
836  entity->postSpawn ();
837}
838
839
840/**
841   \brief add and spawn a new entity to this world
842   \param entity to be added
843   \param absCoor At what coordinates to add this entity.
844   \param absDir In which direction should it look.
845*/
846void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
847{
848  this->entities->add (entity);
849
850  entity->setAbsCoor (absCoor);
851  entity->setAbsDir (absDir);
852
853  entity->postSpawn ();
854}
855
856
857/**
858   \brief add and spawn a new entity to this world
859   \param entity to be added
860   \param entity to be added to (PNode)
861   \param At what relative  coordinates to add this entity.
862   \param In which relative direction should it look.
863*/
864void World::spawn(WorldEntity* entity, PNode* parentNode, 
865                  Vector* relCoor, Quaternion* relDir, 
866                  int parentingMode)
867{
868  this->nullParent = NullParent::getInstance();
869  if( parentNode != NULL)
870    {
871      parentNode->addChild (entity);
872     
873      entity->setRelCoor (relCoor);
874      entity->setRelDir (relDir);
875      entity->setMode(parentingMode);
876     
877      this->entities->add (entity);
878     
879      entity->postSpawn ();
880    }
881}
882
883
884
885/**
886  \brief commands that the world must catch
887  \returns false if not used by the world
888*/
889bool World::command(Command* cmd)
890{
891  if( !strcmp( cmd->cmd, "view0")) this->localCamera->setViewMode(VIEW_NORMAL);
892  else if( !strcmp( cmd->cmd, "view1")) this->localCamera->setViewMode(VIEW_BEHIND);
893  else if( !strcmp( cmd->cmd, "view2")) this->localCamera->setViewMode(VIEW_FRONT);
894  else if( !strcmp( cmd->cmd, "view3")) this->localCamera->setViewMode(VIEW_LEFT);
895  else if( !strcmp( cmd->cmd, "view4")) this->localCamera->setViewMode(VIEW_RIGHT);
896  else if( !strcmp( cmd->cmd, "view5")) this->localCamera->setViewMode(VIEW_TOP);
897 
898  return false;
899}
900
Note: See TracBrowser for help on using the repository browser.