137 lines
4.4 KiB
C++
137 lines
4.4 KiB
C++
/**
|
|
*
|
|
* Copyright (c) 2021, Kitty Barnett
|
|
*
|
|
* The source code in this file is provided to you under the terms of the
|
|
* GNU Lesser General Public License, version 2.1, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
* PARTICULAR PURPOSE. Terms of the LGPL can be found in doc/LGPL-licence.txt
|
|
* in this distribution, or online at http://www.gnu.org/licenses/lgpl-2.1.txt
|
|
*
|
|
* By copying, modifying or distributing this software, you acknowledge that
|
|
* you have read and understood your obligations described above, and agree to
|
|
* abide by those obligations.
|
|
*
|
|
*/
|
|
|
|
#include "llviewerprecompiledheaders.h"
|
|
|
|
#include "llvisualeffect.h"
|
|
|
|
#include <boost/iterator/filter_iterator.hpp>
|
|
#include <boost/range/iterator_range.hpp>
|
|
|
|
// ============================================================================
|
|
// LLTweenableValue class
|
|
//
|
|
|
|
template<>
|
|
float LLTweenableValueLerp<float>::get()
|
|
{
|
|
if (!m_CurValue)
|
|
{
|
|
float curFactor = (LLTimer::getElapsedSeconds() - m_StartTime) / m_Duration;
|
|
if (curFactor < 1.0)
|
|
return lerp(m_StartValue, m_EndValue, curFactor);
|
|
m_CurValue = m_EndValue;
|
|
}
|
|
return m_CurValue.get();
|
|
}
|
|
|
|
template<>
|
|
LLColor3 LLTweenableValueLerp<LLColor3>::get()
|
|
{
|
|
if (!m_CurValue)
|
|
{
|
|
float curFactor = (LLTimer::getElapsedSeconds() - m_StartTime) / m_Duration;
|
|
if (curFactor < 1.0)
|
|
return lerp(m_StartValue, m_EndValue, curFactor);
|
|
m_CurValue = m_EndValue;
|
|
}
|
|
return m_CurValue.get();
|
|
}
|
|
|
|
template<>
|
|
LLVector4 LLTweenableValueLerp<LLVector4>::get()
|
|
{
|
|
if (!m_CurValue)
|
|
{
|
|
float curFactor = (LLTimer::getElapsedSeconds() - m_StartTime) / m_Duration;
|
|
if (curFactor < 1.0)
|
|
return lerp(m_StartValue, m_EndValue, curFactor);
|
|
m_CurValue = m_EndValue;
|
|
}
|
|
return m_CurValue.get();
|
|
}
|
|
|
|
// ============================================================================
|
|
// LLVfxManager class
|
|
//
|
|
|
|
LLVfxManager::LLVfxManager()
|
|
{
|
|
|
|
}
|
|
|
|
bool LLVfxManager::addEffect(LLVisualEffect* 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(EVisualEffect eCode, const LLUUID& idEffect) const
|
|
{
|
|
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(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; });
|
|
if (m_Effects.end() == itEffect)
|
|
return false;
|
|
|
|
delete *itEffect;
|
|
m_Effects.erase(itEffect);
|
|
return true;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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; };
|
|
|
|
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)
|
|
{
|
|
if (pParams)
|
|
pParams->step(itEffect == endEffect);
|
|
(*itEffect)->run(pParams);
|
|
}
|
|
}
|
|
|
|
// ============================================================================
|