Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 9, 2005, 11:29:19 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/heightMap: merged the Trunk back into branches/heightMap:
merged with Command
svn merge -r 3918:HEAD trunk branches/heightMap
conflicts resolved in favor of the Trunk

Location:
orxonox/branches/heightMap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/heightMap

    • Property svn:externals
      •  

        old new  
        1 data http://svn.orxonox.ethz.ch/data
         1
  • orxonox/branches/heightMap/src/game_loader.cc

    r4021 r4122  
    2525#include "command_node.h"
    2626#include "vector.h"
     27#include "resource_manager.h"
     28#include "factory.h"
    2729
    2830#include <string.h>
     
    3537
    3638
    37 GameLoader::GameLoader () {}
     39GameLoader::GameLoader ()
     40{
     41  first = NULL;
     42}
    3843
    3944
     
    7277{
    7378  ErrorMessage errorCode;
    74  
    75   this->currentCampaign = this->fileToCampaign(name);
     79  char* campaignName;
     80  if (ResourceManager::isFile(name))
     81    {
     82      this->currentCampaign = this->fileToCampaign(name);
     83    }
     84  else
     85    {
     86      campaignName = new char[strlen(ResourceManager::getInstance()->getDataDir())+strlen(name)];
     87      sprintf(campaignName, "%s%s", ResourceManager::getInstance()->getDataDir(), name);
     88      this->currentCampaign = this->fileToCampaign(campaignName);
     89      delete campaignName;
     90    }
    7691}
    7792
     
    163178   this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    164179*/
    165 Campaign* GameLoader::fileToCampaign(char *name)
     180Campaign* GameLoader::fileToCampaign(const char *name)
    166181{
    167182  /* do not entirely load the campaign. just the current world
     
    169184     can load everything it needs into memory then.
    170185  */
     186 
     187  if( name == NULL)
     188    {
     189      PRINTF(2)("No filename specified for loading");
     190      return NULL;
     191    }
     192 
     193  TiXmlDocument* XMLDoc = new TiXmlDocument( name);
     194  // load the campaign document
     195  if( !XMLDoc->LoadFile())
     196    {
     197      // report an error
     198      PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", name, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
     199      delete XMLDoc;
     200      return NULL;
     201    }
     202       
     203  // check basic validity
     204  TiXmlElement* root = XMLDoc->RootElement();
     205  assert( root != NULL);
     206       
     207  if( strcmp( root->Value(), "Campaign"))
     208    {
     209      // report an error
     210      PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
     211      delete XMLDoc;
     212      return NULL;
     213    }
     214       
     215  // construct campaign
     216  Campaign* c = new Campaign( root);
     217       
     218  // free the XML data
     219  delete XMLDoc;
     220       
     221  return c;
    171222}
    172223
     
    179230bool GameLoader::worldCommand (Command* cmd)
    180231{
    181   if( !strcmp( cmd->cmd, "up_world"))
     232  if( !strcmp( cmd->cmd, CONFIG_NAME_NEXT_WORLD))
    182233    {
    183234      if( !cmd->bUp)
     
    187238      return true;
    188239    }
    189   else if( !strcmp( cmd->cmd, "down_world"))
     240  else if( !strcmp( cmd->cmd, CONFIG_NAME_PREV_WORLD))
    190241    {
    191242      if( !cmd->bUp)
     
    195246      return true;
    196247    }
    197   else if( !strcmp( cmd->cmd, "pause"))
     248  else if( !strcmp( cmd->cmd, CONFIG_NAME_PAUSE))
    198249    {
    199250      if( !cmd->bUp)
     
    206257      return true;
    207258    }
    208   else if( !strcmp( cmd->cmd, "quit"))
     259  else if( !strcmp( cmd->cmd, CONFIG_NAME_QUIT))
    209260    {
    210261      if( !cmd->bUp) this->stop();
     
    235286    this->currentCampaign->previousLevel();
    236287}
     288
     289/**
     290   \brief add a Factory to the Factory Q
     291   \param factory a Factory to be registered
     292*/
     293void GameLoader::registerFactory( Factory* factory)
     294{
     295        assert( factory != NULL);
     296       
     297        PRINTF(4)("Registered factory for '%s'\n", factory->getFactoryName());
     298       
     299        if( first == NULL) first = factory;
     300        else first->registerFactory( factory);
     301}
     302
     303/**
     304   \brief load a StoryEntity
     305   \param element a XMLElement containing all the needed info
     306*/
     307BaseObject* GameLoader::fabricate( TiXmlElement* element)
     308{
     309  assert( element != NULL);
     310       
     311  if( first == NULL)
     312    {
     313      PRINTF(1)("GameLoader does not know any factories, fabricate() failed\n");
     314      return NULL;
     315    }
     316       
     317  if( element->Value() != NULL)
     318    {
     319      PRINTF(4)("Attempting fabrication of a '%s'\n", element->Value());
     320      BaseObject* b = first->fabricate( element);
     321      if( b == NULL)
     322        PRINTF(2)("Failed to fabricate a '%s'\n", element->Value());
     323      else
     324        PRINTF(4)("Successfully fabricated a '%s'\n", element->Value());
     325      return b;
     326    }
     327       
     328  PRINTF(2)("Fabricate failed, TiXmlElement did not contain a value\n");
     329       
     330  return NULL;
     331}
Note: See TracChangeset for help on using the changeset viewer.