From 1fd98d08d283c55108dbd39d42275a5d158e201f Mon Sep 17 00:00:00 2001 From: Kitty Barnett <develop@catznip.com> Date: Sat, 29 May 2021 19:17:38 +0200 Subject: [PATCH] Allow dynamic changes to effect priority --- indra/newview/llvisualeffect.cpp | 17 ++++++++++++++--- indra/newview/llvisualeffect.h | 8 ++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/indra/newview/llvisualeffect.cpp b/indra/newview/llvisualeffect.cpp index 0d95d565e2e..3a4594ff091 100644 --- a/indra/newview/llvisualeffect.cpp +++ b/indra/newview/llvisualeffect.cpp @@ -69,7 +69,6 @@ LLVector4 LLTweenableValueLerp<LLVector4>::get() // LLVfxManager::LLVfxManager() - : m_Effects(&cmpEffect) { } @@ -81,7 +80,7 @@ bool LLVfxManager::addEffect(LLVisualEffect* pEffectInst) if (m_Effects.end() != itEffect) return false; - m_Effects.insert(pEffectInst); + m_Effects.insert(std::upper_bound(m_Effects.begin(), m_Effects.end(), pEffectInst, cmpEffect), pEffectInst); return true; } @@ -143,6 +142,18 @@ void LLVfxManager::runEffect(std::function<bool(const LLVisualEffect*)> predicat } } +void LLVfxManager::updateEffect(LLVisualEffect* pEffect, bool fEnabled, U32 nPriority) +{ + llassert(m_Effects.end() != std::find(m_Effects.begin(), m_Effects.end(), pEffect)); + + if ( (pEffect->getEnabled() != fEnabled) || (pEffect->getPriority() != nPriority) ) + { + pEffect->setEnabled(fEnabled); + pEffect->setPriority(nPriority); + std::sort(m_Effects.begin(), m_Effects.end(), cmpEffect); + } +} + // static bool LLVfxManager::cmpEffect(const LLVisualEffect* pLHS, const LLVisualEffect* pRHS) { @@ -150,7 +161,7 @@ bool LLVfxManager::cmpEffect(const LLVisualEffect* pLHS, const LLVisualEffect* p { // Sort by code, then priority, then memory address return (pLHS->getCode() == pRHS->getCode()) ? (pLHS->getPriority() == pRHS->getPriority() ? pLHS < pRHS - : pLHS->getPriority() < pRHS->getPriority()) + : pLHS->getPriority() > pRHS->getPriority()) : pLHS->getCode() < pRHS->getCode(); } return (pLHS); diff --git a/indra/newview/llvisualeffect.h b/indra/newview/llvisualeffect.h index dc90327fa94..959e0dbc836 100644 --- a/indra/newview/llvisualeffect.h +++ b/indra/newview/llvisualeffect.h @@ -71,6 +71,7 @@ struct LLShaderEffectParams : LLVisualEffectParams class LLVisualEffect { + friend class LLVfxManager; public: LLVisualEffect(LLUUID id, EVisualEffect eCode, EVisualEffectType eType) : m_id(id), m_eCode(eCode), m_eType(eType) @@ -83,10 +84,12 @@ class LLVisualEffect U32 getPriority() const { return m_nPriority; } EVisualEffectType getType() const { return m_eType;} void setEnabled(bool enable) { m_fEnabled = enable; } - void setPriority(U32 priority) { m_nPriority = priority; } virtual void run(const LLVisualEffectParams* pParams) = 0; +protected: + void setPriority(U32 priority) { m_nPriority = priority; } + /* * Member variables */ @@ -172,6 +175,7 @@ class LLVfxManager : public LLSingleton<LLVfxManager> 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); + void updateEffect(LLVisualEffect* pEffect, bool fEnabled, U32 nPriority); protected: void runEffect(std::function<bool(const LLVisualEffect*)> fnFilter, LLVisualEffectParams* pParams); static bool cmpEffect(const LLVisualEffect* pLHS, const LLVisualEffect* pRHS); @@ -180,7 +184,7 @@ class LLVfxManager : public LLSingleton<LLVfxManager> * Member variables */ protected: - std::set<LLVisualEffect*, decltype(&cmpEffect)> m_Effects; + std::vector<LLVisualEffect*> m_Effects; }; // ============================================================================ -- GitLab