From: Mikko Rasa Date: Wed, 2 May 2018 19:32:14 +0000 (+0300) Subject: Refactor AnimationPlayer ticking X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a993091fbb8fdb76a1d02be9de59529c14b59cf0;p=libs%2Fgl.git Refactor AnimationPlayer ticking 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. --- diff --git a/source/animationplayer.cpp b/source/animationplayer.cpp index a3676ac9..cd716798 100644 --- a/source/animationplayer.cpp +++ b/source/animationplayer.cpp @@ -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::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) diff --git a/source/animationplayer.h b/source/animationplayer.h index 63e6e030..5d5f4cb8 100644 --- a/source/animationplayer.h +++ b/source/animationplayer.h @@ -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 &); };