Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/story_entities/world.cc @ 5924

Last change on this file since 5924 was 5915, checked in by bensch, 19 years ago

orxonox/trunk: merged branches/spaceshipControll back to the trunk:
merged with command:
svn merge -r5835:HEAD branches/spaceshipcontroll trunk
conflicts resolved with dynamic indentation methodology algorithms

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