Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/story_entities/network_world.cc @ 6197

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

orxonox/trunk: merge the ObjectManager to the trunk
merged with command:
svn merge -r6082:HEAD objectmanager/ ../trunk/

conflicts resolution was easy this time :)
but specially merged the world to network_world

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