Changeset 7221 in orxonox.OLD for trunk/src/lib/util/loading/game_loader.cc
- Timestamp:
- Mar 15, 2006, 3:10:45 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/loading/game_loader.cc
r7193 r7221 86 86 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 87 87 */ 88 ErrorMessage GameLoader::loadCampaign(const char*fileName)88 ErrorMessage GameLoader::loadCampaign(const std::string& fileName) 89 89 { 90 90 ErrorMessage errorCode; 91 char*campaignName = ResourceManager::getFullName(fileName);92 if ( campaignName)91 std::string campaignName = ResourceManager::getFullName(fileName); 92 if (!campaignName.empty()) 93 93 { 94 94 this->currentCampaign = this->fileToCampaign(campaignName); 95 delete[] campaignName;96 95 } 97 96 } … … 105 104 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 106 105 */ 107 ErrorMessage GameLoader::loadNetworkCampaign(const char*fileName)106 ErrorMessage GameLoader::loadNetworkCampaign(const std::string& fileName) 108 107 { 109 108 ErrorMessage errorCode; 110 char*campaignName = ResourceManager::getFullName(fileName);111 if ( campaignName)109 std::string campaignName = ResourceManager::getFullName(fileName); 110 if (!campaignName.empty()) 112 111 { 113 112 this->currentCampaign = this->fileToCampaign(campaignName); 114 delete[] campaignName;115 113 } 116 114 } … … 220 218 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 221 219 */ 222 Campaign* GameLoader::fileToCampaign(const char*fileName)220 Campaign* GameLoader::fileToCampaign(const std::string& fileName) 223 221 { 224 222 /* do not entirely load the campaign. just the current world … … 227 225 */ 228 226 229 if( fileName == NULL)227 if( fileName.empty()) 230 228 { 231 229 PRINTF(2)("No filename specified for loading"); … … 233 231 } 234 232 235 TiXmlDocument * XMLDoc = new TiXmlDocument(fileName);233 TiXmlDocument XMLDoc(fileName); 236 234 // load the campaign document 237 if( !XMLDoc ->LoadFile())235 if( !XMLDoc.LoadFile(fileName)) 238 236 { 239 237 // report an error 240 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 241 delete XMLDoc; 238 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName.c_str(), XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol()); 242 239 return NULL; 243 240 } 244 241 245 242 // check basic validity 246 TiXmlElement* root = XMLDoc ->RootElement();243 TiXmlElement* root = XMLDoc.RootElement(); 247 244 assert( root != NULL); 248 245 … … 251 248 // report an error 252 249 PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n"); 253 delete XMLDoc;254 250 return NULL; 255 251 } 256 252 257 253 // construct campaign 258 Campaign* c = new Campaign( root); 259 260 // free the XML data 261 delete XMLDoc; 262 263 return c; 254 return new Campaign( root); 264 255 } 265 256
Note: See TracChangeset
for help on using the changeset viewer.