Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6345 in orxonox.OLD for trunk/src/story_entities/network_world.cc


Ignore:
Timestamp:
Dec 30, 2005, 2:26:12 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: tried to merge the old world to the new one… this was not too good

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/story_entities/network_world.cc

    r6341 r6345  
    2020
    2121#include "shell_command.h"
    22 
     22#include "resource_manager.h"
    2323#include "state.h"
    2424
    2525#include "p_node.h"
    26 #include "pilot_node.h"
    2726#include "world_entity.h"
    2827#include "player.h"
    2928#include "camera.h"
    3029#include "environment.h"
    31 #include "skysphere.h"
    32 #include "skybox.h"
    33 #include "satellite.h"
     30#include "terrain.h"
     31
    3432#include "test_entity.h"
    3533#include "terrain.h"
     
    9189
    9290/**
    93   *  create a new NetworkWorld
    94 
    95     This creates a new empty world!
    96 */
    97 NetworkWorld::NetworkWorld (const char* name)
    98 {
    99   this->path = NULL;
    100   this->constuctorInit(name, -1);
    101 }
    102 
    103 /**
    104  *  creates a new NetworkWorld...
    105  * @param worldID with this ID
    106 */
    107 NetworkWorld::NetworkWorld (int worldID)
    108 {
    109   this->path = NULL;
    110   this->constuctorInit(NULL, worldID);
    111 }
    112 
    113 /**
    11491 *  remove the NetworkWorld from memory
    115 
    116     delete everything explicitly, that isn't contained in the parenting tree!
    117     things contained in the tree are deleted automaticaly
     92 *
     93 *  delete everything explicitly, that isn't contained in the parenting tree!
     94 *  things contained in the tree are deleted automaticaly
    11895 */
    11996NetworkWorld::~NetworkWorld ()
     
    150127  // unload the resources !!
    151128  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
    152 
    153   delete[] this->path;
    154129}
    155130
     
    171146
    172147  this->setName(name);
    173   this->debugNetworkWorldNr = worldID;
    174148  this->gameTime = 0.0f;
    175149  this->setSpeed(1.0);
     
    228202
    229203  GraphicsEngine::getInstance()->displayFPS(true);
     204  this->displayLoadScreen();
    230205}
    231206
     
    233208/**
    234209 *  loads the NetworkWorld by initializing all resources, and set their default values.
    235 */
     210 */
    236211ErrorMessage NetworkWorld::load()
    237212{
     
    242217  if( getPath() == NULL)
    243218    {
    244       PRINTF(1)("NetworkWorld has no path specified for loading");
    245       this->loadDebugNetworkWorld(this->getStoryID());
    246       return (ErrorMessage){213,"Path not specified","NetworkWorld::load()"};
     219      PRINTF(1)("World has no path specified for loading");
     220      return (ErrorMessage){213,"Path not specified","World::load()"};
    247221    }
    248222
     
    323297      if( created != NULL )
    324298      {
    325         if(created->isA(CL_SPAWNING_POINT))
    326           this->spawn(dynamic_cast<WorldEntity*>(created));
     299//        if(created->isA(CL_SPAWNING_POINT))
     300//          this->spawn(dynamic_cast<WorldEntity*>(created));
    327301        printf("Created a Spawning Point %s: %s\n", created->getClassName(), created->getName());
    328302      }
     
    357331        if( created != NULL )
    358332        {
    359           if(created->isA(CL_WORLD_ENTITY))
    360             this->spawn(dynamic_cast<WorldEntity*>(created));
     333//          if(created->isA(CL_WORLD_ENTITY))
     334//            this->spawn(dynamic_cast<WorldEntity*>(created));
    361335          printf("Created a %s: %s\n", created->getClassName(), created->getName());
    362336        }
     
    369343          //todo do this more elegant
    370344        if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
    371           sky = dynamic_cast<SkyBox*>(created);
     345          sky = dynamic_cast<WorldEntity*>(created);
    372346        if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
    373347        {
    374348          terrain = dynamic_cast<Terrain*>(created);
    375349          CDEngine::getInstance()->setTerrain(terrain);
     350
    376351        }
    377352
     
    382357        if( created != NULL )
    383358        {
    384           if(created->isA(CL_WORLD_ENTITY))
    385             this->spawn(dynamic_cast<WorldEntity*>(created));
     359//          if(created->isA(CL_WORLD_ENTITY))
     360//            this->spawn(dynamic_cast<WorldEntity*>(created));
    386361          printf("Created a %s: %s\n", created->getClassName(), created->getName());
    387362        }
     
    394369          //todo do this more elegant
    395370        if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
    396           sky = dynamic_cast<SkyBox*>(created);
     371          sky = dynamic_cast<WorldEntity*>(created);
    397372        if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
    398373        {
     
    434409  }
    435410
    436   // bind camera
    437   playable->addChild (this->localCamera);
    438411
    439412//   //localCamera->setParent(TrackNode::getInstance());
    440413//  tn->addChild(this->localCamera);
    441414  localCamera->setClipRegion(1, 10000.0);
    442   localCamera->lookAt(playable);
     415//  localCamera->lookAt(playable);
    443416//  this->localPlayer->setParentMode(PNODE_ALL);
    444   if (sky != NULL)
    445   {
    446     this->sky->setParent(this->localCamera);
    447     this->sky->setParentMode(PNODE_MOVEMENT);
    448   }
    449 
    450   // initialize debug coord system
    451   objectList = glGenLists(1);
    452   glNewList (objectList, GL_COMPILE);
    453 
    454   glEndList();
    455 
     417  if (this->sky != NULL)
     418  {
     419    this->localCamera->addChild(sky);
     420  }
    456421  SoundEngine::getInstance()->setListener(this->localCamera);
    457422
     
    483448}
    484449
    485 
    486 
    487 /**
    488  * creates a debug world: only for experimental stuff
    489 */
    490 void NetworkWorld::loadDebugNetworkWorld(int worldID)
     450ErrorMessage NetworkWorld::postLoad()
    491451{
    492452  /*monitor progress*/
     
    499459  LightManager::getInstance()->debug();
    500460
    501   switch(this->debugNetworkWorldNr)
    502     {
    503       /*
    504         this loads the hard-coded debug world. this only for simplicity and will be
    505         removed by a reald world-loader, which interprets a world-file.
    506         if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and
    507         make whatever you want...
    508       */
    509     case DEBUG_WORLD_0:
    510       {
    511         LightManager::getInstance()->getLight()->setAbsCoor(-5.0, 10.0, -40.0);
    512         /*monitor progress*/
    513         this->glmis->step();
    514 
    515         // bind camera
    516         this->localCamera = new Camera();
    517         this->localCamera->setName ("camera");
    518         /*monitor progress*/
    519         this->glmis->step();
    520 
    521 
    522         // Create SkySphere
    523         this->sky = new Skysphere("pictures/sky-replace.jpg");
    524         this->sky->setName("SkySphere");
    525         this->spawn(this->sky);
    526         this->localCamera->addChild(this->sky);
    527         this->sky->setParentMode(PNODE_MOVEMENT);
    528         /*monitor progress*/
    529         this->glmis->step();
    530 
    531 
    532         terrain = new Terrain("worlds/newGround.obj");
    533         terrain->setRelCoor(Vector(0,-10,0));
    534         this->spawn(terrain);
    535         /*monitor progress*/
    536         this->glmis->step();
    537 
    538         this->glmis->step();
    539         break;
    540       }
    541     case DEBUG_WORLD_1:
    542       {
    543 
    544         break;
    545       }
    546     case DEBUG_WORLD_2:
    547       {
    548 
    549         break;
    550       }
    551     default:
    552       break;
    553     }
    554 }
     461  this->releaseLoadScreen();
     462}
     463
    555464
    556465/**
     
    560469 * started
    561470*/
    562 ErrorMessage NetworkWorld::init()
     471ErrorMessage NetworkWorld::preStart()
    563472{
    564473  this->bPause = false;
     
    567476  PNode::getNullParent()->updateNode (0.001f);
    568477  PNode::getNullParent()->updateNode (0.001f);
    569 
    570478}
    571479
     
    573481/**
    574482 *  starts the NetworkWorld
    575 */
     483 */
    576484ErrorMessage NetworkWorld::start()
    577485{
    578   PRINTF(3)("NetworkWorld::start() - starting current NetworkWorld: nr %i\n", this->debugNetworkWorldNr);
    579   this->bQuitOrxonox = false;
    580   this->bQuitCurrentGame = false;
     486  this->bQuitWorld = false;
    581487  this->mainLoop();
    582488}
     
    590496{
    591497  PRINTF(3)("NetworkWorld::stop() - got stop signal\n");
    592   this->bQuitCurrentGame = true;
     498  this->bQuitWorld= true;
    593499}
    594500
     
    632538
    633539/**
    634  * removes the loadscreen, and changes over to the game
    635 
    636    @todo take out the delay
     540 * @brief removes the loadscreen, and changes over to the game
     541 *
     542 * @todo take out the delay
    637543*/
    638544void NetworkWorld::releaseLoadScreen ()
     
    655561
    656562/**
    657  *  function to put your own debug stuff into it. it can display informations about
    658    the current class/procedure
    659 */
    660 // void NetworkWorld::debug()
    661 // {
    662 //   PRINTF(0)("Printing out the List of alive NetworkWorldEntities:\n");
    663 //   tIterator<WorldEntity>* iterator = this->entities->getIterator();
    664 //   WorldEntity* entity = iterator->firstElement();
    665 //   while( entity != NULL)
    666 //   {
    667 //     PRINTF(0)("%s::%s\n", entity->getClassName(), entity->getName());
    668 //     entity = iterator->nextElement();
    669 //   }
    670 //   delete iterator;
    671 // }
    672 
    673 
    674 /**
    675563  \brief main loop of the world: executing all world relevant function
    676 
    677564  in this loop we synchronize (if networked), handle input events, give the heart-beat to
    678565  all other member-entities of the world (tick to player, enemies etc.), checking for
     
    682569{
    683570  this->lastFrame = SDL_GetTicks ();
    684   PRINTF(3)("NetworkWorld::mainLoop() - Entering main loop\n");
    685 
    686   while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* @todo implement pause */
    687     {
    688       ++this->cycle;
    689 //      PRINTF(4)("NetworkWorld::mainloop() - number of entities: %i\n", this->entities->getSize());
     571  PRINTF(3)("World::mainLoop() - Entering main loop\n");
     572
     573  while(!this->bQuitWorld) /* @todo implement pause */
     574  {
     575    ++this->cycle;
    690576      // Network
    691       this->synchronize ();
     577    this->synchronize ();
    692578      // Process input
    693       this->handleInput ();
    694       if( this->bQuitCurrentGame || this->bQuitOrxonox)
    695           break;
     579    this->handleInput ();
     580    if( this->bQuitWorld)
     581      break;
    696582      // Process time
    697       this->tick ();
     583    this->tick ();
    698584      // Process collision
    699       this->collide ();
     585    this->collide ();
    700586      // Update the state
    701       this->update ();
     587    this->update ();
    702588      // Draw
    703       this->display ();
    704     }
     589    this->display ();
     590  }
    705591
    706592  PRINTF(3)("NetworkWorld::mainLoop() - Exiting the main loop\n");
     
    775661      this->gameTime += this->dtS;
    776662
    777 /*      this->tick(this->objectManager.getObjectList(OM_DEAD_TICK), this->dtS);
     663      this->tick(this->objectManager.getObjectList(OM_DEAD_TICK), this->dtS);
    778664      this->tick(this->objectManager.getObjectList(OM_COMMON), this->dtS);
    779       this->tick(this->objectManager.getObjectList(OM_GROUP_00), this->dtS);*/
     665      this->tick(this->objectManager.getObjectList(OM_GROUP_00), this->dtS);
    780666      this->tick(this->objectManager.getObjectList(OM_GROUP_01), this->dtS);
    781667      this->tick(this->objectManager.getObjectList(OM_GROUP_01_PROJ), this->dtS);
     
    815701  GraphicsEngine::getInstance()->update(this->dtS);
    816702  PNode::getNullParent()->updateNode (this->dtS);
    817 
    818703  SoundEngine::getInstance()->update();
    819704  //music->update();
     
    864749  engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));
    865750
     751   if( unlikely( this->showBV))  // to draw the bounding boxes of the objects at level 2 for debug purp
     752   {
     753     CDEngine* engine = CDEngine::getInstance();
     754     engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));
     755     engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON));
     756     engine->drawBV(State::getObjectManager()->getObjectList(OM_COMMON));
     757     engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_00));
     758     engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01));
     759     engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));
     760   }
     761
    866762//   {
    867763//     if( entity->isVisible() ) entity->draw();
    868764  //FIXME
    869 //     if( unlikely( this->showBV)) entity->drawBVTree(3, 226);  // to draw the bounding boxes of the objects at level 2 for debug purp
    870765//     entity = iterator->nextElement();
    871766//   }
    872767
    873   glCallList (objectList);
    874 
    875768  ParticleEngine::getInstance()->draw();
    876769
     
    880773  engine->draw();
    881774  //TextEngine::getInstance()->draw();
    882 }
    883 
    884 /**
    885  *  add and spawn a new entity to this world
    886  * @param entity to be added
    887 */
    888 void NetworkWorld::spawn(WorldEntity* entity)
    889 {
    890 //   this->entities->add (entity);
    891   entity->postSpawn ();
    892 
    893 }
    894 
    895 
    896 /**
    897  *  add and spawn a new entity to this world
    898  * @param entity to be added
    899  * @param absCoor At what coordinates to add this entity.
    900  * @param absDir In which direction should it look.
    901 */
    902 void NetworkWorld::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
    903 {
    904 //   this->entities->add (entity);
    905 
    906   entity->setAbsCoor (*absCoor);
    907   entity->setAbsDir (*absDir);
    908 
    909   entity->postSpawn ();
    910 }
    911 
    912 
    913 /**
    914  *  add and spawn a new entity to this world
    915  * @param entity to be added
    916  * @param entity to be added to (PNode)
    917  * @param At what relative  coordinates to add this entity.
    918  * @param In which relative direction should it look.
    919 */
    920 void NetworkWorld::spawn(WorldEntity* entity, PNode* parentNode,
    921                   Vector* relCoor, Quaternion* relDir)
    922 {
    923   if( parentNode != NULL)
    924     {
    925       parentNode->addChild (entity);
    926 
    927       entity->setRelCoor (*relCoor);
    928       entity->setRelDir (*relDir);
    929 
    930 //       this->entities->add (entity);
    931 
    932       entity->postSpawn ();
    933     }
    934775}
    935776
Note: See TracChangeset for help on using the changeset viewer.