Add actual support for effect priority and enabled/disabled state
parent
a0ff6c3542
commit
70237de361
|
|
@ -69,8 +69,8 @@ LLVector4 LLTweenableValueLerp<LLVector4>::get()
|
|||
//
|
||||
|
||||
LLVfxManager::LLVfxManager()
|
||||
: m_Effects(&cmpEffect)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool LLVfxManager::addEffect(LLVisualEffect* pEffectInst)
|
||||
|
|
@ -91,6 +91,20 @@ LLVisualEffect* LLVfxManager::getEffect(EVisualEffect eCode, const LLUUID& idEff
|
|||
return (m_Effects.end() != itEffect) ? *itEffect : nullptr;
|
||||
}
|
||||
|
||||
bool LLVfxManager::getEffects(std::list<LLVisualEffect*>& effectList, std::function<bool(const LLVisualEffect*)> fnFilter)
|
||||
{
|
||||
effectList.clear();
|
||||
|
||||
auto itEffect = boost::make_filter_iterator(fnFilter, m_Effects.begin(), m_Effects.end()),
|
||||
endEffect = boost::make_filter_iterator(fnFilter, m_Effects.end(), m_Effects.end());
|
||||
while (itEffect != endEffect)
|
||||
{
|
||||
effectList.push_back(*itEffect++);
|
||||
}
|
||||
|
||||
return effectList.size();
|
||||
}
|
||||
|
||||
bool LLVfxManager::removeEffect(EVisualEffect eCode, const LLUUID& idEffect)
|
||||
{
|
||||
auto itEffect = std::find_if(m_Effects.begin(), m_Effects.end(), [eCode, &idEffect](const LLVisualEffect* pEffect) { return pEffect->getCode() == eCode && pEffect->getId() == idEffect; });
|
||||
|
|
@ -104,33 +118,42 @@ bool LLVfxManager::removeEffect(EVisualEffect eCode, const LLUUID& idEffect)
|
|||
|
||||
void LLVfxManager::runEffect(EVisualEffect eCode, LLVisualEffectParams* pParams)
|
||||
{
|
||||
// *TODO-Catz: once we're done, check whether iterating over the entire list still has negliable impact
|
||||
auto pred = [eCode](const LLVisualEffect* pEffect) { return pEffect->getCode() == eCode; };
|
||||
|
||||
auto itEffect = boost::make_filter_iterator(pred, m_Effects.begin(), m_Effects.end()),
|
||||
endEffect = boost::make_filter_iterator(pred, m_Effects.end(), m_Effects.end());
|
||||
while (itEffect != endEffect)
|
||||
{
|
||||
LLVisualEffect* pEffect = *itEffect++;
|
||||
if (pParams)
|
||||
pParams->step(itEffect == endEffect);
|
||||
pEffect->run(pParams);
|
||||
}
|
||||
runEffect([eCode](const LLVisualEffect* pEffect) { return pEffect->getCode() == eCode; }, pParams);
|
||||
}
|
||||
|
||||
void LLVfxManager::runEffect(EVisualEffectType eType, LLVisualEffectParams* pParams)
|
||||
{
|
||||
// *TODO-Catz: once we're done, check whether iterating over the entire list still has negliable impact
|
||||
auto pred = [eType](const LLVisualEffect* pEffect) { return pEffect->getType() == eType; };
|
||||
runEffect([eType](const LLVisualEffect* pEffect) { return pEffect->getType() == eType; }, pParams);
|
||||
}
|
||||
|
||||
auto itEffect = boost::make_filter_iterator(pred, m_Effects.begin(), m_Effects.end()),
|
||||
endEffect = boost::make_filter_iterator(pred, m_Effects.end(), m_Effects.end());
|
||||
for (; itEffect != endEffect; ++itEffect)
|
||||
void LLVfxManager::runEffect(std::function<bool(const LLVisualEffect*)> predicate, LLVisualEffectParams* pParams)
|
||||
{
|
||||
// *TODO-Catz: once we're done, check whether iterating over the entire list still has negliable impact
|
||||
auto itEffect = boost::make_filter_iterator(predicate, m_Effects.begin(), m_Effects.end()),
|
||||
endEffect = boost::make_filter_iterator(predicate, m_Effects.end(), m_Effects.end());
|
||||
while (itEffect != endEffect)
|
||||
{
|
||||
if (pParams)
|
||||
pParams->step(itEffect == endEffect);
|
||||
(*itEffect)->run(pParams);
|
||||
LLVisualEffect* pEffect = *itEffect++;
|
||||
if (pEffect->getEnabled())
|
||||
{
|
||||
if (pParams)
|
||||
pParams->step(itEffect == endEffect);
|
||||
pEffect->run(pParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
bool LLVfxManager::cmpEffect(const LLVisualEffect* pLHS, const LLVisualEffect* pRHS)
|
||||
{
|
||||
if (pLHS && pRHS)
|
||||
{
|
||||
// Sort by code, then priority, then memory address
|
||||
return (pLHS->getCode() == pRHS->getCode()) ? (pLHS->getPriority() == pRHS->getPriority() ? pLHS < pRHS
|
||||
: pLHS->getPriority() < pRHS->getPriority())
|
||||
: pLHS->getCode() < pRHS->getCode();
|
||||
}
|
||||
return (pLHS);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
|
|
|||
|
|
@ -78,9 +78,12 @@ public:
|
|||
virtual ~LLVisualEffect() {}
|
||||
|
||||
EVisualEffect getCode() const { return m_eCode;}
|
||||
bool getEnabled() const { return m_fEnabled; }
|
||||
const LLUUID& getId() const { return m_id;}
|
||||
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;
|
||||
|
||||
|
|
@ -91,7 +94,8 @@ protected:
|
|||
LLUUID m_id;
|
||||
EVisualEffect m_eCode;
|
||||
EVisualEffectType m_eType;
|
||||
U32 m_nPriority;
|
||||
bool m_fEnabled = true;
|
||||
U32 m_nPriority = 0;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
|
|
@ -161,18 +165,22 @@ public:
|
|||
bool addEffect(LLVisualEffect* pEffectInst);
|
||||
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 getEffects(std::list<LLVisualEffect*>& effectList, std::function<bool(const LLVisualEffect*)> fnFilter);
|
||||
template<typename T> bool getEffects(std::list<LLVisualEffect*>& effectList) { return getEffects(effectList, [](const LLVisualEffect* pEffect) { return pEffect->getCode() == T::EffectCode; }); }
|
||||
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:
|
||||
void runEffect(std::function<bool(const LLVisualEffect*)> fnFilter, LLVisualEffectParams* pParams);
|
||||
static bool cmpEffect(const LLVisualEffect* pLHS, const LLVisualEffect* pRHS);
|
||||
|
||||
/*
|
||||
* Member variables
|
||||
*/
|
||||
protected:
|
||||
std::set<LLVisualEffect*> m_Effects;
|
||||
std::set<LLVisualEffect*, decltype(&cmpEffect)> m_Effects;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
|
|
|
|||
Loading…
Reference in New Issue