00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef ANIMATED_IMAGE_H_INCLUDED
00019 #define ANIMATED_IMAGE_H_INCLUDED
00020
00021 #include <string>
00022 #include <map>
00023 #include <vector>
00024
00025 void new_animation_frame();
00026 int get_current_animation_tick();
00027
00028
00029 template<typename T>
00030 class void_value
00031 {
00032 public:
00033 const T operator()() { return T(); }
00034 };
00035
00036 template<typename T, typename T_void_value=void_value<T> >
00037 class animated
00038 {
00039 public:
00040
00041 animated(int start_time=0);
00042 virtual ~animated(){};
00043
00044
00045 typedef std::pair<int,T> frame_description;
00046 typedef std::vector<frame_description> anim_description;
00047 animated(const std::vector<frame_description> &cfg, int start_time = 0,bool force_change =false);
00048
00049
00050
00051 void add_frame(int duration, const T& value,bool force_change =false);
00052
00053
00054
00055
00056 void start_animation(int start_time, bool cycles=false);
00057 void pause_animation(){ started_ =false;};
00058 void restart_animation(){if(start_tick_) started_ = true;};
00059
00060 int get_begin_time() const;
00061 int get_end_time() const;
00062 void set_begin_time(int new_begin_time);
00063
00064 int time_to_tick(int animation_time) const;
00065 int tick_to_time(int animation_tick) const;
00066
00067 void update_last_draw_time(double acceleration = 0);
00068 bool need_update() const;
00069
00070 bool cycles() const {return cycles_;};
00071
00072
00073 bool animation_finished() const;
00074 bool animation_finished_potential() const;
00075 int get_animation_time() const;
00076 int get_animation_time_potential() const;
00077
00078 int get_animation_duration() const;
00079 const T& get_current_frame() const;
00080 int get_current_frame_begin_time() const;
00081 int get_current_frame_end_time() const;
00082 int get_current_frame_duration() const;
00083 int get_current_frame_time() const;
00084 const T& get_first_frame() const;
00085 const T& get_last_frame() const;
00086 int get_frames_count() const;
00087 void force_change() {does_not_change_ = false ; }
00088 bool does_not_change() const {return does_not_change_;}
00089
00090 static const T void_value_;
00091
00092 protected:
00093 friend class unit_animation;
00094 int starting_frame_time_;
00095
00096 void remove_frames_until(int starting_time);
00097 void remove_frames_after(int ending_time);
00098
00099 private:
00100 struct frame
00101 {
00102
00103 frame(int duration , const T& value,int start_time) :
00104 duration_(duration),value_(value),start_time_(start_time)
00105 {};
00106 frame():
00107 duration_(0),value_(void_value_),start_time_(0)
00108 {};
00109
00110
00111 int duration_;
00112 T value_;
00113 int start_time_;
00114 };
00115
00116 bool does_not_change_;
00117 bool started_;
00118 bool need_first_update_;
00119 std::vector<frame> frames_;
00120
00121
00122 int start_tick_;
00123 bool cycles_;
00124 double acceleration_;
00125 int last_update_tick_;
00126 int current_frame_key_;
00127
00128 };
00129
00130 #endif
00131