fix an hidden bug when using non zero start time

add comments about bad support of acceleration for some functions

simplify get_animation_duration

remove my previous tempo function (now unneeded)
This commit is contained in:
Ali El Gariani 2007-04-14 10:55:37 +00:00
parent 212fc4d88c
commit 61ab446359
2 changed files with 5 additions and 17 deletions

View file

@ -90,7 +90,6 @@ void animated<T,T_void_value>::start_animation(int start_time, bool cycles, doub
start_tick_ = last_update_tick_ + ( starting_frame_time_ - start_time);
cycles_ = cycles;
acceleration_ = acceleration;
//FIXME: allow negative acceleration -> reverse animation
if(acceleration_ <=0) acceleration_ = 1;
current_frame_key_= 0;
update_last_draw_time();
@ -116,7 +115,7 @@ void animated<T,T_void_value>::update_last_draw_time()
if(cycles_) {
while(get_animation_time() > get_end_time()){ // cut extra time
start_tick_ +=(int)(get_end_time()/acceleration_);
current_frame_key_ =starting_frame_time_;
current_frame_key_ = 0;
}
}
while(get_current_frame_end_time() < get_animation_time() && // catch up
@ -179,17 +178,7 @@ int animated<T,T_void_value>::get_animation_time() const
template<typename T, typename T_void_value>
const int animated<T,T_void_value>::get_animation_duration() const
{
int duration = 0;
for (size_t i=0; i!=frames_.size(); i++) {
duration += frames_[i].duration_;
}
return duration;
}
template<typename T, typename T_void_value>
const int animated<T,T_void_value>::get_animation_tempo() const
{
return get_animation_duration() / get_frames_count();
return get_end_time() - get_begin_time();
}
template<typename T, typename T_void_value>
@ -244,6 +233,7 @@ const int animated<T,T_void_value>::get_current_frame_time() const
{
if(frames_.empty() )
return 0;
//FIXME: get_animation_time() use acceleration but get_current_frame_begin_time() doesn't ?
return maximum<int>(0,get_animation_time() - get_current_frame_begin_time());
}

View file

@ -47,13 +47,12 @@ public:
void add_frame(int duration, const T& value,bool force_change =false);
//Starts an animation cycle. The first frame of the animation to start
//may be set to any value
//may be set to any value by using a start_time different to 0
void start_animation(int start_time, bool cycles=false, double acceleration=1);
int get_begin_time() const;
int get_end_time() const;
//inlined for performance
void update_last_draw_time();
bool need_update() const;
@ -61,9 +60,8 @@ public:
bool animation_finished() const;
bool animation_would_finish() const;
int get_animation_time() const;
//For the moment, all the following functions dont't use (or incorrectly) acceleration
const int get_animation_duration() const;
// get the mean tempo (total duration / number of frames)
const int get_animation_tempo() const;
const T& get_current_frame() const;
// get the next frame (or the current + shift frames)
const T& get_next_frame(int shift = 1) const;