Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/story_entities/world.cc @ 5895

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

controll: playable interface work

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