[Orxonox-commit 3308] r7997 - code/branches/usability/src/orxonox

rgrieder at orxonox.net rgrieder at orxonox.net
Mon Feb 28 04:54:09 CET 2011


Author: rgrieder
Date: 2011-02-28 04:54:09 +0100 (Mon, 28 Feb 2011)
New Revision: 7997

Modified:
   code/branches/usability/src/orxonox/LevelManager.cc
Log:
Added warning for the case two Levels had the same identification (name).
--> 3 warnings popping up now :P

Modified: code/branches/usability/src/orxonox/LevelManager.cc
===================================================================
--- code/branches/usability/src/orxonox/LevelManager.cc	2011-02-28 03:10:21 UTC (rev 7996)
+++ code/branches/usability/src/orxonox/LevelManager.cc	2011-02-28 03:54:09 UTC (rev 7997)
@@ -236,36 +236,47 @@
     */
     void LevelManager::compileAvailableLevelList()
     {
+        // Get all files matching the level criteria
         Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw");
-        // Iterate over all *.oxw level files.
+
+        // We only want to load as little as possible
+        ClassTreeMask mask;
+        mask.exclude(Class(BaseObject));
+        mask.include(Class(LevelInfo));
+
+        // Iterate over all the found *.oxw files
         COUT(3) << "Loading LevelInfos..." << std::endl;
         for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it)
         {
-            //TODO: Replace with tag?
+            // TODO: Replace with tag?
             if (it->find("old/") != 0)
             {
-                size_t pos = it->find(".oxw");
+                LevelInfoItem* info = NULL;
 
                 // Load the LevelInfo object from the level file.
-                bool infoExists = false;
                 XMLFile file = XMLFile(*it);
-                ClassTreeMask mask = ClassTreeMask();
-                mask.exclude(ClassIdentifier<BaseObject>::getIdentifier());
-                mask.include(ClassIdentifier<LevelInfo>::getIdentifier());
                 Loader::load(&file, mask, false, true);
-                // Iterate over all LevelInfos.
+
+                // Find the LevelInfo object we've just loaded (if there was one)
                 for(ObjectList<LevelInfo>::iterator item = ObjectList<LevelInfo>::begin(); item != ObjectList<LevelInfo>::end(); ++item)
+                    if(item->getXMLFilename() == *it)
+                        info = item->copy();
+
+                // We don't need the loaded stuff anymore
+                Loader::unload(&file, mask);
+
+                if(info == NULL) 
                 {
-                    LevelInfoItem* info = item->copy();
-                    if(info->getXMLFilename() == *it) // If the LevelInfo for this level exists we insert it into the list of available levels.
-                    {
-                        this->availableLevels_.insert(info);
-                        infoExists = true;
-                    }
+                    // Create a default LevelInfoItem object that merely contains the name
+                    std::string filenameWOExtension = it->substr(0, it->find(".oxw"));
+                    info = new LevelInfoItem(filenameWOExtension, *it);
                 }
-                Loader::unload(&file, mask);
-                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.
-                    this->availableLevels_.insert(new LevelInfoItem(it->substr(0, pos), *it));
+
+                // Warn about multiple items so that it gets fixed quickly
+                if(availableLevels_.find(info) != availableLevels_.end())
+                    COUT(2) << "Warning: Multiple levels with name '" << info->getName() << "' found!" << std::endl;
+
+                this->availableLevels_.insert(info);
             }
         }
     }




More information about the Orxonox-commit mailing list