Code review for the new RlvBehaviourModifierAnimator class

--HG--
branch : RLVa
master
Kitty Barnett 2018-05-07 12:52:49 +02:00
parent f7dbbd3ad2
commit e8d2f6042d
3 changed files with 21 additions and 31 deletions

View File

@ -71,6 +71,7 @@ const S32 RLVa_VERSION_PATCH = 0;
#define RLV_ROOT_FOLDER "#RLV"
#define RLV_CMD_PREFIX '@'
#define RLV_MODIFIER_ANIMATION_FREQUENCY 10
#define RLV_MODIFIER_TPLOCAL_DEFAULT 256.f // Any teleport that's more than a region away is non-local
#define RLV_MODIFIER_FARTOUCH_DEFAULT 1.5f // Specifies the default @fartouch distance
#define RLV_MODIFIER_SITTP_DEFAULT 1.5f // Specifies the default @sittp distance

View File

@ -24,11 +24,8 @@
RlvBehaviourModifierAnimator::~RlvBehaviourModifierAnimator()
{
if (m_pTimer)
{
delete m_pTimer;
m_pTimer = nullptr;
}
if (!m_TimerHandle.isDead())
m_TimerHandle.markDead();
}
void RlvBehaviourModifierAnimator::addTween(const LLUUID& idObject, ERlvBehaviourModifier eBhvrMod, RlvBehaviourModifierAnimationType eAnimType, const RlvBehaviourModifierValue& endValue, float nDuration)
@ -38,7 +35,7 @@ void RlvBehaviourModifierAnimator::addTween(const LLUUID& idObject, ERlvBehaviou
if (m_Tweens.end() != itTween)
m_Tweens.erase(itTween);
if (RlvBehaviourModifier* pBhvrModifier = RlvBehaviourDictionary::instance().getModifier(eBhvrMod))
if (const RlvBehaviourModifier* pBhvrModifier = RlvBehaviourDictionary::instance().getModifier(eBhvrMod))
{
RlvBehaviourModifierTween newTween;
newTween.idObject = idObject;
@ -50,8 +47,8 @@ void RlvBehaviourModifierAnimator::addTween(const LLUUID& idObject, ERlvBehaviou
newTween.endValue = endValue;
if (newTween.startValue.which() == newTween.endValue.which())
{
if (!m_pTimer)
m_pTimer = new AnimationTimer();
if (m_TimerHandle.isDead())
m_TimerHandle = (new AnimationTimer())->getHandle();
m_Tweens.emplace_back(std::move(newTween));
}
}
@ -60,23 +57,22 @@ void RlvBehaviourModifierAnimator::addTween(const LLUUID& idObject, ERlvBehaviou
void RlvBehaviourModifierAnimator::clearTweens(const LLUUID& idObject, ERlvBehaviourModifier eBhvrMod)
{
m_Tweens.erase(std::remove_if(m_Tweens.begin(), m_Tweens.end(),
[&idObject, eBhvrMod](const RlvBehaviourModifierTween& cmpTween)
{
return cmpTween.idObject == idObject && ((cmpTween.eBhvrMod == eBhvrMod) || (RLV_MODIFIER_UNKNOWN == eBhvrMod));
}), m_Tweens.end());
[&idObject, eBhvrMod](const RlvBehaviourModifierTween& cmpTween)
{
return cmpTween.idObject == idObject && ((cmpTween.eBhvrMod == eBhvrMod) || (RLV_MODIFIER_UNKNOWN == eBhvrMod));
}), m_Tweens.end());
}
// ====================================================================================
// RlvBehaviourModifierAnimator timer
//
#define ANIMATION_FREQUENCY 10
RlvBehaviourModifierAnimator::AnimationTimer::AnimationTimer()
: LLEventTimer(1.f / ANIMATION_FREQUENCY)
: LLEventTimer(1.f / RLV_MODIFIER_ANIMATION_FREQUENCY)
{
}
BOOL RlvBehaviourModifierAnimator::AnimationTimer::tick()
{
RlvBehaviourModifierAnimator& modAnimatior = RlvBehaviourModifierAnimator::instance();
@ -105,7 +101,7 @@ BOOL RlvBehaviourModifierAnimator::AnimationTimer::tick()
auto itTween = std::find_if(modAnimatior.m_Tweens.begin(), modAnimatior.m_Tweens.end(),
[&curTween](const RlvBehaviourModifierTween& t)
{
// NOTE: implementation leak - taking advantage of the fact that we know there can only be one active tween per object/modifier/type combnination
// NOTE: implementation leak - taking advantage of the fact that we know there can only be one active tween per object/modifier/type combination
return t.idObject == curTween.idObject && t.eBhvrMod == curTween.eBhvrMod && t.eAnimType == curTween.eAnimType;
});
modAnimatior.m_Tweens.erase(itTween);
@ -113,12 +109,7 @@ BOOL RlvBehaviourModifierAnimator::AnimationTimer::tick()
}
}
if (modAnimatior.m_Tweens.empty())
{
modAnimatior.m_pTimer = nullptr;
return true;
}
return false;
return modAnimatior.m_Tweens.empty();
}
// ====================================================================================

View File

@ -16,11 +16,12 @@
#pragma once
#include "llhandle.h"
#include "llsingleton.h"
#include "rlvhelper.h"
// ====================================================================================
// RlvBehaviourModifierAnimator - Helper types
// RlvBehaviourModifierAnimator - A class to animate behaviour modifiers
//
enum class RlvBehaviourModifierAnimationType { Lerp };
@ -36,13 +37,8 @@ struct RlvBehaviourModifierTween
RlvBehaviourModifierValue endValue;
};
// ====================================================================================
// RlvBehaviourModifierAnimator - A class to animate behaviour modifiers
//
class RlvBehaviourModifierAnimator : public LLSingleton<RlvBehaviourModifierAnimator>
{
friend class AnimationTimer;
LLSINGLETON_EMPTY_CTOR(RlvBehaviourModifierAnimator);
public:
~RlvBehaviourModifierAnimator() override;
@ -58,7 +54,8 @@ public:
/*
* Animation timer
*/
class AnimationTimer : LLEventTimer
protected:
class AnimationTimer : public LLEventTimer, public LLHandleProvider<AnimationTimer>
{
public:
AnimationTimer();
@ -68,8 +65,9 @@ public:
/*
* Member variables
*/
std::list<struct RlvBehaviourModifierTween> m_Tweens;
AnimationTimer* m_pTimer = nullptr;
protected:
LLHandle<AnimationTimer> m_TimerHandle;
std::list< RlvBehaviourModifierTween> m_Tweens;
};
// ====================================================================================