1 #ifndef MSP_GL_ANIMATIONPLAYER_H_
2 #define MSP_GL_ANIMATIONPLAYER_H_
4 #include <msp/time/timedelta.h>
6 #include "animationeventobserver.h"
15 The bridge between Animations and AnimatedObjects. A single AnimationPlayer
16 can handle an arbitrary number of animations simultaneously.
21 struct PlayingAnimation
23 const Animation *animation;
25 Animation::Iterator iterator;
27 PlayingAnimation(const Animation &, float);
30 struct Target: AnimationEventObserver
33 AnimatedObject *object;
35 const Armature *armature;
36 std::vector<PlayingAnimation> animations;
38 std::vector<AnimationEventObserver *> event_observers;
42 virtual void animation_event(Placeable *, const std::string &, const Variant &);
45 typedef std::map<const Placeable *, Target> ObjectMap;
50 Target &get_slot(Placeable &);
52 Target &play_(Placeable &, const Animation &, bool, float);
54 /// Plays an animation on an object. Any previous animations are replaced.
55 void play(AnimatedObject &, const Animation &, float = 1.0f);
57 void play(Placeable &, const Animation &, float = 1.0f);
59 /** Plays an animation, stacked with other animations. If no animations are
60 playing yet, the object's current matrix is used as the base. */
61 void play_stacked(AnimatedObject &, const Animation &, float = 1.0f);
63 void play_stacked(Placeable &, const Animation &, float = 1.0f);
65 /// Returns the number of animations currently affecting an object.
66 unsigned get_n_active_animations(const AnimatedObject &) const;
68 /** Request delivery of animation events for the given object. Events will
69 be delivered from all current and future animations until the observer is
71 void observe_events(AnimatedObject &, AnimationEventObserver &);
73 /// Remove an event observer from one object.
74 void unobserve_events(AnimatedObject &, AnimationEventObserver &);
76 /// Remove an event observer from all objects.
77 void unobserve_events(AnimationEventObserver &);
79 /// Stops all animations affecting an object.
80 void stop(AnimatedObject &);
82 /// Stops a single animation affecting an object.
83 void stop(AnimatedObject &, const Animation &);
85 /** Advances all playing animations. Should be called in a regular manner,
86 preferably just before rendering. */
87 void tick(const Time::TimeDelta &);
90 void tick_single(Target &, const Time::TimeDelta &);
91 void tick_stacked(Target &, const Time::TimeDelta &);
92 static void set_object_uniform(AnimatedObject &, const std::string &, const KeyFrame::AnimatedUniform &);