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

actorid
Chris Robinson 13 years ago
parent 9a139f511f
commit 8056a7f20b

@ -86,7 +86,8 @@ namespace MWSound
float &volume, float &min, float &max)
{
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)
volume = 0.0f;
@ -224,34 +225,32 @@ namespace MWSound
void SoundManager::playSound(const std::string& soundId, float volume, float pitch, bool loop)
{
float min, max;
std::string file = lookup(soundId, volume, min, max);
if(!file.empty())
try
{
try
{
Sound *sound;
sound = mOutput->playSound(file, volume, pitch, loop);
mLooseSounds[soundId] = SoundPtr(sound);
}
catch(std::exception &e)
{
std::cout <<"Sound play error: "<<e.what()<< std::endl;
}
std::string file = lookup(soundId, volume, min, max);
Sound *sound = mOutput->playSound(file, volume, pitch, loop);
mLooseSounds[soundId] = SoundPtr(sound);
}
catch(std::exception &e)
{
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,
float volume, float pitch, bool loop, bool untracked)
{
// Look up the sound in the ESM data
float min, max;
std::string file = lookup(soundId, volume, min, max);
if(!file.empty())
try
{
// Look up the sound in the ESM data
std::string file = lookup(soundId, volume, min, max);
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)

Loading…
Cancel
Save