mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-23 14:11:34 +00:00
Use normalized path to store playlist music files
This commit is contained in:
parent
82931059fd
commit
38b005cda6
2 changed files with 12 additions and 7 deletions
|
@ -300,13 +300,16 @@ namespace MWSound
|
||||||
|
|
||||||
void SoundManager::startRandomTitle()
|
void SoundManager::startRandomTitle()
|
||||||
{
|
{
|
||||||
const std::vector<std::string>& filelist = mMusicFiles[mCurrentPlaylist];
|
const auto playlist = mMusicFiles.find(mCurrentPlaylist);
|
||||||
if (filelist.empty())
|
|
||||||
|
if (playlist == mMusicFiles.end() || playlist->second.empty())
|
||||||
{
|
{
|
||||||
advanceMusic(std::string());
|
advanceMusic(std::string());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<VFS::Path::Normalized>& filelist = playlist->second;
|
||||||
|
|
||||||
auto& tracklist = mMusicToPlay[mCurrentPlaylist];
|
auto& tracklist = mMusicToPlay[mCurrentPlaylist];
|
||||||
|
|
||||||
// Do a Fisher-Yates shuffle
|
// Do a Fisher-Yates shuffle
|
||||||
|
@ -359,18 +362,20 @@ namespace MWSound
|
||||||
if (mCurrentPlaylist == playlist)
|
if (mCurrentPlaylist == playlist)
|
||||||
return;
|
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) + '/';
|
auto playlistPath = Misc::ResourceHelpers::correctMusicPath(playlist) + '/';
|
||||||
for (const auto& name : mVFS->getRecursiveDirectoryIterator(playlistPath))
|
for (const auto& name : mVFS->getRecursiveDirectoryIterator(playlistPath))
|
||||||
filelist.push_back(name);
|
filelist.push_back(name);
|
||||||
|
|
||||||
mMusicFiles[playlist] = std::move(filelist);
|
it = mMusicFiles.emplace_hint(it, playlist, std::move(filelist));
|
||||||
}
|
}
|
||||||
|
|
||||||
// No Battle music? Use Explore playlist
|
// No Battle music? Use Explore playlist
|
||||||
if (playlist == "Battle" && mMusicFiles[playlist].empty())
|
if (playlist == "Battle" && it->second.empty())
|
||||||
{
|
{
|
||||||
playPlaylist("Explore");
|
playPlaylist("Explore");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace MWSound
|
||||||
std::unique_ptr<Sound_Output> mOutput;
|
std::unique_ptr<Sound_Output> mOutput;
|
||||||
|
|
||||||
// Caches available music tracks by <playlist name, (sound files) >
|
// 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::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
|
std::string mLastPlayedMusic; // The music file that was last played
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue