Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6139 in orxonox.OLD for trunk/src/util/loading


Ignore:
Timestamp:
Dec 16, 2005, 6:45:32 PM (19 years ago)
Author:
patrick
Message:

trunk: merged branche network with trunk using command: svn merge -r5999:HEAD, conflicts resolved in favor of the trunk bla

Location:
trunk/src/util/loading
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/util/loading/game_loader.cc

    r5982 r6139  
    4646/**
    4747 *  simple constructor
    48 */
     48 */
    4949GameLoader::GameLoader ()
    5050{
     
    5757/**
    5858 *  simple deconstructor
    59 */
     59 */
    6060GameLoader::~GameLoader ()
    6161{
     
    6969 *  this class is a singleton class
    7070 * @returns an instance of itself
    71 
    72    if you are unsure about singleton classes, check the theory out on the internet :)
    73 */
     71 *
     72 * if you are unsure about singleton classes, check the theory out on the internet :)
     73 */
    7474GameLoader* GameLoader::getInstance()
    7575{
     
    8181/**
    8282 *  initializes the GameLoader
    83 */
     83 */
    8484ErrorMessage GameLoader::init()
    8585{
     
    100100 * @param fileName to be loaded
    101101 * @returns the loaded campaign
    102 
    103    this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    104 */
     102 *
     103 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     104 */
    105105ErrorMessage GameLoader::loadCampaign(const char* fileName)
    106106{
     
    112112      delete[] campaignName;
    113113    }
    114 //   World* world0 = new World(DEBUG_WORLD_0);
    115 //   world0->setNextStoryID(WORLD_ID_GAMEEND);
    116 //   this->currentCampaign->addEntity(world0, WORLD_ID_2);
    117 }
     114}
     115
     116
     117/**
     118 *  reads a campaign definition file into a campaign class
     119 * @param fileName to be loaded
     120 * @returns the loaded campaign
     121 *
     122 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     123 */
     124ErrorMessage GameLoader::loadNetworkCampaign(const char* fileName)
     125{
     126  ErrorMessage errorCode;
     127  char* campaignName = ResourceManager::getFullName(fileName);
     128  if (campaignName)
     129  {
     130    this->currentCampaign = this->fileToNetworkCampaign(campaignName);
     131    delete[] campaignName;
     132  }
     133}
     134
    118135
    119136/**
     
    121138 * @param campaignID the identifier of the campaign.
    122139 * @returns error message if not able to do so.
    123 */
     140 */
    124141ErrorMessage GameLoader::loadDebugCampaign(Uint32 campaignID)
    125142{
     
    156173
    157174/**
    158   *  starts the current entity
    159   * @returns error code if this action has caused a error
    160 */
     175 *  starts the current entity
     176 * @returns error code if this action has caused a error
     177 */
    161178ErrorMessage GameLoader::start()
    162179{
     
    167184
    168185/**
    169   *  stops the current entity
    170   * @returns error code if this action has caused a error
    171 
    172     ATTENTION: this function shouldn't call other functions, or if so, they must return
    173     after finishing. If you ignore or forget to do so, the current entity is not able to
    174     terminate and it will run in the background or the ressources can't be freed or even
    175     worse: are freed and the program will end in a segmentation fault!
    176     hehehe, have ya seen it... :)
    177 */
     186 *  stops the current entity
     187 * @returns error code if this action has caused a error
     188 *
     189 *  ATTENTION: this function shouldn't call other functions, or if so, they must return
     190 *  after finishing. If you ignore or forget to do so, the current entity is not able to
     191 *  terminate and it will run in the background or the ressources can't be freed or even
     192 *  worse: are freed and the program will end in a segmentation fault!
     193 *  hehehe, have ya seen it... :)
     194 */
    178195void GameLoader::stop()
    179196{
     
    184201
    185202/**
    186   *  pause the current entity
    187   * @returns error code if this action has caused a error
    188 
    189    this pauses the current entity or passes this call forth to the running entity.
    190 */
     203 *  pause the current entity
     204 * @returns error code if this action has caused a error
     205 *
     206 * this pauses the current entity or passes this call forth to the running entity.
     207 */
    191208ErrorMessage GameLoader::pause()
    192209{
     
    198215
    199216/**
    200   *  resumes a pause
    201   * @returns error code if this action has caused a error
    202 
    203     this resumess the current entity or passes this call forth to the running entity.
    204 */
     217 *  resumes a pause
     218 * @returns error code if this action has caused a error
     219 *
     220 *  this resumess the current entity or passes this call forth to the running entity.
     221 */
    205222ErrorMessage GameLoader::resume()
    206223{
     
    224241 * @param fileName to be loaded
    225242 * @returns the loaded campaign
    226 
    227    this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    228 */
     243 *
     244 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     245 */
    229246Campaign* GameLoader::fileToCampaign(const char* fileName)
    230247{
     
    273290
    274291/**
     292 *  reads a campaign definition file into a campaign class
     293 * @param fileName to be loaded
     294 * @returns the loaded campaign
     295 *
     296 *  this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     297 */
     298Campaign* GameLoader::fileToNetworkCampaign(const char* fileName)
     299{
     300  /* do not entirely load the campaign. just the current world
     301  before start of each world, it has to be initialized so it
     302  can load everything it needs into memory then.
     303  */
     304
     305  if( fileName == NULL)
     306  {
     307    PRINTF(2)("No filename specified for loading");
     308    return NULL;
     309  }
     310
     311  TiXmlDocument* XMLDoc = new TiXmlDocument( fileName);
     312  // load the campaign document
     313  if( !XMLDoc->LoadFile())
     314  {
     315      // report an error
     316    PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
     317    delete XMLDoc;
     318    return NULL;
     319  }
     320
     321  // check basic validity
     322  TiXmlElement* root = XMLDoc->RootElement();
     323  assert( root != NULL);
     324
     325  if( strcmp( root->Value(), "Campaign"))
     326  {
     327      // report an error
     328    PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
     329    delete XMLDoc;
     330    return NULL;
     331  }
     332
     333  // construct campaign
     334  Campaign* c = new Campaign( root);
     335
     336  // free the XML data
     337  delete XMLDoc;
     338
     339  return c;
     340}
     341
     342
     343/**
    275344 *  handle keyboard commands
    276345 * @param event the event to handle
     
    312381
    313382/**
    314   \brief this changes to the next level
    315 */
     383 * \brief this changes to the next level
     384 */
    316385void GameLoader::nextLevel()
    317386{
     
    322391
    323392/**
    324   \brief change to the previous level - not implemented
    325 
    326   this propably useless
    327 */
     393 * change to the previous level - not implemented
     394 *
     395 * this propably useless
     396 */
    328397void GameLoader::previousLevel()
    329398{
  • trunk/src/util/loading/game_loader.h

    r5982 r6139  
    4040{
    4141
     42
    4243 public:
    4344  ~GameLoader ();
     
    4647
    4748  ErrorMessage init();
    48   ErrorMessage loadCampaign(const char* name);
    4949  ErrorMessage start();
    5050  void stop();
     
    5353  ErrorMessage destroy();
    5454
     55  ErrorMessage loadCampaign(const char* name);
     56  ErrorMessage loadDebugCampaign(Uint32 campaignID);
     57  ErrorMessage loadNetworkCampaign(const char* fileName);
     58
    5559  void nextLevel();
    5660  void previousLevel();
    5761
    58   /** \brief a world command to send to the GameLoader @param cmd the command */
    59   bool worldCommand(Command* cmd);
    60   ErrorMessage loadDebugCampaign(Uint32 campaignID);
     62  void process(const Event &event);
    6163
    62   void process(const Event &event);
    6364
    6465 private:
     
    6667
    6768  Campaign* fileToCampaign(const char* name);
     69  Campaign* fileToNetworkCampaign(const char* fileName);
     70
    6871
    6972 private:
Note: See TracChangeset for help on using the changeset viewer.