diff options
author | krzys-h <krzys_h@interia.pl> | 2013-12-31 16:58:21 +0100 |
---|---|---|
committer | krzys-h <krzys_h@interia.pl> | 2013-12-31 16:58:21 +0100 |
commit | 999490e88bc699b671b94b88c9a4327d963db378 (patch) | |
tree | d2f27e5c80fe00358e5759e9ee40b2fd11d1ccff /src/sound/oalsound | |
parent | 4a237f5925eb0d371e097416b17dd5e919cd2258 (diff) | |
download | colobot-999490e88bc699b671b94b88c9a4327d963db378.tar.gz colobot-999490e88bc699b671b94b88c9a4327d963db378.tar.bz2 colobot-999490e88bc699b671b94b88c9a4327d963db378.zip |
Code for changing music in pause mode
As requested by @Emxx52. Only code for now, we don't have the music yet. Temporairly in developements builds music will change to Prototype (in CBot editor) and Constructive Destruction (in SatCom)
Diffstat (limited to 'src/sound/oalsound')
-rw-r--r-- | src/sound/oalsound/alsound.cpp | 54 | ||||
-rw-r--r-- | src/sound/oalsound/alsound.h | 9 | ||||
-rw-r--r-- | src/sound/oalsound/channel.cpp | 15 | ||||
-rw-r--r-- | src/sound/oalsound/channel.h | 1 |
4 files changed, 76 insertions, 3 deletions
diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 7f5d1f1..5058141 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -31,6 +31,8 @@ ALSound::ALSound() m_currentMusic = nullptr; m_eye.LoadZero(); m_lookat.LoadZero(); + m_previousMusic.fadeTime = 0.0f; + m_previousMusic.music = nullptr; } @@ -62,6 +64,11 @@ void ALSound::CleanUp() { delete item.music; } + + if (m_previousMusic.music) + { + delete m_previousMusic.music; + } for (auto item : m_sounds) { @@ -552,6 +559,15 @@ void ALSound::FrameMove(float delta) } } + if (m_previousMusic.fadeTime > 0.0f) { + if (m_previousMusic.currentTime >= m_previousMusic.fadeTime) { + m_previousMusic.music->Pause(); + } else { + m_previousMusic.currentTime += delta; + m_previousMusic.music->SetVolume(((m_previousMusic.fadeTime-m_previousMusic.currentTime) / m_previousMusic.fadeTime) * m_musicVolume); + } + } + for (auto it : toRemove) m_oldMusic.remove(it); } @@ -609,6 +625,7 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim buffer = new Buffer(); buffer->LoadFromFile(file.str(), static_cast<Sound>(-1)); + m_music[filename] = buffer; } else { @@ -633,6 +650,43 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim return true; } +bool ALSound::PlayPauseMusic(const std::string &filename) +{ + if (m_previousMusic.fadeTime > 0.0f) { + OldMusic old; + old.music = m_currentMusic; + old.fadeTime = 2.0f; + old.currentTime = 0.0f; + m_oldMusic.push_back(old); + m_currentMusic = nullptr; + } else { + if (m_currentMusic) { + m_previousMusic.music = m_currentMusic; + m_previousMusic.fadeTime = 2.0f; + m_previousMusic.currentTime = 0.0f; + m_currentMusic = nullptr; + } + } + return PlayMusic(filename, true); +} + +void ALSound::StopPauseMusic() +{ + if (m_previousMusic.fadeTime > 0.0f) { + StopMusic(); + + m_currentMusic = m_previousMusic.music; + m_previousMusic.music = nullptr; + if(m_currentMusic != nullptr) { + m_currentMusic->SetVolume(m_musicVolume); + if(m_previousMusic.currentTime >= m_previousMusic.fadeTime) { + m_currentMusic->Play(); + } + } + m_previousMusic.fadeTime = 0.0f; + } +} + bool ALSound::RestartMusic() { diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index cd3bdd5..6fb832e 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -72,12 +72,14 @@ public: bool StopAll(); bool MuteAll(bool bMute); - bool PlayMusic(int rank, bool bRepeat, float fadeTime=5.0f); - bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=5.0f); + bool PlayMusic(int rank, bool bRepeat, float fadeTime=2.0f); + bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=2.0f); bool RestartMusic(); void SuspendMusic(); - void StopMusic(float fadeTime=5.0f); + void StopMusic(float fadeTime=2.0f); bool IsPlayingMusic(); + bool PlayPauseMusic(const std::string &filename); + void StopPauseMusic(); private: void CleanUp(); @@ -94,6 +96,7 @@ private: std::map<int, Channel*> m_channels; Channel *m_currentMusic; std::list<OldMusic> m_oldMusic; + OldMusic m_previousMusic; Math::Vector m_eye; Math::Vector m_lookat; }; diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index b053316..e58ab54 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -74,6 +74,21 @@ bool Channel::Play() return true; } +bool Channel::Pause() +{ + if(!m_ready || !IsPlaying()) + { + return false; + } + + alSourcePause(m_source); + if (alCheck()) + { + GetLogger()->Warn("Could not pause audio sound source. Code: %d\n", alGetCode()); + } + return true; +} + bool Channel::SetPosition(const Math::Vector &pos) { diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index 0c6cafc..f973198 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -50,6 +50,7 @@ public: ~Channel(); bool Play(); + bool Pause(); bool Stop(); bool SetPosition(const Math::Vector &); |