Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the christmas branche to the trunk
merged with command:
svn merge -r6165:HEAD christmas_branche/ ../trunk/
no conflicts

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