diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-09-15 11:55:38 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-09-15 11:55:38 +0300 |
commit | be002b5d8b9137011e37df519ddc5d5174179103 (patch) | |
tree | 3b1f1bff7dbce4a73c923e557b8cdffaec96f31c /src/soundmanager.cpp | |
parent | 54d665ca2ff9244ef4b5a6dc48424d4a3364a40c (diff) | |
download | manaplus-be002b5d8b9137011e37df519ddc5d5174179103.tar.gz manaplus-be002b5d8b9137011e37df519ddc5d5174179103.tar.bz2 manaplus-be002b5d8b9137011e37df519ddc5d5174179103.tar.xz manaplus-be002b5d8b9137011e37df519ddc5d5174179103.zip |
add option to not unload sounds after using.
It configured by default for not unload sounds/music.
Diffstat (limited to 'src/soundmanager.cpp')
-rw-r--r-- | src/soundmanager.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/soundmanager.cpp b/src/soundmanager.cpp index 2a3f362b7..83d42e108 100644 --- a/src/soundmanager.cpp +++ b/src/soundmanager.cpp @@ -56,11 +56,12 @@ SoundManager::SoundManager(): mMusicVolume(60), mCurrentMusicFile(), mMusic(nullptr), + mGuiChannel(-1), mPlayBattle(false), mPlayGui(false), mPlayMusic(false), mFadeoutMusic(true), - mGuiChannel(-1) + mCacheSounds(true) { // This set up our callback function used to // handle fade outs endings. @@ -94,6 +95,8 @@ void SoundManager::optionChanged(const std::string &value) setMusicVolume(config.getIntValue("musicVolume")); else if (value == "fadeoutmusic") mFadeoutMusic = config.getIntValue("fadeoutmusic"); + else if (value == "uselonglivesounds") + mCacheSounds = config.getIntValue("uselonglivesounds"); } void SoundManager::init() @@ -110,6 +113,7 @@ void SoundManager::init() mFadeoutMusic = config.getBoolValue("fadeoutmusic"); mMusicVolume = config.getIntValue("musicVolume"); mSfxVolume = config.getIntValue("sfxVolume"); + mCacheSounds = config.getIntValue("uselonglivesounds"); config.addListener("playBattleSound", this); config.addListener("playGuiSound", this); @@ -117,6 +121,7 @@ void SoundManager::init() config.addListener("sfxVolume", this); config.addListener("musicVolume", this); config.addListener("fadeoutmusic", this); + config.addListener("uselonglivesounds", this); if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) { @@ -360,7 +365,7 @@ void SoundManager::playSfx(const std::string &path, else tmpPath = paths.getValue("sfx", "sfx/").append(path); ResourceManager *const resman = ResourceManager::getInstance(); - const SoundEffect *const sample = resman->getSoundEffect(tmpPath); + SoundEffect *const sample = resman->getSoundEffect(tmpPath); if (sample) { logger->log("SoundManager::playSfx() Playing: %s", path.c_str()); @@ -380,6 +385,8 @@ void SoundManager::playSfx(const std::string &path, vol -= dist * 8; } sample->play(0, vol); + if (!mCacheSounds) + sample->decRef(); } } @@ -400,13 +407,15 @@ void SoundManager::playGuiSfx(const std::string &path) else tmpPath = paths.getValue("sfx", "sfx/").append(path); ResourceManager *const resman = ResourceManager::getInstance(); - const SoundEffect *const sample = resman->getSoundEffect(tmpPath); + SoundEffect *const sample = resman->getSoundEffect(tmpPath); if (sample) { logger->log("SoundManager::playGuiSfx() Playing: %s", path.c_str()); const int ret = sample->play(0, 120, mGuiChannel); if (ret != -1) mGuiChannel = ret; + if (!mCacheSounds) + sample->decRef(); } } |