]> git.tdb.fi Git - libs/gl.git/blob - source/animationplayer.h
Recognize in and out qualifiers for function parameters
[libs/gl.git] / source / animationplayer.h
1 #ifndef MSP_GL_ANIMATIONPLAYER_H_
2 #define MSP_GL_ANIMATIONPLAYER_H_
3
4 #include <msp/time/timedelta.h>
5 #include "animation.h"
6 #include "animationeventobserver.h"
7 #include "matrix.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class AnimatedObject;
13
14 /**
15 The bridge between Animations and AnimatedObjects.  A single AnimationPlayer
16 can handle an arbitrary number of animations simultaneously.
17 */
18 class AnimationPlayer
19 {
20 private:
21         struct PlayingAnimation
22         {
23                 const Animation *animation;
24                 Animation::Iterator iterator;
25
26                 PlayingAnimation(const Animation &);
27         };
28
29         struct Target: AnimationEventObserver
30         {
31                 AnimatedObject &object;
32                 Matrix base_matrix;
33                 const Armature *armature;
34                 std::vector<PlayingAnimation> animations;
35                 bool stacked;
36                 std::vector<AnimationEventObserver *> event_observers;
37
38                 Target(AnimatedObject &);
39
40                 virtual void animation_event(AnimatedObject *, const std::string &, const Variant &);
41         };
42
43         typedef std::map<const AnimatedObject *, Target> ObjectMap;
44
45         ObjectMap objects;
46
47 private:
48         Target &get_slot(AnimatedObject &);
49
50 public:
51         /// Plays an animation on an object.  Any previous animations are replaced.
52         void play(AnimatedObject &, const Animation &);
53
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 &);
57
58         /// Returns the number of animations currently affecting an object.
59         unsigned get_n_active_animations(const AnimatedObject &) const;
60
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
63         removed. */
64         void observe_events(AnimatedObject &, AnimationEventObserver &);
65
66         /// Remove an event observer from one object.
67         void unobserve_events(AnimatedObject &, AnimationEventObserver &);
68
69         /// Remove an event observer from all objects.
70         void unobserve_events(AnimationEventObserver &);
71
72         /// Stops all animations affecting an object.
73         void stop(AnimatedObject &);
74
75         /// Stops a single animation affecting an object.
76         void stop(AnimatedObject &, const Animation &);
77
78         /** Advances all playing animations.  Should be called in a regular manner,
79         preferably just before rendering. */
80         void tick(const Time::TimeDelta &);
81
82 private:
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 &);
86 };
87
88 } // namespace GL
89 } // namespace Msp
90
91 #endif