]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor AnimationPlayer ticking
authorMikko Rasa <tdb@tdb.fi>
Wed, 2 May 2018 19:32:14 +0000 (22:32 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 2 May 2018 22:07:15 +0000 (01:07 +0300)
It's not more consistent between single and stacked animations.  There
shouldn't be significant performance penalty since the animation states
would be freed upon removing the target anyway.

source/animationplayer.cpp
source/animationplayer.h

index a3676ac90543331ddcba021b60d1c1f2c038f10b..cd71679800fffea672ebea6c4ef84ed796622104 100644 (file)
@@ -70,20 +70,19 @@ void AnimationPlayer::tick(const Time::TimeDelta &dt)
 {
        for(ObjectMap::iterator i=objects.begin(); i!=objects.end(); )
        {
-               bool keep = false;
                if(i->second.stacked)
-                       keep = tick_stacked(i->second, dt);
+                       tick_stacked(i->second, dt);
                else
-                       keep = tick_single(i->second, dt);
+                       tick_single(i->second, dt);
 
-               if(!keep)
+               if(i->second.animations.empty())
                        objects.erase(i++);
                else
                        ++i;
        }
 }
 
-bool AnimationPlayer::tick_single(Target &target, const Time::TimeDelta &dt)
+void AnimationPlayer::tick_single(Target &target, const Time::TimeDelta &dt)
 {
        PlayingAnimation &anim = target.animations.front();
        anim.iterator += dt;
@@ -100,10 +99,11 @@ bool AnimationPlayer::tick_single(Target &target, const Time::TimeDelta &dt)
                        target.object.set_pose_matrix(i, anim.iterator.get_pose_matrix(i));
        }
 
-       return !anim.iterator.is_end();
+       if(!anim.iterator.is_end())
+               target.animations.clear();
 }
 
-bool AnimationPlayer::tick_stacked(Target &target, const Time::TimeDelta &dt)
+void AnimationPlayer::tick_stacked(Target &target, const Time::TimeDelta &dt)
 {
        Matrix matrix = target.base_matrix;
        for(vector<PlayingAnimation>::iterator i=target.animations.begin(); i!=target.animations.end(); ++i)
@@ -140,7 +140,8 @@ bool AnimationPlayer::tick_stacked(Target &target, const Time::TimeDelta &dt)
                        ++i;
        }
 
-       return !target.animations.empty();
+       if(target.animations.empty())
+               target.stacked = false;
 }
 
 void AnimationPlayer::set_object_uniform(AnimatedObject &obj, const string &name, const KeyFrame::AnimatedUniform &uni)
index 63e6e030d03aa68b30efa2a63aa169b077986402..5d5f4cb85a260f88f9d5a109004b71b982c05564 100644 (file)
@@ -65,8 +65,8 @@ public:
        void tick(const Time::TimeDelta &);
 
 private:
-       bool tick_single(Target &, const Time::TimeDelta &);
-       bool tick_stacked(Target &, const Time::TimeDelta &);
+       void tick_single(Target &, const Time::TimeDelta &);
+       void tick_stacked(Target &, const Time::TimeDelta &);
        static void set_object_uniform(AnimatedObject &, const std::string &, const KeyFrame::AnimatedUniform &);
 };