mirror of
https://github.com/glest/glest-source.git
synced 2025-09-01 20:12:40 +02:00
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:
@@ -1783,16 +1783,15 @@ namespace Glest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
StaticSound *PlaySoundClip::getSound(const std::string& playSoundVal) {
|
StaticSound *PlaySoundClip::getSound(const std::string& playSoundVal) {
|
||||||
CoreData coreData;
|
static int soundCtr = 0;
|
||||||
int loadAttemptLookupKey = coreData.tsyst_COUNT + 6;
|
if (alertSoundMap.find(playSoundVal) == alertSoundMap.end()) {
|
||||||
if (coreData.itemLoadAttempted.find(loadAttemptLookupKey) ==
|
alertSoundMap[playSoundVal] = soundCtr;
|
||||||
coreData.itemLoadAttempted.end()) {
|
playSound.resize(soundCtr + 1);
|
||||||
|
|
||||||
coreData.itemLoadAttempted[loadAttemptLookupKey] = true;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
CoreData & coreData = CoreData::getInstance();
|
||||||
string data_path = coreData.getDataPath();
|
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) {
|
} catch (const megaglest_runtime_error & ex) {
|
||||||
message(ex.what(),
|
message(ex.what(),
|
||||||
GlobalStaticFlags::getIsNonGraphicalModeEnabled(),
|
GlobalStaticFlags::getIsNonGraphicalModeEnabled(),
|
||||||
@@ -1800,7 +1799,7 @@ namespace Glest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &playSound;
|
return &playSound[alertSoundMap[playSoundVal]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================== PRIVATE ========================
|
// ================== PRIVATE ========================
|
||||||
|
@@ -55,7 +55,6 @@ namespace Glest {
|
|||||||
class GameSettings;
|
class GameSettings;
|
||||||
|
|
||||||
class CoreData {
|
class CoreData {
|
||||||
friend class PlaySoundClip;
|
|
||||||
private:
|
private:
|
||||||
std::map < int, bool > itemLoadAttempted;
|
std::map < int, bool > itemLoadAttempted;
|
||||||
|
|
||||||
@@ -162,6 +161,8 @@ namespace Glest {
|
|||||||
void cleanup();
|
void cleanup();
|
||||||
void loadFonts();
|
void loadFonts();
|
||||||
|
|
||||||
|
string getDataPath();
|
||||||
|
|
||||||
// Textures
|
// Textures
|
||||||
Texture2D *getTextureBySystemId(TextureSystemType type);
|
Texture2D *getTextureBySystemId(TextureSystemType type);
|
||||||
|
|
||||||
@@ -309,7 +310,6 @@ namespace Glest {
|
|||||||
void loadMainMenuMedia(string data_path);
|
void loadMainMenuMedia(string data_path);
|
||||||
void loadBattleEndMedia(string data_path);
|
void loadBattleEndMedia(string data_path);
|
||||||
|
|
||||||
string getDataPath();
|
|
||||||
void loadTextureIfRequired(Texture2D ** tex, string data_path,
|
void loadTextureIfRequired(Texture2D ** tex, string data_path,
|
||||||
string uniqueFilePath, int texSystemId,
|
string uniqueFilePath, int texSystemId,
|
||||||
bool setMipMap, bool setAlpha,
|
bool setMipMap, bool setAlpha,
|
||||||
@@ -336,7 +336,8 @@ namespace Glest {
|
|||||||
|
|
||||||
class PlaySoundClip {
|
class PlaySoundClip {
|
||||||
private:
|
private:
|
||||||
StaticSound playSound;
|
std::vector<StaticSound> playSound;
|
||||||
|
std::map <string, int> alertSoundMap;
|
||||||
public:
|
public:
|
||||||
StaticSound * getSound(const std::string& playSoundVal);
|
StaticSound * getSound(const std::string& playSoundVal);
|
||||||
static const string sfxAttention;
|
static const string sfxAttention;
|
||||||
@@ -346,6 +347,7 @@ namespace Glest {
|
|||||||
static const string sfxMenuClickA;
|
static const string sfxMenuClickA;
|
||||||
static const string sfxMenuClickB;
|
static const string sfxMenuClickB;
|
||||||
static const string sfxMenuClickC;
|
static const string sfxMenuClickC;
|
||||||
|
|
||||||
PlaySoundClip();
|
PlaySoundClip();
|
||||||
~PlaySoundClip();
|
~PlaySoundClip();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user