mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-11-03 23:56:47 +00:00 
			
		
		
		
	SoundManager: Set up the priority for file look up right and take care of a corner case
This commit is contained in:
		
							parent
							
								
									054a176c86
								
							
						
					
					
						commit
						ad6175c78a
					
				
					 3 changed files with 24 additions and 22 deletions
				
			
		| 
						 | 
					@ -71,9 +71,6 @@ namespace MWSound
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if(useSound)
 | 
					        if(useSound)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // Temporary list of all sound directories
 | 
					 | 
				
			||||||
            Files::PathContainer soundDirs;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // The music library will accept these filetypes
 | 
					            // The music library will accept these filetypes
 | 
				
			||||||
            // If none is given then it will accept all filetypes
 | 
					            // If none is given then it will accept all filetypes
 | 
				
			||||||
            std::vector<std::string> acceptableExtensions;
 | 
					            std::vector<std::string> acceptableExtensions;
 | 
				
			||||||
| 
						 | 
					@ -82,16 +79,14 @@ namespace MWSound
 | 
				
			||||||
            acceptableExtensions.push_back(".ogg");
 | 
					            acceptableExtensions.push_back(".ogg");
 | 
				
			||||||
            acceptableExtensions.push_back(".flac");
 | 
					            acceptableExtensions.push_back(".flac");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (Files::PathContainer::const_iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
 | 
					            // Makes a list of all sound files, searches in reverse for priority reasons
 | 
				
			||||||
 | 
					            for (Files::PathContainer::const_reverse_iterator it = dataDirs.rbegin(); it != dataDirs.rend(); ++it)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                soundDirs.push_back( *it / std::string("Sound"));
 | 
					                Files::FileLister(*it / std::string("Sound"), mSoundFiles, true);
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            for (Files::PathContainer::const_iterator it = soundDirs.begin(); it != soundDirs.end(); ++it)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Files::FileLister(*it, mSoundFiles, true);
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (Files::PathContainer::const_iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
 | 
					            // Makes a FileLibrary of all music files, searches in reverse for priority reasons
 | 
				
			||||||
 | 
					            for (Files::PathContainer::const_reverse_iterator it = dataDirs.rbegin(); it != dataDirs.rend(); ++it)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                mMusicLibrary.add(*it / std::string("Music"), true, mFSStrict, acceptableExtensions);
 | 
					                mMusicLibrary.add(*it / std::string("Music"), true, mFSStrict, acceptableExtensions);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -292,7 +287,6 @@ namespace MWSound
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void SoundManager::streamMusic(const std::string& filename)
 | 
					    void SoundManager::streamMusic(const std::string& filename)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::cout << filename << std::endl;
 | 
					 | 
				
			||||||
        std::string filePath = mMusicLibrary.locate(filename, mFSStrict).string();
 | 
					        std::string filePath = mMusicLibrary.locate(filename, mFSStrict).string();
 | 
				
			||||||
        if(!filePath.empty())
 | 
					        if(!filePath.empty())
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <boost/filesystem.hpp>
 | 
				
			||||||
#include <boost/algorithm/string.hpp>
 | 
					#include <boost/algorithm/string.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Files
 | 
					namespace Files
 | 
				
			||||||
| 
						 | 
					@ -22,13 +23,24 @@ namespace Files
 | 
				
			||||||
    void FileLibrary::add(const boost::filesystem::path &root, bool recursive, bool strict,
 | 
					    void FileLibrary::add(const boost::filesystem::path &root, bool recursive, bool strict,
 | 
				
			||||||
            const StringVector &acceptableExtensions)
 | 
					            const StringVector &acceptableExtensions)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        PathContainer list;
 | 
					        if (!boost::filesystem::exists(root))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            std::cout << "Warning " << root.string() << " does not exist.\n";
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        std::string fileExtension;
 | 
					        std::string fileExtension;
 | 
				
			||||||
        std::string type;
 | 
					        std::string type;
 | 
				
			||||||
        FileLister(root, list, recursive);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (PathContainer::iterator listIter = list.begin();
 | 
					        // remember the last location of the priority list when listing new items
 | 
				
			||||||
            listIter != list.end(); ++listIter)
 | 
					        int length = mPriorityList.size();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // First makes a list of all candidate files
 | 
				
			||||||
 | 
					        FileLister(root, mPriorityList, recursive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Then sort these files into sections according to the folder they belong to
 | 
				
			||||||
 | 
					        for (PathContainer::iterator listIter = mPriorityList.begin() + length;
 | 
				
			||||||
 | 
					            listIter != mPriorityList.end(); ++listIter)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if( !acceptableExtensions.empty() )
 | 
					            if( !acceptableExtensions.empty() )
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
| 
						 | 
					@ -82,12 +94,7 @@ namespace Files
 | 
				
			||||||
        boost::filesystem::path result("");
 | 
					        boost::filesystem::path result("");
 | 
				
			||||||
        if (sectionName == "")
 | 
					        if (sectionName == "")
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            for(StringPathContMap::iterator iter = mMap.begin(); iter != mMap.end(); iter++)
 | 
					            return FileListLocator(mPriorityList, boost::filesystem::path(item), strict);
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                result = FileListLocator(iter->second, boost::filesystem::path(item), strict);
 | 
					 | 
				
			||||||
                if (result != boost::filesystem::path(""))
 | 
					 | 
				
			||||||
                    return result;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,7 @@ namespace Files
 | 
				
			||||||
        private:
 | 
					        private:
 | 
				
			||||||
            StringPathContMap mMap;
 | 
					            StringPathContMap mMap;
 | 
				
			||||||
            PathContainer mEmptyPath;
 | 
					            PathContainer mEmptyPath;
 | 
				
			||||||
 | 
					            PathContainer mPriorityList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public:
 | 
					        public:
 | 
				
			||||||
            /// Searches a path and adds the results to the library
 | 
					            /// Searches a path and adds the results to the library
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue