Changeset 8079 for code/trunk/src/orxonox/LevelManager.cc
- Timestamp:
- Mar 15, 2011, 9:47:11 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/LevelManager.cc
r7839 r8079 75 75 LevelManager::~LevelManager() 76 76 { 77 // Delete all the LevelInfoItem objects because the LevelManager created them 78 std::set<LevelInfoItem*, LevelInfoCompare>::iterator it = availableLevels_.begin(); 79 for (; it != availableLevels_.end(); ++it) 80 delete *it; 77 81 } 78 82 … … 237 241 void LevelManager::compileAvailableLevelList() 238 242 { 243 // Get all files matching the level criteria 239 244 Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw"); 240 // Iterate over all *.oxw level files. 245 246 // We only want to load as little as possible 247 ClassTreeMask mask; 248 mask.exclude(Class(BaseObject)); 249 mask.include(Class(LevelInfo)); 250 251 // Iterate over all the found *.oxw files 241 252 COUT(3) << "Loading LevelInfos..." << std::endl; 253 std::set<std::string> names; 242 254 for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it) 243 255 { 244 // TODO: Replace with tag?256 // TODO: Replace with tag? 245 257 if (it->find("old/") != 0) 246 258 { 247 size_t pos = it->find(".oxw");259 LevelInfoItem* info = NULL; 248 260 249 261 // Load the LevelInfo object from the level file. 250 bool infoExists = false;251 262 XMLFile file = XMLFile(*it); 252 ClassTreeMask mask = ClassTreeMask(); 253 mask.exclude(ClassIdentifier<BaseObject>::getIdentifier()); 254 mask.include(ClassIdentifier<LevelInfo>::getIdentifier()); 255 Loader::load(&file, mask, false); 256 // Iterate over all LevelInfos. 263 Loader::load(&file, mask, false, true); 264 265 // Find the LevelInfo object we've just loaded (if there was one) 257 266 for(ObjectList<LevelInfo>::iterator item = ObjectList<LevelInfo>::begin(); item != ObjectList<LevelInfo>::end(); ++item) 267 if(item->getXMLFilename() == *it) 268 info = item->copy(); 269 270 // We don't need the loaded stuff anymore 271 Loader::unload(&file); 272 273 if(info == NULL) 258 274 { 259 LevelInfoItem* info = item->copy(); 260 if(info->getXMLFilename() == *it) // If the LevelInfo for this level exists we insert it into the list of available levels. 261 { 262 this->availableLevels_.insert(info); 263 infoExists = true; 264 } 275 // Create a default LevelInfoItem object that merely contains the name 276 std::string filenameWOExtension = it->substr(0, it->find(".oxw")); 277 info = new LevelInfoItem(filenameWOExtension, *it); 265 278 } 266 Loader::unload(&file, mask); 267 if(!infoExists) // If the LevelInfo for this level doesn't exist, we create a new one and insert it into the list of available levels. 268 this->availableLevels_.insert(new LevelInfoItem(it->substr(0, pos), *it)); 279 280 // Warn about levels with the same name. 281 if(!names.insert(info->getName()).second) 282 COUT(2) << "Warning: Multiple levels (" << info->getXMLFilename() << ") with name '" << info->getName() << "' found!" << std::endl; 283 284 // Warn about multiple items so that it gets fixed quickly 285 if(availableLevels_.find(info) != availableLevels_.end()) 286 { 287 COUT(2) << "Warning: Multiple levels (" << info->getXMLFilename() << ") with same name '" << info->getName() << "' and filename found! Exluding..." << std::endl; 288 // Delete LevelInfoItem to avoid a dangling pointer 289 delete info; 290 } 291 else 292 this->availableLevels_.insert(info); 269 293 } 270 294 }
Note: See TracChangeset
for help on using the changeset viewer.