Added music files cache
parent
e3b92fb9d8
commit
cdba398d29
|
@ -3983,6 +3983,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
{
|
{
|
||||||
m_audioTrack = OpInt(line, "track", 0);
|
m_audioTrack = OpInt(line, "track", 0);
|
||||||
m_audioRepeat = OpInt(line, "repeat", 1);
|
m_audioRepeat = OpInt(line, "repeat", 1);
|
||||||
|
if(m_audioTrack != 0) {
|
||||||
|
std::stringstream filename;
|
||||||
|
filename << "music" << std::setfill('0') << std::setw(3) << m_audioTrack << ".ogg";
|
||||||
|
m_sound->CacheMusic(filename.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cmd(line, "AudioChange") && !resetObject && m_version >= 2)
|
if (Cmd(line, "AudioChange") && !resetObject && m_version >= 2)
|
||||||
|
@ -3998,6 +4003,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
OpString(line, "filename", m_audioChange[i].music);
|
OpString(line, "filename", m_audioChange[i].music);
|
||||||
m_audioChange[i].repeat = OpInt(line, "repeat", 1);
|
m_audioChange[i].repeat = OpInt(line, "repeat", 1);
|
||||||
m_audioChange[i].changed = false;
|
m_audioChange[i].changed = false;
|
||||||
|
m_sound->CacheMusic(m_audioChange[i].music);
|
||||||
m_audioChangeTotal ++;
|
m_audioChangeTotal ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,10 @@ void ALSound::CleanUp()
|
||||||
delete item.second;
|
delete item.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto item : mMusic) {
|
||||||
|
delete item.second;
|
||||||
|
}
|
||||||
|
|
||||||
mEnabled = false;
|
mEnabled = false;
|
||||||
|
|
||||||
mCurrentMusic->FreeBuffer();
|
mCurrentMusic->FreeBuffer();
|
||||||
|
@ -160,6 +164,18 @@ bool ALSound::Cache(Sound sound, std::string filename)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ALSound::CacheMusic(std::string filename)
|
||||||
|
{
|
||||||
|
Buffer *buffer = new Buffer();
|
||||||
|
std::stringstream file;
|
||||||
|
file << m_soundPath << "/" << filename;
|
||||||
|
if (buffer->LoadFromFile(file.str(), static_cast<Sound>(-1))) {
|
||||||
|
mMusic[filename] = buffer;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int ALSound::GetPriority(Sound sound)
|
int ALSound::GetPriority(Sound sound)
|
||||||
{
|
{
|
||||||
|
@ -555,16 +571,20 @@ bool ALSound::PlayMusic(std::string filename, bool bRepeat)
|
||||||
std::stringstream file;
|
std::stringstream file;
|
||||||
file << m_soundPath << "/" << filename;
|
file << m_soundPath << "/" << filename;
|
||||||
|
|
||||||
if (!boost::filesystem::exists(file.str())) {
|
// check if we have music in cache
|
||||||
GetLogger()->Warn("Requested music %s was not found.\n", filename.c_str());
|
if (mMusic.find(filename) == mMusic.end()) {
|
||||||
return false;
|
GetLogger()->Warn("Music %s was not cached!\n", filename.c_str());
|
||||||
|
if (!boost::filesystem::exists(file.str())) {
|
||||||
|
GetLogger()->Warn("Requested music %s was not found.\n", filename.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Buffer *buffer = new Buffer();
|
||||||
|
buffer->LoadFromFile(file.str(), static_cast<Sound>(-1));
|
||||||
|
mCurrentMusic->SetBuffer(buffer);
|
||||||
|
} else {
|
||||||
|
GetLogger()->Debug("Music loaded from cache\n");
|
||||||
|
mCurrentMusic->SetBuffer(mMusic[filename]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Cache
|
|
||||||
|
|
||||||
Buffer *buffer = new Buffer();
|
|
||||||
buffer->LoadFromFile(file.str(), static_cast<Sound>(-1));
|
|
||||||
mCurrentMusic->SetBuffer(buffer);
|
|
||||||
|
|
||||||
mCurrentMusic->SetVolume(mMusicVolume);
|
mCurrentMusic->SetVolume(mMusicVolume);
|
||||||
mCurrentMusic->SetLoop(bRepeat);
|
mCurrentMusic->SetLoop(bRepeat);
|
||||||
|
|
|
@ -40,6 +40,7 @@ class ALSound : public CSoundInterface
|
||||||
|
|
||||||
bool Create(bool b3D);
|
bool Create(bool b3D);
|
||||||
bool Cache(Sound, std::string);
|
bool Cache(Sound, std::string);
|
||||||
|
bool CacheMusic(std::string);
|
||||||
|
|
||||||
bool GetEnable();
|
bool GetEnable();
|
||||||
|
|
||||||
|
@ -91,6 +92,7 @@ class ALSound : public CSoundInterface
|
||||||
ALCdevice* mDevice;
|
ALCdevice* mDevice;
|
||||||
ALCcontext* mContext;
|
ALCcontext* mContext;
|
||||||
std::map<Sound, Buffer*> mSounds;
|
std::map<Sound, Buffer*> mSounds;
|
||||||
|
std::map<std::string, Buffer*> mMusic;
|
||||||
std::map<int, Channel*> mChannels;
|
std::map<int, Channel*> mChannels;
|
||||||
Channel *mCurrentMusic;
|
Channel *mCurrentMusic;
|
||||||
Math::Vector mEye;
|
Math::Vector mEye;
|
||||||
|
|
|
@ -178,6 +178,8 @@ class CSoundInterface
|
||||||
/** Function called to add all music files to list */
|
/** Function called to add all music files to list */
|
||||||
inline void AddMusicFiles(std::string path) {
|
inline void AddMusicFiles(std::string path) {
|
||||||
m_soundPath = path;
|
m_soundPath = path;
|
||||||
|
CacheMusic("sound010.ogg");
|
||||||
|
CacheMusic("sound011.ogg");
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Function called to cache sound effect file.
|
/** Function called to cache sound effect file.
|
||||||
|
@ -188,6 +190,13 @@ class CSoundInterface
|
||||||
*/
|
*/
|
||||||
inline virtual bool Cache(Sound bSound, std::string bFile) { return true; };
|
inline virtual bool Cache(Sound bSound, std::string bFile) { return true; };
|
||||||
|
|
||||||
|
/** Function called to cache music file.
|
||||||
|
* This function is called by CRobotMain for each file used in the mission.
|
||||||
|
* \param bFile - file to load
|
||||||
|
* \return return true on success
|
||||||
|
*/
|
||||||
|
inline virtual bool CacheMusic(std::string bFile) { return true; };
|
||||||
|
|
||||||
/** Return if plugin is enabled
|
/** Return if plugin is enabled
|
||||||
* \return return true if plugin is enabled
|
* \return return true if plugin is enabled
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue