Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 13, 2005, 5:16:24 PM (19 years ago)
Author:
chris
Message:

orxonox/branches/levelloader: Implemented support for loading tracks in the WorldDataFiles

File:
1 edited

Legend:

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

    r3503 r3523  
    133133ErrorMessage World::load()
    134134{
    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         }
     135        GameLoader* loader = GameLoader::getInstance();
     136       
     137  if( getPath() == NULL)
     138  {
     139                PRINTF(ERR)("World has no path specified for loading");
     140                return (ErrorMessage){213,"Path not specified","World::load()"};
     141  }
     142 
     143        TiXMLDocument* XMLDoc = new TiXMLDocument( name);
     144        // load the campaign document
     145        if( !XMLDoc.LoadFile())
     146        {
     147                // report an error
     148                PRINTF(ERR)("Error loading XML File: %s @ %d:%d\n", XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());
     149                delete XMLDoc;
     150                return (ErrorMessage){213,"XML File parsing error","World::load()"};
     151        }
     152       
     153        // check basic validity
     154        TiXMLElement* root = XMLDoc.RootElement();
     155        assert( root != NULL);
     156       
     157        element = root->FirstChildElement( "WorldDataFile");
     158       
     159        if( root == NULL )
     160        {
     161                // report an error
     162                PRINTF(ERR)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
     163                delete XMLDoc;
     164                return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"};
     165        }
     166       
     167        // load the parameters
     168                // name
     169        TiXMLElement* element;
     170        char* temp;
     171        char* string = grabParameter( root, "name");
     172        if( string == NULL)
     173        {
     174                PRINTF(ERR)("World is missing a proper 'name'\n");
     175                setStoryId( -1);
     176        }
     177        else
     178        {
     179                temp = new char[strlen(string + 2)];
     180                worldName = temp;
     181        }
     182       
     183       
     184        // find WorldEntities
     185  element = root->FirstChildElement( "WorldEntities");
     186 
     187  if( element == NULL)
     188  {
     189                PRINTF(ERR)("World is missing 'WorldEntities'\n");
     190  }
     191  else
     192  {
     193        element = element->FirstChildElement();
     194          // load Players/Objects/Whatever
     195                while( element != NULL)
     196                {
     197                        WorldEntity* created = (WorldEntity*) loader->fabricate( element);
     198                        if( created != NULL) spawn( created);
     199                        element = element->nextSiblingElement();
     200                }
     201        }
     202       
     203        // find Track
     204  element = root->FirstChildElement( "Track");
     205  if( element == NULL)
     206  {
     207                PRINTF(ERR)("World is missing a 'Track'\n");
     208  }
     209  else
     210  {     
     211        //load track
     212        trackManager = TrackManager::getInstance();
     213        trackManager->loadTrack( element);
     214        }
     215 
     216       
     217        // free the XML data
     218        delete XMLDoc;
    202219       
    203220  //  BezierCurve* tmpCurve = new BezierCurve();
Note: See TracChangeset for help on using the changeset viewer.