Changeset 4122 in orxonox.OLD for orxonox/branches/heightMap/src/game_loader.cc
- Timestamp:
- May 9, 2005, 11:29:19 AM (19 years ago)
- Location:
- orxonox/branches/heightMap
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/heightMap
- Property svn:externals
-
old new 1 data http://svn.orxonox.ethz.ch/data 1
-
- Property svn:externals
-
orxonox/branches/heightMap/src/game_loader.cc
r4021 r4122 25 25 #include "command_node.h" 26 26 #include "vector.h" 27 #include "resource_manager.h" 28 #include "factory.h" 27 29 28 30 #include <string.h> … … 35 37 36 38 37 GameLoader::GameLoader () {} 39 GameLoader::GameLoader () 40 { 41 first = NULL; 42 } 38 43 39 44 … … 72 77 { 73 78 ErrorMessage errorCode; 74 75 this->currentCampaign = this->fileToCampaign(name); 79 char* campaignName; 80 if (ResourceManager::isFile(name)) 81 { 82 this->currentCampaign = this->fileToCampaign(name); 83 } 84 else 85 { 86 campaignName = new char[strlen(ResourceManager::getInstance()->getDataDir())+strlen(name)]; 87 sprintf(campaignName, "%s%s", ResourceManager::getInstance()->getDataDir(), name); 88 this->currentCampaign = this->fileToCampaign(campaignName); 89 delete campaignName; 90 } 76 91 } 77 92 … … 163 178 this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 164 179 */ 165 Campaign* GameLoader::fileToCampaign(c har *name)180 Campaign* GameLoader::fileToCampaign(const char *name) 166 181 { 167 182 /* do not entirely load the campaign. just the current world … … 169 184 can load everything it needs into memory then. 170 185 */ 186 187 if( name == NULL) 188 { 189 PRINTF(2)("No filename specified for loading"); 190 return NULL; 191 } 192 193 TiXmlDocument* XMLDoc = new TiXmlDocument( name); 194 // load the campaign document 195 if( !XMLDoc->LoadFile()) 196 { 197 // report an error 198 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", name, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 199 delete XMLDoc; 200 return NULL; 201 } 202 203 // check basic validity 204 TiXmlElement* root = XMLDoc->RootElement(); 205 assert( root != NULL); 206 207 if( strcmp( root->Value(), "Campaign")) 208 { 209 // report an error 210 PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n"); 211 delete XMLDoc; 212 return NULL; 213 } 214 215 // construct campaign 216 Campaign* c = new Campaign( root); 217 218 // free the XML data 219 delete XMLDoc; 220 221 return c; 171 222 } 172 223 … … 179 230 bool GameLoader::worldCommand (Command* cmd) 180 231 { 181 if( !strcmp( cmd->cmd, "up_world"))232 if( !strcmp( cmd->cmd, CONFIG_NAME_NEXT_WORLD)) 182 233 { 183 234 if( !cmd->bUp) … … 187 238 return true; 188 239 } 189 else if( !strcmp( cmd->cmd, "down_world"))240 else if( !strcmp( cmd->cmd, CONFIG_NAME_PREV_WORLD)) 190 241 { 191 242 if( !cmd->bUp) … … 195 246 return true; 196 247 } 197 else if( !strcmp( cmd->cmd, "pause"))248 else if( !strcmp( cmd->cmd, CONFIG_NAME_PAUSE)) 198 249 { 199 250 if( !cmd->bUp) … … 206 257 return true; 207 258 } 208 else if( !strcmp( cmd->cmd, "quit"))259 else if( !strcmp( cmd->cmd, CONFIG_NAME_QUIT)) 209 260 { 210 261 if( !cmd->bUp) this->stop(); … … 235 286 this->currentCampaign->previousLevel(); 236 287 } 288 289 /** 290 \brief add a Factory to the Factory Q 291 \param factory a Factory to be registered 292 */ 293 void GameLoader::registerFactory( Factory* factory) 294 { 295 assert( factory != NULL); 296 297 PRINTF(4)("Registered factory for '%s'\n", factory->getFactoryName()); 298 299 if( first == NULL) first = factory; 300 else first->registerFactory( factory); 301 } 302 303 /** 304 \brief load a StoryEntity 305 \param element a XMLElement containing all the needed info 306 */ 307 BaseObject* GameLoader::fabricate( TiXmlElement* element) 308 { 309 assert( element != NULL); 310 311 if( first == NULL) 312 { 313 PRINTF(1)("GameLoader does not know any factories, fabricate() failed\n"); 314 return NULL; 315 } 316 317 if( element->Value() != NULL) 318 { 319 PRINTF(4)("Attempting fabrication of a '%s'\n", element->Value()); 320 BaseObject* b = first->fabricate( element); 321 if( b == NULL) 322 PRINTF(2)("Failed to fabricate a '%s'\n", element->Value()); 323 else 324 PRINTF(4)("Successfully fabricated a '%s'\n", element->Value()); 325 return b; 326 } 327 328 PRINTF(2)("Fabricate failed, TiXmlElement did not contain a value\n"); 329 330 return NULL; 331 }
Note: See TracChangeset
for help on using the changeset viewer.