1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-02 08:15:54 +00:00

Throw an exception when looking up a sound instead of returning an empty string

This commit is contained in:
Chris Robinson 2012-03-21 18:20:32 -07:00
parent 9a139f511f
commit 8056a7f20b

View file

@ -86,7 +86,8 @@ namespace MWSound
float &volume, float &min, float &max) float &volume, float &min, float &max)
{ {
const ESM::Sound *snd = mEnvironment.mWorld->getStore().sounds.search(soundId); const ESM::Sound *snd = mEnvironment.mWorld->getStore().sounds.search(soundId);
if(snd == NULL) return ""; if(snd == NULL)
throw std::runtime_error(std::string("Failed to lookup sound ")+soundId);
if(snd->data.volume == 0) if(snd->data.volume == 0)
volume = 0.0f; volume = 0.0f;
@ -224,13 +225,10 @@ namespace MWSound
void SoundManager::playSound(const std::string& soundId, float volume, float pitch, bool loop) void SoundManager::playSound(const std::string& soundId, float volume, float pitch, bool loop)
{ {
float min, max; float min, max;
std::string file = lookup(soundId, volume, min, max);
if(!file.empty())
{
try try
{ {
Sound *sound; std::string file = lookup(soundId, volume, min, max);
sound = mOutput->playSound(file, volume, pitch, loop); Sound *sound = mOutput->playSound(file, volume, pitch, loop);
mLooseSounds[soundId] = SoundPtr(sound); mLooseSounds[soundId] = SoundPtr(sound);
} }
catch(std::exception &e) catch(std::exception &e)
@ -238,20 +236,21 @@ namespace MWSound
std::cout <<"Sound play error: "<<e.what()<< std::endl; std::cout <<"Sound play error: "<<e.what()<< std::endl;
} }
} }
else
std::cout << "Sound file " << soundId << " not found, skipping.\n";
}
void SoundManager::playSound3D(MWWorld::Ptr ptr, const std::string& soundId, void SoundManager::playSound3D(MWWorld::Ptr ptr, const std::string& soundId,
float volume, float pitch, bool loop, bool untracked) float volume, float pitch, bool loop, bool untracked)
{ {
// Look up the sound in the ESM data
float min, max; float min, max;
try
{
// Look up the sound in the ESM data
std::string file = lookup(soundId, volume, min, max); std::string file = lookup(soundId, volume, min, max);
if(!file.empty())
play3d(file, ptr, soundId, volume, pitch, min, max, loop, untracked); play3d(file, ptr, soundId, volume, pitch, min, max, loop, untracked);
else }
std::cout << "Sound file " << soundId << " not found, skipping.\n"; catch(std::exception &e)
{
std::cout <<"Sound play error: "<<e.what()<< std::endl;
}
} }
void SoundManager::stopSound3D(MWWorld::Ptr ptr, const std::string& soundId) void SoundManager::stopSound3D(MWWorld::Ptr ptr, const std::string& soundId)