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;
24 Animation::Iterator iterator;
26 PlayingAnimation(const Animation &);
29 struct Target: AnimationEventObserver
31 AnimatedObject &object;
33 const Armature *armature;
34 std::vector<PlayingAnimation> animations;
36 std::vector<AnimationEventObserver *> event_observers;
38 Target(AnimatedObject &);
40 virtual void animation_event(AnimatedObject *, const std::string &, const Variant &);
43 typedef std::map<const AnimatedObject *, Target> ObjectMap;
48 Target &get_slot(AnimatedObject &);
51 /// Plays an animation on an object. Any previous animations are replaced.
52 void play(AnimatedObject &, const Animation &);
54 /** Plays an animation, stacked with other animations. If no animations are
55 playing yet, the object's current matrix is used as the base. */
56 void play_stacked(AnimatedObject &, const Animation &);
58 /// Returns the number of animations currently affecting an object.
59 unsigned get_n_active_animations(const AnimatedObject &) const;
61 /** Request delivery of animation events for the given object. Events will
62 be delivered from all current and future animations until the observer is
64 void observe_events(AnimatedObject &, AnimationEventObserver &);
66 /// Remove an event observer from one object.
67 void unobserve_events(AnimatedObject &, AnimationEventObserver &);
69 /// Remove an event observer from all objects.
70 void unobserve_events(AnimationEventObserver &);
72 /// Stops all animations affecting an object.
73 void stop(AnimatedObject &);
75 /// Stops a single animation affecting an object.
76 void stop(AnimatedObject &, const Animation &);
78 /** Advances all playing animations. Should be called in a regular manner,
79 preferably just before rendering. */
80 void tick(const Time::TimeDelta &);
83 void tick_single(Target &, const Time::TimeDelta &);
84 void tick_stacked(Target &, const Time::TimeDelta &);
85 static void set_object_uniform(AnimatedObject &, const std::string &, const KeyFrame::AnimatedUniform &);