Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3903 in orxonox.OLD for orxonox/branches/levelLoader.tmp/src


Ignore:
Timestamp:
Apr 20, 2005, 12:42:37 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/levelLoader.tmp: some merges

Location:
orxonox/branches/levelLoader.tmp/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelLoader.tmp/src/game_loader.cc

    r3727 r3903  
    1515   co-programmer: ...
    1616*/
    17 
    1817
    1918#include "game_loader.h"
     
    2524#include "command_node.h"
    2625#include "vector.h"
     26#include "factory.h"
     27#include "debug.h"
    2728
    2829#include <string.h>
     
    3536
    3637
    37 GameLoader::GameLoader () {}
     38GameLoader::GameLoader ()
     39{
     40        first = NULL;
     41}
    3842
    3943
     
    164168     can load everything it needs into memory then.
    165169  */
     170 
     171  if( name == NULL)
     172  {
     173                PRINTF0("No filename specified for loading");
     174                return NULL;
     175  }
     176 
     177        TiXmlDocument* XMLDoc = new TiXmlDocument( name);
     178        // load the campaign document
     179        if( !XMLDoc->LoadFile())
     180        {
     181                // report an error
     182                PRINTF0("Error loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
     183                delete XMLDoc;
     184                return NULL;
     185        }
     186       
     187        // check basic validity
     188        TiXmlElement* root = XMLDoc->RootElement();
     189        assert( root != NULL);
     190       
     191        if( strcmp( root->Value(), "Campaign"))
     192        {
     193                // report an error
     194                PRINTF0("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
     195                delete XMLDoc;
     196                return NULL;
     197        }
     198       
     199        // construct campaign
     200        Campaign* c = new Campaign( root);
     201       
     202        // free the XML data
     203        delete XMLDoc;
     204       
     205        return c;
    166206}
    167207
     
    230270    this->currentCampaign->previousLevel();
    231271}
     272
     273
     274/**
     275   \brief add a Factory to the Factory Q
     276   \param factory a Factory to be registered
     277*/
     278void GameLoader::registerFactory( Factory* factory)
     279{
     280        assert( factory != NULL);
     281       
     282        PRINTF0("Registered factory for '%s'\n", factory->getClassname());
     283       
     284        if( first == NULL) first = factory;
     285        else first->registerFactory( factory);
     286}
     287
     288/**
     289   \brief load a StoryEntity
     290   \param element a XMLElement containing all the needed info
     291*/
     292BaseObject* GameLoader::fabricate( TiXmlElement* element)
     293{
     294        assert( element != NULL);
     295       
     296        if( first == NULL)
     297        {
     298                PRINTF0("GameLoader does not know any factories, fabricate() failed\n");
     299                return NULL;
     300        }
     301       
     302        if( element->Value() != NULL)
     303        {
     304                PRINTF0("Attempting fabrication of a '%s'\n", element->Value());
     305                BaseObject* b = first->fabricate( element);
     306                if( b == NULL) PRINTF0("Failed to fabricate a '%s'\n", element->Value());
     307                else PRINTF0("Successfully fabricated a '%s'\n", element->Value());
     308                return b;
     309        }
     310       
     311        PRINTF0("Fabricate failed, TiXmlElement did not contain a value\n");
     312       
     313        return NULL;
     314}
  • orxonox/branches/levelLoader.tmp/src/game_loader.h

    r3629 r3903  
    99//#include "stdincl.h"
    1010#include "story_def.h"
     11#include "factory.h"
    1112#include "comincl.h"
     13#include "error.h"
    1214
    1315//-----------------------------------------------------------------------------
     
    5153  ErrorMessage loadDebugCampaign(Uint32 campaignID);
    5254 
     55  void registerFactory( Factory* factory);
     56  BaseObject* fabricate( TiXmlElement* data);
     57 
    5358 private:
    5459  GameLoader ();
     
    6267  Campaign* fileToCampaign(char* name);
    6368
     69  Factory* first;
    6470};
    6571
  • orxonox/branches/levelLoader.tmp/src/util/levelloader/factory.h

    r3901 r3903  
    2525
    2626#include "stdincl.h"
     27#include "tinyxml.h"
    2728
    2829class BaseObject;
     
    4041        virtual BaseObject* fabricate( TiXmlElement* root);
    4142        void initialize();
    42   void registerFactory( Factory* factory);
     43        void registerFactory( Factory* factory);
    4344        void setClassname(char* name) {classname = name;}
    4445        char* getClassname() {return classname;};
Note: See TracChangeset for help on using the changeset viewer.