mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-14 01:19:59 +00:00
Use normalized path to store playlist music files
This commit is contained in:
parent
82931059fd
commit
38b005cda6
@ -300,13 +300,16 @@ namespace MWSound
|
||||
|
||||
void SoundManager::startRandomTitle()
|
||||
{
|
||||
const std::vector<std::string>& filelist = mMusicFiles[mCurrentPlaylist];
|
||||
if (filelist.empty())
|
||||
const auto playlist = mMusicFiles.find(mCurrentPlaylist);
|
||||
|
||||
if (playlist == mMusicFiles.end() || playlist->second.empty())
|
||||
{
|
||||
advanceMusic(std::string());
|
||||
return;
|
||||
}
|
||||
|
||||
const std::vector<VFS::Path::Normalized>& filelist = playlist->second;
|
||||
|
||||
auto& tracklist = mMusicToPlay[mCurrentPlaylist];
|
||||
|
||||
// Do a Fisher-Yates shuffle
|
||||
@ -359,18 +362,20 @@ namespace MWSound
|
||||
if (mCurrentPlaylist == playlist)
|
||||
return;
|
||||
|
||||
if (mMusicFiles.find(playlist) == mMusicFiles.end())
|
||||
auto it = mMusicFiles.find(playlist);
|
||||
|
||||
if (it == mMusicFiles.end())
|
||||
{
|
||||
std::vector<std::string> filelist;
|
||||
std::vector<VFS::Path::Normalized> filelist;
|
||||
auto playlistPath = Misc::ResourceHelpers::correctMusicPath(playlist) + '/';
|
||||
for (const auto& name : mVFS->getRecursiveDirectoryIterator(playlistPath))
|
||||
filelist.push_back(name);
|
||||
|
||||
mMusicFiles[playlist] = std::move(filelist);
|
||||
it = mMusicFiles.emplace_hint(it, playlist, std::move(filelist));
|
||||
}
|
||||
|
||||
// No Battle music? Use Explore playlist
|
||||
if (playlist == "Battle" && mMusicFiles[playlist].empty())
|
||||
if (playlist == "Battle" && it->second.empty())
|
||||
{
|
||||
playPlaylist("Explore");
|
||||
return;
|
||||
|
@ -52,7 +52,7 @@ namespace MWSound
|
||||
std::unique_ptr<Sound_Output> mOutput;
|
||||
|
||||
// Caches available music tracks by <playlist name, (sound files) >
|
||||
std::unordered_map<std::string, std::vector<std::string>> mMusicFiles;
|
||||
std::unordered_map<std::string, std::vector<VFS::Path::Normalized>> mMusicFiles;
|
||||
std::unordered_map<std::string, std::vector<int>> mMusicToPlay; // A list with music files not yet played
|
||||
std::string mLastPlayedMusic; // The music file that was last played
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user