Browse Source

Added IsAtEnd() function to AnimationController.

Lasse Öörni 10 years ago
parent
commit
3e930c5a6f

+ 11 - 0
Source/Urho3D/Graphics/AnimationController.cpp

@@ -412,6 +412,17 @@ bool AnimationController::IsFadingOut(const String& name) const
         || (!state->IsLooped() && state->GetTime() >= state->GetLength() && animations_[index].autoFadeTime_);
         || (!state->IsLooped() && state->GetTime() >= state->GetLength() && animations_[index].autoFadeTime_);
 }
 }
 
 
+bool AnimationController::IsAtEnd(const String& name) const
+{
+    unsigned index;
+    AnimationState* state;
+    FindAnimation(name, index, state);
+    if (index == M_MAX_UNSIGNED || !state)
+        return false;
+    else
+        return state->GetTime() >= state->GetLength();
+}
+
 unsigned char AnimationController::GetLayer(const String& name) const
 unsigned char AnimationController::GetLayer(const String& name) const
 {
 {
     AnimationState* state = GetAnimationState(name);
     AnimationState* state = GetAnimationState(name);

+ 4 - 2
Source/Urho3D/Graphics/AnimationController.h

@@ -122,15 +122,17 @@ public:
     bool SetLooped(const String& name, bool enable);
     bool SetLooped(const String& name, bool enable);
     /// Set animation speed. Return true on success.
     /// Set animation speed. Return true on success.
     bool SetSpeed(const String& name, float speed);
     bool SetSpeed(const String& name, float speed);
-    /// Set animation autofade on stop (non-looped animations only.) Zero time disables. Return true on success.
+    /// Set animation autofade at end (non-looped animations only.) Zero time disables. Return true on success.
     bool SetAutoFade(const String& name, float fadeOutTime);
     bool SetAutoFade(const String& name, float fadeOutTime);
 
 
-    /// Return whether an animation is active.
+    /// Return whether an animation is active. Note that non-looping animations that are being clamped at the end also return true.
     bool IsPlaying(const String& name) const;
     bool IsPlaying(const String& name) const;
     /// Return whether an animation is fading in.
     /// Return whether an animation is fading in.
     bool IsFadingIn(const String& name) const;
     bool IsFadingIn(const String& name) const;
     /// Return whether an animation is fading out.
     /// Return whether an animation is fading out.
     bool IsFadingOut(const String& name) const;
     bool IsFadingOut(const String& name) const;
+    /// Return whether an animation is at its end. Will return false if the animation is not active at all.
+    bool IsAtEnd(const String& name) const;
     /// Return animation blending layer.
     /// Return animation blending layer.
     unsigned char GetLayer(const String& name) const;
     unsigned char GetLayer(const String& name) const;
     /// Return animation start bone, or null if no such animation.
     /// Return animation start bone, or null if no such animation.

+ 1 - 0
Source/Urho3D/LuaScript/pkgs/Graphics/AnimationController.pkg

@@ -37,6 +37,7 @@ class AnimationController : public Component
     bool IsPlaying(const String name) const;
     bool IsPlaying(const String name) const;
     bool IsFadingIn(const String name) const;
     bool IsFadingIn(const String name) const;
     bool IsFadingOut(const String name) const;
     bool IsFadingOut(const String name) const;
+    bool IsAtEnd(const String name) const;
     unsigned char GetLayer(const String name) const;
     unsigned char GetLayer(const String name) const;
     Bone* GetStartBone(const String name) const;
     Bone* GetStartBone(const String name) const;
     const String GetStartBoneName(const String name) const;
     const String GetStartBoneName(const String name) const;

+ 1 - 0
Source/Urho3D/Script/GraphicsAPI.cpp

@@ -1180,6 +1180,7 @@ static void RegisterAnimationController(asIScriptEngine* engine)
     engine->RegisterObjectMethod("AnimationController", "bool IsPlaying(const String&in) const", asMETHOD(AnimationController, IsPlaying), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "bool IsPlaying(const String&in) const", asMETHOD(AnimationController, IsPlaying), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "bool IsFadingIn(const String&in) const", asMETHOD(AnimationController, IsFadingIn), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "bool IsFadingIn(const String&in) const", asMETHOD(AnimationController, IsFadingIn), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "bool IsFadingOut(const String&in) const", asMETHOD(AnimationController, IsFadingOut), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "bool IsFadingOut(const String&in) const", asMETHOD(AnimationController, IsFadingOut), asCALL_THISCALL);
+    engine->RegisterObjectMethod("AnimationController", "bool IsAtEnd(const String&in) const", asMETHOD(AnimationController, IsAtEnd), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "uint8 GetLayer(const String&in) const", asMETHOD(AnimationController, GetLayer), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "uint8 GetLayer(const String&in) const", asMETHOD(AnimationController, GetLayer), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "const String& GetStartBone(const String&in) const", asMETHOD(AnimationController, GetStartBoneName), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "const String& GetStartBone(const String&in) const", asMETHOD(AnimationController, GetStartBoneName), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "float GetTime(const String&in) const", asMETHOD(AnimationController, GetTime), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationController", "float GetTime(const String&in) const", asMETHOD(AnimationController, GetTime), asCALL_THISCALL);