Changeset 4194 in orxonox.OLD for orxonox/branches/openAL/src/game_loader.cc
- Timestamp:
- May 16, 2005, 1:33:19 PM (20 years ago)
- Location:
- orxonox/branches/openAL
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/openAL
- Property svn:externals
-
old new 1 data http://svn.orxonox.ethz.ch/data 1
-
- Property svn:externals
-
orxonox/branches/openAL/src/game_loader.cc
r3727 r4194 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 … … 158 173 this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 159 174 */ 160 Campaign* GameLoader::fileToCampaign(c har *name)175 Campaign* GameLoader::fileToCampaign(const char *name) 161 176 { 162 177 /* do not entirely load the campaign. just the current world … … 164 179 can load everything it needs into memory then. 165 180 */ 181 182 if( name == NULL) 183 { 184 PRINTF(2)("No filename specified for loading"); 185 return NULL; 186 } 187 188 TiXmlDocument* XMLDoc = new TiXmlDocument( name); 189 // load the campaign document 190 if( !XMLDoc->LoadFile()) 191 { 192 // report an error 193 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", name, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 194 delete XMLDoc; 195 return NULL; 196 } 197 198 // check basic validity 199 TiXmlElement* root = XMLDoc->RootElement(); 200 assert( root != NULL); 201 202 if( strcmp( root->Value(), "Campaign")) 203 { 204 // report an error 205 PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n"); 206 delete XMLDoc; 207 return NULL; 208 } 209 210 // construct campaign 211 Campaign* c = new Campaign( root); 212 213 // free the XML data 214 delete XMLDoc; 215 216 return c; 166 217 } 167 218 … … 174 225 bool GameLoader::worldCommand (Command* cmd) 175 226 { 176 if( !strcmp( cmd->cmd, "up_world"))227 if( !strcmp( cmd->cmd, CONFIG_NAME_NEXT_WORLD)) 177 228 { 178 229 if( !cmd->bUp) … … 182 233 return true; 183 234 } 184 else if( !strcmp( cmd->cmd, "down_world"))235 else if( !strcmp( cmd->cmd, CONFIG_NAME_PREV_WORLD)) 185 236 { 186 237 if( !cmd->bUp) … … 190 241 return true; 191 242 } 192 else if( !strcmp( cmd->cmd, "pause"))243 else if( !strcmp( cmd->cmd, CONFIG_NAME_PAUSE)) 193 244 { 194 245 if( !cmd->bUp) … … 201 252 return true; 202 253 } 203 else if( !strcmp( cmd->cmd, "quit"))254 else if( !strcmp( cmd->cmd, CONFIG_NAME_QUIT)) 204 255 { 205 256 if( !cmd->bUp) this->stop(); … … 230 281 this->currentCampaign->previousLevel(); 231 282 } 283 284 /** 285 \brief add a Factory to the Factory Q 286 \param factory a Factory to be registered 287 */ 288 void GameLoader::registerFactory( Factory* factory) 289 { 290 assert( factory != NULL); 291 292 PRINTF(4)("Registered factory for '%s'\n", factory->getFactoryName()); 293 294 if( first == NULL) first = factory; 295 else first->registerFactory( factory); 296 } 297 298 /** 299 \brief load a StoryEntity 300 \param element a XMLElement containing all the needed info 301 */ 302 BaseObject* GameLoader::fabricate( TiXmlElement* element) 303 { 304 assert( element != NULL); 305 306 if( first == NULL) 307 { 308 PRINTF(1)("GameLoader does not know any factories, fabricate() failed\n"); 309 return NULL; 310 } 311 312 if( element->Value() != NULL) 313 { 314 PRINTF(4)("Attempting fabrication of a '%s'\n", element->Value()); 315 BaseObject* b = first->fabricate( element); 316 if( b == NULL) 317 PRINTF(2)("Failed to fabricate a '%s'\n", element->Value()); 318 else 319 PRINTF(4)("Successfully fabricated a '%s'\n", element->Value()); 320 return b; 321 } 322 323 PRINTF(2)("Fabricate failed, TiXmlElement did not contain a value\n"); 324 325 return NULL; 326 }
Note: See TracChangeset
for help on using the changeset viewer.