Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 2, 2006, 11:00:14 PM (18 years ago)
Author:
patrick
Message:

network: much more work on the StoryEntity functions and reimplementations of the DataTanks of each StoryEntity

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/story_entities/game_world.cc

    r6386 r6387  
    9191  this->music = NULL;
    9292  this->shell = NULL;
    93   this->localPlayer = NULL;
    94   this->localCamera = NULL;
    9593
    9694  this->showPNodes = false;
     
    9896
    9997  this->path = NULL;
     98
     99  this->gameWorldData = new GameWorldData();
    100100}
    101101
     
    108108GameWorld::~GameWorld ()
    109109{
    110   delete this->shell;
    111   PRINTF(3)("GameWorld::~GameWorld() - deleting current world\n");
    112 
    113   delete this->localPlayer;
    114 
    115   // delete all the initialized Engines.
    116   FastFactory::flushAll(true);
    117   delete LightManager::getInstance();
    118   delete ParticleEngine::getInstance();
    119   delete AnimationPlayer::getInstance();
    120   delete PhysicsEngine::getInstance();
    121 
    122   // external engines initialized by the orxonox-class get deleted
    123   SoundEngine::getInstance()->flushAllBuffers();
    124   SoundEngine::getInstance()->flushAllSources();
    125 
    126   if (State::getObjectManager() == &this->objectManager)
    127     State::setObjectManager(NULL);
    128   // erease everything that is left.
    129   delete PNode::getNullParent();
    130 
    131   //secondary cleanup of PNodes;
    132   const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);
    133   if (nodeList != NULL)
    134     while (!nodeList->empty())
    135       delete nodeList->front();
    136 
    137   Shader::suspendShader();
    138 
    139   // unload the resources !!
    140   ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
     110  if( this->gameWorldData)
     111    delete this->gameWorldData;
    141112}
    142113
     
    179150  PhysicsEngine::getInstance();
    180151
    181   this->localCamera = new Camera();
    182   this->localCamera->setName ("GameWorld-Camera");
    183 
    184   State::setCamera(this->localCamera, this->localCamera->getTarget());
     152  this->gameWorldData->localCamera = new Camera();
     153  this->gameWorldData->localCamera->setName ("GameWorld-Camera");
     154
     155  State::setCamera(this->gameWorldData->localCamera, this->gameWorldData->localCamera->getTarget());
    185156
    186157  GraphicsEngine::getInstance()->displayFPS(true);
     
    240211    }
    241212
    242   ////////////////
    243   // LOADSCREEN //
    244   ////////////////
    245   element = root->FirstChildElement("LoadScreen");
    246   if (element == NULL)
    247     {
    248       PRINTF(2)("no LoadScreen specified, loading default\n");
    249 
    250       glmis->setBackgroundImage("pictures/load_screen.jpg");
    251       this->glmis->setMaximum(8);
    252       this->glmis->draw();
    253     }
    254   else
    255     {
    256       this->glmis->loadParams(element);
    257       this->glmis->draw();
    258     }
    259   this->glmis->draw();
    260 
    261   ////////////////////////
    262   // find WorldEntities //
    263   ////////////////////////
    264 
    265   element = root->FirstChildElement("WorldEntities");
    266 
    267   if( element == NULL)
    268     {
    269       PRINTF(1)("GameWorld is missing 'WorldEntities'\n");
    270     }
    271   else
    272     {
    273       element = element->FirstChildElement();
    274       // load Players/Objects/Whatever
    275       PRINTF(4)("Loading WorldEntities\n");
    276       while( element != NULL)
    277         {
    278           BaseObject* created = Factory::fabricate(element);
    279           if( created != NULL )
    280             printf("Created a %s: %s\n", created->getClassName(), created->getName());
    281 
    282 
    283           //todo do this more elegant
    284           if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
    285             this->sky = dynamic_cast<WorldEntity*>(created);
    286           if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
    287           {
    288             terrain = dynamic_cast<Terrain*>(created);
    289             CDEngine::getInstance()->setTerrain(terrain);
    290           }
    291           element = element->NextSiblingElement();
    292           glmis->step(); //! @todo temporary
    293         }
    294       PRINTF(4)("Done loading WorldEntities\n");
    295     }
     213
     214
     215    this->gameWorldData->loadGUI(root);
     216
     217
     218    this->gameWorldData->loadWorldEntities(root);
    296219
    297220    //////////////////////////////
     
    310233
    311234
    312   // Create a Player
    313   this->localPlayer = new Player();
    314 
    315   Playable* playable;
    316   const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
    317   if (playableList != NULL)
    318   {
    319     playable = dynamic_cast<Playable*>(playableList->front());
    320     this->localPlayer->setControllable(playable);
    321   }
     235
    322236
    323237
    324238//   //localCamera->setParent(TrackNode::getInstance());
    325239//  tn->addChild(this->localCamera);
    326   localCamera->setClipRegion(1, 10000.0);
     240  this->gameWorldData->localCamera->setClipRegion(1, 10000.0);
    327241//  localCamera->lookAt(playable);
    328242//  this->localPlayer->setParentMode(PNODE_ALL);
    329   if (this->sky != NULL)
    330   {
    331     this->localCamera->addChild(sky);
    332   }
    333   SoundEngine::getInstance()->setListener(this->localCamera);
     243  if (this->gameWorldData->sky != NULL)
     244  {
     245    this->gameWorldData->localCamera->addChild(this->gameWorldData->sky);
     246  }
     247  SoundEngine::getInstance()->setListener(this->gameWorldData->localCamera);
    334248
    335249  /* some static stuff*/
     
    348262
    349263/**
     264 *  unload the data of this GameWorld
     265 */
     266ErrorMessage GameWorld::unloadData()
     267{
     268  delete this->shell;
     269  PRINTF(3)("GameWorld::~GameWorld() - unloading the current GameWorld\n");
     270
     271  // delete all the initialized Engines.
     272  FastFactory::flushAll(true);
     273  delete LightManager::getInstance();
     274  delete ParticleEngine::getInstance();
     275  delete AnimationPlayer::getInstance();
     276  delete PhysicsEngine::getInstance();
     277
     278  // external engines initialized by the orxonox-class get deleted
     279  SoundEngine::getInstance()->flushAllBuffers();
     280  SoundEngine::getInstance()->flushAllSources();
     281
     282  if (State::getObjectManager() == &this->objectManager)
     283    State::setObjectManager(NULL);
     284  // erease everything that is left.
     285  delete PNode::getNullParent();
     286
     287  //secondary cleanup of PNodes;
     288  const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);
     289  if (nodeList != NULL)
     290    while (!nodeList->empty())
     291      delete nodeList->front();
     292
     293  Shader::suspendShader();
     294
     295  // unload the resources !!
     296  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
     297}
     298
     299
     300/**
    350301 *  starts the GameWorld
    351302 */
    352 ErrorMessage GameWorld::start()
     303bool GameWorld::start()
    353304{
    354305  this->isPaused = false;
    355306  this->isRunning = true;
    356   this->mainLoop();
     307
     308  this->run();
    357309}
    358310
     
    362314   This happens, when the player decides to end the Level.
    363315*/
    364 ErrorMessage GameWorld::stop()
     316bool GameWorld::stop()
    365317{
    366318  PRINTF(3)("GameWorld::stop() - got stop signal\n");
     
    371323 *  pauses the Game
    372324*/
    373 ErrorMessage GameWorld::pause()
     325bool GameWorld::pause()
    374326{
    375327  this->isPaused = true;
     
    379331 *  ends the pause Phase
    380332*/
    381 ErrorMessage GameWorld::resume()
     333bool GameWorld::resume()
    382334{
    383335  this->isPaused = false;
     
    391343{
    392344  PRINTF(3)("GameWorld::displayLoadScreen - start\n");
    393   this->glmis = new GLMenuImageScreen();
    394   this->glmis->setMaximum(8);
     345  this->gameWorldData->glmis = new GLMenuImageScreen();
     346  this->gameWorldData->glmis->setMaximum(8);
    395347  PRINTF(3)("GameWorld::displayLoadScreen - end\n");
    396348}
     
    405357{
    406358  PRINTF(3)("GameWorld::releaseLoadScreen - start\n");
    407   this->glmis->setValue(this->glmis->getMaximum());
     359  this->gameWorldData->glmis->setValue(this->gameWorldData->glmis->getMaximum());
    408360  PRINTF(3)("GameWorld::releaseLoadScreen - end\n");
    409   delete this->glmis;
     361  delete this->gameWorldData->glmis;
    410362}
    411363
     
    485437
    486438      /* update tick the rest */
    487       this->localCamera->tick(this->dtS);
     439      this->gameWorldData->localCamera->tick(this->dtS);
    488440      // tick the engines
    489441      AnimationPlayer::getInstance()->tick(this->dtS);
     
    541493  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    542494  // set camera
    543   this->localCamera->apply ();
     495  this->gameWorldData->localCamera->apply ();
    544496  // draw world
    545497  this->draw();
     
    600552 * collisions drawing everything to the screen.
    601553 */
    602 void GameWorld::mainLoop()
     554void GameWorld::run()
    603555{
    604556  this->lastFrame = SDL_GetTicks ();
     
    659611}
    660612
     613
     614
     615
     616
     617
     618
     619GameWorldData::GameWorldData()
     620{
     621  this->localPlayer = NULL;
     622  this->localCamera = NULL;
     623
     624  this->glmis = NULL;
     625
     626  this->localCamera = NULL;
     627  this->localPlayer = NULL;
     628  this->sky = NULL;
     629  this->terrain = NULL;
     630
     631}
     632
     633
     634GameWorldData::~GameWorldData()
     635{
     636  if( this->localPlayer)
     637    delete this->localPlayer;
     638}
     639
     640
     641
     642ErrorMessage GameWorldData::loadData(TiXmlElement* root)
     643{}
     644
     645
     646
     647
     648ErrorMessage GameWorldData::loadGUI(TiXmlElement* root)
     649{
     650  ////////////////
     651  // LOADSCREEN //
     652  ////////////////
     653  TiXmlElement* element = root->FirstChildElement("LoadScreen");
     654  if( element == NULL)
     655  {
     656    PRINTF(2)("no LoadScreen specified, loading default\n");
     657
     658    glmis->setBackgroundImage("pictures/load_screen.jpg");
     659    this->glmis->setMaximum(8);
     660    this->glmis->draw();
     661  }
     662  else
     663  {
     664    this->glmis->loadParams(element);
     665    this->glmis->draw();
     666  }
     667  this->glmis->draw();
     668
     669}
     670
     671
     672ErrorMessage GameWorldData::loadWorldEntities(TiXmlElement* root)
     673{
     674  ////////////////////////
     675  // find WorldEntities //
     676  ////////////////////////
     677
     678  TiXmlElement* element = root->FirstChildElement("WorldEntities");
     679
     680  if( element == NULL)
     681  {
     682    PRINTF(1)("GameWorld is missing 'WorldEntities'\n");
     683  }
     684  else
     685  {
     686    element = element->FirstChildElement();
     687      // load Players/Objects/Whatever
     688    PRINTF(4)("Loading WorldEntities\n");
     689    while( element != NULL)
     690    {
     691      BaseObject* created = Factory::fabricate(element);
     692      if( created != NULL )
     693        printf("Created a %s: %s\n", created->getClassName(), created->getName());
     694
     695
     696          //todo do this more elegant
     697      if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
     698        this->sky = dynamic_cast<WorldEntity*>(created);
     699      if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
     700      {
     701        this->terrain = dynamic_cast<Terrain*>(created);
     702        CDEngine::getInstance()->setTerrain(terrain);
     703      }
     704      element = element->NextSiblingElement();
     705      this->glmis->step(); //! @todo temporary
     706    }
     707    PRINTF(4)("Done loading WorldEntities\n");
     708  }
     709
     710    // Create a Player
     711  this->localPlayer = new Player();
     712
     713  Playable* playable;
     714  const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
     715  if (playableList != NULL)
     716  {
     717    playable = dynamic_cast<Playable*>(playableList->front());
     718    this->localPlayer->setControllable(playable);
     719  }
     720}
     721
     722
     723ErrorMessage GameWorldData::loadScene(TiXmlElement* root)
     724{}
     725
Note: See TracChangeset for help on using the changeset viewer.