From a8e01ed69d7d56c8c7c03ade55b7a83350680796 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Thu, 31 Jan 2013 20:00:38 +0000 Subject: [PATCH] ios stuff --- .../Salmon Engine.xcodeproj/project.pbxproj | 2 +- include/SoundManager/SoundManagerIos.h | 5 ++ src/SoundManager/SoundManagerIos.mm | 49 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/iOS/Salmon Engine/Salmon Engine.xcodeproj/project.pbxproj b/iOS/Salmon Engine/Salmon Engine.xcodeproj/project.pbxproj index 8d50aed..7fdd592 100644 --- a/iOS/Salmon Engine/Salmon Engine.xcodeproj/project.pbxproj +++ b/iOS/Salmon Engine/Salmon Engine.xcodeproj/project.pbxproj @@ -306,6 +306,7 @@ 4C8CE91215B0A0FB00078175 /* src */ = { isa = PBXGroup; children = ( + 4C8CE94015B0A57F00078175 /* Console */, 4CF8747416B65183009B1214 /* GUIManager */, 4CF8747316B65173009B1214 /* HalibutAnimation */, 4CF8747116B6514F009B1214 /* PhysicsManager */, @@ -387,7 +388,6 @@ 4C8CE96B15B0B31F00078175 /* PngHelper.h */, 4C8CE94B15B0AA8000078175 /* Utils.h */, 4C8CE94D15B0AA9600078175 /* SerializeInterface */, - 4C8CE94015B0A57F00078175 /* Console */, 4C8CE94215B0A57F00078175 /* ErrorTypes */, 4C8CE94415B0A57F00078175 /* FileUtils */, 4C8CE91415B0A11A00078175 /* DataTypes */, diff --git a/include/SoundManager/SoundManagerIos.h b/include/SoundManager/SoundManagerIos.h index 4f86361..1bd0fcc 100644 --- a/include/SoundManager/SoundManagerIos.h +++ b/include/SoundManager/SoundManagerIos.h @@ -30,6 +30,11 @@ public: virtual void PlayMusicLooped(const std::string& musicName); virtual void StopMusic(const std::string& musicName); + virtual void StopAllMusic(); + + virtual void TryStopAndPlayMusicLooped(const std::string& musicName); + + }; diff --git a/src/SoundManager/SoundManagerIos.mm b/src/SoundManager/SoundManagerIos.mm index 1d283da..5dcbb7e 100644 --- a/src/SoundManager/SoundManagerIos.mm +++ b/src/SoundManager/SoundManagerIos.mm @@ -104,6 +104,8 @@ void TSoundManagerIos::PlayMusic(const std::string& musicName) AudioSourceMap[musicName].looped = false; [AudioSourceMap[musicName] playAtListenerPosition]; + + //AudioSourceMap[musicName].isPlaying = true; } void TSoundManagerIos::PlayMusicLooped(const std::string& musicName) @@ -116,6 +118,8 @@ void TSoundManagerIos::PlayMusicLooped(const std::string& musicName) AudioSourceMap[musicName].looped = true; [AudioSourceMap[musicName] playAtListenerPosition]; + + //AudioSourceMap[musicName].isPlaying = true; } void TSoundManagerIos::StopMusic(const std::string& musicName) @@ -126,7 +130,52 @@ void TSoundManagerIos::StopMusic(const std::string& musicName) } [AudioSourceMap[musicName] stop]; + //AudioSourceMap[musicName].isPlaying = false; } +void TSoundManagerIos::StopAllMusic() +{ + for (auto i = AudioSourceMap.begin(); i != AudioSourceMap.end(); ++i) + { + PASoundSource* s = i->second; + if (s.isPlaying) + { + [s stop]; + //s.isPlaying = false; + } + } +} + +void TSoundManagerIos::TryStopAndPlayMusicLooped(const std::string& musicName) +{ + if (AudioSourceMap.count(musicName) == 0) + { + throw ErrorToLog("Sound or music not exists: "+musicName); + } + + for (auto i = AudioSourceMap.begin(); i != AudioSourceMap.end(); ++i) + { + if (i->first != musicName) + { + PASoundSource* s = i->second; + if (s.isPlaying) + { + [s stop]; + //s.isPlaying = false; + } + } + } + + PASoundSource* s = AudioSourceMap[musicName]; + + if (!s.isPlaying) + { + AudioSourceMap[musicName].looped = true; + + //AudioSourceMap[musicName].isPlaying = true; + + [AudioSourceMap[musicName] playAtListenerPosition]; + } +} } //namespace SE \ No newline at end of file