Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: game server world loadin

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