mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-27 03:35:27 +00:00
Throw an exception when looking up a sound instead of returning an empty string
This commit is contained in:
parent
9a139f511f
commit
8056a7f20b
@ -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,34 +225,32 @@ 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);
|
try
|
||||||
if(!file.empty())
|
|
||||||
{
|
{
|
||||||
try
|
std::string file = lookup(soundId, volume, min, max);
|
||||||
{
|
Sound *sound = mOutput->playSound(file, volume, pitch, loop);
|
||||||
Sound *sound;
|
mLooseSounds[soundId] = SoundPtr(sound);
|
||||||
sound = mOutput->playSound(file, volume, pitch, loop);
|
}
|
||||||
mLooseSounds[soundId] = SoundPtr(sound);
|
catch(std::exception &e)
|
||||||
}
|
{
|
||||||
catch(std::exception &e)
|
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;
|
||||||
std::string file = lookup(soundId, volume, min, max);
|
try
|
||||||
if(!file.empty())
|
{
|
||||||
|
// 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);
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user