Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/ll2trunktemp: some more headers, now the level really gets loaded

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