mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:19:55 +00:00
Don't play the same music track twice in a row (Fixes #746)
This commit is contained in:
parent
d60df66811
commit
d970cc06d7
2 changed files with 26 additions and 6 deletions
|
@ -179,6 +179,7 @@ namespace MWSound
|
|||
if(!mOutput->isInitialized())
|
||||
return;
|
||||
std::cout <<"Playing "<<filename<< std::endl;
|
||||
mLastPlayedMusic = filename;
|
||||
try
|
||||
{
|
||||
stopMusic();
|
||||
|
@ -203,7 +204,8 @@ namespace MWSound
|
|||
void SoundManager::startRandomTitle()
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -211,11 +213,25 @@ namespace MWSound
|
|||
"Music/"+mCurrentPlaylist+"/*");
|
||||
filelist.insert(filelist.end(), resourcesInThisGroup->begin(), resourcesInThisGroup->end());
|
||||
}
|
||||
mMusicFiles[mCurrentPlaylist] = filelist;
|
||||
}
|
||||
else
|
||||
filelist = mMusicFiles[mCurrentPlaylist];
|
||||
|
||||
if(!filelist.size())
|
||||
return;
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,10 @@ namespace MWSound
|
|||
|
||||
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 mSFXVolume;
|
||||
float mMusicVolume;
|
||||
|
|
Loading…
Reference in a new issue