]> git.tdb.fi Git - libs/gl.git/blobdiff - source/animation.h
Implement an event system for animations
[libs/gl.git] / source / animation.h
index dd3cc688c41290316450858a7d540a79e93dcfb8..c190bdbfd1cb11048020ad7ba06a44fff81d1a24 100644 (file)
@@ -9,6 +9,7 @@
 namespace Msp {
 namespace GL {
 
 namespace Msp {
 namespace GL {
 
+class AnimationEventObserver;
 class Armature;
 class Matrix;
 class Pose;
 class Armature;
 class Matrix;
 class Pose;
@@ -31,6 +32,12 @@ public:
        private:
                void init();
 
        private:
                void init();
 
+               void event(const std::string &);
+               void event1i(const std::string &, int);
+               void event1f(const std::string &, float);
+               void event2f(const std::string &, float, float);
+               void event3f(const std::string &, float, float, float);
+               void event4f(const std::string &, float, float, float, float);
                void keyframe(const std::string &);
                void keyframe_inline();
                void interval(float);
                void keyframe(const std::string &);
                void keyframe_inline();
                void interval(float);
@@ -72,6 +79,13 @@ private:
                void prepare(const Animation &);
        };
 
                void prepare(const Animation &);
        };
 
+       struct Event
+       {
+               Time::TimeDelta time;
+               std::string name;
+               Variant value;
+       };
+
        struct UniformInfo
        {
                std::string name;
        struct UniformInfo
        {
                std::string name;
@@ -86,6 +100,7 @@ public:
        private:
                const Animation *animation;
                std::vector<TimedKeyFrame>::const_iterator iter;
        private:
                const Animation *animation;
                std::vector<TimedKeyFrame>::const_iterator iter;
+               std::vector<Event>::const_iterator event_iter;
                Time::TimeDelta time_since_keyframe;
                bool end;
 
                Time::TimeDelta time_since_keyframe;
                bool end;
 
@@ -93,6 +108,7 @@ public:
                Iterator(const Animation &);
 
                Iterator &operator+=(const Time::TimeDelta &);
                Iterator(const Animation &);
 
                Iterator &operator+=(const Time::TimeDelta &);
+               void dispatch_events(AnimationEventObserver &);
 
                bool is_end() const { return end; }
                Matrix get_matrix() const;
 
                bool is_end() const { return end; }
                Matrix get_matrix() const;
@@ -103,6 +119,7 @@ public:
 private:
        const Armature *armature;
        std::vector<TimedKeyFrame> keyframes;
 private:
        const Armature *armature;
        std::vector<TimedKeyFrame> keyframes;
+       std::vector<Event> events;
        bool looping;
        std::vector<UniformInfo> uniforms;
 
        bool looping;
        std::vector<UniformInfo> uniforms;
 
@@ -121,8 +138,9 @@ public:
 private:
        void add_keyframe(const Time::TimeDelta &, const RefPtr<const KeyFrame> &);
        void prepare_keyframe(TimedKeyFrame &);
 private:
        void add_keyframe(const Time::TimeDelta &, const RefPtr<const KeyFrame> &);
        void prepare_keyframe(TimedKeyFrame &);
-
 public:
 public:
+       void add_event(const Time::TimeDelta &, const std::string &, const Variant & = Variant());
+
        void set_looping(bool);
 };
 
        void set_looping(bool);
 };