From: Mikko Rasa Date: Sun, 2 Aug 2015 09:58:59 +0000 (+0300) Subject: Add a function to stop a single animation X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=dfc784f7acd3132e5fcb9c43c0bda638df3b52f2 Add a function to stop a single animation --- diff --git a/source/animationplayer.cpp b/source/animationplayer.cpp index ffb902a8..59c6f595 100644 --- a/source/animationplayer.cpp +++ b/source/animationplayer.cpp @@ -48,6 +48,23 @@ void AnimationPlayer::stop(AnimatedObject &obj) objects.erase(&obj); } +void AnimationPlayer::stop(AnimatedObject &obj, const Animation &anim) +{ + ObjectMap::iterator i = objects.find(&obj); + if(i==objects.end()) + return; + + for(AnimationList::iterator j=i->second.animations.begin(); j!=i->second.animations.end(); ++j) + if(&j->animation==&anim) + { + i->second.animations.erase(j); + break; + } + + if(i->second.animations.empty()) + objects.erase(i); +} + void AnimationPlayer::tick(const Time::TimeDelta &dt) { for(ObjectMap::iterator i=objects.begin(); i!=objects.end(); ) diff --git a/source/animationplayer.h b/source/animationplayer.h index 6211fd66..34a282d6 100644 --- a/source/animationplayer.h +++ b/source/animationplayer.h @@ -56,9 +56,12 @@ public: /// Returns the number of animations currently affecting an object. unsigned get_n_active_animations(const AnimatedObject &) const; - /// Stops any animations affecting an object. + /// Stops all animations affecting an object. void stop(AnimatedObject &); + /// Stops a single animation affecting an object. + void stop(AnimatedObject &, const Animation &); + /** Advances all playing animations. Should be called in a regular manner, preferably just before rendering. */ void tick(const Time::TimeDelta &);