Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3503 in orxonox.OLD


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

Location:
orxonox/branches/levelloader/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelloader/src/game_loader.cc

    r3501 r3503  
    2525#include "command_node.h"
    2626#include "vector.h"
     27#include "factory.h"
    2728
    2829#include <string.h>
     
    162163  {
    163164                PRINTF(ERR)("No filename specified for loading");
     165                return NULL;
    164166  }
    165167 
  • orxonox/branches/levelloader/src/game_loader.h

    r3501 r3503  
    3535 
    3636  void registerFactory( Factory* factory);
    37   StoryEntity* fabricate( TiXMLElement* data);
     37  BaseObject* fabricate( TiXMLElement* data);
    3838 
    3939 private:
  • orxonox/branches/levelloader/src/story_entities/campaign.cc

    r3501 r3503  
    2121#include "camera.h"
    2222#include "story_entity.h"
     23#include "factory.h"
    2324
    2425using namespace std;
     
    3637{
    3738        TiXMLElement* element;
     39        char string;
     40        int id;
    3841       
    3942        assert( root != NULL);
     
    4447 
    4548  // grab all the necessary parameters
    46  
     49        string = grabParameter( root, "identifier");
     50        if( string == NULL || if( sscanf(string, "%d", &id) != 1))
     51        {
     52                PRINTF(ERR)("Campaign is missing a proper 'identifier'\n");
     53                setStoryId( -1);
     54        }
     55        else setStoryId( id);
     56       
    4757  // find WorldList
    4858  element = root->FirstChildElement( "WorldList");
    4959 
    50   // load Worlds
     60  // load Worlds/Subcampaigns/Whatever
    5161        while( element != NULL)
    5262        {
    53                 StoryEntity created = loader->fabricate( element);
     63                StoryEntity* created = (StoryEntity*) loader->fabricate( element);
    5464                if( created != NULL) addEntity( created);
    5565                element = element->nextSiblingElement();
  • 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}
  • orxonox/branches/levelloader/src/story_entities/world.h

    r3501 r3503  
    5252  void spawn (WorldEntity* entity);
    5353  void spawn (WorldEntity* entity, Vector* absCoor, Quaternion* absDir);
    54 
     54       
     55        void setPath( char* name);
     56        char* getPath();
    5557
    5658
     
    6567
    6668  char* worldName;              //!< The name of this World
     69  char* path;                                                                           //!< The path to the data file used by this World
    6770  int debugWorldNr;             //!< The Debug Nr. needed, if something goes wrong
    6871
Note: See TracChangeset for help on using the changeset viewer.