|
@@ -109,7 +109,7 @@ bool Animatable::LoadXML(const XMLElement& source, bool setInstanceDefault)
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
SetObjectAnimation(0);
|
|
SetObjectAnimation(0);
|
|
|
- attributeAnimationInstances_.Clear();
|
|
|
|
|
|
|
+ attributeAnimationInfos_.Clear();
|
|
|
|
|
|
|
|
XMLElement elem = source.GetChild("objectanimation");
|
|
XMLElement elem = source.GetChild("objectanimation");
|
|
|
if (elem)
|
|
if (elem)
|
|
@@ -162,7 +162,7 @@ bool Animatable::SaveXML(XMLElement& dest) const
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- for (HashMap<String, SharedPtr<AttributeAnimationInfo> >::ConstIterator i = attributeAnimationInstances_.Begin(); i != attributeAnimationInstances_.End(); ++i)
|
|
|
|
|
|
|
+ for (HashMap<String, SharedPtr<AttributeAnimationInfo> >::ConstIterator i = attributeAnimationInfos_.Begin(); i != attributeAnimationInfos_.End(); ++i)
|
|
|
{
|
|
{
|
|
|
ValueAnimation* attributeAnimation = i->second_->GetAnimation();
|
|
ValueAnimation* attributeAnimation = i->second_->GetAnimation();
|
|
|
if (attributeAnimation->GetOwner())
|
|
if (attributeAnimation->GetOwner())
|
|
@@ -197,21 +197,24 @@ void Animatable::SetObjectAnimation(ObjectAnimation* objectAnimation)
|
|
|
|
|
|
|
|
void Animatable::SetAttributeAnimation(const String& name, ValueAnimation* attributeAnimation, WrapMode wrapMode, float speed)
|
|
void Animatable::SetAttributeAnimation(const String& name, ValueAnimation* attributeAnimation, WrapMode wrapMode, float speed)
|
|
|
{
|
|
{
|
|
|
- AttributeAnimationInfo* currentInstance = GetAttributeAnimationInstance(name);
|
|
|
|
|
|
|
+ AttributeAnimationInfo* info = GetAttributeAnimationInfo(name);
|
|
|
|
|
|
|
|
if (attributeAnimation)
|
|
if (attributeAnimation)
|
|
|
{
|
|
{
|
|
|
- if (currentInstance && attributeAnimation == currentInstance->GetAnimation())
|
|
|
|
|
|
|
+ if (info && attributeAnimation == info->GetAnimation())
|
|
|
{
|
|
{
|
|
|
- currentInstance->SetWrapMode(wrapMode);
|
|
|
|
|
- currentInstance->SetSpeed(speed);
|
|
|
|
|
|
|
+ info->SetWrapMode(wrapMode);
|
|
|
|
|
+ info->SetSpeed(speed);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Use shared ptr to avoid memory leak
|
|
|
|
|
+ SharedPtr<ValueAnimation> animationPtr(attributeAnimation);
|
|
|
|
|
+
|
|
|
// Get attribute info
|
|
// Get attribute info
|
|
|
const AttributeInfo* attributeInfo = 0;
|
|
const AttributeInfo* attributeInfo = 0;
|
|
|
- if (currentInstance)
|
|
|
|
|
- attributeInfo = ¤tInstance->GetAttributeInfo();
|
|
|
|
|
|
|
+ if (info)
|
|
|
|
|
+ attributeInfo = &info->GetAttributeInfo();
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
const Vector<AttributeInfo>* attributes = GetAttributes();
|
|
const Vector<AttributeInfo>* attributes = GetAttributes();
|
|
@@ -238,7 +241,7 @@ void Animatable::SetAttributeAnimation(const String& name, ValueAnimation* attri
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Check value type is same with attribute type
|
|
// Check value type is same with attribute type
|
|
|
- if (attributeAnimation->GetValueType() != attributeInfo->type_)
|
|
|
|
|
|
|
+ if (animationPtr->GetValueType() != attributeInfo->type_)
|
|
|
{
|
|
{
|
|
|
LOGERROR("Invalid value type");
|
|
LOGERROR("Invalid value type");
|
|
|
return;
|
|
return;
|
|
@@ -248,37 +251,37 @@ void Animatable::SetAttributeAnimation(const String& name, ValueAnimation* attri
|
|
|
if (attributeInfo->mode_ & AM_NET)
|
|
if (attributeInfo->mode_ & AM_NET)
|
|
|
animatedNetworkAttributes_.Insert(attributeInfo);
|
|
animatedNetworkAttributes_.Insert(attributeInfo);
|
|
|
|
|
|
|
|
- attributeAnimationInstances_[name] = new AttributeAnimationInfo(this, *attributeInfo, attributeAnimation, wrapMode, speed);
|
|
|
|
|
|
|
+ attributeAnimationInfos_[name] = new AttributeAnimationInfo(this, *attributeInfo, animationPtr, wrapMode, speed);
|
|
|
|
|
|
|
|
- if (!currentInstance)
|
|
|
|
|
|
|
+ if (!info)
|
|
|
OnAttributeAnimationAdded();
|
|
OnAttributeAnimationAdded();
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- if (!currentInstance)
|
|
|
|
|
|
|
+ if (!info)
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
// Remove network attribute from set
|
|
// Remove network attribute from set
|
|
|
- if (currentInstance->GetAttributeInfo().mode_ & AM_NET)
|
|
|
|
|
- animatedNetworkAttributes_.Erase(¤tInstance->GetAttributeInfo());
|
|
|
|
|
|
|
+ if (info->GetAttributeInfo().mode_ & AM_NET)
|
|
|
|
|
+ animatedNetworkAttributes_.Erase(&info->GetAttributeInfo());
|
|
|
|
|
|
|
|
- attributeAnimationInstances_.Erase(name);
|
|
|
|
|
|
|
+ attributeAnimationInfos_.Erase(name);
|
|
|
OnAttributeAnimationRemoved();
|
|
OnAttributeAnimationRemoved();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Animatable::SetAttributeAnimationWrapMode(const String& name, WrapMode wrapMode)
|
|
void Animatable::SetAttributeAnimationWrapMode(const String& name, WrapMode wrapMode)
|
|
|
{
|
|
{
|
|
|
- AttributeAnimationInfo* currentInstance = GetAttributeAnimationInstance(name);
|
|
|
|
|
- if (currentInstance)
|
|
|
|
|
- currentInstance->SetWrapMode(wrapMode);
|
|
|
|
|
|
|
+ AttributeAnimationInfo* info = GetAttributeAnimationInfo(name);
|
|
|
|
|
+ if (info)
|
|
|
|
|
+ info->SetWrapMode(wrapMode);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Animatable::SetAttributeAnimationSpeed(const String& name, float speed)
|
|
void Animatable::SetAttributeAnimationSpeed(const String& name, float speed)
|
|
|
{
|
|
{
|
|
|
- AttributeAnimationInfo* currentInstance = GetAttributeAnimationInstance(name);
|
|
|
|
|
- if (currentInstance)
|
|
|
|
|
- currentInstance->SetSpeed(speed);
|
|
|
|
|
|
|
+ AttributeAnimationInfo* info = GetAttributeAnimationInfo(name);
|
|
|
|
|
+ if (info)
|
|
|
|
|
+ info->SetSpeed(speed);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ObjectAnimation* Animatable::GetObjectAnimation() const
|
|
ObjectAnimation* Animatable::GetObjectAnimation() const
|
|
@@ -288,20 +291,20 @@ ObjectAnimation* Animatable::GetObjectAnimation() const
|
|
|
|
|
|
|
|
ValueAnimation* Animatable::GetAttributeAnimation(const String& name) const
|
|
ValueAnimation* Animatable::GetAttributeAnimation(const String& name) const
|
|
|
{
|
|
{
|
|
|
- const AttributeAnimationInfo* instance = GetAttributeAnimationInstance(name);
|
|
|
|
|
- return instance ? instance->GetAnimation() : 0;
|
|
|
|
|
|
|
+ const AttributeAnimationInfo* info = GetAttributeAnimationInfo(name);
|
|
|
|
|
+ return info ? info->GetAnimation() : 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
WrapMode Animatable::GetAttributeAnimationWrapMode(const String& name) const
|
|
WrapMode Animatable::GetAttributeAnimationWrapMode(const String& name) const
|
|
|
{
|
|
{
|
|
|
- const AttributeAnimationInfo* instance = GetAttributeAnimationInstance(name);
|
|
|
|
|
- return instance ? instance->GetWrapMode() : WM_LOOP;
|
|
|
|
|
|
|
+ const AttributeAnimationInfo* info = GetAttributeAnimationInfo(name);
|
|
|
|
|
+ return info ? info->GetWrapMode() : WM_LOOP;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
float Animatable::GetAttributeAnimationSpeed(const String& name) const
|
|
float Animatable::GetAttributeAnimationSpeed(const String& name) const
|
|
|
{
|
|
{
|
|
|
- const AttributeAnimationInfo* instance = GetAttributeAnimationInstance(name);
|
|
|
|
|
- return instance ? instance->GetSpeed() : 1.0f;
|
|
|
|
|
|
|
+ const AttributeAnimationInfo* info = GetAttributeAnimationInfo(name);
|
|
|
|
|
+ return info ? info->GetSpeed() : 1.0f;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Animatable::SetObjectAnimationAttr(ResourceRef value)
|
|
void Animatable::SetObjectAnimationAttr(ResourceRef value)
|
|
@@ -340,7 +343,7 @@ void Animatable::OnObjectAnimationRemoved(ObjectAnimation* objectAnimation)
|
|
|
|
|
|
|
|
// Just remove all attribute animations from the object animation
|
|
// Just remove all attribute animations from the object animation
|
|
|
Vector<String> names;
|
|
Vector<String> names;
|
|
|
- for (HashMap<String, SharedPtr<AttributeAnimationInfo> >::Iterator i = attributeAnimationInstances_.Begin(); i != attributeAnimationInstances_.End(); ++i)
|
|
|
|
|
|
|
+ for (HashMap<String, SharedPtr<AttributeAnimationInfo> >::Iterator i = attributeAnimationInfos_.Begin(); i != attributeAnimationInfos_.End(); ++i)
|
|
|
{
|
|
{
|
|
|
if (i->second_->GetAnimation()->GetOwner() == objectAnimation)
|
|
if (i->second_->GetAnimation()->GetOwner() == objectAnimation)
|
|
|
names.Push(i->first_);
|
|
names.Push(i->first_);
|
|
@@ -356,7 +359,7 @@ void Animatable::UpdateAttributeAnimations(float timeStep)
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
Vector<String> finishedNames;
|
|
Vector<String> finishedNames;
|
|
|
- for (HashMap<String, SharedPtr<AttributeAnimationInfo> >::ConstIterator i = attributeAnimationInstances_.Begin(); i != attributeAnimationInstances_.End(); ++i)
|
|
|
|
|
|
|
+ for (HashMap<String, SharedPtr<AttributeAnimationInfo> >::ConstIterator i = attributeAnimationInfos_.Begin(); i != attributeAnimationInfos_.End(); ++i)
|
|
|
{
|
|
{
|
|
|
if (i->second_->Update(timeStep))
|
|
if (i->second_->Update(timeStep))
|
|
|
finishedNames.Push(i->second_->GetAttributeInfo().name_);
|
|
finishedNames.Push(i->second_->GetAttributeInfo().name_);
|
|
@@ -371,10 +374,10 @@ bool Animatable::IsAnimatedNetworkAttribute(const AttributeInfo& attrInfo) const
|
|
|
return animatedNetworkAttributes_.Find(&attrInfo) != animatedNetworkAttributes_.End();
|
|
return animatedNetworkAttributes_.Find(&attrInfo) != animatedNetworkAttributes_.End();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-AttributeAnimationInfo* Animatable::GetAttributeAnimationInstance(const String& name) const
|
|
|
|
|
|
|
+AttributeAnimationInfo* Animatable::GetAttributeAnimationInfo(const String& name) const
|
|
|
{
|
|
{
|
|
|
- HashMap<String, SharedPtr<AttributeAnimationInfo> >::ConstIterator i = attributeAnimationInstances_.Find(name);
|
|
|
|
|
- if (i != attributeAnimationInstances_.End())
|
|
|
|
|
|
|
+ HashMap<String, SharedPtr<AttributeAnimationInfo> >::ConstIterator i = attributeAnimationInfos_.Find(name);
|
|
|
|
|
+ if (i != attributeAnimationInfos_.End())
|
|
|
return i->second_;
|
|
return i->second_;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|