Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: branche comiles again

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