Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5974 in orxonox.OLD


Ignore:
Timestamp:
Dec 7, 2005, 5:13:00 PM (18 years ago)
Author:
patrick
Message:

network: cleaned up the game_loader

Location:
branches/network/src/util/loading
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/util/loading/game_loader.cc

    r5972 r5974  
    3737
    3838SHELL_COMMAND(quit, GameLoader, stop)
    39     ->describe("quits the game")
    40     ->setAlias("orxoquit");
     39->describe("quits the game")
     40->setAlias("orxoquit");
    4141
    4242
     
    6767
    6868
     69/**
     70 *  load a StoryEntity
     71 * @param element a XMLElement containing all the needed info
     72 */
     73BaseObject* GameLoader::fabricate(const TiXmlElement* element)
     74{
     75  assert( element != NULL);
     76
     77  if( Factory::getFirst() == NULL)
     78  {
     79    PRINTF(1)("GameLoader does not know any factories, fabricate() failed\n");
     80    return NULL;
     81  }
     82
     83  if( element->Value() != NULL)
     84  {
     85    PRINTF(4)("Attempting fabrication of a '%s'\n", element->Value());
     86    BaseObject* b = Factory::getFirst()->fabricate( element);
     87    if( b == NULL)
     88      PRINTF(2)("Failed to fabricate a '%s'\n", element->Value());
     89    else
     90      PRINTF(4)("Successfully fabricated a '%s'\n", element->Value());
     91    return b;
     92  }
     93
     94  PRINTF(2)("Fabricate failed, TiElement did not contain a value\n");
     95
     96  return NULL;
     97}
     98
     99
    69100
    70101/**
     
    73104ErrorMessage GameLoader::init()
    74105{
    75   if(this->currentCampaign != NULL)
     106  if( this->currentCampaign != NULL)
    76107    this->currentCampaign->init();
    77108
    78   this->eventHandler = EventHandler::getInstance();
    79   this->eventHandler->subscribe(this, ES_GAME, KeyMapper::PEV_PAUSE);
    80   this->eventHandler->subscribe(this, ES_ALL, EV_MAIN_QUIT);          //< External Quit Event
    81   this->eventHandler->subscribe(this, ES_ALL, KeyMapper::PEV_QUIT);
    82   this->eventHandler->subscribe(this, ES_GAME, KeyMapper::PEV_NEXT_WORLD);
    83   this->eventHandler->subscribe(this, ES_GAME, KeyMapper::PEV_PREVIOUS_WORLD);
     109  EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_PAUSE);
     110  EventHandler::getInstance()->subscribe(this, ES_ALL, EV_MAIN_QUIT);          //< External Quit Event
     111  EventHandler::getInstance()->subscribe(this, ES_ALL, KeyMapper::PEV_QUIT);
     112  EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_NEXT_WORLD);
     113  EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_PREVIOUS_WORLD);
    84114}
    85115
     
    97127  ErrorMessage errorCode;
    98128  char* campaignName = ResourceManager::getFullName(fileName);
    99   if (campaignName)
    100     {
    101       this->currentCampaign = this->fileToCampaign(campaignName);
    102       delete[] campaignName;
    103     }
    104 //   World* world0 = new World(DEBUG_WORLD_0);
    105 //   world0->setNextStoryID(WORLD_ID_GAMEEND);
    106 //   this->currentCampaign->addEntity(world0, WORLD_ID_2);
     129  if( campaignName)
     130  {
     131    this->currentCampaign = this->fileToCampaign(campaignName);
     132    delete[] campaignName;
     133  }
    107134}
    108135
     
    116143 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    117144 */
    118 ErrorMessage loadNetworkCampaign(const char* name)
     145ErrorMessage GameLoader::loadNetworkCampaign(const char* name)
    119146{}
    120147
     
    128155ErrorMessage GameLoader::loadDebugCampaign(Uint32 campaignID)
    129156{
    130   switch(campaignID)
    131     {
     157  switch( campaignID)
     158  {
    132159      /*
    133160         Debug Level 0: Debug level used to test the base frame work.
     
    155182        break;
    156183      }
    157     }
     184  }
    158185}
    159186
     
    165192ErrorMessage GameLoader::start()
    166193{
    167   if(this->currentCampaign != NULL)
     194  if( this->currentCampaign != NULL)
    168195    this->currentCampaign->start();
    169196}
     
    182209void GameLoader::stop()
    183210{
    184   if(this->currentCampaign != NULL)
     211  if( this->currentCampaign != NULL)
    185212    this->currentCampaign->stop();
    186213}
     
    196223{
    197224  this->isPaused = true;
    198   if(this->currentCampaign != NULL)
     225  if( this->currentCampaign != NULL)
    199226    this->currentCampaign->pause();
    200227}
     
    210237{
    211238  this->isPaused = false;
    212   if(this->currentCampaign != NULL)
     239  if( this->currentCampaign != NULL)
    213240    this->currentCampaign->resume();
    214241}
     
    220247ErrorMessage GameLoader::destroy()
    221248{
    222 
    223249}
    224250
     
    239265
    240266  if( fileName == NULL)
    241     {
    242       PRINTF(2)("No filename specified for loading");
    243       return NULL;
    244     }
     267  {
     268    PRINTF(2)("No filename specified for loading");
     269    return NULL;
     270  }
    245271
    246272  TiXmlDocument* XMLDoc = new TiXmlDocument( fileName);
    247273  // load the campaign document
    248274  if( !XMLDoc->LoadFile())
    249     {
    250       // report an error
    251       PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
    252       delete XMLDoc;
    253       return NULL;
    254     }
     275  {
     276    // report an error
     277    PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
     278    delete XMLDoc;
     279    return NULL;
     280  }
    255281
    256282  // check basic validity
     
    259285
    260286  if( strcmp( root->Value(), "Campaign"))
    261     {
    262       // report an error
    263       PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
    264       delete XMLDoc;
    265       return NULL;
    266     }
     287  {
     288    // report an error
     289    PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
     290    delete XMLDoc;
     291    return NULL;
     292  }
    267293
    268294  // construct campaign
     
    332358void GameLoader::previousLevel()
    333359{
    334   if(this->currentCampaign != NULL)
     360  if( this->currentCampaign != NULL)
    335361    this->currentCampaign->previousLevel();
    336362}
    337363
    338 /**
    339  *  load a StoryEntity
    340  * @param element a XMLElement containing all the needed info
    341  */
    342 BaseObject* GameLoader::fabricate(const TiXmlElement* element)
    343 {
    344   assert( element != NULL);
    345 
    346   if( Factory::getFirst() == NULL)
    347     {
    348       PRINTF(1)("GameLoader does not know any factories, fabricate() failed\n");
    349       return NULL;
    350     }
    351 
    352   if( element->Value() != NULL)
    353     {
    354       PRINTF(4)("Attempting fabrication of a '%s'\n", element->Value());
    355       BaseObject* b = Factory::getFirst()->fabricate( element);
    356       if( b == NULL)
    357         PRINTF(2)("Failed to fabricate a '%s'\n", element->Value());
    358       else
    359         PRINTF(4)("Successfully fabricated a '%s'\n", element->Value());
    360       return b;
    361     }
    362 
    363   PRINTF(2)("Fabricate failed, TiElement did not contain a value\n");
    364 
    365   return NULL;
    366 }
     364
  • branches/network/src/util/loading/game_loader.h

    r5972 r5974  
    4040{
    4141
    42  
     42
    4343 public:
    4444  ~GameLoader ();
     
    4646  /**  this class is a singleton class @returns an instance of itself  */
    4747  static GameLoader* getInstance() { if(singletonRef == NULL) singletonRef = new GameLoader();  return singletonRef; }
     48
     49  void registerFactory( Factory* factory );
     50  BaseObject* fabricate(const TiXmlElement* data);
    4851
    4952  ErrorMessage init();
     
    5457  ErrorMessage destroy();
    5558
     59  ErrorMessage loadDebugCampaign(Uint32 campaignID);
     60  ErrorMessage loadCampaign(const char* name);
     61  ErrorMessage loadNetworkCampaign(const char* name);
     62
     63  void process(const Event &event);
     64
    5665  void nextLevel();
    5766  void previousLevel();
    5867
    59   ErrorMessage loadDebugCampaign(Uint32 campaignID);
    60   ErrorMessage loadCampaign(const char* name);
    61   ErrorMessage loadNetworkCampaign(const char* name);
    62  
    6368
    64   void registerFactory( Factory* factory );
    65   BaseObject* fabricate(const TiXmlElement* data);
    66 
    67   void process(const Event &event);
    68 
    69  
    7069 private:
    7170  GameLoader ();
     
    7372  Campaign* fileToCampaign(const char* name);
    7473
    75  
     74
    7675 private:
    7776  static GameLoader*     singletonRef;         //!< The singleton-reference to this object
    78 
    79   Uint32                 startTime;            //!< start time of the campaign
    80   bool                   isPaused;             //!< if the game is paused
    81 
    8277  Campaign*              currentCampaign;      //!< reference to the current campaign playing
    8378
    84   EventHandler*          eventHandler;         //!< reference to the eventHandler
     79  bool                   isPaused;             //!< if the game is paused
    8580};
    8681
Note: See TracChangeset for help on using the changeset viewer.