Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 11, 2005, 6:44:55 PM (19 years ago)
Author:
chris
Message:

orxonox/branches/levelloader: Implemented loadability of worlds and campaigns from files. Theoretically any Story_Entity and World_Entity can now be loaded from the files if somebody adjusts the classes to be loadable. System still needs testing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelloader/src/story_entities/world.cc

    r3501 r3503  
    2929#include "light.h"
    3030#include "fontset.h"
     31#include "factory.h"
    3132
    3233using namespace std;
     
    3536World::World( TiXMLElement* root)
    3637{
    37         TiXMLElement* element;
    38         // load parameters
    39                 // identifier
    40         element = FirstChildrenElement("identifier");
    41         if( element == NULL)
    42         {
    43                 PRINTF(ERR)("World created with missing identifier\n");
    44                 setStoryID( -1);
    45         }
    46                 // file
     38        char *string, *name;
     39        int id;
     40
     41        // identifier
     42        string = grabParameter( root, "identifier");
     43        if( string == NULL || if( sscanf(string, "%d", &id) != 1))
     44        {
     45                PRINTF(ERR)("World is missing a proper 'identifier'\n");
     46                setStoryId( -1);
     47        }
     48        else setStoryId( id);
     49       
     50        // path
     51        string = grabParameter( root, "path");
     52        if( string == NULL)
     53        {
     54                PRINTF(ERR)("World is missing a proper 'path'\n");
     55                setPath( NULL);
     56        }
     57        else
     58        {
     59                name = new char[strlen(string + 2)];
     60                strcpy( name, string);
     61                setPath( name);
     62        }
     63       
     64       
    4765}
    4866
     
    115133ErrorMessage World::load()
    116134{
     135        if( 0)  // temporary until we really load from files
     136        {
     137                        GameLoader* loader = GameLoader::getInstance();
     138                       
     139                  if( getPath() == NULL)
     140                  {
     141                                PRINTF(ERR)("World has no path specified for loading");
     142                                return (ErrorMessage){213,"Path not specified","World::load()"};
     143                  }
     144                 
     145                        TiXMLDocument* XMLDoc = new TiXMLDocument( name);
     146                        // load the campaign document
     147                        if( !XMLDoc.LoadFile())
     148                        {
     149                                // report an error
     150                                PRINTF(ERR)("Error loading XML File: %s @ %d:%d\n", XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());
     151                                delete XMLDoc;
     152                                return (ErrorMessage){213,"XML File parsing error","World::load()"};
     153                        }
     154                       
     155                        // check basic validity
     156                        TiXMLElement* element = XMLDoc.RootElement();
     157                        assert( element != NULL);
     158                       
     159                        element = element->FirstChildElement( "WorldDataFile");
     160                       
     161                        if( element == NULL )
     162                        {
     163                                // report an error
     164                                PRINTF(ERR)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
     165                                delete XMLDoc;
     166                                return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"};
     167                        }
     168                       
     169                        // load the parameters
     170                                // name
     171                        char* temp;
     172                        char* string = grabParameter( root, "name");
     173                        if( string == NULL)
     174                        {
     175                                PRINTF(ERR)("World is missing a proper 'name'\n");
     176                                setStoryId( -1);
     177                        }
     178                        else
     179                        {
     180                                temp = new char[strlen(string + 2)];
     181                                worldName = temp;
     182                        }
     183                       
     184                       
     185                        // find WorldEntities
     186                  element = root->FirstChildElement( "WorldEntities");
     187                 
     188                  // load Players/Objects/Whatever
     189                        while( element != NULL)
     190                        {
     191                                WorldEntity* created = (WorldEntity*) loader->fabricate( element);
     192                                if( created != NULL) spawn( created);
     193                                element = element->nextSiblingElement();
     194                        }
     195                       
     196                        // find Track
     197                                // TODO: load the track somehow
     198                       
     199                        // free the XML data
     200                        delete XMLDoc;
     201        }
     202       
    117203  //  BezierCurve* tmpCurve = new BezierCurve();
    118204  if(this->debugWorldNr != -1)
     
    9161002}
    9171003
     1004void World::setPath( char* name)
     1005{
     1006        path = name;
     1007}
     1008
     1009char* World::getPath()
     1010{
     1011        return path;
     1012}
Note: See TracChangeset for help on using the changeset viewer.