From 16f72886e93c9b5233d4d9ae025a5ce15265c376 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 23 Nov 2015 07:51:52 -0800 Subject: [PATCH] Use separate lists for openal sounds and streams --- apps/openmw/mwsound/openal_output.cpp | 65 +++++++++++---------------- apps/openmw/mwsound/openal_output.hpp | 7 ++- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 47acb414e..0d8a994ae 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -296,7 +296,7 @@ OpenAL_SoundStream::OpenAL_SoundStream(OpenAL_Output &output, ALuint src, Decode mBufferSize = static_cast(sBufferLength*srate); mBufferSize = framesToBytes(mBufferSize, chans, type); - mOutput.mActiveSounds.push_back(this); + mOutput.mActiveStreams.push_back(this); } catch(std::exception&) { @@ -318,8 +318,8 @@ OpenAL_SoundStream::~OpenAL_SoundStream() mDecoder->close(); - mOutput.mActiveSounds.erase(std::find(mOutput.mActiveSounds.begin(), - mOutput.mActiveSounds.end(), this)); + mOutput.mActiveStreams.erase(std::find(mOutput.mActiveStreams.begin(), + mOutput.mActiveStreams.end(), this)); } void OpenAL_SoundStream::play() @@ -802,12 +802,11 @@ void OpenAL_Output::unloadSound(Sound_Handle data) SoundVec::const_iterator iter = mActiveSounds.begin(); for(;iter != mActiveSounds.end();++iter) { - OpenAL_Sound *sound = dynamic_cast(*iter); - if(sound && sound->mSource && sound->mBuffer == buffer) + if((*iter)->mSource && (*iter)->mBuffer == buffer) { - alSourceStop(sound->mSource); - alSourcei(sound->mSource, AL_BUFFER, 0); - sound->mBuffer = 0; + alSourceStop((*iter)->mSource); + alSourcei((*iter)->mSource, AL_BUFFER, 0); + (*iter)->mBuffer = 0; } } alDeleteBuffers(1, &buffer); @@ -947,22 +946,17 @@ void OpenAL_Output::updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdi void OpenAL_Output::pauseSounds(int types) { std::vector sources; - SoundVec::const_iterator iter = mActiveSounds.begin(); - while(iter != mActiveSounds.end()) + SoundVec::const_iterator sound = mActiveSounds.begin(); + for(;sound != mActiveSounds.end();++sound) { - const OpenAL_SoundStream *stream = dynamic_cast(*iter); - if(stream) - { - if(stream->mSource && (stream->getPlayType()&types)) - sources.push_back(stream->mSource); - } - else - { - const OpenAL_Sound *sound = dynamic_cast(*iter); - if(sound && sound->mSource && (sound->getPlayType()&types)) - sources.push_back(sound->mSource); - } - ++iter; + if(*sound && (*sound)->mSource && ((*sound)->getPlayType()&types)) + sources.push_back((*sound)->mSource); + } + StreamVec::const_iterator stream = mActiveStreams.begin(); + for(;stream != mActiveStreams.end();++stream) + { + if(*stream && (*stream)->mSource && ((*stream)->getPlayType()&types)) + sources.push_back((*stream)->mSource); } if(!sources.empty()) { @@ -974,22 +968,17 @@ void OpenAL_Output::pauseSounds(int types) void OpenAL_Output::resumeSounds(int types) { std::vector sources; - SoundVec::const_iterator iter = mActiveSounds.begin(); - while(iter != mActiveSounds.end()) + SoundVec::const_iterator sound = mActiveSounds.begin(); + for(;sound != mActiveSounds.end();++sound) { - const OpenAL_SoundStream *stream = dynamic_cast(*iter); - if(stream) - { - if(stream->mSource && (stream->getPlayType()&types)) - sources.push_back(stream->mSource); - } - else - { - const OpenAL_Sound *sound = dynamic_cast(*iter); - if(sound && sound->mSource && (sound->getPlayType()&types)) - sources.push_back(sound->mSource); - } - ++iter; + if(*sound && (*sound)->mSource && ((*sound)->getPlayType()&types)) + sources.push_back((*sound)->mSource); + } + StreamVec::const_iterator stream = mActiveStreams.begin(); + for(;stream != mActiveStreams.end();++stream) + { + if(*stream && (*stream)->mSource && ((*stream)->getPlayType()&types)) + sources.push_back((*stream)->mSource); } if(!sources.empty()) { diff --git a/apps/openmw/mwsound/openal_output.hpp b/apps/openmw/mwsound/openal_output.hpp index 3186706a3..9a9d188d9 100644 --- a/apps/openmw/mwsound/openal_output.hpp +++ b/apps/openmw/mwsound/openal_output.hpp @@ -16,6 +16,9 @@ namespace MWSound class SoundManager; class Sound; + class OpenAL_Sound; + class OpenAL_SoundStream; + class OpenAL_Output : public Sound_Output { ALCdevice *mDevice; @@ -24,8 +27,10 @@ namespace MWSound typedef std::deque IDDq; IDDq mFreeSources; - typedef std::vector SoundVec; + typedef std::vector SoundVec; SoundVec mActiveSounds; + typedef std::vector StreamVec; + StreamVec mActiveStreams; Environment mLastEnvironment;