diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-05-24 04:29:03 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-05-24 04:29:03 +0300 |
commit | 9ba40776e3b0b00235e821c1157c6b4e0245417d (patch) | |
tree | 1934b95a1c73818d9e6f6d77d04b8daa8ef79e59 /src | |
parent | 3e5dbaaa903d4f4ea039902ab83259cb1e11a2f4 (diff) | |
download | plus-9ba40776e3b0b00235e821c1157c6b4e0245417d.tar.gz plus-9ba40776e3b0b00235e821c1157c6b4e0245417d.tar.bz2 plus-9ba40776e3b0b00235e821c1157c6b4e0245417d.tar.xz plus-9ba40776e3b0b00235e821c1157c6b4e0245417d.zip |
Fix asserts with missing default music files.
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 4 | ||||
-rw-r--r-- | src/dyetool/client.cpp | 4 | ||||
-rw-r--r-- | src/gui/widgets/tabs/setup_audio.cpp | 5 | ||||
-rw-r--r-- | src/net/ea/playerrecv.cpp | 3 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 4 | ||||
-rw-r--r-- | src/soundmanager.cpp | 27 | ||||
-rw-r--r-- | src/soundmanager.h | 5 | ||||
-rw-r--r-- | src/test/testlauncher.cpp | 2 |
8 files changed, 40 insertions, 14 deletions
diff --git a/src/client.cpp b/src/client.cpp index f026ecd33..325a11a40 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -536,7 +536,9 @@ void Client::initSoundManager() logger->log("Warning: %s", err); } soundManager.playMusic(branding.getValue( - "loginMusic", "Magick - Real.ogg")); + "loginMusic", + "Magick - Real.ogg"), + SkipError_true); } void Client::initGraphics() diff --git a/src/dyetool/client.cpp b/src/dyetool/client.cpp index 610617c34..a8f7270f0 100644 --- a/src/dyetool/client.cpp +++ b/src/dyetool/client.cpp @@ -352,7 +352,9 @@ void Client::initSoundManager() logger->log("Warning: %s", err); } soundManager.playMusic(branding.getValue( - "loginMusic", "Magick - Real.ogg")); + "loginMusic", + "Magick - Real.ogg"), + SkipError_true); } void Client::initGraphics() diff --git a/src/gui/widgets/tabs/setup_audio.cpp b/src/gui/widgets/tabs/setup_audio.cpp index 860a21f58..d6fc4e616 100644 --- a/src/gui/widgets/tabs/setup_audio.cpp +++ b/src/gui/widgets/tabs/setup_audio.cpp @@ -183,7 +183,10 @@ void Setup_Audio::apply() { const Map *const map = viewport->getMap(); if (map) - soundManager.playMusic(map->getMusicFile()); + { + soundManager.playMusic(map->getMusicFile(), + SkipError_false); + } } else { diff --git a/src/net/ea/playerrecv.cpp b/src/net/ea/playerrecv.cpp index 1b7add026..8035b9612 100644 --- a/src/net/ea/playerrecv.cpp +++ b/src/net/ea/playerrecv.cpp @@ -224,7 +224,8 @@ void PlayerRecv::processMapMusic(Net::MessageIn &msg) { const int size = msg.readInt16("len") - 5; const std::string music = msg.readString(size, "name"); - soundManager.playMusic(music); + soundManager.playMusic(music, + SkipError_false); Map *const map = viewport->getMap(); if (map) diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 7c3c0a2ca..b5cad0661 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -50,6 +50,7 @@ #include "utils/base64.h" #include "utils/delete2.h" +#include "utils/physfstools.h" #include "utils/stringmap.h" #include <zlib.h> @@ -1209,5 +1210,6 @@ void MapReader::updateMusic(Map *const map) if (p != std::string::npos) name = name.substr(0, p); name.append(".ogg"); - map->setProperty("music", name); + if (PhysFs::exists(paths.getStringValue("music").append(name).c_str())) + map->setProperty("music", name); } diff --git a/src/soundmanager.cpp b/src/soundmanager.cpp index 42a642188..45490d497 100644 --- a/src/soundmanager.cpp +++ b/src/soundmanager.cpp @@ -33,6 +33,9 @@ #include "resources/resourcemanager.h" #include "resources/soundeffect.h" +#include "utils/checkutils.h" +#include "utils/physfstools.h" + #include <SDL.h> #include "debug.h" @@ -172,7 +175,7 @@ void SoundManager::init() mInstalled = true; if (!mCurrentMusicFile.empty() && mPlayMusic) - playMusic(mCurrentMusicFile); + playMusic(mCurrentMusicFile, SkipError_true); } void SoundManager::testAudio() @@ -316,13 +319,21 @@ void SoundManager::setSfxVolume(const int volume) Mix_Volume(-1, mSfxVolume); } -static SDLMusic *loadMusic(const std::string &fileName) +static SDLMusic *loadMusic(const std::string &fileName, + const SkipError skipError) { - return resourceManager->getMusic( - paths.getStringValue("music").append(fileName)); + const std::string path = paths.getStringValue("music").append(fileName); + if (!PhysFs::exists(path.c_str())) + { + if (skipError == SkipError_false) + reportAlways("Music file not found: %s", fileName.c_str()); + return nullptr; + } + return resourceManager->getMusic(path); } -void SoundManager::playMusic(const std::string &fileName) +void SoundManager::playMusic(const std::string &fileName, + const SkipError skipError) { if (!mInstalled || !mPlayMusic) return; @@ -336,7 +347,8 @@ void SoundManager::playMusic(const std::string &fileName) if (!fileName.empty()) { - mMusic = loadMusic(fileName); + mMusic = loadMusic(fileName, + skipError); if (mMusic) mMusic->play(); } @@ -416,7 +428,8 @@ void SoundManager::logic() if (!mNextMusicFile.empty()) { - playMusic(mNextMusicFile); + playMusic(mNextMusicFile, + SkipError_false); mNextMusicFile.clear(); } } diff --git a/src/soundmanager.h b/src/soundmanager.h index 8de7b0dfa..fa30d3aeb 100644 --- a/src/soundmanager.h +++ b/src/soundmanager.h @@ -33,6 +33,8 @@ #endif #include <SDL_mixer.h> +#include "enums/simpletypes/skiperror.h" + #include "listeners/configlistener.h" #include "localconsts.h" @@ -71,7 +73,8 @@ class SoundManager final : public ConfigListener * * @param fileName The name of the music file. */ - void playMusic(const std::string &fileName); + void playMusic(const std::string &fileName, + const SkipError skipError); /** * Stops currently running background music track. diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp index cc3074965..9c1ee464a 100644 --- a/src/test/testlauncher.cpp +++ b/src/test/testlauncher.cpp @@ -134,7 +134,7 @@ int TestLauncher::testSound() const soundManager.playGuiSfx("system/newmessage.ogg"); sleep(1); soundManager.playSfx("system/newmessage.ogg", 0, 0); - soundManager.playMusic("sfx/system/newmessage.ogg"); + soundManager.playMusic("sfx/system/newmessage.ogg", SkipError_false); sleep(3); soundManager.stopMusic(); return 0; |