Procházet zdrojové kódy

Added a way to get an animation from an AnimationTarget.

Darryl Gough před 14 roky
rodič
revize
5532ed322d

+ 12 - 0
gameplay/src/Animation.cpp

@@ -172,6 +172,18 @@ void Animation::pause(const char * clipId)
     }
     }
 }
 }
 
 
+bool Animation::targets(AnimationTarget* target) const
+{
+    for (std::vector<Animation::Channel*>::const_iterator itr = _channels.begin(); itr != _channels.end(); ++itr)
+    {
+        if ((*itr)->_target == target)
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
 void Animation::createDefaultClip()
 void Animation::createDefaultClip()
 {
 {
     _defaultClip = new AnimationClip("default_clip", this, 0.0f, _duration);
     _defaultClip = new AnimationClip("default_clip", this, 0.0f, _duration);

+ 5 - 0
gameplay/src/Animation.h

@@ -89,6 +89,11 @@ public:
      */
      */
     void pause(const char* clipId = NULL);
     void pause(const char* clipId = NULL);
 
 
+    /**
+     * Returns true if this animation targets the given AnimationTarget.
+     */
+    bool targets(AnimationTarget* target) const;
+
 private:
 private:
 
 
     /**
     /**

+ 16 - 0
gameplay/src/AnimationController.cpp

@@ -112,6 +112,22 @@ Animation* AnimationController::getAnimation(const char* id) const
     return NULL;
     return NULL;
 }
 }
 
 
+Animation* AnimationController::getAnimation(AnimationTarget* target) const
+{
+    if (!target)
+        return NULL;
+    const unsigned int animationCount = _animations.size();
+    for (unsigned int i = 0; i < animationCount; ++i)
+    {
+        Animation* animation = _animations[i];
+        if (animation->targets(target))
+        {
+            return animation;
+        }
+    }
+    return NULL;
+}
+
 void AnimationController::stopAllAnimations() 
 void AnimationController::stopAllAnimations() 
 {
 {
     std::list<AnimationClip*>::iterator clipIter = _runningClips.begin();
     std::list<AnimationClip*>::iterator clipIter = _runningClips.begin();

+ 5 - 0
gameplay/src/AnimationController.h

@@ -106,6 +106,11 @@ public:
      */
      */
     Animation* getAnimation(const char* id) const;
     Animation* getAnimation(const char* id) const;
 
 
+    /**
+     * Returns the first animation that targets the given AnimationTarget.
+     */
+    Animation* getAnimation(AnimationTarget* target) const;
+
     /** 
     /** 
      * Stops all AnimationClips currently playing on the AnimationController.
      * Stops all AnimationClips currently playing on the AnimationController.
      */
      */