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 std::map<const Placeable *, Target> objects;
48 Target &get_slot(Placeable &);
50 Target &play_(Placeable &, const Animation &, bool, float);
52 /// Plays an animation on an object. Any previous animations are replaced.
53 void play(AnimatedObject &, const Animation &, float = 1.0f);
55 void play(Placeable &, const Animation &, float = 1.0f);
57 /** Plays an animation, stacked with other animations. If no animations are
58 playing yet, the object's current matrix is used as the base. */
59 void play_stacked(AnimatedObject &, const Animation &, float = 1.0f);
61 void play_stacked(Placeable &, const Animation &, float = 1.0f);
63 /// Returns the number of animations currently affecting an object.
64 unsigned get_n_active_animations(const AnimatedObject &) const;
66 /** Request delivery of animation events for the given object. Events will
67 be delivered from all current and future animations until the observer is
69 void observe_events(AnimatedObject &, AnimationEventObserver &);
71 /// Remove an event observer from one object.
72 void unobserve_events(AnimatedObject &, AnimationEventObserver &);
74 /// Remove an event observer from all objects.
75 void unobserve_events(AnimationEventObserver &);
77 /// Stops all animations affecting an object.
78 void stop(Placeable &);
80 /// Stops a single animation affecting an object.
81 void stop(Placeable &, const Animation &);
83 /** Advances all playing animations. Should be called in a regular manner,
84 preferably just before rendering. */
85 void tick(const Time::TimeDelta &);
88 void tick_single(Target &, const Time::TimeDelta &);
89 void tick_stacked(Target &, const Time::TimeDelta &);
90 static void set_object_uniform(AnimatedObject &, const std::string &, const KeyFrame::AnimatedUniform &);