Fixed win/lost scene music cached at startup not being ever used

master
krzys-h 2015-08-14 19:44:31 +02:00
parent 870f89ac4a
commit 0ec3f29e68
7 changed files with 27 additions and 50 deletions

View File

@ -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<CAudioChangeCondition>();
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;
}

View File

@ -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);
}

View File

@ -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<Buffer>();
if (buffer->LoadFromFile("music/"+filename, static_cast<SoundType>(-1)))
if (buffer->LoadFromFile(filename, static_cast<SoundType>(-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>();
buffer = newBuffer.get();
if (!newBuffer->LoadFromFile("music/"+filename, static_cast<SoundType>(-1)))
if (!newBuffer->LoadFromFile(filename, static_cast<SoundType>(-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)

View File

@ -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;
};

View File

@ -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;

View File

@ -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();
};

View File

@ -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);
}
}