Changeset 3496 in orxonox.OLD for orxonox/branches/levelloader/src/levelfactory.cc
- Timestamp:
- Mar 11, 2005, 10:25:27 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/levelloader/src/levelfactory.cc
r3482 r3496 19 19 #include "levelfactory.h" 20 20 21 22 21 using namespace std; 23 22 … … 47 46 if( !XMLDoc.LoadFile()) 48 47 { 49 // report an error somehow50 printf("Error loading XML File: %s @ %d:%d\n", XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());51 delete ( XMLDoc);48 // report an error 49 PRINTF(ERR)("Error loading XML File: %s @ %d:%d\n", XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol()); 50 delete XMLDoc; 52 51 return -1; 53 52 } 54 53 55 54 // get orxonox simpleton 55 Orxonox* orx = Orxonox::getInstance(); 56 56 57 // find the world 58 World world = orx->getWorld; 59 60 // check basic validity 61 TiXMLElement* element = XMLDoc.RootElement(); 62 TiXMLNode* comment = element->FirstChild( COMMENT); 63 64 if( comment == NULL || ( !strcmp( comment->Value(), "OrxoLev"))) 65 { 66 // report an error 67 PRINTF(ERR)("Specified XML File is not an orxonox data file (OrxoLev comment missing)\n"); 68 delete XMLDoc; 69 return -1; 70 } 71 57 72 // start loading objects into world 73 loadFromXMLElement( element), world, NULL); 74 58 75 // free the XML data 76 delete XMLDoc; 77 } 78 79 /** 80 \brief recursive XML document parsing and loading function 81 \param root the XML Element to be parsed 82 \param world the world where the loaded objects shall be spawned 83 \param parent the object that is parent to all objects in current element 84 */ 85 86 void loadFromXMLElement( TiXMLElement* root, World* world, BaseObject* parent) 87 { 88 TiXMLElement *child, *sibling; 89 BaseObject* object; 90 LoadParameters* data; 91 void* data; 92 93 if( root == NULL) 94 { 95 PRINTF(ERR)("LevelFactory tried to load from a NULL element\n"); 96 return; 97 } 98 99 // load root first 100 101 // check for LevelFactory integrity 102 if( first == NULL) 103 { 104 PRINTF(ERR)("LevelFactory does not know any ObjectFactories, loading not possible\n"); 105 return; 106 } 107 108 // gather & compile attributes 109 data = new LoadParameters( root); 110 111 // load the object 112 object = first->load( root->Value(), data); 113 114 // get rid of parameters 115 delete data; 116 117 if( object != NULL) 118 { 119 // set parent 120 121 // spawn object 122 world->spawn( object); 123 PRINTF(INFO)("Successfully loaded a '%s'\n", root->value()); 124 } 125 else 126 { 127 PRINTF(ERR)("No ObjectFactory found to load '%s'\n", root->value()) 128 } 129 130 // walk children 131 child = root->FirstChildElement(); 132 if( child != NULL) loadFromXMLElement( child, world, object); 133 134 // siblings third 135 sibling = root->NextSiblingElement(); 136 if( sibling != NULL) loadFromXMLElement( sibling, world, parent); 59 137 } 60 138 … … 87 165 void LevelFactory::registerFactory( ObjectFactory* factory) 88 166 { 167 // just to see whether it works 168 PRINTF(INFO)("'%s' registered to LevelFactory\n", factory->getClassname()); 89 169 if( first == NULL) first = factory; 90 170 else first->registerFactory( factory); … … 153 233 fct.registerFactory( this); 154 234 } 235 236 /* -------------------------------------------------- 237 * LoadParameters 238 * -------------------------------------------------- 239 */ 240 241 const char* LoadParameters::grabParameter( const char* name) 242 { 243 return root->Attribute( name); 244 } 245 246 const char* LoadParameters::grabParameter( const char* name, int* i) 247 { 248 return root->Attribute( name, i); 249 } 250 251 const char* LoadParameters::grabParameter( const char* name, double* d) 252 { 253 return root->Attribute( name, d); 254 }
Note: See TracChangeset
for help on using the changeset viewer.