1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 19:19:56 +00:00

Don't play the same music track twice in a row (Fixes #746)

This commit is contained in:
scrawl 2014-06-11 18:10:58 +02:00
parent d60df66811
commit d970cc06d7
2 changed files with 26 additions and 6 deletions

View file

@ -179,6 +179,7 @@ namespace MWSound
if(!mOutput->isInitialized()) if(!mOutput->isInitialized())
return; return;
std::cout <<"Playing "<<filename<< std::endl; std::cout <<"Playing "<<filename<< std::endl;
mLastPlayedMusic = filename;
try try
{ {
stopMusic(); stopMusic();
@ -203,19 +204,34 @@ namespace MWSound
void SoundManager::startRandomTitle() void SoundManager::startRandomTitle()
{ {
Ogre::StringVector filelist; Ogre::StringVector filelist;
if (mMusicFiles.find(mCurrentPlaylist) == mMusicFiles.end())
Ogre::StringVector groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups ();
for (Ogre::StringVector::iterator it = groups.begin(); it != groups.end(); ++it)
{ {
Ogre::StringVectorPtr resourcesInThisGroup = mResourceMgr.findResourceNames(*it, Ogre::StringVector groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups ();
"Music/"+mCurrentPlaylist+"/*"); for (Ogre::StringVector::iterator it = groups.begin(); it != groups.end(); ++it)
filelist.insert(filelist.end(), resourcesInThisGroup->begin(), resourcesInThisGroup->end()); {
Ogre::StringVectorPtr resourcesInThisGroup = mResourceMgr.findResourceNames(*it,
"Music/"+mCurrentPlaylist+"/*");
filelist.insert(filelist.end(), resourcesInThisGroup->begin(), resourcesInThisGroup->end());
}
mMusicFiles[mCurrentPlaylist] = filelist;
} }
else
filelist = mMusicFiles[mCurrentPlaylist];
if(!filelist.size()) if(!filelist.size())
return; return;
int i = rand()%filelist.size(); int i = rand()%filelist.size();
// Don't play the same music track twice in a row
if (filelist[i] == mLastPlayedMusic)
{
if (i-1 == int(filelist.size()))
i = 0;
else
++i;
}
streamMusicFull(filelist[i]); streamMusicFull(filelist[i]);
} }

View file

@ -31,6 +31,10 @@ namespace MWSound
std::auto_ptr<Sound_Output> mOutput; std::auto_ptr<Sound_Output> mOutput;
// Caches available music tracks by <playlist name, (sound files) >
std::map<std::string, Ogre::StringVector> mMusicFiles;
std::string mLastPlayedMusic; // The music file that was last played
float mMasterVolume; float mMasterVolume;
float mSFXVolume; float mSFXVolume;
float mMusicVolume; float mMusicVolume;