Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: the network core is almost finished

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      {
360        BaseObject* created = Factory::fabricate(element);
361        if( created != NULL )
362        {
363          if(created->isA(CL_WORLD_ENTITY))
364            this->spawn(dynamic_cast<WorldEntity*>(created));
365          printf("Created a %s: %s\n", created->getClassName(), created->getName());
366        }
367
368          // if we load a 'Player' we use it as localPlayer
369
370
371          //todo do this more elegant
372        if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
373          sky = dynamic_cast<SkyBox*>(created);
374        if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
375        {
376          terrain = dynamic_cast<Terrain*>(created);
377          CDEngine::getInstance()->setTerrain(terrain);
378        }
379
380      }
381      element = element->NextSiblingElement();
382      glmis->step(); //! @todo temporary
383      PRINTF(4)("Done loading NetworkWorldEntities\n");
384    }
385  }
386
387
388    //////////////////////////////
389    // LOADING ADDITIONAL STUFF //
390    //////////////////////////////
391
392    LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);
393
394   LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);
395//   LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);
396
397  // free the XML data
398
399  delete XMLDoc;
400  /* GENERIC LOADING PROCESS FINISHED */
401
402
403  // Create a Player
404  this->localPlayer = new Player();
405
406  Playable* playable;
407  const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
408  if (playableList != NULL)
409  {
410    playable = dynamic_cast<Playable*>(playableList->front());
411    this->localPlayer->setControllable(playable);
412  }
413
414  // bind camera
415  playable->addChild (this->localCamera);
416
417//   //localCamera->setParent(TrackNode::getInstance());
418//  tn->addChild(this->localCamera);
419  localCamera->setClipRegion(1, 10000.0);
420  localCamera->lookAt(playable);
421//  this->localPlayer->setParentMode(PNODE_ALL);
422  if (sky != NULL)
423  {
424    this->sky->setParent(this->localCamera);
425    this->sky->setParentMode(PNODE_MOVEMENT);
426  }
427
428  // initialize debug coord system
429  objectList = glGenLists(1);
430  glNewList (objectList, GL_COMPILE);
431
432  glEndList();
433
434  SoundEngine::getInstance()->setListener(this->localCamera);
435
436
437
438  ////////////
439  // STATIC //
440  ////////////
441
442
443//   TestEntity* testEntity = new TestEntity();
444//   testEntity->setRelCoor(Vector(570, 10, -15));
445//   testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
446//   this->spawn(testEntity);
447
448  for(int i = 0; i < 100; i++)
449  {
450    WorldEntity* tmp = new NPCTest1();
451    char npcChar[10];
452    sprintf (npcChar, "NPC_%d", i);
453        tmp->setName(npcChar);
454    tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
455    this->spawn(tmp);
456  }
457
458  this->music = NULL;//(OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL);
459  //music->playback();
460}
461
462
463
464/**
465 * creates a debug world: only for experimental stuff
466*/
467void NetworkWorld::loadDebugNetworkWorld(int worldID)
468{
469  /*monitor progress*/
470  this->glmis->step();
471  // stuff beyond this point remains to be loaded properly
472
473  // LIGHT initialisation
474  LightManager::getInstance()->setAmbientColor(.1,.1,.1);
475//  LightManager::getInstance()->addLight();
476  LightManager::getInstance()->debug();
477
478  switch(this->debugNetworkWorldNr)
479    {
480      /*
481        this loads the hard-coded debug world. this only for simplicity and will be
482        removed by a reald world-loader, which interprets a world-file.
483        if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and
484        make whatever you want...
485      */
486    case DEBUG_WORLD_0:
487      {
488        LightManager::getInstance()->getLight()->setAbsCoor(-5.0, 10.0, -40.0);
489        /*monitor progress*/
490        this->glmis->step();
491
492        // bind camera
493        this->localCamera = new Camera();
494        this->localCamera->setName ("camera");
495        /*monitor progress*/
496        this->glmis->step();
497
498
499        // Create SkySphere
500        this->sky = new Skysphere("pictures/sky-replace.jpg");
501        this->sky->setName("SkySphere");
502        this->spawn(this->sky);
503        this->localCamera->addChild(this->sky);
504        this->sky->setParentMode(PNODE_MOVEMENT);
505        /*monitor progress*/
506        this->glmis->step();
507
508
509        terrain = new Terrain("worlds/newGround.obj");
510        terrain->setRelCoor(Vector(0,-10,0));
511        this->spawn(terrain);
512        /*monitor progress*/
513        this->glmis->step();
514
515        this->glmis->step();
516        break;
517      }
518    case DEBUG_WORLD_1:
519      {
520
521        break;
522      }
523    case DEBUG_WORLD_2:
524      {
525
526        break;
527      }
528    default:
529      break;
530    }
531}
532
533/**
534 *  initializes a new NetworkWorld shortly before start
535 *
536 * this is the function, that will be loaded shortly before the world is
537 * started
538*/
539ErrorMessage NetworkWorld::init()
540{
541  this->bPause = false;
542
543  /* update the object position before game start - so there are no wrong coordinates used in the first processing */
544  NullParent::getInstance()->updateNode (0.001f);
545  NullParent::getInstance()->updateNode (0.001f);
546
547}
548
549
550/**
551 *  starts the NetworkWorld
552*/
553ErrorMessage NetworkWorld::start()
554{
555  PRINTF(3)("NetworkWorld::start() - starting current NetworkWorld: nr %i\n", this->debugNetworkWorldNr);
556  this->bQuitOrxonox = false;
557  this->bQuitCurrentGame = false;
558  this->mainLoop();
559}
560
561/**
562 *  stops the world.
563
564   This happens, when the player decides to end the Level.
565*/
566ErrorMessage NetworkWorld::stop()
567{
568  PRINTF(3)("NetworkWorld::stop() - got stop signal\n");
569  this->bQuitCurrentGame = true;
570}
571
572/**
573 *  pauses the Game
574*/
575ErrorMessage NetworkWorld::pause()
576{
577  this->isPaused = true;
578}
579
580/**
581 *  ends the pause Phase
582*/
583ErrorMessage NetworkWorld::resume()
584{
585  this->isPaused = false;
586}
587
588/**
589 *  destroys the NetworkWorld
590*/
591ErrorMessage NetworkWorld::destroy()
592{
593
594}
595
596/**
597 *  shows the loading screen
598*/
599void NetworkWorld::displayLoadScreen ()
600{
601  PRINTF(3)("NetworkWorld::displayLoadScreen - start\n");
602
603  //GLMenuImageScreen*
604  this->glmis = new GLMenuImageScreen();
605  this->glmis->setMaximum(8);
606
607  PRINTF(3)("NetworkWorld::displayLoadScreen - end\n");
608}
609
610/**
611 *  removes the loadscreen, and changes over to the game
612
613   @todo take out the delay
614*/
615void NetworkWorld::releaseLoadScreen ()
616{
617  PRINTF(3)("NetworkWorld::releaseLoadScreen - start\n");
618  this->glmis->setValue(this->glmis->getMaximum());
619  PRINTF(3)("NetworkWorld::releaseLoadScreen - end\n");
620  delete this->glmis;
621}
622
623
624/**
625 *  gets the list of entities from the world
626 * @returns entity list
627*/
628tList<WorldEntity>* NetworkWorld::getEntities()
629{
630  return this->entities;
631}
632
633
634/**
635 *  this returns the current game time
636 * @returns elapsed game time
637*/
638double NetworkWorld::getGameTime()
639{
640  return this->gameTime;
641}
642
643
644/**
645 *  function to put your own debug stuff into it. it can display informations about
646   the current class/procedure
647*/
648void NetworkWorld::debug()
649{
650  PRINTF(0)("Printing out the List of alive NetworkWorldEntities:\n");
651  tIterator<WorldEntity>* iterator = this->entities->getIterator();
652  WorldEntity* entity = iterator->firstElement();
653  while( entity != NULL)
654  {
655    PRINTF(0)("%s::%s\n", entity->getClassName(), entity->getName());
656    entity = iterator->nextElement();
657  }
658  delete iterator;
659}
660
661
662/**
663  \brief main loop of the world: executing all world relevant function
664
665  in this loop we synchronize (if networked), handle input events, give the heart-beat to
666  all other member-entities of the world (tick to player, enemies etc.), checking for
667  collisions drawing everything to the screen.
668*/
669void NetworkWorld::mainLoop()
670{
671  this->lastFrame = SDL_GetTicks ();
672  PRINTF(3)("NetworkWorld::mainLoop() - Entering main loop\n");
673
674  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* @todo implement pause */
675    {
676      ++this->cycle;
677      PRINTF(4)("NetworkWorld::mainloop() - number of entities: %i\n", this->entities->getSize());
678      // Network
679      this->synchronize ();
680      // Process input
681      this->handleInput ();
682      if( this->bQuitCurrentGame || this->bQuitOrxonox)
683          break;
684      // Process time
685      this->tick ();
686      // Process collision
687      this->collide ();
688      // Update the state
689      this->update ();
690      // Draw
691      this->display ();
692    }
693
694  PRINTF(3)("NetworkWorld::mainLoop() - Exiting the main loop\n");
695}
696
697
698/**
699 *  synchronize local data with remote data
700*/
701void NetworkWorld::synchronize ()
702{
703  // Get remote input
704  // Update synchronizables
705/*  NetworkManager::getInstance()->synchronize();*/
706}
707
708
709/**
710 *  run all input processing
711
712   the command node is the central input event dispatcher. the node uses the even-queue from
713   sdl and has its own event-passing-queue.
714*/
715void NetworkWorld::handleInput ()
716{
717  EventHandler::getInstance()->process();
718
719  // remoteinput
720}
721
722
723/**
724 *  advance the timeline
725
726   this calculates the time used to process one frame (with all input handling, drawing, etc)
727   the time is mesured in ms and passed to all world-entities and other classes that need
728   a heart-beat.
729*/
730void NetworkWorld::tick ()
731{
732  Uint32 currentFrame = SDL_GetTicks();
733  if(!this->bPause)
734    {
735      this->dt = currentFrame - this->lastFrame;
736
737      if( this->dt > 10)
738        {
739          float fps = 1000/dt;
740
741          // temporary, only for showing how fast the text-engine is
742          char tmpChar[20];
743          sprintf(tmpChar, "fps: %4.0f", fps);
744        }
745      else
746        {
747          /* the frame-rate is limited to 100 frames per second, all other things are for
748             nothing.
749          */
750          PRINTF(3)("fps = 1000 - frame rate is adjusted\n");
751          SDL_Delay(10-dt);
752          this->dt = 10;
753        }
754
755      this->dtS = (float)this->dt / 1000.0 * this->speed;
756      this->gameTime += this->dtS;
757
758      tIterator<WorldEntity>* iterator = this->entities->getIterator();
759      WorldEntity* entity = iterator->firstElement();
760      while( entity != NULL)
761        {
762          entity->tick (this->dtS);
763          entity = iterator->nextElement();
764        }
765      delete iterator;
766
767      /* update tick the rest */
768      this->localCamera->tick(this->dtS);
769      // tick the engines
770      AnimationPlayer::getInstance()->tick(this->dtS);
771//      if (this->cycle > 5)
772        PhysicsEngine::getInstance()->tick(this->dtS);
773
774      ParticleEngine::getInstance()->tick(this->dtS);
775      GarbageCollector::getInstance()->tick(this->dtS);
776
777
778      /** actualy the Graphics Engine should tick the world not the other way around...
779         but since we like the things not too complicated we got it this way around
780         until there is need or time to do it the other way around.
781         @todo: GraphicsEngine ticks world: separation of processes and data...
782
783        bensch: in my opinion the GraphicsEngine could draw the world, but not tick it,
784         beceause graphics have nothing(or at least not much) to do with Motion.
785      */
786      GraphicsEngine::getInstance()->tick(this->dtS);
787    }
788  this->lastFrame = currentFrame;
789}
790
791
792/**
793 *  this function gives the world a consistant state
794
795   after ticking (updating the world state) this will give a constistant
796   state to the whole system.
797*/
798void NetworkWorld::update()
799{
800  GarbageCollector::getInstance()->update();
801  GraphicsEngine::getInstance()->update(this->dtS);
802  NullParent::getInstance()->updateNode (this->dtS);
803
804  SoundEngine::getInstance()->update();
805  //music->update();
806}
807
808
809void NetworkWorld::collide()
810{
811  CDEngine::getInstance()->checkCollisions();
812}
813
814/**
815 *  render the current frame
816
817   clear all buffers and draw the world
818*/
819void NetworkWorld::display ()
820{
821  // clear buffer
822  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
823  // set camera
824  this->localCamera->apply ();
825  // draw world
826  this->draw();
827  // draw HUD
828  /** @todo draw HUD */
829  // flip buffers
830  GraphicsEngine::swapBuffers();
831  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
832  //SDL_Flip (screen);
833}
834
835
836/**
837 *  runs through all entities calling their draw() methods
838 */
839void NetworkWorld::draw ()
840{
841  /* draw entities */
842  WorldEntity* entity;
843  glLoadIdentity();
844  tIterator<WorldEntity>* iterator = this->entities->getIterator();
845  entity = iterator->firstElement();
846  while( entity != NULL )
847  {
848    if( entity->isVisible() ) entity->draw();
849    if( unlikely( this->showBV)) entity->drawBVTree(3, 226);  // to draw the bounding boxes of the objects at level 2 for debug purp
850    entity = iterator->nextElement();
851  }
852  delete iterator;
853
854  glCallList (objectList);
855
856  ParticleEngine::getInstance()->draw();
857
858  if (unlikely(this->showPNodes))
859    NullParent::getInstance()->debugDraw(0);
860
861  GraphicsEngine::getInstance()->draw();
862  //TextEngine::getInstance()->draw();
863}
864
865/**
866 *  add and spawn a new entity to this world
867 * @param entity to be added
868*/
869void NetworkWorld::spawn(WorldEntity* entity)
870{
871  this->entities->add (entity);
872  entity->postSpawn ();
873}
874
875
876/**
877 *  add and spawn a new entity to this world
878 * @param entity to be added
879 * @param absCoor At what coordinates to add this entity.
880 * @param absDir In which direction should it look.
881*/
882void NetworkWorld::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
883{
884  this->entities->add (entity);
885
886  entity->setAbsCoor (*absCoor);
887  entity->setAbsDir (*absDir);
888
889  entity->postSpawn ();
890}
891
892
893/**
894 *  add and spawn a new entity to this world
895 * @param entity to be added
896 * @param entity to be added to (PNode)
897 * @param At what relative  coordinates to add this entity.
898 * @param In which relative direction should it look.
899*/
900void NetworkWorld::spawn(WorldEntity* entity, PNode* parentNode,
901                  Vector* relCoor, Quaternion* relDir)
902{
903  if( parentNode != NULL)
904    {
905      parentNode->addChild (entity);
906
907      entity->setRelCoor (*relCoor);
908      entity->setRelDir (*relDir);
909
910      this->entities->add (entity);
911
912      entity->postSpawn ();
913    }
914}
915
916void NetworkWorld::setPath( const char* name)
917{
918  if (this->path)
919    delete this->path;
920  if (ResourceManager::isFile(name))
921  {
922    this->path = new char[strlen(name)+1];
923    strcpy(this->path, name);
924  }
925  else
926    {
927      this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1];
928      sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name);
929    }
930}
931
932const char* NetworkWorld::getPath( void)
933{
934  return path;
935}
Note: See TracBrowser for help on using the repository browser.