mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-24 02:41:33 +00:00
Choose next action for water sound in a separate function
This commit is contained in:
parent
080b0d6319
commit
b424aac25e
2 changed files with 62 additions and 32 deletions
|
@ -892,25 +892,48 @@ namespace MWSound
|
||||||
const ESM::Cell *curcell = player.getCell()->getCell();
|
const ESM::Cell *curcell = player.getCell()->getCell();
|
||||||
const auto update = mWaterSoundUpdater.update(player, *world);
|
const auto update = mWaterSoundUpdater.update(player, *world);
|
||||||
|
|
||||||
|
WaterSoundAction action;
|
||||||
|
Sound_Buffer* sfx;
|
||||||
|
std::tie(action, sfx) = getWaterSoundAction(update, curcell);
|
||||||
|
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case WaterSoundAction::DoNothing:
|
||||||
|
break;
|
||||||
|
case WaterSoundAction::SetVolume:
|
||||||
|
mNearWaterSound->setVolume(update.mVolume * sfx->mVolume);
|
||||||
|
break;
|
||||||
|
case WaterSoundAction::FinishSound:
|
||||||
|
mOutput->finishSound(mNearWaterSound);
|
||||||
|
mNearWaterSound = nullptr;
|
||||||
|
break;
|
||||||
|
case WaterSoundAction::PlaySound:
|
||||||
|
if (mNearWaterSound)
|
||||||
|
mOutput->finishSound(mNearWaterSound);
|
||||||
|
mNearWaterSound = playSound(update.mId, update.mVolume, 1.0f, Type::Sfx, PlayMode::Loop);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mLastCell = curcell;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<SoundManager::WaterSoundAction, Sound_Buffer*> SoundManager::getWaterSoundAction(
|
||||||
|
const WaterSoundUpdate& update, const ESM::Cell* cell) const
|
||||||
|
{
|
||||||
if (mNearWaterSound)
|
if (mNearWaterSound)
|
||||||
{
|
{
|
||||||
if (update.mVolume == 0.0f)
|
if (update.mVolume == 0.0f)
|
||||||
{
|
return {WaterSoundAction::FinishSound, nullptr};
|
||||||
mOutput->finishSound(mNearWaterSound);
|
|
||||||
mNearWaterSound = nullptr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool soundIdChanged = false;
|
bool soundIdChanged = false;
|
||||||
|
|
||||||
Sound_Buffer* sfx = lookupSound(update.mId);
|
Sound_Buffer* sfx = lookupSound(update.mId);
|
||||||
if (mLastCell != curcell)
|
if (mLastCell != cell)
|
||||||
{
|
{
|
||||||
mLastCell = curcell;
|
const auto snditer = mActiveSounds.find(MWWorld::ConstPtr());
|
||||||
SoundMap::const_iterator snditer = mActiveSounds.find(MWWorld::Ptr());
|
|
||||||
if (snditer != mActiveSounds.end())
|
if (snditer != mActiveSounds.end())
|
||||||
{
|
{
|
||||||
SoundBufferRefPairList::const_iterator pairiter = std::find_if(
|
const auto pairiter = std::find_if(
|
||||||
snditer->second.begin(), snditer->second.end(),
|
snditer->second.begin(), snditer->second.end(),
|
||||||
[this](const SoundBufferRefPairList::value_type &item) -> bool
|
[this](const SoundBufferRefPairList::value_type &item) -> bool
|
||||||
{ return mNearWaterSound == item.first; }
|
{ return mNearWaterSound == item.first; }
|
||||||
|
@ -921,19 +944,15 @@ namespace MWSound
|
||||||
}
|
}
|
||||||
|
|
||||||
if (soundIdChanged)
|
if (soundIdChanged)
|
||||||
{
|
return {WaterSoundAction::PlaySound, nullptr};
|
||||||
mOutput->finishSound(mNearWaterSound);
|
|
||||||
mNearWaterSound = playSound(update.mId, update.mVolume, 1.0f, Type::Sfx, PlayMode::Loop);
|
if (sfx)
|
||||||
}
|
return {WaterSoundAction::SetVolume, sfx};
|
||||||
else if (sfx)
|
|
||||||
mNearWaterSound->setVolume(update.mVolume * sfx->mVolume);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (update.mVolume > 0.0f)
|
else if (update.mVolume > 0.0f)
|
||||||
{
|
return {WaterSoundAction::PlaySound, nullptr};
|
||||||
mLastCell = curcell;
|
|
||||||
mNearWaterSound = playSound(update.mId, update.mVolume, 1.0f, Type::Sfx, PlayMode::Loop);
|
return {WaterSoundAction::DoNothing, nullptr};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::updateSounds(float duration)
|
void SoundManager::updateSounds(float duration)
|
||||||
|
|
|
@ -143,6 +143,17 @@ namespace MWSound
|
||||||
|
|
||||||
float volumeFromType(Type type) const;
|
float volumeFromType(Type type) const;
|
||||||
|
|
||||||
|
enum class WaterSoundAction
|
||||||
|
{
|
||||||
|
DoNothing,
|
||||||
|
SetVolume,
|
||||||
|
FinishSound,
|
||||||
|
PlaySound,
|
||||||
|
};
|
||||||
|
|
||||||
|
std::pair<WaterSoundAction, Sound_Buffer*> getWaterSoundAction(const WaterSoundUpdate& update,
|
||||||
|
const ESM::Cell* cell) const;
|
||||||
|
|
||||||
SoundManager(const SoundManager &rhs);
|
SoundManager(const SoundManager &rhs);
|
||||||
SoundManager& operator=(const SoundManager &rhs);
|
SoundManager& operator=(const SoundManager &rhs);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue