Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: singleton fix

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