diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 1961fbac6..b9fd3ca3a 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -1783,16 +1783,15 @@ namespace Glest { }; StaticSound *PlaySoundClip::getSound(const std::string& playSoundVal) { - CoreData coreData; - int loadAttemptLookupKey = coreData.tsyst_COUNT + 6; - if (coreData.itemLoadAttempted.find(loadAttemptLookupKey) == - coreData.itemLoadAttempted.end()) { - - coreData.itemLoadAttempted[loadAttemptLookupKey] = true; - + static int soundCtr = 0; + if (alertSoundMap.find(playSoundVal) == alertSoundMap.end()) { + alertSoundMap[playSoundVal] = soundCtr; + playSound.resize(soundCtr + 1); try { + CoreData & coreData = CoreData::getInstance(); string data_path = coreData.getDataPath(); - playSound.load(getGameCustomCoreDataPath(data_path, playSoundVal)); + playSound[soundCtr].load(getGameCustomCoreDataPath(data_path, playSoundVal)); + soundCtr++; } catch (const megaglest_runtime_error & ex) { message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), @@ -1800,7 +1799,7 @@ namespace Glest { } } - return &playSound; + return &playSound[alertSoundMap[playSoundVal]]; } // ================== PRIVATE ======================== diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index 73a6b5671..81dae8153 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -55,7 +55,6 @@ namespace Glest { class GameSettings; class CoreData { - friend class PlaySoundClip; private: std::map < int, bool > itemLoadAttempted; @@ -162,6 +161,8 @@ namespace Glest { void cleanup(); void loadFonts(); + string getDataPath(); + // Textures Texture2D *getTextureBySystemId(TextureSystemType type); @@ -309,7 +310,6 @@ namespace Glest { void loadMainMenuMedia(string data_path); void loadBattleEndMedia(string data_path); - string getDataPath(); void loadTextureIfRequired(Texture2D ** tex, string data_path, string uniqueFilePath, int texSystemId, bool setMipMap, bool setAlpha, @@ -336,7 +336,8 @@ namespace Glest { class PlaySoundClip { private: - StaticSound playSound; + std::vector playSound; + std::map alertSoundMap; public: StaticSound * getSound(const std::string& playSoundVal); static const string sfxAttention; @@ -346,6 +347,7 @@ namespace Glest { static const string sfxMenuClickA; static const string sfxMenuClickB; static const string sfxMenuClickC; + PlaySoundClip(); ~PlaySoundClip();