Made announcers repeat their lines less

This commit is contained in:
Mark Blum
2018-01-20 15:23:12 -05:00
parent 598e70dbb7
commit e125053f4c
+25 -1
View File
@@ -83,6 +83,8 @@ static RageThread MusicThread;
vector<RString> g_SoundsToPlayOnce;
vector<RString> g_SoundsToPlayOnceFromDir;
vector<RString> g_SoundsToPlayOnceFromAnnouncer;
// This should get updated to unordered_map when once C++11 is supported
std::map<RString, vector<int>> g_DirSoundOrder;
struct MusicToPlay
{
@@ -298,9 +300,31 @@ static void DoPlayOnceFromDir( RString sPath )
GetDirListing( sPath + "*.oga", arraySoundFiles );
if( arraySoundFiles.empty() )
{
return;
}
else if (arraySoundFiles.size() == 1)
{
DoPlayOnce( sPath + arraySoundFiles[0] );
return;
}
g_Mutex->Lock();
vector<int> &order = g_DirSoundOrder.insert({sPath, vector<int>()}).first->second;
// If order is exhausted, repopulate and reshuffle
if (order.size() == 0)
{
for (int i = 0; i < arraySoundFiles.size(); ++i)
{
order.push_back(i);
}
std::random_shuffle(order.begin(), order.end());
}
int index = order.back();
order.pop_back();
g_Mutex->Unlock();
int index = RandomInt( arraySoundFiles.size( ));
DoPlayOnce( sPath + arraySoundFiles[index] );
}