1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-21 21:17:49 +02:00

CAudioBase: move mutex to base class since CSoundHandler need it

This commit is contained in:
Arseniy Shestakov 2017-09-14 11:57:19 +03:00 committed by DJWarmonger
parent c5ca75bc53
commit d96a3aa5b7
2 changed files with 7 additions and 7 deletions

View File

@ -281,6 +281,7 @@ bool CSoundHandler::ambientCheckVisitable() const
void CSoundHandler::ambientUpdateChannels(std::map<std::string, int> sounds) void CSoundHandler::ambientUpdateChannels(std::map<std::string, int> sounds)
{ {
boost::mutex::scoped_lock guard(mutex);
std::vector<std::string> stoppedSounds; std::vector<std::string> stoppedSounds;
for(auto & pair : ambientChannels) for(auto & pair : ambientChannels)
{ {
@ -310,6 +311,7 @@ void CSoundHandler::ambientUpdateChannels(std::map<std::string, int> sounds)
void CSoundHandler::ambientStopAllChannels() void CSoundHandler::ambientStopAllChannels()
{ {
boost::mutex::scoped_lock guard(mutex);
for(auto ch : ambientChannels) for(auto ch : ambientChannels)
{ {
ambientStopSound(ch.first); ambientStopSound(ch.first);
@ -375,7 +377,7 @@ void CMusicHandler::release()
{ {
if (initialized) if (initialized)
{ {
boost::mutex::scoped_lock guard(musicMutex); boost::mutex::scoped_lock guard(mutex);
Mix_HookMusicFinished(nullptr); Mix_HookMusicFinished(nullptr);
@ -439,7 +441,7 @@ void CMusicHandler::queueNext(std::unique_ptr<MusicEntry> queued)
if (!initialized) if (!initialized)
return; return;
boost::mutex::scoped_lock guard(musicMutex); boost::mutex::scoped_lock guard(mutex);
next = std::move(queued); next = std::move(queued);
@ -468,7 +470,7 @@ void CMusicHandler::stopMusic(int fade_ms)
if (!initialized) if (!initialized)
return; return;
boost::mutex::scoped_lock guard(musicMutex); boost::mutex::scoped_lock guard(mutex);
if (current.get() != nullptr) if (current.get() != nullptr)
current->stop(fade_ms); current->stop(fade_ms);
@ -485,7 +487,7 @@ void CMusicHandler::setVolume(ui32 percent)
void CMusicHandler::musicFinishedCallback(void) void CMusicHandler::musicFinishedCallback(void)
{ {
boost::mutex::scoped_lock guard(musicMutex); boost::mutex::scoped_lock guard(mutex);
if (current.get() != nullptr) if (current.get() != nullptr)
{ {

View File

@ -20,6 +20,7 @@ struct Mix_Chunk;
class CAudioBase { class CAudioBase {
protected: protected:
boost::mutex mutex;
bool initialized; bool initialized;
int volume; // from 0 (mute) to 100 int volume; // from 0 (mute) to 100
@ -118,9 +119,6 @@ public:
class CMusicHandler: public CAudioBase class CMusicHandler: public CAudioBase
{ {
private: private:
// Because we use the SDL music callback, our music variables must
// be protected
boost::mutex musicMutex;
//update volume on configuration change //update volume on configuration change
SettingsListener listener; SettingsListener listener;
void onVolumeChange(const JsonNode &volumeNode); void onVolumeChange(const JsonNode &volumeNode);