summaryrefslogtreecommitdiffstats
path: root/src/sound/oalsound/alsound.cpp
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2013-04-13 11:44:16 +0200
committerkrzys-h <krzys_h@interia.pl>2013-04-13 11:44:16 +0200
commitebffda717b1b633baba7a313267505614f89f26e (patch)
tree58450559d64938e2d98af4bdf746ffd7fb91e995 /src/sound/oalsound/alsound.cpp
parent69e52e5f24d3e02dde20bda5ee322697bafc92c8 (diff)
downloadcolobot-ebffda717b1b633baba7a313267505614f89f26e.tar.gz
colobot-ebffda717b1b633baba7a313267505614f89f26e.tar.bz2
colobot-ebffda717b1b633baba7a313267505614f89f26e.zip
Implemented AudioChange (partially)
There is some issues due to #173 Issue #172
Diffstat (limited to 'src/sound/oalsound/alsound.cpp')
-rw-r--r--src/sound/oalsound/alsound.cpp48
1 files changed, 18 insertions, 30 deletions
diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp
index 3ce975b..48fcc15 100644
--- a/src/sound/oalsound/alsound.cpp
+++ b/src/sound/oalsound/alsound.cpp
@@ -539,44 +539,32 @@ void ALSound::SetListener(Math::Vector eye, Math::Vector lookat)
}
}
-
bool ALSound::PlayMusic(int rank, bool bRepeat)
{
+ std::stringstream filename;
+ filename << "music" << std::setfill('0') << std::setw(3) << rank << ".ogg";
+ return PlayMusic(filename.str(), bRepeat);
+}
+
+bool ALSound::PlayMusic(std::string filename, bool bRepeat)
+{
if (!mEnabled) {
return false;
}
-
- if (static_cast<int>(mCurrentMusic->GetSoundType()) != rank) {
- // check if we have music in cache
- for (auto music : mMusicCache) {
- if (static_cast<int>(music->GetSoundType()) == rank) {
- GetLogger()->Debug("Music loaded from cache\n");
- mCurrentMusic->SetBuffer(music);
-
- mCurrentMusic->SetVolume(mMusicVolume);
- mCurrentMusic->SetLoop(bRepeat);
- mCurrentMusic->Play();
- return true;
- }
- }
-
- // we cache only 3 music files
- if (mMusicCache.size() == 3) {
- mCurrentMusic->FreeBuffer();
- mMusicCache.pop_back();
- }
- if (mMusic.find(rank) == mMusic.end()) {
- GetLogger()->Info("Requested music %d was not found.\n", rank);
- return false;
- }
+ std::stringstream file;
+ file << m_soundPath << "/" << filename;
- Buffer *buffer = new Buffer();
- mMusicCache.push_front(buffer);
- buffer->LoadFromFile(mMusic.at(rank), static_cast<Sound>(rank));
- mCurrentMusic->SetBuffer(buffer);
- mMusicCache[rank] = buffer;
+ if (!boost::filesystem::exists(file.str())) {
+ GetLogger()->Warn("Requested music %s was not found.\n", filename.c_str());
+ return false;
}
+
+ // TODO: Cache
+
+ Buffer *buffer = new Buffer();
+ buffer->LoadFromFile(file.str(), static_cast<Sound>(-1));
+ mCurrentMusic->SetBuffer(buffer);
mCurrentMusic->SetVolume(mMusicVolume);
mCurrentMusic->SetLoop(bRepeat);