Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 7, 2005, 3:54:49 PM (19 years ago)
Author:
chris
Message:

orxonox/branches/levelloader: Merged trunk into branch… still not working though…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelloader/src/story_entities/world.cc

    r3606 r3746  
    1818
    1919#include "world.h"
    20 #include "world_entity.h"
    21 #include "track_manager.h"
    22 #include "player.h"
    23 #include "command_node.h"
    24 #include "camera.h"
    25 #include "environment.h"
    26 #include "primitive.h"
     20
     21#include "orxonox.h"
     22
    2723#include "p_node.h"
    2824#include "null_parent.h"
    2925#include "helper_parent.h"
     26#include "track_node.h"
     27#include "world_entity.h"
     28#include "player.h"
     29#include "camera.h"
     30#include "environment.h"
     31#include "skysphere.h"
     32#include "terrain.h"
     33#include "light.h"
     34
     35#include "track_manager.h"
     36#include "garbage_collector.h"
     37#include "simple_animation.h"
     38
     39#include "command_node.h"
    3040#include "glmenu_imagescreen.h"
    31 #include "skysphere.h"
    32 #include "light.h"
    3341#include "fontset.h"
     42#include "list.h"
    3443#include "factory.h"
    3544#include "game_loader.h"
     
    3746#include "terrain.h"
    3847
     48
     49
    3950using namespace std;
    4051
    4152CREATE_FACTORY(World);
     53
     54WorldInterface* WorldInterface::singletonRef = 0;
     55
     56
     57/**
     58   \brief private constructor because of singleton
     59*/
     60WorldInterface::WorldInterface()
     61{
     62  this->worldIsInitialized = false;
     63  this->worldReference = NULL;
     64}
     65
     66/**
     67   \brief public deconstructor
     68*/
     69WorldInterface::~WorldInterface()
     70{
     71  this->singletonRef = NULL;
     72  this->worldIsInitialized = false;
     73  this->worldReference = NULL;
     74}
     75
     76/**
     77   \brief gets the singleton instance
     78   \returns singleton instance
     79*/
     80WorldInterface* WorldInterface::getInstance()
     81{
     82  if( singletonRef == NULL)
     83    singletonRef = new WorldInterface();
     84  return singletonRef;
     85}
     86
     87
     88/**
     89   \brief initializes the interface
     90   \param reference to the world
     91
     92   if the worldinterface is not initilizes, there wont be any
     93   useable interface
     94*/
     95void WorldInterface::init(World* world)
     96{
     97  this->worldReference = world;
     98  if( world != NULL)
     99    {
     100      this->worldIsInitialized = true;
     101      PRINTF(3)("WorldInterface up and running\n");
     102    }
     103}
     104
     105
     106/**
     107   \brief gets the entity list from the world
     108   \return entity list
     109*/
     110tList<WorldEntity>* WorldInterface::getEntityList()
     111{
     112  if( this->worldIsInitialized)
     113    return this->worldReference->getEntities();
     114  PRINT(1)("Someone tried to use the WorldInterface before it has been initizlized! this can result in SEGFAULTs!\n");
     115  return NULL;
     116}
     117
     118
    42119
    43120World::World( TiXmlElement* root)
     
    110187  cn->reset();
    111188
     189  ResourceManager::getInstance()->debug();
     190  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
     191  ResourceManager::getInstance()->debug();
     192
     193  delete WorldInterface::getInstance();
     194
    112195  delete this->nullParent;
    113196  delete this->entities;
     
    116199  if( this->worldName) delete this->worldName;
    117200  if( this->path) delete this->path;
    118 }
    119 
    120 /**
    121    \brief initializes a new World
     201
     202  //delete garbagecollecor
     203  //delete animator
     204}
     205
     206/**
     207   \brief initializes the world.
     208
     209   set all stuff here that is world generic and does not use to much memory
     210   because the real init() function StoryEntity::init() will be called
     211   shortly before start of the game. 
     212   since all worlds are initiated/referenced before they will be started.
     213   NO LEVEL LOADING HERE - NEVER!
    122214*/
    123215void World::init(char* name, int worldID)
     
    128220  this->debugWorldNr = worldID;
    129221  this->entities = new tList<WorldEntity>();
    130 
    131   // Enable default GL stuff
    132   glEnable(GL_DEPTH_TEST);
    133 
     222}
     223
     224
     225/**
     226   \brief this is executed before load
     227
     228   since the load function sometimes needs data, that has been init before
     229   the load and after the proceeding storyentity has finished
     230*/
     231ErrorMessage World::preLoad()
     232{
     233  /* init the world interface */
     234  WorldInterface* wi = WorldInterface::getInstance();
     235  wi->init(this);
     236  this->garbageCollector = GarbageCollector::getInstance();
     237  this->simpleAnimation = SimpleAnimation::getInstance();
    134238}
    135239
     
    153257        // load the campaign document
    154258        if( !XMLDoc->LoadFile())
     259      this->glmis->step();
    155260
    156261        {
     
    257362   
    258363        // bind camera
    259     this->localCamera = new Camera(this);
     364    this->localCamera = new Camera();
    260365    this->localCamera->setName ("camera");
    261     this->localCamera->bind (localPlayer);
     366    //this->localCamera->bind (localPlayer);
    262367    this->localPlayer->addChild (this->localCamera);
    263368
     
    267372      /*monitor progress*/
    268373  //  this->glmis->step();
     374
     375      // LIGHT initialisation
     376      lightMan = LightManager::getInstance();
     377      lightMan->setAmbientColor(.1,.1,.1);
     378      lightMan->addLight();
     379      //      lightMan->setAttenuation(1.0, .01, 0.0);
     380      //      lightMan->setDiffuseColor(1,1,1);
     381      //  lightMan->addLight(1);
     382      //  lightMan->setPosition(20, 10, -20);
     383      //  lightMan->setDiffuseColor(0,0,0);
     384      lightMan->debug();
     385            lightMan->setPosition(-5.0, 10.0, -40.0);
     386
    269387
    270388            // Create SkySphere
     
    274392            this->skySphere->setMode(PNODE_MOVEMENT);
    275393
    276             /*monitor progress*/
    277           //  this->glmis->step();
    278          
    279           //  trackManager->setBindSlave(env);
     394
     395            //      trackManager->setBindSlave(env);
     396            PNode* tn = trackManager->getTrackNode();
     397            tn->addChild(this->localPlayer);
     398
     399            //localCamera->setParent(TrackNode::getInstance());
     400            tn->addChild(this->localCamera);
     401            //      localCamera->lookAt(tn);
     402            this->localPlayer->setMode(PNODE_ALL);
     403            //Vector* cameraOffset = new Vector (0, 5, -10);
     404            //trackManager->condition(2, LEFTRIGHT, this->localPlayer);
    280405
    281406  // initialize debug coord system
     
    290415  terrain->setRelCoor(new Vector(0,-10,0));
    291416  this->spawn(terrain);
    292 
    293 }
    294 
    295 /**
    296    \brief initializes a new World
     417}
     418
     419
     420/**
     421   \brief initializes a new World shortly before start
     422
     423   this is the function, that will be loaded shortly before the world is
     424   started
    297425*/
    298426ErrorMessage World::init()
     
    302430  cn->addToWorld(this);
    303431  cn->enable(true);
    304 
    305432PRINTF0("> Done Loading world: '%s'\n", getPath());
    306433}
     
    363490  this->glmis = GLMenuImageScreen::getInstance();
    364491  this->glmis->init();
    365   this->glmis->setMaximum(10);
     492  this->glmis->setMaximum(8);
    366493  this->glmis->draw();
    367494 
     
    378505  PRINTF(3)("World::releaseLoadScreen - start\n");
    379506  this->glmis->setValue(this->glmis->getMaximum());
    380   SDL_Delay(500);
     507  //SDL_Delay(500);
    381508  PRINTF(3)("World::releaseLoadScreen - end\n");
     509}
     510
     511
     512/**
     513   \brief gets the list of entities from the world
     514   \returns entity list
     515*/
     516tList<WorldEntity>* World::getEntities()
     517{
     518  return this->entities;
     519}
     520
     521
     522/**
     523   \brief this returns the current game time
     524   \returns elapsed game time
     525*/
     526double World::getGameTime()
     527{
     528  return this->gameTime;
    382529}
    383530
     
    435582  glLoadIdentity();
    436583
    437   entity = this->entities->enumerate();
     584  //entity = this->entities->enumerate();
     585  tIterator<WorldEntity>* iterator = this->entities->getIterator();
     586  entity = iterator->nextElement();
    438587  while( entity != NULL )
    439588    {
    440589      if( entity->bDraw ) entity->draw();
    441       entity = this->entities->nextElement();
    442     }
     590      //entity = this->entities->nextElement();
     591      entity = iterator->nextElement();
     592    }
     593  delete iterator;
    443594 
    444595  glCallList (objectList);
     
    477628  p4->debug ();
    478629 
    479   p1->update ();
     630  p1->update (0);
    480631
    481632  printf ("World::debug() - update\n");
     
    486637
    487638  p2->shiftCoor (new Vector(-1, -1, -1));
    488   p1->update ();
     639  p1->update (0);
    489640
    490641  p1->debug ();
     
    496647
    497648
    498  p1->update ();
     649 p1->update (0);
    499650
    500651  p1->debug ();
     
    593744  if(!this->bPause)
    594745    {
    595       Uint32 dt = currentFrame - this->lastFrame;
     746      this->dt = currentFrame - this->lastFrame;
    596747     
    597       if(dt > 0)
     748      if( this->dt > 0)
    598749        {
    599750          float fps = 1000/dt;
     
    607758          PRINTF(2)("fps = 1000 - frame rate is adjusted\n");
    608759          SDL_Delay(10);
    609           dt = 10;
     760          this->dt = 10;
    610761        }
    611762      //this->timeSlice (dt);
    612763     
    613764      /* function to let all entities tick (iterate through list) */
    614       WorldEntity* entity;
    615       float seconds = dt / 1000.0; 
    616       assert( this->nullParent != NULL);
    617       entity = entities->enumerate();
     765      float seconds = this->dt / 1000.0;     
     766      this->gameTime += seconds;
     767      //entity = entities->enumerate();
     768      tIterator<WorldEntity>* iterator = this->entities->getIterator();
     769      WorldEntity* entity = iterator->nextElement();
    618770      while( entity != NULL)
    619771        {
    620772          entity->tick (seconds);
    621           entity = entities->nextElement();
    622         }
     773          entity = iterator->nextElement();
     774        }
     775      delete iterator;
     776      //skySphere->updatePosition(localCamera->absCoordinate);
     777     
    623778      /* update tick the rest */
     779      this->trackManager->tick(this->dt);
    624780      assert( this->localCamera != NULL);
    625781      assert( this->trackManager != NULL);
    626       this->localCamera->tick(dt);
    627 
    628       this->trackManager->tick(dt);
     782      this->localCamera->tick(this->dt);
     783      this->garbageCollector->tick(seconds);
     784      this->simpleAnimation->tick(seconds);
    629785    }
    630786  this->lastFrame = currentFrame;
     
    640796void World::update()
    641797{
    642   this->nullParent->update ();
     798  this->garbageCollector->update();
     799  this->nullParent->update (dt);
    643800}
    644801
     
    728885bool World::command(Command* cmd)
    729886{
     887  if( !strcmp( cmd->cmd, "view0")) this->localCamera->setViewMode(VIEW_NORMAL);
     888  else if( !strcmp( cmd->cmd, "view1")) this->localCamera->setViewMode(VIEW_BEHIND);
     889  else if( !strcmp( cmd->cmd, "view2")) this->localCamera->setViewMode(VIEW_FRONT);
     890  else if( !strcmp( cmd->cmd, "view3")) this->localCamera->setViewMode(VIEW_LEFT);
     891  else if( !strcmp( cmd->cmd, "view4")) this->localCamera->setViewMode(VIEW_RIGHT);
     892  else if( !strcmp( cmd->cmd, "view5")) this->localCamera->setViewMode(VIEW_TOP);
     893 
    730894  return false;
    731895}
Note: See TracChangeset for help on using the changeset viewer.