From 5563f583ff6821337ae49c385986c84730925c6f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 17 Mar 2012 09:51:03 -0700 Subject: [PATCH] Add and implement methods to update tracked sounds on an object --- apps/openmw/mwsound/openal_output.cpp | 20 ++++++++++++++++++++ apps/openmw/mwsound/sound.hpp | 3 +++ apps/openmw/mwsound/soundmanager.cpp | 14 ++++++++++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 9131bbe29..c460aeb29 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -95,6 +95,7 @@ public: void Play(float volume, float pitch); virtual void Stop(); virtual bool isPlaying(); + virtual void Update(MWWorld::Ptr ptr); }; class OpenAL_Sound : public Sound @@ -108,6 +109,7 @@ public: virtual void Stop(); virtual bool isPlaying(); + virtual void Update(MWWorld::Ptr ptr); }; @@ -231,6 +233,15 @@ bool OpenAL_SoundStream::isPlaying() return true; } +void OpenAL_SoundStream::Update(MWWorld::Ptr ptr) +{ + const float *pos = ptr.getCellRef().pos.pos; + alSource3f(Source, AL_POSITION, pos[0], pos[2], -pos[1]); + alSource3f(Source, AL_DIRECTION, 0.0f, 0.0f, 0.0f); + alSource3f(Source, AL_VELOCITY, 0.0f, 0.0f, 0.0f); + throwALerror(); +} + OpenAL_Sound::OpenAL_Sound(ALuint src, ALuint buf) : Source(src), Buffer(buf) @@ -259,6 +270,15 @@ bool OpenAL_Sound::isPlaying() return state==AL_PLAYING; } +void OpenAL_Sound::Update(MWWorld::Ptr ptr) +{ + const float *pos = ptr.getCellRef().pos.pos; + alSource3f(Source, AL_POSITION, pos[0], pos[2], -pos[1]); + alSource3f(Source, AL_DIRECTION, 0.0f, 0.0f, 0.0f); + alSource3f(Source, AL_VELOCITY, 0.0f, 0.0f, 0.0f); + throwALerror(); +} + bool OpenAL_Output::Initialize(const std::string &devname) { diff --git a/apps/openmw/mwsound/sound.hpp b/apps/openmw/mwsound/sound.hpp index 5fb996e28..99be9dfeb 100644 --- a/apps/openmw/mwsound/sound.hpp +++ b/apps/openmw/mwsound/sound.hpp @@ -3,12 +3,15 @@ #include +#include "../mwworld/ptr.hpp" + namespace MWSound { class Sound { virtual void Stop() = 0; virtual bool isPlaying() = 0; + virtual void Update(MWWorld::Ptr ptr) = 0; public: virtual ~Sound() { } diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index cab179f61..5918a9cf7 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -353,15 +353,21 @@ namespace MWSound bool SoundManager::getSoundPlaying(MWWorld::Ptr ptr, const std::string& soundId) const { - // Mark all sounds as playing, otherwise the scripts will just - // keep trying to play them every frame. - return isPlaying(ptr, soundId); } void SoundManager::updateObject(MWWorld::Ptr ptr) { - // FIXME: Update tracked sounds that are using this ptr + SoundMap::iterator snditer = ActiveSounds.find(ptr); + if(snditer == ActiveSounds.end()) + return; + + IDMap::iterator iditer = snditer->second.begin(); + while(iditer != snditer->second.end()) + { + iditer->second->Update(ptr); + iditer++; + } } void SoundManager::updateRegionSound(float duration)