void Animatable::OnObjectAnimationAdded(ObjectAnimation* objectAnimation) { if (!objectAnimation) return; // Set all attribute animations from the object animation const HashMap<String, SharedPtr<AttributeAnimationInfo> >& attributeAnimationInfos = objectAnimation->GetAttributeAnimationInfos(); for (HashMap<String, SharedPtr<AttributeAnimationInfo> >::ConstIterator i = attributeAnimationInfos.Begin(); i != attributeAnimationInfos.End(); ++i) { const String& name = i->first_; AttributeAnimationInfo* info = i->second_; SetAttributeAnimation(name, info->GetAttributeAnimation(), info->GetWrapMode(), info->GetSpeed()); } }
void Animatable::UpdateAttributeAnimations(float timeStep) { if (!animationEnabled_) return; Vector<String> finishedNames; for (HashMap<String, SharedPtr<AttributeAnimationInstance> >::ConstIterator i = attributeAnimationInstances_.Begin(); i != attributeAnimationInstances_.End(); ++i) { if (i->second_->Update(timeStep)) finishedNames.Push(i->second_->GetAttributeInfo().name_); } for (unsigned i = 0; i < finishedNames.Size(); ++i) SetAttributeAnimation(finishedNames[i], 0); }
void Animatable::OnObjectAnimationRemoved(ObjectAnimation* objectAnimation) { if (!objectAnimation) return; // Just remove all attribute animations from the object animation Vector<String> names; for (HashMap<String, SharedPtr<AttributeAnimationInstance> >::Iterator i = attributeAnimationInstances_.Begin(); i != attributeAnimationInstances_.End(); ++i) { if (i->second_->GetAttributeAnimation()->GetObjectAnimation() == objectAnimation) names.Push(i->first_); } for (unsigned int i = 0; i < names.Size(); ++i) SetAttributeAnimation(names[i], 0); }
bool Animatable::LoadXML(const XMLElement& source, bool setInstanceDefault) { if (!Serializable::LoadXML(source, setInstanceDefault)) return false; SetObjectAnimation(0); attributeAnimationInstances_.Clear(); XMLElement elem = source.GetChild("objectanimation"); if (elem) { SharedPtr<ObjectAnimation> objectAnimation(new ObjectAnimation(context_)); if (!objectAnimation->LoadXML(elem)) return false; SetObjectAnimation(objectAnimation); } elem = source.GetChild("attributeanimation"); while (elem) { String name = elem.GetAttribute("name"); SharedPtr<AttributeAnimation> attributeAnimation(new AttributeAnimation(context_)); if (!attributeAnimation->LoadXML(elem)) return false; String wrapModeString = source.GetAttribute("wrapmode"); WrapMode wrapMode = WM_LOOP; for (int i = 0; i <= WM_CLAMP; ++i) { if (wrapModeString == wrapModeNames[i]) { wrapMode = (WrapMode)i; break; } } float speed = elem.GetFloat("speed"); SetAttributeAnimation(name, attributeAnimation, wrapMode, speed); elem = elem.GetNext("attributeanimation"); } return true; }
void Animatable::SetObjectAttributeAnimation(const String& name, ValueAnimation* attributeAnimation, WrapMode wrapMode, float speed) { SetAttributeAnimation(name, attributeAnimation, wrapMode, speed); }