Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6341 was 6341, checked in by bensch, 18 years ago

orxonox/trunk: merged the network branche back to the trunk, so we do not get away from each other to fast

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