From 0ec3f29e68d8bcd105f3883cb272f04358cd80d1 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 14 Aug 2015 19:44:31 +0200 Subject: [PATCH] Fixed win/lost scene music cached at startup not being ever used --- src/level/robotmain.cpp | 18 +++++++++--------- src/level/scene_conditions.cpp | 2 +- src/sound/oalsound/alsound.cpp | 25 +++++++++---------------- src/sound/oalsound/alsound.h | 2 -- src/sound/sound.cpp | 13 ++++--------- src/sound/sound.h | 9 --------- src/ui/mainui.cpp | 8 ++++---- 7 files changed, 27 insertions(+), 50 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index d14762c9..1a61ef9f 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -2877,7 +2877,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { std::string filename = line->GetParam("filename")->AsPath("music"); m_ui->GetLoadingScreen()->SetProgress(0.15f, RT_LOADING_MUSIC, filename); - m_sound->CacheMusic(std::string("../")+filename); + m_sound->CacheMusic(filename); continue; } @@ -2885,7 +2885,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { auto audioChange = MakeUnique(); audioChange->Read(line.get()); - m_ui->GetLoadingScreen()->SetProgress(0.15f, RT_LOADING_MUSIC, CResourceManager::CleanPath("music/"+audioChange->music)); + m_ui->GetLoadingScreen()->SetProgress(0.15f, RT_LOADING_MUSIC, audioChange->music); m_sound->CacheMusic(audioChange->music); m_audioChange.push_back(std::move(audioChange)); continue; @@ -2903,7 +2903,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (trackid != 0) { std::stringstream filenameStr; - filenameStr << "music" << std::setfill('0') << std::setw(3) << trackid << ".ogg"; + filenameStr << "music/music" << std::setfill('0') << std::setw(3) << trackid << ".ogg"; m_audioTrack = filenameStr.str(); } else @@ -2915,7 +2915,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { if (line->GetParam("filename")->IsDefined()) { - m_audioTrack = "../"+line->GetParam("filename")->AsPath("music"); + m_audioTrack = line->GetParam("filename")->AsPath("music"); } else { @@ -2929,7 +2929,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetParam("satcom")->IsDefined()) { - m_satcomTrack = "../"+line->GetParam("satcom")->AsPath("music"); + m_satcomTrack = line->GetParam("satcom")->AsPath("music"); m_satcomRepeat = line->GetParam("satcomRepeat")->AsBool(true); } else @@ -2939,7 +2939,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetParam("editor")->IsDefined()) { - m_editorTrack = "../"+line->GetParam("editor")->AsPath("music"); + m_editorTrack = line->GetParam("editor")->AsPath("music"); m_editorRepeat = line->GetParam("editorRepeat")->AsBool(true); } else @@ -2949,18 +2949,18 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (!m_audioTrack.empty()) { - m_ui->GetLoadingScreen()->SetProgress(0.15f, RT_LOADING_MUSIC, CResourceManager::CleanPath("music/"+m_audioTrack)); + m_ui->GetLoadingScreen()->SetProgress(0.15f, RT_LOADING_MUSIC, m_audioTrack); m_sound->CacheMusic(m_audioTrack); } if (!m_satcomTrack.empty()) { + m_ui->GetLoadingScreen()->SetProgress(0.15f, RT_LOADING_MUSIC, m_satcomTrack); m_sound->CacheMusic(m_satcomTrack); - m_ui->GetLoadingScreen()->SetProgress(0.15f, RT_LOADING_MUSIC, CResourceManager::CleanPath("music/"+m_satcomTrack)); } if (!m_editorTrack.empty()) { + m_ui->GetLoadingScreen()->SetProgress(0.15f, RT_LOADING_MUSIC, m_editorTrack); m_sound->CacheMusic(m_editorTrack); - m_ui->GetLoadingScreen()->SetProgress(0.15f, RT_LOADING_MUSIC, CResourceManager::CleanPath("music/"+m_editorTrack)); } continue; } diff --git a/src/level/scene_conditions.cpp b/src/level/scene_conditions.cpp index e774a1f1..df294756 100644 --- a/src/level/scene_conditions.cpp +++ b/src/level/scene_conditions.cpp @@ -166,6 +166,6 @@ Error CSceneEndCondition::GetMissionResult() void CAudioChangeCondition::Read(CLevelParserLine* line) { CSceneCondition::Read(line); - this->music = std::string("../")+line->GetParam("filename")->AsPath("music"); + this->music = line->GetParam("filename")->AsPath("music"); this->repeat = line->GetParam("repeat")->AsBool(true); } diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index dcaf92d4..d290fe75 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -156,12 +156,12 @@ bool ALSound::Cache(SoundType sound, const std::string &filename) bool ALSound::CacheMusic(const std::string &filename) { - if (m_music.find("music/"+filename) == m_music.end()) + if (m_music.find(filename) == m_music.end()) { auto buffer = MakeUnique(); - if (buffer->LoadFromFile("music/"+filename, static_cast(-1))) + if (buffer->LoadFromFile(filename, static_cast(-1))) { - m_music["music/"+filename] = std::move(buffer); + m_music[filename] = std::move(buffer); return true; } } @@ -175,7 +175,7 @@ bool ALSound::IsCached(SoundType sound) bool ALSound::IsCachedMusic(const std::string &filename) { - return m_music.find("music/"+filename) != m_music.end(); + return m_music.find(filename) != m_music.end(); } int ALSound::GetPriority(SoundType sound) @@ -594,13 +594,6 @@ void ALSound::SetListener(const Math::Vector &eye, const Math::Vector &lookat) } -bool ALSound::PlayMusic(int rank, bool repeat, float fadeTime) -{ - std::stringstream filename; - filename << "music" << std::setfill('0') << std::setw(3) << rank << ".ogg"; - return PlayMusic(filename.str(), repeat, fadeTime); -} - bool ALSound::PlayMusic(const std::string &filename, bool repeat, float fadeTime) { if (!m_enabled) @@ -611,10 +604,10 @@ bool ALSound::PlayMusic(const std::string &filename, bool repeat, float fadeTime Buffer *buffer = nullptr; // check if we have music in cache - if (m_music.find("music/"+filename) == m_music.end()) + if (m_music.find(filename) == m_music.end()) { GetLogger()->Debug("Music %s was not cached!\n", filename.c_str()); - /* TODO: if (!boost::filesystem::exists("music/"+filename)) + /* TODO: if (!boost::filesystem::exists(filename)) { GetLogger()->Debug("Requested music %s was not found.\n", filename.c_str()); return false; @@ -622,16 +615,16 @@ bool ALSound::PlayMusic(const std::string &filename, bool repeat, float fadeTime auto newBuffer = MakeUnique(); buffer = newBuffer.get(); - if (!newBuffer->LoadFromFile("music/"+filename, static_cast(-1))) + if (!newBuffer->LoadFromFile(filename, static_cast(-1))) { return false; } - m_music["music/"+filename] = std::move(newBuffer); + m_music[filename] = std::move(newBuffer); } else { GetLogger()->Debug("Music loaded from cache\n"); - buffer = m_music["music/"+filename].get(); + buffer = m_music[filename].get(); } if (m_currentMusic) diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index 80809de2..fb68672b 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -86,7 +86,6 @@ public: bool StopAll() override; bool MuteAll(bool mute) override; - bool PlayMusic(int rank, bool repeat, float fadeTime=2.0f) override; bool PlayMusic(const std::string &filename, bool repeat, float fadeTime=2.0f) override; bool RestartMusic() override; void SuspendMusic() override; @@ -116,4 +115,3 @@ private: Math::Vector m_eye; Math::Vector m_lookat; }; - diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index fbf90b58..27c20e6e 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -56,10 +56,10 @@ void CSoundInterface::CacheAll() void CSoundInterface::AddMusicFiles() { - CacheMusic("Intro1.ogg"); - CacheMusic("Intro2.ogg"); - CacheMusic("music010.ogg"); - CacheMusic("music011.ogg"); + CacheMusic("music/Intro1.ogg"); + CacheMusic("music/Intro2.ogg"); + CacheMusic("music/music010.ogg"); + CacheMusic("music/music011.ogg"); } bool CSoundInterface::Cache(SoundType sound, const std::string &file) @@ -158,11 +158,6 @@ bool CSoundInterface::MuteAll(bool bMute) return true; } -bool CSoundInterface::PlayMusic(int rank, bool repeat, float fadeTime) -{ - return true; -} - bool CSoundInterface::PlayMusic(const std::string &filename, bool repeat, float fadeTime) { return true; diff --git a/src/sound/sound.h b/src/sound/sound.h index fb0d4aa7..dc627321 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -201,14 +201,6 @@ public: */ virtual bool MuteAll(bool mute); - /** Start playing music - * \param rank - track number - * \param repeat - repeat playing - * \param fadeTime - time of transition between music - * \return return true on success - */ - virtual bool PlayMusic(int rank, bool repeat, float fadeTime=2.0f); - /** Start playing music * \param filename - name of file to play * \param repeat - repeat playing @@ -248,4 +240,3 @@ public: */ virtual void StopPauseMusic(); }; - diff --git a/src/ui/mainui.cpp b/src/ui/mainui.cpp index 5ae1f6cb..02aaec68 100644 --- a/src/ui/mainui.cpp +++ b/src/ui/mainui.cpp @@ -212,9 +212,9 @@ void CMainUserInterface::ChangePhase(Phase phase) if ( IsMainMenuPhase(m_phase) ) { - if (!m_sound->IsPlayingMusic() && m_sound->IsCachedMusic("Intro1.ogg")) + if (!m_sound->IsPlayingMusic() && m_sound->IsCachedMusic("music/Intro1.ogg")) { - m_sound->PlayMusic("Intro1.ogg", false); + m_sound->PlayMusic("music/Intro1.ogg", false); } } @@ -238,9 +238,9 @@ bool CMainUserInterface::EventProcess(const Event &event) { if ( IsMainMenuPhase(m_phase) ) { - if (!m_sound->IsPlayingMusic() && m_sound->IsCachedMusic("Intro2.ogg")) + if (!m_sound->IsPlayingMusic() && m_sound->IsCachedMusic("music/Intro2.ogg")) { - m_sound->PlayMusic("Intro2.ogg", true); + m_sound->PlayMusic("music/Intro2.ogg", true); } }