[[Animation fixes]]

- update the anim before rendering it (but continue to avoid skipping
frames) This fix a off-by-one frame bug in few cases where the update
is not automatic (e.g. last frame of idle anim was sometimes missed)

- now a starting anim is considered as a change and so in need_update state

- fix some inconsitencies with the use of update_last_draw_time()
This commit is contained in:
Ali El Gariani 2007-11-03 16:45:29 +00:00
parent 24935ba641
commit 1181a44579
4 changed files with 13 additions and 5 deletions

View file

@ -104,6 +104,7 @@ private:
bool does_not_change_; // Optimization for 1-frame permanent animations bool does_not_change_; // Optimization for 1-frame permanent animations
bool started_; bool started_;
bool need_first_update_;
std::vector<frame> frames_; std::vector<frame> frames_;
// These are only valid when anim is started // These are only valid when anim is started

View file

@ -47,6 +47,7 @@ animated<T,T_void_value>::animated(int start_time) :
starting_frame_time_(start_time), starting_frame_time_(start_time),
does_not_change_(true), does_not_change_(true),
started_(false), started_(false),
need_first_update_(false),
start_tick_(0), start_tick_(0),
cycles_(false), cycles_(false),
acceleration_(1), acceleration_(1),
@ -61,6 +62,7 @@ animated<T,T_void_value>::animated(const std::vector<std::pair<int,T> > &cfg, in
starting_frame_time_(start_time), starting_frame_time_(start_time),
does_not_change_(true), does_not_change_(true),
started_(false), started_(false),
need_first_update_(false),
start_tick_(0), start_tick_(0),
cycles_(false), cycles_(false),
acceleration_(1), acceleration_(1),
@ -102,7 +104,8 @@ void animated<T,T_void_value>::start_animation(int start_time, bool cycles, doub
acceleration_ = acceleration; acceleration_ = acceleration;
if(acceleration_ <=0) acceleration_ = 1; if(acceleration_ <=0) acceleration_ = 1;
current_frame_key_= 0; current_frame_key_= 0;
update_last_draw_time(); need_first_update_ = !frames_.empty();
//update_last_draw_time();
// need to force last frame key in the case of starting anim... // need to force last frame key in the case of starting anim...
last_frame_key_ = -1; last_frame_key_ = -1;
} }
@ -113,6 +116,10 @@ void animated<T,T_void_value>::update_last_draw_time()
{ {
last_update_tick_ = current_ticks; last_update_tick_ = current_ticks;
last_frame_key_ = current_frame_key_; last_frame_key_ = current_frame_key_;
if (need_first_update_) {
need_first_update_ = false;
return;
}
if(does_not_change_) if(does_not_change_)
return; return;
@ -141,6 +148,9 @@ void animated<T,T_void_value>::update_last_draw_time()
template<typename T, typename T_void_value> template<typename T, typename T_void_value>
bool animated<T,T_void_value>::need_update() const bool animated<T,T_void_value>::need_update() const
{ {
if(need_first_update_) {
return true;
}
if(does_not_change_) { if(does_not_change_) {
return false; return false;
} }

View file

@ -107,9 +107,6 @@ effect::effect(int xpos, int ypos, const animated<std::string>::anim_description
images_.start_animation(0,infinite); images_.start_animation(0,infinite);
if(!images_.animation_finished()) {
images_.update_last_draw_time();
}
} }
void effect::set_location(int x, int y) void effect::set_location(int x, int y)

View file

@ -1681,6 +1681,7 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc)
if(!anim_) { if(!anim_) {
set_standing(disp,loc); set_standing(disp,loc);
} }
anim_->update_last_draw_time();
if(frame_begin_time_ != anim_->get_current_frame_begin_time()) { if(frame_begin_time_ != anim_->get_current_frame_begin_time()) {
frame_begin_time_ = anim_->get_current_frame_begin_time(); frame_begin_time_ = anim_->get_current_frame_begin_time();
@ -1877,7 +1878,6 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc)
anim_->redraw(); anim_->redraw();
refreshing_ = false; refreshing_ = false;
anim_->update_last_draw_time();
} }
void unit::clear_haloes() void unit::clear_haloes()