From 61068c7278279ce1b6269041396a8709cfab76d1 Mon Sep 17 00:00:00 2001 From: hiker Date: Fri, 10 Oct 2014 16:45:29 +1100 Subject: [PATCH] Replaces sfx->getStatus with isPlaying() functi n which is faster (for #1511). --- src/audio/dummy_sfx.hpp | 2 +- src/audio/sfx_base.hpp | 1 + src/audio/sfx_openal.cpp | 16 +++++++++++++++- src/audio/sfx_openal.hpp | 4 ++++ src/karts/kart.cpp | 4 ++-- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/audio/dummy_sfx.hpp b/src/audio/dummy_sfx.hpp index 9840c2233..012a75d00 100644 --- a/src/audio/dummy_sfx.hpp +++ b/src/audio/dummy_sfx.hpp @@ -48,7 +48,7 @@ public: virtual SFXManager::SFXStatus getStatus() { return SFXManager::SFX_STOPPED; } virtual void onSoundEnabledBack() {} virtual void setRolloff(float rolloff) {} - + virtual bool isPlaying() { return false; } virtual const SFXBuffer* getBuffer() const { return NULL; } }; // DummySFX diff --git a/src/audio/sfx_base.hpp b/src/audio/sfx_base.hpp index 033d57c05..65809307b 100644 --- a/src/audio/sfx_base.hpp +++ b/src/audio/sfx_base.hpp @@ -48,6 +48,7 @@ public: virtual bool init() = 0; virtual void position(const Vec3 &position) = 0; virtual void setLoop(bool status) = 0; + virtual bool isPlaying() = 0; virtual void play() = 0; virtual void reallyPlayNow() = 0; virtual void stop() = 0; diff --git a/src/audio/sfx_openal.cpp b/src/audio/sfx_openal.cpp index c80002b14..bb220d7c5 100644 --- a/src/audio/sfx_openal.cpp +++ b/src/audio/sfx_openal.cpp @@ -43,6 +43,7 @@ SFXOpenAL::SFXOpenAL(SFXBuffer* buffer, bool positional, float gain, bool ownsBu m_soundBuffer = buffer; m_soundSource = 0; m_ok = false; + m_is_playing = false; m_positional = positional; m_defaultGain = gain; m_loop = false; @@ -187,7 +188,8 @@ void SFXOpenAL::stop() { if(!m_ok) return; - m_loop = false; + m_is_playing = false; + m_loop = false; alSourcei(m_soundSource, AL_LOOPING, AL_FALSE); alSourceStop(m_soundSource); SFXManager::checkError("stoping"); @@ -228,6 +230,10 @@ void SFXOpenAL::resume() */ void SFXOpenAL::play() { + // Technically the sfx is only playing after the sfx thread starts it, + // but for STK this is correct since we don't want to start the same + // sfx twice. + m_is_playing = true; SFXManager::get()->queue(this); } // play @@ -250,6 +256,14 @@ void SFXOpenAL::reallyPlayNow() SFXManager::checkError("playing"); } // reallyPlayNow +//----------------------------------------------------------------------------- +/** Returns true if the sound effect is currently playing. + */ +bool SFXOpenAL::isPlaying() +{ + return m_is_playing; +} // isPlaying + //----------------------------------------------------------------------------- /** Sets the position where this sound effects is played. * \param position Position of the sound effect. diff --git a/src/audio/sfx_openal.hpp b/src/audio/sfx_openal.hpp index 58a93eafb..807111a33 100644 --- a/src/audio/sfx_openal.hpp +++ b/src/audio/sfx_openal.hpp @@ -55,6 +55,9 @@ private: the sound source won't be created and we'll be left with no clue when enabling sounds later. */ float m_gain; + + /** True when the sfx is currently playing. */ + bool m_is_playing; /** The master gain set in user preferences */ float m_master_gain; @@ -72,6 +75,7 @@ public: virtual void play(); virtual void reallyPlayNow(); virtual void setLoop(bool status); + virtual bool isPlaying(); virtual void stop(); virtual void pause(); virtual void resume(); diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index aee0d8b7c..3e8112ced 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -2018,10 +2018,10 @@ void Kart::updatePhysics(float dt) m_skidding->getSkidState() == Skidding::SKID_ACCUMULATE_RIGHT ) && m_skidding->getGraphicalJumpOffset()==0) { - if(m_skid_sound->getStatus() != SFXManager::SFX_PLAYING &&!isWheeless()) + if(!m_skid_sound->isPlaying() && !isWheeless()) m_skid_sound->play(); } - else if(m_skid_sound->getStatus() == SFXManager::SFX_PLAYING) + else if(m_skid_sound->isPlaying()) { m_skid_sound->stop(); }