#include <msp/time/timedelta.h>
#include "animation.h"
+#include "animationeventobserver.h"
#include "matrix.h"
namespace Msp {
class AnimationPlayer
{
private:
- struct AnimationSlot
+ struct PlayingAnimation
{
const Animation *animation;
Animation::Iterator iterator;
- AnimationSlot(const Animation &);
+ PlayingAnimation(const Animation &);
};
- struct ObjectSlot
+ struct Target: AnimationEventObserver
{
AnimatedObject &object;
Matrix base_matrix;
const Armature *armature;
- std::vector<AnimationSlot> animations;
+ std::vector<PlayingAnimation> animations;
bool stacked;
+ std::vector<AnimationEventObserver *> event_observers;
- ObjectSlot(AnimatedObject &);
+ Target(AnimatedObject &);
+
+ virtual void animation_event(AnimatedObject *, const std::string &, const Variant &);
};
- typedef std::map<const AnimatedObject *, ObjectSlot> ObjectMap;
+ typedef std::map<const AnimatedObject *, Target> ObjectMap;
ObjectMap objects;
private:
- ObjectSlot &get_slot(AnimatedObject &);
+ Target &get_slot(AnimatedObject &);
public:
/// Plays an animation on an object. Any previous animations are replaced.
/// Returns the number of animations currently affecting an object.
unsigned get_n_active_animations(const AnimatedObject &) const;
+ /** Request delivery of animation events for the given object. Events will
+ be delivered from all current and future animations until the observer is
+ removed. */
+ void observe_events(AnimatedObject &, AnimationEventObserver &);
+
+ /// Remove an event observer from one object.
+ void unobserve_events(AnimatedObject &, AnimationEventObserver &);
+
+ /// Remove an event observer from all objects.
+ void unobserve_events(AnimationEventObserver &);
+
/// Stops all animations affecting an object.
void stop(AnimatedObject &);
void tick(const Time::TimeDelta &);
private:
- bool tick_single(ObjectSlot &, const Time::TimeDelta &);
- bool tick_stacked(ObjectSlot &, const Time::TimeDelta &);
+ void tick_single(Target &, const Time::TimeDelta &);
+ void tick_stacked(Target &, const Time::TimeDelta &);
static void set_object_uniform(AnimatedObject &, const std::string &, const KeyFrame::AnimatedUniform &);
};