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
32 AnimatedObject *object;
34 const Armature *armature;
35 std::vector<PlayingAnimation> animations;
37 std::vector<AnimationEventObserver *> event_observers;
41 virtual void animation_event(Placeable *, const std::string &, const Variant &);
44 typedef std::map<const Placeable *, Target> ObjectMap;
49 Target &get_slot(Placeable &);
51 Target &play_(Placeable &, const Animation &, bool);
53 /// Plays an animation on an object. Any previous animations are replaced.
54 void play(AnimatedObject &, const Animation &);
56 void play(Placeable &, const Animation &);
58 /** Plays an animation, stacked with other animations. If no animations are
59 playing yet, the object's current matrix is used as the base. */
60 void play_stacked(AnimatedObject &, const Animation &);
62 void play_stacked(Placeable &, const Animation &);
64 /// Returns the number of animations currently affecting an object.
65 unsigned get_n_active_animations(const AnimatedObject &) const;
67 /** Request delivery of animation events for the given object. Events will
68 be delivered from all current and future animations until the observer is
70 void observe_events(AnimatedObject &, AnimationEventObserver &);
72 /// Remove an event observer from one object.
73 void unobserve_events(AnimatedObject &, AnimationEventObserver &);
75 /// Remove an event observer from all objects.
76 void unobserve_events(AnimationEventObserver &);
78 /// Stops all animations affecting an object.
79 void stop(AnimatedObject &);
81 /// Stops a single animation affecting an object.
82 void stop(AnimatedObject &, const Animation &);
84 /** Advances all playing animations. Should be called in a regular manner,
85 preferably just before rendering. */
86 void tick(const Time::TimeDelta &);
89 void tick_single(Target &, const Time::TimeDelta &);
90 void tick_stacked(Target &, const Time::TimeDelta &);
91 static void set_object_uniform(AnimatedObject &, const std::string &, const KeyFrame::AnimatedUniform &);