Changeset 3903 in orxonox.OLD for orxonox/branches/levelLoader.tmp/src/game_loader.cc
- Timestamp:
- Apr 20, 2005, 12:42:37 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/levelLoader.tmp/src/game_loader.cc
r3727 r3903 15 15 co-programmer: ... 16 16 */ 17 18 17 19 18 #include "game_loader.h" … … 25 24 #include "command_node.h" 26 25 #include "vector.h" 26 #include "factory.h" 27 #include "debug.h" 27 28 28 29 #include <string.h> … … 35 36 36 37 37 GameLoader::GameLoader () {} 38 GameLoader::GameLoader () 39 { 40 first = NULL; 41 } 38 42 39 43 … … 164 168 can load everything it needs into memory then. 165 169 */ 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; 166 206 } 167 207 … … 230 270 this->currentCampaign->previousLevel(); 231 271 } 272 273 274 /** 275 \brief add a Factory to the Factory Q 276 \param factory a Factory to be registered 277 */ 278 void 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 */ 292 BaseObject* 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 }
Note: See TracChangeset
for help on using the changeset viewer.