core_data:improve playSound function

@Jammyjamjamman after playing with this code I started understanding better what you were trying to explain to me (months ago). I believe this will now work as intended.
This commit is contained in:
Andy Alt
2018-09-23 22:43:14 -05:00
committed by GitHub
parent e82c807491
commit 0f26a90df7
2 changed files with 13 additions and 12 deletions

View File

@@ -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 ========================

View File

@@ -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<StaticSound> playSound;
std::map <string, int> 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();