Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/story_entities/network_world.cc @ 6104

Last change on this file since 6104 was 6104, checked in by patrick, 18 years ago

network: added the sync loop again

File size: 23.1 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer: Christian Meyer
14   co-programmer: Benjamin Grauer
15*/
16
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
18
19#include "network_world.h"
20
21#include "shell_command.h"
22
23#include "state.h"
24
25#include "p_node.h"
26#include "null_parent.h"
27#include "pilot_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 "test_entity.h"
36#include "terrain.h"
37#include "light.h"
38#include "load_param.h"
39#include "shell.h"
40
41#include "garbage_collector.h"
42#include "fast_factory.h"
43#include "animation_player.h"
44#include "particle_engine.h"
45#include "graphics_engine.h"
46#include "physics_engine.h"
47#include "fields.h"
48
49#include "md2Model.h"
50
51#include "glmenu_imagescreen.h"
52#include "list.h"
53#include "game_loader.h"
54
55#include "animation3d.h"
56
57#include "substring.h"
58
59#include "factory.h"
60
61#include "weapons/projectile.h"
62#include "event_handler.h"
63#include "sound_engine.h"
64#include "ogg_player.h"
65
66#include "class_list.h"
67
68#include "cd_engine.h"
69#include "npcs/npc_test1.h"
70#include "shader.h"
71
72#include "playable.h"
73#include "network_manager.h"
74#include "playable.h"
75
76
77SHELL_COMMAND(speed, NetworkWorld, setSpeed);
78SHELL_COMMAND(togglePNodeVisibility, NetworkWorld, togglePNodeVisibility);
79SHELL_COMMAND(toggleBVVisibility, NetworkWorld, toggleBVVisibility);
80
81using namespace std;
82
83//! This creates a Factory to fabricate a NetworkWorld
84CREATE_FACTORY(NetworkWorld, CL_WORLD);
85
86NetworkWorld::NetworkWorld(const TiXmlElement* root)
87{
88  this->constuctorInit("", -1);
89  this->path = NULL;
90
91  this->loadParams(root);
92}
93
94/**
95  *  create a new NetworkWorld
96
97    This creates a new empty world!
98*/
99NetworkWorld::NetworkWorld (const char* name)
100{
101  this->path = NULL;
102  this->constuctorInit(name, -1);
103}
104
105/**
106 *  creates a new NetworkWorld...
107 * @param worldID with this ID
108*/
109NetworkWorld::NetworkWorld (int worldID)
110{
111  this->path = NULL;
112  this->constuctorInit(NULL, worldID);
113}
114
115/**
116 *  remove the NetworkWorld from memory
117
118    delete everything explicitly, that isn't contained in the parenting tree!
119    things contained in the tree are deleted automaticaly
120 */
121NetworkWorld::~NetworkWorld ()
122{
123  delete this->shell;
124  PRINTF(3)("NetworkWorld::~NetworkWorld() - deleting current world\n");
125
126
127  // here everything that is alocated by the NetworkWorld is deleted
128  delete this->entities;
129  State::setWorldEntityList(NULL);
130
131  delete this->localPlayer;
132
133  // delete all the initialized Engines.
134  FastFactory::flushAll(true);
135  delete LightManager::getInstance();
136  delete ParticleEngine::getInstance();
137  delete AnimationPlayer::getInstance();
138  delete PhysicsEngine::getInstance();
139
140  // external engines initialized by the orxonox-class get deleted
141  SoundEngine::getInstance()->flushAllBuffers();
142  SoundEngine::getInstance()->flushAllSources();
143
144
145  // erease everything that is left.
146  delete NullParent::getInstance();
147
148  Shader::suspendShader();
149
150  // unload the resources !!
151  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
152
153  delete[] this->path;
154}
155
156/**
157 * initializes the world.
158 * @param name the name of the world
159 * @param worldID the ID of this world
160 *
161 * set all stuff here that is world generic and does not use to much memory
162 * because the real init() function StoryEntity::init() will be called
163 * shortly before start of the game.
164 * since all worlds are initiated/referenced before they will be started.
165 * NO LEVEL LOADING HERE - NEVER!
166*/
167void NetworkWorld::constuctorInit(const char* name, int worldID)
168{
169  this->setClassID(CL_WORLD, "NetworkWorld");
170
171  this->setName(name);
172  this->debugNetworkWorldNr = worldID;
173  this->gameTime = 0.0f;
174  this->setSpeed(1.0);
175  this->music = NULL;
176  this->shell = NULL;
177  this->entities = NULL;
178  this->localPlayer = NULL;
179  this->localCamera = NULL;
180
181  this->showPNodes = false;
182  this->showBV = false;
183}
184
185/**
186 * loads the parameters of a NetworkWorld from an XML-element
187 * @param root the XML-element to load from
188 */
189void NetworkWorld::loadParams(const TiXmlElement* root)
190{
191  PRINTF(4)("Creating a NetworkWorld\n");
192
193  LoadParam(root, "identifier", this, NetworkWorld, setStoryID)
194    .describe("Sets the StoryID of this world");
195
196  LoadParam(root, "nextid", this, NetworkWorld, setNextStoryID)
197    .describe("Sets the ID of the next world");
198
199  LoadParam(root, "path", this, NetworkWorld, setPath)
200    .describe("The Filename of this NetworkWorld (relative from the data-dir)");
201}
202
203/**
204 * this is executed just before load
205 *
206 * since the load function sometimes needs data, that has been initialized
207 * before the load and after the proceeding storyentity has finished
208*/
209ErrorMessage NetworkWorld::preLoad()
210{
211  State::setWorldEntityList(this->entities = new tList<WorldEntity>());
212  this->cycle = 0;
213
214  /* init the world interface */
215  this->shell = new Shell();
216
217  LightManager::getInstance();
218  NullParent::getInstance ();
219
220  AnimationPlayer::getInstance(); // initializes the animationPlayer
221  ParticleEngine::getInstance();
222  PhysicsEngine::getInstance();
223
224  this->localCamera = new Camera();
225  this->localCamera->setName ("NetworkWorld-Camera");
226
227  State::setCamera(this->localCamera, this->localCamera->getTarget());
228
229  GraphicsEngine::getInstance()->displayFPS(true);
230
231  CDEngine::getInstance()->setEntityList( this->entities);
232}
233
234
235/**
236 *  loads the NetworkWorld by initializing all resources, and set their default values.
237*/
238ErrorMessage NetworkWorld::load()
239{
240  PRINTF(3)("> Loading world: '%s'\n", getPath());
241  TiXmlElement* element;
242  GameLoader* loader = GameLoader::getInstance();
243
244  if( getPath() == NULL)
245    {
246      PRINTF(1)("NetworkWorld has no path specified for loading");
247      this->loadDebugNetworkWorld(this->getStoryID());
248      return (ErrorMessage){213,"Path not specified","NetworkWorld::load()"};
249    }
250
251  TiXmlDocument* XMLDoc = new TiXmlDocument( getPath());
252  // load the campaign document
253  if( !XMLDoc->LoadFile())
254  {
255    // report an error
256    PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
257    delete XMLDoc;
258    return (ErrorMessage){213,"XML File parsing error","NetworkWorld::load()"};
259  }
260
261  // check basic validity
262  TiXmlElement* root = XMLDoc->RootElement();
263  assert( root != NULL);
264
265  if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))
266    {
267      // report an error
268      PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
269      delete XMLDoc;
270      return (ErrorMessage){213,"Path not a WorldDataFile","NetworkWorld::load()"};
271    }
272
273
274  // load the parameters
275  // name
276  const char* string = grabParameter( root, "name");
277  if( string == NULL)
278    {
279      PRINTF(2)("World is missing a proper 'name'\n");
280      this->setName("Unknown");
281    }
282  else
283    {
284      this->setName(string);
285    }
286
287
288  ////////////////
289  // LOADSCREEN //
290  ////////////////
291  element = root->FirstChildElement("LoadScreen");
292  if (element == NULL)
293    {
294      PRINTF(2)("no LoadScreen specified, loading default\n");
295
296      glmis->setBackgroundImage("pictures/load_screen.jpg");
297      this->glmis->setMaximum(8);
298      this->glmis->draw();
299    }
300  else
301    {
302      this->glmis->loadParams(element);
303      this->glmis->draw();
304    }
305  this->glmis->draw();
306
307
308
309  ////////////////////////////
310  // Loading Spawning Point //
311  ////////////////////////////
312  element = root->FirstChildElement("SpawningPoints");
313  if( element == NULL)
314  {
315    PRINTF(1)("NetworkWorld is missing 'SpawningPoints'\n");
316  }
317  else
318  {
319    element = element->FirstChildElement();
320      // load Players/Objects/Whatever
321    PRINTF(4)("Loading Spawning Points\n");
322    while( element != NULL)
323    {
324      BaseObject* created = Factory::fabricate(element);
325      if( created != NULL )
326      {
327        if(created->isA(CL_SPAWNING_POINT))
328          this->spawn(dynamic_cast<WorldEntity*>(created));
329        printf("Created a Spawning Point %s: %s\n", created->getClassName(), created->getName());
330      }
331
332
333      element = element->NextSiblingElement();
334      glmis->step(); //! @todo temporary
335    }
336    PRINTF(4)("Done loading NetworkWorldEntities\n");
337  }
338
339
340  ////////////////////////
341  // find WorldEntities //
342  ////////////////////////
343  if( NetworkManager::getInstance()->isGameServer())
344  {}
345
346  element = root->FirstChildElement("WorldEntities");
347  if( element == NULL)
348  {
349    PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n");
350  }
351  else
352  {
353    element = element->FirstChildElement();
354      // load Players/Objects/Whatever
355    PRINTF(4)("Loading NetworkWorldEntities\n");
356    while( element != NULL)
357    {
358      if( NetworkManager::getInstance()->isGameServer() || !strcmp( element->Value(), "SkyBox") || !strcmp( element->Value(), "Terrain")
359          || !strcmp( element->Value(), "SpaceShip"))
360      {
361        BaseObject* created = Factory::fabricate(element);
362        if( created != NULL )
363        {
364          if(created->isA(CL_WORLD_ENTITY))
365            this->spawn(dynamic_cast<WorldEntity*>(created));
366          printf("Created a %s: %s\n", created->getClassName(), created->getName());
367        }
368
369          // if we load a 'Player' we use it as localPlayer
370
371
372          //todo do this more elegant
373        if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
374          sky = dynamic_cast<SkyBox*>(created);
375        if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
376        {
377          terrain = dynamic_cast<Terrain*>(created);
378          CDEngine::getInstance()->setTerrain(terrain);
379        }
380
381      }
382      element = element->NextSiblingElement();
383      glmis->step(); //! @todo temporary
384      PRINTF(4)("Done loading NetworkWorldEntities\n");
385    }
386  }
387
388
389    //////////////////////////////
390    // LOADING ADDITIONAL STUFF //
391    //////////////////////////////
392
393    LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);
394
395   LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);
396//   LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);
397
398  // free the XML data
399
400  delete XMLDoc;
401  /* GENERIC LOADING PROCESS FINISHED */
402
403
404  // Create a Player
405  this->localPlayer = new Player();
406
407  Playable* playable;
408  const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
409  if (playableList != NULL)
410  {
411    playable = dynamic_cast<Playable*>(playableList->front());
412    this->localPlayer->setControllable(playable);
413  }
414
415  // bind camera
416  playable->addChild (this->localCamera);
417
418//   //localCamera->setParent(TrackNode::getInstance());
419//  tn->addChild(this->localCamera);
420  localCamera->setClipRegion(1, 10000.0);
421  localCamera->lookAt(playable);
422//  this->localPlayer->setParentMode(PNODE_ALL);
423  if (sky != NULL)
424  {
425    this->sky->setParent(this->localCamera);
426    this->sky->setParentMode(PNODE_MOVEMENT);
427  }
428
429  // initialize debug coord system
430  objectList = glGenLists(1);
431  glNewList (objectList, GL_COMPILE);
432
433  glEndList();
434
435  SoundEngine::getInstance()->setListener(this->localCamera);
436
437
438
439  ////////////
440  // STATIC //
441  ////////////
442
443
444//   TestEntity* testEntity = new TestEntity();
445//   testEntity->setRelCoor(Vector(570, 10, -15));
446//   testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
447//   this->spawn(testEntity);
448
449  for(int i = 0; i < 100; i++)
450  {
451    WorldEntity* tmp = new NPCTest1();
452    char npcChar[10];
453    sprintf (npcChar, "NPC_%d", i);
454        tmp->setName(npcChar);
455    tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
456    this->spawn(tmp);
457  }
458
459  this->music = NULL;//(OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL);
460  //music->playback();
461}
462
463
464
465/**
466 * creates a debug world: only for experimental stuff
467*/
468void NetworkWorld::loadDebugNetworkWorld(int worldID)
469{
470  /*monitor progress*/
471  this->glmis->step();
472  // stuff beyond this point remains to be loaded properly
473
474  // LIGHT initialisation
475  LightManager::getInstance()->setAmbientColor(.1,.1,.1);
476//  LightManager::getInstance()->addLight();
477  LightManager::getInstance()->debug();
478
479  switch(this->debugNetworkWorldNr)
480    {
481      /*
482        this loads the hard-coded debug world. this only for simplicity and will be
483        removed by a reald world-loader, which interprets a world-file.
484        if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and
485        make whatever you want...
486      */
487    case DEBUG_WORLD_0:
488      {
489        LightManager::getInstance()->getLight()->setAbsCoor(-5.0, 10.0, -40.0);
490        /*monitor progress*/
491        this->glmis->step();
492
493        // bind camera
494        this->localCamera = new Camera();
495        this->localCamera->setName ("camera");
496        /*monitor progress*/
497        this->glmis->step();
498
499
500        // Create SkySphere
501        this->sky = new Skysphere("pictures/sky-replace.jpg");
502        this->sky->setName("SkySphere");
503        this->spawn(this->sky);
504        this->localCamera->addChild(this->sky);
505        this->sky->setParentMode(PNODE_MOVEMENT);
506        /*monitor progress*/
507        this->glmis->step();
508
509
510        terrain = new Terrain("worlds/newGround.obj");
511        terrain->setRelCoor(Vector(0,-10,0));
512        this->spawn(terrain);
513        /*monitor progress*/
514        this->glmis->step();
515
516        this->glmis->step();
517        break;
518      }
519    case DEBUG_WORLD_1:
520      {
521
522        break;
523      }
524    case DEBUG_WORLD_2:
525      {
526
527        break;
528      }
529    default:
530      break;
531    }
532}
533
534/**
535 *  initializes a new NetworkWorld shortly before start
536 *
537 * this is the function, that will be loaded shortly before the world is
538 * started
539*/
540ErrorMessage NetworkWorld::init()
541{
542  this->bPause = false;
543
544  /* update the object position before game start - so there are no wrong coordinates used in the first processing */
545  NullParent::getInstance()->updateNode (0.001f);
546  NullParent::getInstance()->updateNode (0.001f);
547
548}
549
550
551/**
552 *  starts the NetworkWorld
553*/
554ErrorMessage NetworkWorld::start()
555{
556  PRINTF(3)("NetworkWorld::start() - starting current NetworkWorld: nr %i\n", this->debugNetworkWorldNr);
557  this->bQuitOrxonox = false;
558  this->bQuitCurrentGame = false;
559  this->mainLoop();
560}
561
562/**
563 *  stops the world.
564
565   This happens, when the player decides to end the Level.
566*/
567ErrorMessage NetworkWorld::stop()
568{
569  PRINTF(3)("NetworkWorld::stop() - got stop signal\n");
570  this->bQuitCurrentGame = true;
571}
572
573/**
574 *  pauses the Game
575*/
576ErrorMessage NetworkWorld::pause()
577{
578  this->isPaused = true;
579}
580
581/**
582 *  ends the pause Phase
583*/
584ErrorMessage NetworkWorld::resume()
585{
586  this->isPaused = false;
587}
588
589/**
590 *  destroys the NetworkWorld
591*/
592ErrorMessage NetworkWorld::destroy()
593{
594
595}
596
597/**
598 *  shows the loading screen
599*/
600void NetworkWorld::displayLoadScreen ()
601{
602  PRINTF(3)("NetworkWorld::displayLoadScreen - start\n");
603
604  //GLMenuImageScreen*
605  this->glmis = new GLMenuImageScreen();
606  this->glmis->setMaximum(8);
607
608  PRINTF(3)("NetworkWorld::displayLoadScreen - end\n");
609}
610
611/**
612 *  removes the loadscreen, and changes over to the game
613
614   @todo take out the delay
615*/
616void NetworkWorld::releaseLoadScreen ()
617{
618  PRINTF(3)("NetworkWorld::releaseLoadScreen - start\n");
619  this->glmis->setValue(this->glmis->getMaximum());
620  PRINTF(3)("NetworkWorld::releaseLoadScreen - end\n");
621  delete this->glmis;
622}
623
624
625/**
626 *  gets the list of entities from the world
627 * @returns entity list
628*/
629tList<WorldEntity>* NetworkWorld::getEntities()
630{
631  return this->entities;
632}
633
634
635/**
636 *  this returns the current game time
637 * @returns elapsed game time
638*/
639double NetworkWorld::getGameTime()
640{
641  return this->gameTime;
642}
643
644
645/**
646 *  function to put your own debug stuff into it. it can display informations about
647   the current class/procedure
648*/
649void NetworkWorld::debug()
650{
651  PRINTF(0)("Printing out the List of alive NetworkWorldEntities:\n");
652  tIterator<WorldEntity>* iterator = this->entities->getIterator();
653  WorldEntity* entity = iterator->firstElement();
654  while( entity != NULL)
655  {
656    PRINTF(0)("%s::%s\n", entity->getClassName(), entity->getName());
657    entity = iterator->nextElement();
658  }
659  delete iterator;
660}
661
662
663/**
664  \brief main loop of the world: executing all world relevant function
665
666  in this loop we synchronize (if networked), handle input events, give the heart-beat to
667  all other member-entities of the world (tick to player, enemies etc.), checking for
668  collisions drawing everything to the screen.
669*/
670void NetworkWorld::mainLoop()
671{
672  this->lastFrame = SDL_GetTicks ();
673  PRINTF(3)("NetworkWorld::mainLoop() - Entering main loop\n");
674
675  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* @todo implement pause */
676    {
677      ++this->cycle;
678      PRINTF(4)("NetworkWorld::mainloop() - number of entities: %i\n", this->entities->getSize());
679      // Network
680      this->synchronize ();
681      // Process input
682      this->handleInput ();
683      if( this->bQuitCurrentGame || this->bQuitOrxonox)
684          break;
685      // Process time
686      this->tick ();
687      // Process collision
688      this->collide ();
689      // Update the state
690      this->update ();
691      // Draw
692      this->display ();
693    }
694
695  PRINTF(3)("NetworkWorld::mainLoop() - Exiting the main loop\n");
696}
697
698
699/**
700 *  synchronize local data with remote data
701*/
702void NetworkWorld::synchronize ()
703{
704  // Get remote input
705  // Update synchronizables
706  NetworkManager::getInstance()->synchronize();
707}
708
709
710/**
711 *  run all input processing
712
713   the command node is the central input event dispatcher. the node uses the even-queue from
714   sdl and has its own event-passing-queue.
715*/
716void NetworkWorld::handleInput ()
717{
718  EventHandler::getInstance()->process();
719
720  // remoteinput
721}
722
723
724/**
725 *  advance the timeline
726
727   this calculates the time used to process one frame (with all input handling, drawing, etc)
728   the time is mesured in ms and passed to all world-entities and other classes that need
729   a heart-beat.
730*/
731void NetworkWorld::tick ()
732{
733  Uint32 currentFrame = SDL_GetTicks();
734  if(!this->bPause)
735    {
736      this->dt = currentFrame - this->lastFrame;
737
738      if( this->dt > 10)
739        {
740          float fps = 1000/dt;
741
742          // temporary, only for showing how fast the text-engine is
743          char tmpChar[20];
744          sprintf(tmpChar, "fps: %4.0f", fps);
745        }
746      else
747        {
748          /* the frame-rate is limited to 100 frames per second, all other things are for
749             nothing.
750          */
751          PRINTF(3)("fps = 1000 - frame rate is adjusted\n");
752          SDL_Delay(10-dt);
753          this->dt = 10;
754        }
755
756      this->dtS = (float)this->dt / 1000.0 * this->speed;
757      this->gameTime += this->dtS;
758
759      tIterator<WorldEntity>* iterator = this->entities->getIterator();
760      WorldEntity* entity = iterator->firstElement();
761      while( entity != NULL)
762        {
763          entity->tick (this->dtS);
764          entity = iterator->nextElement();
765        }
766      delete iterator;
767
768      /* update tick the rest */
769      this->localCamera->tick(this->dtS);
770      // tick the engines
771      AnimationPlayer::getInstance()->tick(this->dtS);
772//      if (this->cycle > 5)
773        PhysicsEngine::getInstance()->tick(this->dtS);
774
775      ParticleEngine::getInstance()->tick(this->dtS);
776      GarbageCollector::getInstance()->tick(this->dtS);
777
778
779      /** actualy the Graphics Engine should tick the world not the other way around...
780         but since we like the things not too complicated we got it this way around
781         until there is need or time to do it the other way around.
782         @todo: GraphicsEngine ticks world: separation of processes and data...
783
784        bensch: in my opinion the GraphicsEngine could draw the world, but not tick it,
785         beceause graphics have nothing(or at least not much) to do with Motion.
786      */
787      GraphicsEngine::getInstance()->tick(this->dtS);
788    }
789  this->lastFrame = currentFrame;
790}
791
792
793/**
794 *  this function gives the world a consistant state
795
796   after ticking (updating the world state) this will give a constistant
797   state to the whole system.
798*/
799void NetworkWorld::update()
800{
801  GarbageCollector::getInstance()->update();
802  GraphicsEngine::getInstance()->update(this->dtS);
803  NullParent::getInstance()->updateNode (this->dtS);
804
805  SoundEngine::getInstance()->update();
806  //music->update();
807}
808
809
810void NetworkWorld::collide()
811{
812  CDEngine::getInstance()->checkCollisions();
813}
814
815/**
816 *  render the current frame
817
818   clear all buffers and draw the world
819*/
820void NetworkWorld::display ()
821{
822  // clear buffer
823  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
824  // set camera
825  this->localCamera->apply ();
826  // draw world
827  this->draw();
828  // draw HUD
829  /** @todo draw HUD */
830  // flip buffers
831  GraphicsEngine::swapBuffers();
832  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
833  //SDL_Flip (screen);
834}
835
836
837/**
838 *  runs through all entities calling their draw() methods
839 */
840void NetworkWorld::draw ()
841{
842  /* draw entities */
843  WorldEntity* entity;
844  glLoadIdentity();
845  tIterator<WorldEntity>* iterator = this->entities->getIterator();
846  entity = iterator->firstElement();
847  while( entity != NULL )
848  {
849    if( entity->isVisible() ) entity->draw();
850    if( unlikely( this->showBV)) entity->drawBVTree(3, 226);  // to draw the bounding boxes of the objects at level 2 for debug purp
851    entity = iterator->nextElement();
852  }
853  delete iterator;
854
855  glCallList (objectList);
856
857  ParticleEngine::getInstance()->draw();
858
859  if (unlikely(this->showPNodes))
860    NullParent::getInstance()->debugDraw(0);
861
862  GraphicsEngine::getInstance()->draw();
863  //TextEngine::getInstance()->draw();
864}
865
866/**
867 *  add and spawn a new entity to this world
868 * @param entity to be added
869*/
870void NetworkWorld::spawn(WorldEntity* entity)
871{
872  this->entities->add (entity);
873  entity->postSpawn ();
874}
875
876
877/**
878 *  add and spawn a new entity to this world
879 * @param entity to be added
880 * @param absCoor At what coordinates to add this entity.
881 * @param absDir In which direction should it look.
882*/
883void NetworkWorld::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
884{
885  this->entities->add (entity);
886
887  entity->setAbsCoor (*absCoor);
888  entity->setAbsDir (*absDir);
889
890  entity->postSpawn ();
891}
892
893
894/**
895 *  add and spawn a new entity to this world
896 * @param entity to be added
897 * @param entity to be added to (PNode)
898 * @param At what relative  coordinates to add this entity.
899 * @param In which relative direction should it look.
900*/
901void NetworkWorld::spawn(WorldEntity* entity, PNode* parentNode,
902                  Vector* relCoor, Quaternion* relDir)
903{
904  if( parentNode != NULL)
905    {
906      parentNode->addChild (entity);
907
908      entity->setRelCoor (*relCoor);
909      entity->setRelDir (*relDir);
910
911      this->entities->add (entity);
912
913      entity->postSpawn ();
914    }
915}
916
917void NetworkWorld::setPath( const char* name)
918{
919  if (this->path)
920    delete this->path;
921  if (ResourceManager::isFile(name))
922  {
923    this->path = new char[strlen(name)+1];
924    strcpy(this->path, name);
925  }
926  else
927    {
928      this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1];
929      sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name);
930    }
931}
932
933const char* NetworkWorld::getPath( void)
934{
935  return path;
936}
Note: See TracBrowser for help on using the repository browser.