diff --git a/indra/newview/llvisualeffect.cpp b/indra/newview/llvisualeffect.cpp index 0f4ea959e8bc37c33e6b7eb2eb5ba49dc5b6c10c..ae1ea11695faccf0e24cf56238edf7f67ce0c4ba 100644 --- a/indra/newview/llvisualeffect.cpp +++ b/indra/newview/llvisualeffect.cpp @@ -75,30 +75,25 @@ LLVfxManager::LLVfxManager() bool LLVfxManager::addEffect(LLVisualEffect* pEffectInst) { - if (m_Effects.end() != m_Effects.find(pEffectInst)) + // Effect IDs can be reused across effects but should be unique for all effect instances sharing the same effect code + auto itEffect = std::find_if(m_Effects.begin(), m_Effects.end(), [pEffectInst](const LLVisualEffect* pEffect) { return pEffect->getCode() == pEffectInst->getCode() && pEffect->getId() == pEffectInst->getId(); }); + llassert(m_Effects.end() == itEffect); + if (m_Effects.end() != itEffect) return false; m_Effects.insert(pEffectInst); - return true; } -LLVisualEffect* LLVfxManager::getEffect(const LLUUID& idEffect) const -{ - auto itEffect = std::find_if(m_Effects.begin(), m_Effects.end(), [&idEffect](const LLVisualEffect* pEffect) { return pEffect->getId() == idEffect; }); - return (m_Effects.end() != itEffect) ? *itEffect : nullptr; -} - -LLVisualEffect* LLVfxManager::getEffect(EVisualEffect eCode) const +LLVisualEffect* LLVfxManager::getEffect(EVisualEffect eCode, const LLUUID& idEffect) const { - // NOTE: returns the first found but there could be more - auto itEffect = std::find_if(m_Effects.begin(), m_Effects.end(), [eCode](const LLVisualEffect* pEffect) { return pEffect->getCode() == eCode; }); + auto itEffect = std::find_if(m_Effects.begin(), m_Effects.end(), [eCode, &idEffect](const LLVisualEffect* pEffect) { return pEffect->getCode() == eCode && pEffect->getId() == idEffect; }); return (m_Effects.end() != itEffect) ? *itEffect : nullptr; } -bool LLVfxManager::removeEffect(const LLUUID& idEffect) +bool LLVfxManager::removeEffect(EVisualEffect eCode, const LLUUID& idEffect) { - auto itEffect = std::find_if(m_Effects.begin(), m_Effects.end(), [&idEffect](const LLVisualEffect* pEffect) { return pEffect->getId() == idEffect; }); + auto itEffect = std::find_if(m_Effects.begin(), m_Effects.end(), [eCode, &idEffect](const LLVisualEffect* pEffect) { return pEffect->getCode() == eCode && pEffect->getId() == idEffect; }); if (m_Effects.end() == itEffect) return false; diff --git a/indra/newview/llvisualeffect.h b/indra/newview/llvisualeffect.h index 69387d49af895fe6971acdc1410b78e116cf0e8f..55fbd13468136e8d807846b35c65c4e260c1d4cc 100644 --- a/indra/newview/llvisualeffect.h +++ b/indra/newview/llvisualeffect.h @@ -159,12 +159,11 @@ class LLVfxManager : public LLSingleton<LLVfxManager> */ public: bool addEffect(LLVisualEffect* pEffectInst); - LLVisualEffect* getEffect(const LLUUID& idEffect) const; - template<typename T> T* getEffect(const LLUUID& idEffect) const { return dynamic_cast<T*>(getEffect(idEffect)); } - LLVisualEffect* getEffect(EVisualEffect eCode) const; - template<typename T> T* getEffect(EVisualEffect eCode) const { return dynamic_cast<T*>(getEffect(eCode)); } - bool hasEffect(EVisualEffect eCode) const { return getEffect(eCode); } - bool removeEffect(const LLUUID& idEffect); + LLVisualEffect* getEffect(EVisualEffect eCode, const LLUUID& idEffect) const; + template<typename T> T* getEffect(const LLUUID& idEffect) const { return dynamic_cast<T*>(getEffect(T::EffectCode, idEffect)); } + bool hasEffect(EVisualEffect eCode) const; + bool removeEffect(EVisualEffect eCode, const LLUUID& idEffect); + template<typename T> bool removeEffect(const LLUUID& idEffect) { return removeEffect(T::EffectCode, idEffect); } void runEffect(EVisualEffect eCode, LLVisualEffectParams* pParams = nullptr); void runEffect(EVisualEffectType eType, LLVisualEffectParams* pParams = nullptr); protected: @@ -177,3 +176,12 @@ class LLVfxManager : public LLSingleton<LLVfxManager> }; // ============================================================================ +// Inlined member functions +// + +inline bool LLVfxManager::hasEffect(EVisualEffect eCode) const +{ + return m_Effects.end() != std::find_if(m_Effects.begin(), m_Effects.end(), [eCode](const LLVisualEffect* pEffect) { return pEffect->getCode() == eCode; }); +} + +// ============================================================================