Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: network world changes and spawning points

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