Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00025
00028
00029 #ifndef THOR_ANIMATOR_HPP
00030 #define THOR_ANIMATOR_HPP
00031
00032 #include <Thor/Config.hpp>
00033
00034 #include <SFML/System/Time.hpp>
00035
00036 #include <map>
00037 #include <functional>
00038 #include <cassert>
00039 #include <cmath>
00040
00041
00042 namespace thor
00043 {
00044
00047
00051 template <class Animated, typename Id>
00052 class Animator
00053 {
00054
00055
00056 public:
00061 typedef std::function<void(Animated&, float)> AnimationFunction;
00062
00063
00064
00065
00066 public:
00069 Animator();
00070
00073 Animator(const Animator& origin);
00074
00077 Animator& operator= (const Animator& origin);
00078
00081 Animator(Animator&& source);
00082
00085 Animator& operator= (Animator&& source);
00086
00089 ~Animator();
00090
00096 void addAnimation(const Id& id, const AnimationFunction& animation, sf::Time duration);
00097
00101 void playAnimation(const Id& id, bool loop = false);
00102
00106 void stopAnimation();
00107
00111 bool isPlayingAnimation() const;
00112
00116 Id getPlayingAnimation() const;
00117
00120 void update(sf::Time dt);
00121
00125 void animate(Animated& animated) const;
00126
00127
00128
00129
00130 private:
00131 typedef std::pair<AnimationFunction, sf::Time> ScaledAnimation;
00132 typedef std::map<Id, ScaledAnimation> AnimationMap;
00133 typedef typename AnimationMap::iterator AnimationMapIterator;
00134
00135
00136
00137
00138 private:
00139 void playAnimation(AnimationMapIterator animation, bool loop);
00140
00141 template <typename T>
00142 void adopt(T& source);
00143
00144
00145
00146
00147 private:
00148 AnimationMap mAnimationMap;
00149 AnimationMapIterator mPlayingAnimation;
00150 float mProgress;
00151 bool mLoop;
00152 };
00153
00155
00156 }
00157
00158 #include <Thor/Animations/Detail/Animator.inl>
00159 #endif // THOR_ANIMATOR_HPP