Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4010 in orxonox.OLD for orxonox/trunk/src/game_loader.cc


Ignore:
Timestamp:
May 2, 2005, 3:14:57 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the levelloader from lltrunktemp to the trunk. Big thanks to fuzzy to make this so easy for us, and for implementing it in the first place.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/game_loader.cc

    r3727 r4010  
    2525#include "command_node.h"
    2626#include "vector.h"
     27#include "factory.h"
    2728
    2829#include <string.h>
     
    164165     can load everything it needs into memory then.
    165166  */
     167 
     168  if( name == NULL)
     169    {
     170      PRINTF0("No filename specified for loading");
     171      return NULL;
     172    }
     173 
     174  TiXmlDocument* XMLDoc = new TiXmlDocument( name);
     175  // load the campaign document
     176  if( !XMLDoc->LoadFile())
     177    {
     178      // report an error
     179      PRINTF0("Error loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
     180      delete XMLDoc;
     181      return NULL;
     182    }
     183       
     184  // check basic validity
     185  TiXmlElement* root = XMLDoc->RootElement();
     186  assert( root != NULL);
     187       
     188  if( strcmp( root->Value(), "Campaign"))
     189    {
     190      // report an error
     191      PRINTF(0)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
     192      delete XMLDoc;
     193      return NULL;
     194    }
     195       
     196  // construct campaign
     197  Campaign* c = new Campaign( root);
     198       
     199  // free the XML data
     200  delete XMLDoc;
     201       
     202  return c;
    166203}
    167204
     
    230267    this->currentCampaign->previousLevel();
    231268}
     269
     270/**
     271   \brief add a Factory to the Factory Q
     272   \param factory a Factory to be registered
     273*/
     274void GameLoader::registerFactory( Factory* factory)
     275{
     276        assert( factory != NULL);
     277       
     278        PRINTF0("Registered factory for '%s'\n", factory->getClassname());
     279       
     280        if( first == NULL) first = factory;
     281        else first->registerFactory( factory);
     282}
     283
     284/**
     285   \brief load a StoryEntity
     286   \param element a XMLElement containing all the needed info
     287*/
     288BaseObject* GameLoader::fabricate( TiXmlElement* element)
     289{
     290        assert( element != NULL);
     291       
     292        if( first == NULL)
     293        {
     294                PRINTF0("GameLoader does not know any factories, fabricate() failed\n");
     295                return NULL;
     296        }
     297       
     298        if( element->Value() != NULL)
     299        {
     300                PRINTF0("Attempting fabrication of a '%s'\n", element->Value());
     301                BaseObject* b = first->fabricate( element);
     302                if( b == NULL) PRINTF0("Failed to fabricate a '%s'\n", element->Value());
     303                else PRINTF0("Successfully fabricated a '%s'\n", element->Value());
     304                return b;
     305        }
     306       
     307        PRINTF0("Fabricate failed, TiXmlElement did not contain a value\n");
     308       
     309        return NULL;
     310}
Note: See TracChangeset for help on using the changeset viewer.