Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7997


Ignore:
Timestamp:
Feb 28, 2011, 4:54:09 AM (14 years ago)
Author:
rgrieder
Message:

Added warning for the case two Levels had the same identification (name).
—> 3 warnings popping up now :P

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/usability/src/orxonox/LevelManager.cc

    r7963 r7997  
    237237    void LevelManager::compileAvailableLevelList()
    238238    {
     239        // Get all files matching the level criteria
    239240        Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw");
    240         // Iterate over all *.oxw level files.
     241
     242        // We only want to load as little as possible
     243        ClassTreeMask mask;
     244        mask.exclude(Class(BaseObject));
     245        mask.include(Class(LevelInfo));
     246
     247        // Iterate over all the found *.oxw files
    241248        COUT(3) << "Loading LevelInfos..." << std::endl;
    242249        for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it)
    243250        {
    244             //TODO: Replace with tag?
     251            // TODO: Replace with tag?
    245252            if (it->find("old/") != 0)
    246253            {
    247                 size_t pos = it->find(".oxw");
     254                LevelInfoItem* info = NULL;
    248255
    249256                // Load the LevelInfo object from the level file.
    250                 bool infoExists = false;
    251257                XMLFile file = XMLFile(*it);
    252                 ClassTreeMask mask = ClassTreeMask();
    253                 mask.exclude(ClassIdentifier<BaseObject>::getIdentifier());
    254                 mask.include(ClassIdentifier<LevelInfo>::getIdentifier());
    255258                Loader::load(&file, mask, false, true);
    256                 // Iterate over all LevelInfos.
     259
     260                // Find the LevelInfo object we've just loaded (if there was one)
    257261                for(ObjectList<LevelInfo>::iterator item = ObjectList<LevelInfo>::begin(); item != ObjectList<LevelInfo>::end(); ++item)
     262                    if(item->getXMLFilename() == *it)
     263                        info = item->copy();
     264
     265                // We don't need the loaded stuff anymore
     266                Loader::unload(&file, mask);
     267
     268                if(info == NULL)
    258269                {
    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                     }
     270                    // Create a default LevelInfoItem object that merely contains the name
     271                    std::string filenameWOExtension = it->substr(0, it->find(".oxw"));
     272                    info = new LevelInfoItem(filenameWOExtension, *it);
    265273                }
    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));
     274
     275                // Warn about multiple items so that it gets fixed quickly
     276                if(availableLevels_.find(info) != availableLevels_.end())
     277                    COUT(2) << "Warning: Multiple levels with name '" << info->getName() << "' found!" << std::endl;
     278
     279                this->availableLevels_.insert(info);
    269280            }
    270281        }
Note: See TracChangeset for help on using the changeset viewer.