Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/ll2trunktemp/src/story_entities/world.cc @ 3940

Last change on this file since 3940 was 3940, checked in by chris, 19 years ago

orxonox/branches/ll2trunktemp: I tried… Not working…

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