X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fanimationplayer.h;h=4c6e9ceca50bbc2fc0c7beeb5f256658a81c7150;hp=34a282d6b5bba2f36dce446a243c84b841176714;hb=7a2427020ec6ead73258aeb326dfb7e0121520f9;hpb=dfc784f7acd3132e5fcb9c43c0bda638df3b52f2 diff --git a/source/animationplayer.h b/source/animationplayer.h index 34a282d6..4c6e9cec 100644 --- a/source/animationplayer.h +++ b/source/animationplayer.h @@ -3,6 +3,7 @@ #include #include "animation.h" +#include "animationeventobserver.h" #include "matrix.h" namespace Msp { @@ -17,33 +18,34 @@ can handle an arbitrary number of animations simultaneously. class AnimationPlayer { private: - struct AnimationSlot + struct PlayingAnimation { - const Animation &animation; + const Animation *animation; Animation::Iterator iterator; - AnimationSlot(const Animation &); + PlayingAnimation(const Animation &); }; - typedef std::list AnimationList; - - struct ObjectSlot + struct Target: AnimationEventObserver { AnimatedObject &object; Matrix base_matrix; const Armature *armature; - AnimationList animations; + std::vector animations; bool stacked; + std::vector event_observers; + + Target(AnimatedObject &); - ObjectSlot(AnimatedObject &); + virtual void animation_event(AnimatedObject *, const std::string &, const Variant &); }; - typedef std::map ObjectMap; + typedef std::map ObjectMap; ObjectMap objects; private: - ObjectSlot &get_slot(AnimatedObject &); + Target &get_slot(AnimatedObject &); public: /// Plays an animation on an object. Any previous animations are replaced. @@ -56,6 +58,17 @@ public: /// Returns the number of animations currently affecting an object. unsigned get_n_active_animations(const AnimatedObject &) const; + /** Request delivery of animation events for the given object. Events will + be delivered from all current and future animations until the observer is + removed. */ + void observe_events(AnimatedObject &, AnimationEventObserver &); + + /// Remove an event observer from one object. + void unobserve_events(AnimatedObject &, AnimationEventObserver &); + + /// Remove an event observer from all objects. + void unobserve_events(AnimationEventObserver &); + /// Stops all animations affecting an object. void stop(AnimatedObject &); @@ -67,8 +80,9 @@ public: void tick(const Time::TimeDelta &); private: - bool tick_single(ObjectSlot &, const Time::TimeDelta &); - bool tick_stacked(ObjectSlot &, 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 &); }; } // namespace GL