Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/textEngine: rewind and constant work

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