Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: debug less and client fix

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