From e125053f4c2a562ee01817c8499d020230c72ac1 Mon Sep 17 00:00:00 2001 From: Mark Blum Date: Sat, 20 Jan 2018 15:23:12 -0500 Subject: [PATCH] Made announcers repeat their lines less --- src/GameSoundManager.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/GameSoundManager.cpp b/src/GameSoundManager.cpp index 34c810b922..170b1f954c 100644 --- a/src/GameSoundManager.cpp +++ b/src/GameSoundManager.cpp @@ -83,6 +83,8 @@ static RageThread MusicThread; vector g_SoundsToPlayOnce; vector g_SoundsToPlayOnceFromDir; vector g_SoundsToPlayOnceFromAnnouncer; +// This should get updated to unordered_map when once C++11 is supported +std::map> 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 &order = g_DirSoundOrder.insert({sPath, vector()}).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] ); }