Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4178 in orxonox.OLD for orxonox/branches/physics/src/game_loader.cc


Ignore:
Timestamp:
May 13, 2005, 11:16:33 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/physics: merged the Trunk into the physics Branche again:
merged with command:
svn merge ../trunk physics -r 3953:HEAD
no important conflicts

Location:
orxonox/branches/physics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/physics

    • Property svn:externals
      •  

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

    r3727 r4178  
    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
     
    158173   this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    159174*/
    160 Campaign* GameLoader::fileToCampaign(char *name)
     175Campaign* GameLoader::fileToCampaign(const char *name)
    161176{
    162177  /* do not entirely load the campaign. just the current world
     
    164179     can load everything it needs into memory then.
    165180  */
     181 
     182  if( name == NULL)
     183    {
     184      PRINTF(2)("No filename specified for loading");
     185      return NULL;
     186    }
     187 
     188  TiXmlDocument* XMLDoc = new TiXmlDocument( name);
     189  // load the campaign document
     190  if( !XMLDoc->LoadFile())
     191    {
     192      // report an error
     193      PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", name, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
     194      delete XMLDoc;
     195      return NULL;
     196    }
     197       
     198  // check basic validity
     199  TiXmlElement* root = XMLDoc->RootElement();
     200  assert( root != NULL);
     201       
     202  if( strcmp( root->Value(), "Campaign"))
     203    {
     204      // report an error
     205      PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
     206      delete XMLDoc;
     207      return NULL;
     208    }
     209       
     210  // construct campaign
     211  Campaign* c = new Campaign( root);
     212       
     213  // free the XML data
     214  delete XMLDoc;
     215       
     216  return c;
    166217}
    167218
     
    174225bool GameLoader::worldCommand (Command* cmd)
    175226{
    176   if( !strcmp( cmd->cmd, "up_world"))
     227  if( !strcmp( cmd->cmd, CONFIG_NAME_NEXT_WORLD))
    177228    {
    178229      if( !cmd->bUp)
     
    182233      return true;
    183234    }
    184   else if( !strcmp( cmd->cmd, "down_world"))
     235  else if( !strcmp( cmd->cmd, CONFIG_NAME_PREV_WORLD))
    185236    {
    186237      if( !cmd->bUp)
     
    190241      return true;
    191242    }
    192   else if( !strcmp( cmd->cmd, "pause"))
     243  else if( !strcmp( cmd->cmd, CONFIG_NAME_PAUSE))
    193244    {
    194245      if( !cmd->bUp)
     
    201252      return true;
    202253    }
    203   else if( !strcmp( cmd->cmd, "quit"))
     254  else if( !strcmp( cmd->cmd, CONFIG_NAME_QUIT))
    204255    {
    205256      if( !cmd->bUp) this->stop();
     
    230281    this->currentCampaign->previousLevel();
    231282}
     283
     284/**
     285   \brief add a Factory to the Factory Q
     286   \param factory a Factory to be registered
     287*/
     288void GameLoader::registerFactory( Factory* factory)
     289{
     290        assert( factory != NULL);
     291       
     292        PRINTF(4)("Registered factory for '%s'\n", factory->getFactoryName());
     293       
     294        if( first == NULL) first = factory;
     295        else first->registerFactory( factory);
     296}
     297
     298/**
     299   \brief load a StoryEntity
     300   \param element a XMLElement containing all the needed info
     301*/
     302BaseObject* GameLoader::fabricate( TiXmlElement* element)
     303{
     304  assert( element != NULL);
     305       
     306  if( first == NULL)
     307    {
     308      PRINTF(1)("GameLoader does not know any factories, fabricate() failed\n");
     309      return NULL;
     310    }
     311       
     312  if( element->Value() != NULL)
     313    {
     314      PRINTF(4)("Attempting fabrication of a '%s'\n", element->Value());
     315      BaseObject* b = first->fabricate( element);
     316      if( b == NULL)
     317        PRINTF(2)("Failed to fabricate a '%s'\n", element->Value());
     318      else
     319        PRINTF(4)("Successfully fabricated a '%s'\n", element->Value());
     320      return b;
     321    }
     322       
     323  PRINTF(2)("Fabricate failed, TiXmlElement did not contain a value\n");
     324       
     325  return NULL;
     326}
Note: See TracChangeset for help on using the changeset viewer.