Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5979 in orxonox.OLD for branches/network/src/util/loading


Ignore:
Timestamp:
Dec 7, 2005, 5:58:01 PM (19 years ago)
Author:
patrick
Message:

network: now the game-loader is prepeared for network play

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

Legend:

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

    r5974 r5979  
    143143 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    144144 */
    145 ErrorMessage GameLoader::loadNetworkCampaign(const char* name)
    146 {}
     145ErrorMessage GameLoader::loadNetworkCampaign(const char* fileName)
     146{
     147  ErrorMessage errorCode;
     148  char* campaignName = ResourceManager::getFullName(fileName);
     149  if( campaignName)
     150  {
     151    this->currentCampaign = this->fileToNetworkCampaign(campaignName);
     152    delete[] campaignName;
     153  }
     154}
    147155
    148156
     
    303311
    304312/**
     313 *  reads a campaign definition file into a campaign class
     314 * @param fileName to be loaded
     315 * @returns the loaded campaign
     316 *
     317 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     318 */
     319Campaign* GameLoader::fileToNetworkCampaign(const char* fileName)
     320{
     321  /* do not entirely load the campaign. just the current world
     322  before start of each world, it has to be initialized so it
     323  can load everything it needs into memory then.
     324  */
     325
     326  if( fileName == NULL)
     327  {
     328    PRINTF(2)("No filename specified for loading");
     329    return NULL;
     330  }
     331
     332  TiXmlDocument* XMLDoc = new TiXmlDocument( fileName);
     333  // load the campaign document
     334  if( !XMLDoc->LoadFile())
     335  {
     336    // report an error
     337    PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
     338    delete XMLDoc;
     339    return NULL;
     340  }
     341
     342  // check basic validity
     343  TiXmlElement* root = XMLDoc->RootElement();
     344  assert( root != NULL);
     345
     346  if( strcmp( root->Value(), "Campaign"))
     347  {
     348    // report an error
     349    PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
     350    delete XMLDoc;
     351    return NULL;
     352  }
     353
     354  // construct campaign
     355  Campaign* c = new Campaign( root);
     356
     357  // free the XML data
     358  delete XMLDoc;
     359
     360  return c;
     361}
     362
     363
     364/**
    305365 *  handle keyboard commands
    306366 * @param event the event to handle
  • branches/network/src/util/loading/game_loader.h

    r5974 r5979  
    5858
    5959  ErrorMessage loadDebugCampaign(Uint32 campaignID);
    60   ErrorMessage loadCampaign(const char* name);
    61   ErrorMessage loadNetworkCampaign(const char* name);
     60  ErrorMessage loadCampaign(const char* fileName);
     61  ErrorMessage loadNetworkCampaign(const char* fileName);
    6262
    6363  void process(const Event &event);
     
    7070  GameLoader ();
    7171
    72   Campaign* fileToCampaign(const char* name);
     72  Campaign* fileToCampaign(const char* fileName);
     73  Campaign* fileToNetworkCampaign(const char* fileName);
    7374
    7475
Note: See TracChangeset for help on using the changeset viewer.