Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: network game manager now sounds good

File size: 24.0 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 "pilot_node.h"
27#include "world_entity.h"
28#include "player.h"
29#include "camera.h"
30#include "environment.h"
31#include "skysphere.h"
32#include "skybox.h"
33#include "satellite.h"
34#include "test_entity.h"
35#include "terrain.h"
36#include "light.h"
37#include "load_param.h"
38#include "shell.h"
39
40#include "fast_factory.h"
41#include "animation_player.h"
42#include "particle_engine.h"
43#include "graphics_engine.h"
44#include "physics_engine.h"
45#include "fields.h"
46
47#include "md2Model.h"
48
49#include "glmenu_imagescreen.h"
50#include "list.h"
51#include "game_loader.h"
52
53#include "animation3d.h"
54
55#include "substring.h"
56
57#include "factory.h"
58
59#include "weapons/projectile.h"
60#include "event_handler.h"
61#include "sound_engine.h"
62#include "ogg_player.h"
63
64#include "class_list.h"
65
66#include "cd_engine.h"
67#include "npcs/npc_test1.h"
68#include "shader.h"
69
70#include "playable.h"
71#include "network_manager.h"
72#include "network_game_manager.h"
73#include "playable.h"
74
75
76SHELL_COMMAND(speed, NetworkWorld, setSpeed);
77SHELL_COMMAND(togglePNodeVisibility, NetworkWorld, togglePNodeVisibility);
78SHELL_COMMAND(toggleBVVisibility, NetworkWorld, toggleBVVisibility);
79
80using namespace std;
81
82//! This creates a Factory to fabricate a NetworkWorld
83CREATE_FACTORY(NetworkWorld, CL_WORLD);
84
85NetworkWorld::NetworkWorld(const TiXmlElement* root)
86{
87  this->constuctorInit("", -1);
88  this->path = NULL;
89
90  this->loadParams(root);
91}
92
93/**
94  *  create a new NetworkWorld
95
96    This creates a new empty world!
97*/
98NetworkWorld::NetworkWorld (const char* name)
99{
100  this->path = NULL;
101  this->constuctorInit(name, -1);
102}
103
104/**
105 *  creates a new NetworkWorld...
106 * @param worldID with this ID
107*/
108NetworkWorld::NetworkWorld (int worldID)
109{
110  this->path = NULL;
111  this->constuctorInit(NULL, worldID);
112}
113
114/**
115 *  remove the NetworkWorld from memory
116
117    delete everything explicitly, that isn't contained in the parenting tree!
118    things contained in the tree are deleted automaticaly
119 */
120NetworkWorld::~NetworkWorld ()
121{
122  delete this->shell;
123  PRINTF(3)("NetworkWorld::~NetworkWorld() - deleting current world\n");
124
125  delete this->localPlayer;
126
127  // delete all the initialized Engines.
128  FastFactory::flushAll(true);
129  delete LightManager::getInstance();
130  delete ParticleEngine::getInstance();
131  delete AnimationPlayer::getInstance();
132  delete PhysicsEngine::getInstance();
133
134  // external engines initialized by the orxonox-class get deleted
135  SoundEngine::getInstance()->flushAllBuffers();
136  SoundEngine::getInstance()->flushAllSources();
137
138  if (State::getObjectManager() == &this->objectManager)
139    State::setObjectManager(NULL);
140  // erease everything that is left.
141  delete PNode::getNullParent();
142
143  //secondary cleanup of PNodes;
144  const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);
145  if (nodeList != NULL)
146    while (!nodeList->empty())
147      delete nodeList->front();
148
149  Shader::suspendShader();
150
151  // unload the resources !!
152  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
153
154  delete[] this->path;
155}
156
157/**
158 * initializes the world.
159 * @param name the name of the world
160 * @param worldID the ID of this world
161 *
162 * set all stuff here that is world generic and does not use to much memory
163 * because the real init() function StoryEntity::init() will be called
164 * shortly before start of the game.
165 * since all worlds are initiated/referenced before they will be started.
166 * NO LEVEL LOADING HERE - NEVER!
167*/
168void NetworkWorld::constuctorInit(const char* name, int worldID)
169{
170  this->setClassID(CL_WORLD, "NetworkWorld");
171  PRINTF(0)("START\n");
172
173  this->setName(name);
174  this->debugNetworkWorldNr = worldID;
175  this->gameTime = 0.0f;
176  this->setSpeed(1.0);
177  this->music = NULL;
178  this->shell = NULL;
179  this->localPlayer = NULL;
180  this->localCamera = NULL;
181
182  this->showPNodes = false;
183  this->showBV = false;
184}
185
186/**
187 * loads the parameters of a NetworkWorld from an XML-element
188 * @param root the XML-element to load from
189 */
190void NetworkWorld::loadParams(const TiXmlElement* root)
191{
192  PRINTF(4)("Creating a NetworkWorld\n");
193
194  LoadParam(root, "identifier", this, NetworkWorld, setStoryID)
195    .describe("Sets the StoryID of this world");
196
197  LoadParam(root, "nextid", this, NetworkWorld, setNextStoryID)
198    .describe("Sets the ID of the next world");
199
200  LoadParam(root, "path", this, NetworkWorld, setPath)
201    .describe("The Filename of this NetworkWorld (relative from the data-dir)");
202}
203
204/**
205 * this is executed just before load
206 *
207 * since the load function sometimes needs data, that has been initialized
208 * before the load and after the proceeding storyentity has finished
209*/
210ErrorMessage NetworkWorld::preLoad()
211{
212  State::setObjectManager(&this->objectManager);
213  this->cycle = 0;
214
215  /* init the world interface */
216  this->shell = new Shell();
217
218  LightManager::getInstance();
219  PNode::getNullParent();
220
221  AnimationPlayer::getInstance(); // initializes the animationPlayer
222  ParticleEngine::getInstance();
223  PhysicsEngine::getInstance();
224
225  this->localCamera = new Camera();
226  this->localCamera->setName ("NetworkWorld-Camera");
227
228  State::setCamera(this->localCamera, this->localCamera->getTarget());
229
230  GraphicsEngine::getInstance()->displayFPS(true);
231}
232
233
234/**
235 *  loads the NetworkWorld by initializing all resources, and set their default values.
236*/
237ErrorMessage NetworkWorld::load()
238{
239  PRINTF(3)("> Loading world: '%s'\n", getPath());
240  TiXmlElement* element;
241  GameLoader* loader = GameLoader::getInstance();
242
243  if( getPath() == NULL)
244    {
245      PRINTF(1)("NetworkWorld has no path specified for loading");
246      this->loadDebugNetworkWorld(this->getStoryID());
247      return (ErrorMessage){213,"Path not specified","NetworkWorld::load()"};
248    }
249
250  TiXmlDocument* XMLDoc = new TiXmlDocument( getPath());
251  // load the campaign document
252  if( !XMLDoc->LoadFile())
253  {
254    // report an error
255    PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
256    delete XMLDoc;
257    return (ErrorMessage){213,"XML File parsing error","NetworkWorld::load()"};
258  }
259
260  // check basic validity
261  TiXmlElement* root = XMLDoc->RootElement();
262  assert( root != NULL);
263
264  if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))
265    {
266      // report an error
267      PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
268      delete XMLDoc;
269      return (ErrorMessage){213,"Path not a WorldDataFile","NetworkWorld::load()"};
270    }
271
272
273  // load the parameters
274  // name
275  const char* string = grabParameter( root, "name");
276  if( string == NULL)
277    {
278      PRINTF(2)("World is missing a proper 'name'\n");
279      this->setName("Unknown");
280    }
281  else
282    {
283      this->setName(string);
284    }
285
286
287  ////////////////
288  // LOADSCREEN //
289  ////////////////
290  element = root->FirstChildElement("LoadScreen");
291  if (element == NULL)
292    {
293      PRINTF(2)("no LoadScreen specified, loading default\n");
294
295      glmis->setBackgroundImage("pictures/load_screen.jpg");
296      this->glmis->setMaximum(8);
297      this->glmis->draw();
298    }
299  else
300    {
301      this->glmis->loadParams(element);
302      this->glmis->draw();
303    }
304  this->glmis->draw();
305
306
307
308  ////////////////////////////
309  // Loading Spawning Point //
310  ////////////////////////////
311  element = root->FirstChildElement("SpawningPoints");
312  if( element == NULL)
313  {
314    PRINTF(1)("NetworkWorld is missing 'SpawningPoints'\n");
315  }
316  else
317  {
318    element = element->FirstChildElement();
319      // load Players/Objects/Whatever
320    PRINTF(4)("Loading Spawning Points\n");
321    while( element != NULL)
322    {
323      BaseObject* created = Factory::fabricate(element);
324      if( created != NULL )
325      {
326        if(created->isA(CL_SPAWNING_POINT))
327          this->spawn(dynamic_cast<WorldEntity*>(created));
328        printf("Created a Spawning Point %s: %s\n", created->getClassName(), created->getName());
329      }
330
331
332      element = element->NextSiblingElement();
333      glmis->step(); //! @todo temporary
334    }
335    PRINTF(4)("Done loading NetworkWorldEntities\n");
336  }
337
338
339  ////////////////////////
340  // find WorldEntities //
341  ////////////////////////
342  element = root->FirstChildElement("WorldEntities");
343  if( element == NULL)
344  {
345    PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n");
346  }
347  else
348  {
349    element = element->FirstChildElement();
350      // load Players/Objects/Whatever
351    PRINTF(4)("Loading NetworkWorldEntities\n");
352    while( element != NULL)
353    {
354      if( NetworkManager::getInstance()->isGameServer() || !strcmp( element->Value(), "SkyBox") || !strcmp( element->Value(), "Terrain")
355          || !strcmp( element->Value(), "SpaceShip"))
356      {
357
358        BaseObject* created = NetworkGameManager::getInstance()->createEntity(element);
359        if( created != NULL )
360        {
361          if(created->isA(CL_WORLD_ENTITY))
362            this->spawn(dynamic_cast<WorldEntity*>(created));
363          printf("Created a %s: %s\n", created->getClassName(), created->getName());
364        }
365        else
366          PRINTF(1)("NetworkWorld: could not create this entity\n");
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 = NetworkGameManager::;
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;
459  //(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  PNode::getNullParent()->updateNode (0.001f);
546  PNode::getNullParent()->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 *  this returns the current game time
627 * @returns elapsed game time
628*/
629double NetworkWorld::getGameTime()
630{
631  return this->gameTime;
632}
633
634/**
635 *  function to put your own debug stuff into it. it can display informations about
636   the current class/procedure
637*/
638// void NetworkWorld::debug()
639// {
640//   PRINTF(0)("Printing out the List of alive NetworkWorldEntities:\n");
641//   tIterator<WorldEntity>* iterator = this->entities->getIterator();
642//   WorldEntity* entity = iterator->firstElement();
643//   while( entity != NULL)
644//   {
645//     PRINTF(0)("%s::%s\n", entity->getClassName(), entity->getName());
646//     entity = iterator->nextElement();
647//   }
648//   delete iterator;
649// }
650
651
652/**
653  \brief main loop of the world: executing all world relevant function
654
655  in this loop we synchronize (if networked), handle input events, give the heart-beat to
656  all other member-entities of the world (tick to player, enemies etc.), checking for
657  collisions drawing everything to the screen.
658*/
659void NetworkWorld::mainLoop()
660{
661  this->lastFrame = SDL_GetTicks ();
662  PRINTF(3)("NetworkWorld::mainLoop() - Entering main loop\n");
663
664  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* @todo implement pause */
665    {
666      ++this->cycle;
667//      PRINTF(4)("NetworkWorld::mainloop() - number of entities: %i\n", this->entities->getSize());
668      // Network
669      this->synchronize ();
670      // Process input
671      this->handleInput ();
672      if( this->bQuitCurrentGame || this->bQuitOrxonox)
673          break;
674      // Process time
675      this->tick ();
676      // Process collision
677      this->collide ();
678      // Update the state
679      this->update ();
680      // Draw
681      this->display ();
682    }
683
684  PRINTF(3)("NetworkWorld::mainLoop() - Exiting the main loop\n");
685}
686
687
688/**
689 *  synchronize local data with remote data
690*/
691void NetworkWorld::synchronize ()
692{
693  // Get remote input
694  // Update synchronizables
695  NetworkManager::getInstance()->synchronize();
696}
697
698
699/**
700 *  run all input processing
701
702   the command node is the central input event dispatcher. the node uses the even-queue from
703   sdl and has its own event-passing-queue.
704*/
705void NetworkWorld::handleInput ()
706{
707  EventHandler::getInstance()->process();
708
709  // remoteinput
710}
711
712void NetworkWorld::tick(std::list<WorldEntity*> entityList, float dt)
713{
714  std::list<WorldEntity*>::iterator entity;
715  for (entity = entityList.begin(); entity != entityList.end(); entity++)
716    (*entity)->tick(dt);
717
718}
719
720/**
721 *  advance the timeline
722
723   this calculates the time used to process one frame (with all input handling, drawing, etc)
724   the time is mesured in ms and passed to all world-entities and other classes that need
725   a heart-beat.
726*/
727void NetworkWorld::tick ()
728{
729  Uint32 currentFrame = SDL_GetTicks();
730  if(!this->bPause)
731    {
732      this->dt = currentFrame - this->lastFrame;
733
734      if( this->dt > 10)
735        {
736          float fps = 1000/dt;
737
738          // temporary, only for showing how fast the text-engine is
739          char tmpChar[20];
740          sprintf(tmpChar, "fps: %4.0f", fps);
741        }
742      else
743        {
744          /* the frame-rate is limited to 100 frames per second, all other things are for
745             nothing.
746          */
747          PRINTF(3)("fps = 1000 - frame rate is adjusted\n");
748          SDL_Delay(10-dt);
749          this->dt = 10;
750        }
751
752      this->dtS = (float)this->dt / 1000.0 * this->speed;
753      this->gameTime += this->dtS;
754
755/*      this->tick(this->objectManager.getObjectList(OM_DEAD_TICK), this->dtS);
756      this->tick(this->objectManager.getObjectList(OM_COMMON), this->dtS);
757      this->tick(this->objectManager.getObjectList(OM_GROUP_00), this->dtS);*/
758      this->tick(this->objectManager.getObjectList(OM_GROUP_01), this->dtS);
759      this->tick(this->objectManager.getObjectList(OM_GROUP_01_PROJ), this->dtS);
760
761      /* update tick the rest */
762      this->localCamera->tick(this->dtS);
763      // tick the engines
764      AnimationPlayer::getInstance()->tick(this->dtS);
765//      if (this->cycle > 5)
766        PhysicsEngine::getInstance()->tick(this->dtS);
767
768      ParticleEngine::getInstance()->tick(this->dtS);
769
770
771      /** actualy the Graphics Engine should tick the world not the other way around...
772         but since we like the things not too complicated we got it this way around
773         until there is need or time to do it the other way around.
774         @todo: GraphicsEngine ticks world: separation of processes and data...
775
776        bensch: in my opinion the GraphicsEngine could draw the world, but not tick it,
777         beceause graphics have nothing(or at least not much) to do with Motion.
778      */
779      GraphicsEngine::getInstance()->tick(this->dtS);
780    }
781  this->lastFrame = currentFrame;
782}
783
784
785/**
786 *  this function gives the world a consistant state
787
788   after ticking (updating the world state) this will give a constistant
789   state to the whole system.
790*/
791void NetworkWorld::update()
792{
793  GraphicsEngine::getInstance()->update(this->dtS);
794  PNode::getNullParent()->updateNode (this->dtS);
795
796  SoundEngine::getInstance()->update();
797  //music->update();
798}
799
800
801void NetworkWorld::collide()
802{
803  CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_00),
804                                            this->objectManager.getObjectList(OM_GROUP_01_PROJ));
805  CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_01),
806                                            this->objectManager.getObjectList(OM_COMMON));
807}
808
809/**
810 *  render the current frame
811
812   clear all buffers and draw the world
813*/
814void NetworkWorld::display ()
815{
816  // clear buffer
817  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
818  // set camera
819  this->localCamera->apply ();
820  // draw world
821  this->draw();
822  // draw HUD
823  /** @todo draw HUD */
824  // flip buffers
825  GraphicsEngine::swapBuffers();
826  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
827  //SDL_Flip (screen);
828}
829
830
831/**
832 *  runs through all entities calling their draw() methods
833 */
834void NetworkWorld::draw ()
835{
836  GraphicsEngine* engine = GraphicsEngine::getInstance();
837  engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));
838  engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON));
839  engine->draw(State::getObjectManager()->getObjectList(OM_COMMON));
840  engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_00));
841  engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01));
842  engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));
843
844//   {
845//     if( entity->isVisible() ) entity->draw();
846  //FIXME
847//     if( unlikely( this->showBV)) entity->drawBVTree(3, 226);  // to draw the bounding boxes of the objects at level 2 for debug purp
848//     entity = iterator->nextElement();
849//   }
850
851  glCallList (objectList);
852
853  ParticleEngine::getInstance()->draw();
854
855  if (unlikely(this->showPNodes))
856    PNode::getNullParent()->debugDraw(0);
857
858  engine->draw();
859  //TextEngine::getInstance()->draw();
860}
861
862/**
863 *  add and spawn a new entity to this world
864 * @param entity to be added
865*/
866void NetworkWorld::spawn(WorldEntity* entity)
867{
868//   this->entities->add (entity);
869  entity->postSpawn ();
870
871}
872
873
874/**
875 *  add and spawn a new entity to this world
876 * @param entity to be added
877 * @param absCoor At what coordinates to add this entity.
878 * @param absDir In which direction should it look.
879*/
880void NetworkWorld::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
881{
882//   this->entities->add (entity);
883
884  entity->setAbsCoor (*absCoor);
885  entity->setAbsDir (*absDir);
886
887  entity->postSpawn ();
888}
889
890
891/**
892 *  add and spawn a new entity to this world
893 * @param entity to be added
894 * @param entity to be added to (PNode)
895 * @param At what relative  coordinates to add this entity.
896 * @param In which relative direction should it look.
897*/
898void NetworkWorld::spawn(WorldEntity* entity, PNode* parentNode,
899                  Vector* relCoor, Quaternion* relDir)
900{
901  if( parentNode != NULL)
902    {
903      parentNode->addChild (entity);
904
905      entity->setRelCoor (*relCoor);
906      entity->setRelDir (*relDir);
907
908//       this->entities->add (entity);
909
910      entity->postSpawn ();
911    }
912}
913
914void NetworkWorld::setPath( const char* name)
915{
916  if (this->path)
917    delete this->path;
918  if (ResourceManager::isFile(name))
919  {
920    this->path = new char[strlen(name)+1];
921    strcpy(this->path, name);
922  }
923  else
924    {
925      this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1];
926      sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name);
927    }
928}
929
930const char* NetworkWorld::getPath( void)
931{
932  return path;
933}
Note: See TracBrowser for help on using the repository browser.