fix a bad case of animation skipping...

that could cause the whole movement anim to be skipped if we had a lot
to redraw at the very beginning of the movement
This commit is contained in:
Jérémy Rosen 2008-02-08 19:35:23 +00:00
parent 2d7e5c4d43
commit f4ea29865f
6 changed files with 32 additions and 14 deletions

View file

@ -69,8 +69,9 @@ public:
//! Returns true if the current animation was finished.
bool animation_finished() const;
bool animation_would_finish() const;
bool animation_finished_potential() const;
int get_animation_time() const;
int get_animation_time_potential() const;
const int get_animation_duration() const;
const T& get_current_frame() const;

View file

@ -39,6 +39,7 @@ int get_current_animation_tick()
return current_ticks;
}
extern int animation_debug;
template<typename T, typename T_void_value>
const T animated<T,T_void_value>::void_value_ = T_void_value()();
@ -98,6 +99,7 @@ void animated<T,T_void_value>::start_animation(int start_time, bool cycles, doub
acceleration_ = acceleration;
start_tick_ = last_update_tick_ +
static_cast<int>(( starting_frame_time_ - start_time)/acceleration_);
//if(animation_debug) printf("clock %d starting sft %d st %d acc %f\n",SDL_GetTicks(),starting_frame_time_,start_tick_,acceleration_);
cycles_ = cycles;
if(acceleration_ <=0) acceleration_ = 1;
@ -114,6 +116,7 @@ void animated<T,T_void_value>::update_last_draw_time(double acceleration)
acceleration_ = acceleration;
start_tick_ = time_to_tick(tmp);
}
//if(animation_debug) printf("%s clock %d time %d sft %d st %d acc %f\n",__FUNCTION__,SDL_GetTicks(),last_update_tick_,starting_frame_time_,start_tick_,acceleration_);
last_update_tick_ = current_ticks;
if (need_first_update_) {
need_first_update_ = false;
@ -168,7 +171,7 @@ bool animated<T,T_void_value>::need_update() const
}
template<typename T, typename T_void_value>
bool animated<T,T_void_value>::animation_would_finish() const
bool animated<T,T_void_value>::animation_finished_potential() const
{
if(frames_.empty())
return true;
@ -196,6 +199,14 @@ bool animated<T,T_void_value>::animation_finished() const
return false;
}
template<typename T, typename T_void_value>
int animated<T,T_void_value>::get_animation_time_potential() const
{
if(!started_ ) return starting_frame_time_;
return tick_to_time(current_ticks);
}
template<typename T, typename T_void_value>
int animated<T,T_void_value>::get_animation_time() const
{
@ -283,7 +294,7 @@ template<typename T, typename T_void_value>
int animated<T,T_void_value>::time_to_tick(int animation_time) const
{
if(!started_) return 0;
return start_tick_ + static_cast<int>(animation_time/acceleration_);
return start_tick_ + static_cast<int>((animation_time-starting_frame_time_)/acceleration_);
}
template<typename T, typename T_void_value>
int animated<T,T_void_value>::tick_to_time(int animation_tick) const

View file

@ -127,7 +127,7 @@ public:
void new_level();
//! Called on every draw
void refresh(const game_display& disp,const gamemap::location& loc) {
if (state_ == STATE_FORGET && anim_ && anim_->animation_would_finish()) {
if (state_ == STATE_FORGET && anim_ && anim_->animation_finished_potential()) {
set_standing( loc);
return;
}

View file

@ -686,12 +686,12 @@ bool unit_animation::animation_finished() const
return true;
}
bool unit_animation::animation_would_finish() const
bool unit_animation::animation_finished_potential() const
{
if(!unit_anim_.animation_would_finish()) return false;
if(!unit_anim_.animation_finished_potential()) return false;
std::map<std::string,crude_animation>::const_iterator anim_itor =sub_anims_.begin();
for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
if(!anim_itor->second.animation_would_finish()) return false;
if(!anim_itor->second.animation_finished_potential()) return false;
}
return true;
}
@ -890,7 +890,7 @@ void unit_animator::replace_anim_if_invalid(unit* animated_unit,const std::strin
if(!animated_unit) return;
game_display*disp = game_display::get_singleton();
if(animated_unit->get_animation() &&
!animated_unit->get_animation()->animation_would_finish() &&
!animated_unit->get_animation()->animation_finished_potential() &&
animated_unit->get_animation()->matches(*disp,src,animated_unit,event,value,hit_type,attack,second_attack,swing_num) >unit_animation::MATCH_FAIL) {
anim_elem tmp;
tmp.my_unit = animated_unit;
@ -931,7 +931,7 @@ bool unit_animator::would_end() const
{
bool finished = true;
for(std::vector<anim_elem>::const_iterator anim = animated_units_.begin(); anim != animated_units_.end();anim++) {
finished &= anim->my_unit->get_animation()->animation_would_finish();
finished &= anim->my_unit->get_animation()->animation_finished_potential();
}
return finished;
}
@ -961,7 +961,7 @@ void unit_animator::wait_for_end() const
disp->delay(10);
finished = true;
for(std::vector<anim_elem>::const_iterator anim = animated_units_.begin(); anim != animated_units_.end();anim++) {
finished &= anim->my_unit->get_animation()->animation_would_finish();
finished &= anim->my_unit->get_animation()->animation_finished_potential();
}
}
}
@ -969,6 +969,10 @@ int unit_animator::get_animation_time() const{
return animated_units_[0].my_unit->get_animation()->get_animation_time() ;
}
int unit_animator::get_animation_time_potential() const{
return animated_units_[0].my_unit->get_animation()->get_animation_time_potential() ;
}
int unit_animator::get_end_time() const
{
int end_time = INT_MIN;

View file

@ -44,12 +44,13 @@ class unit_animation
bool need_update() const;
bool animation_finished() const;
bool animation_would_finish() const;
bool animation_finished_potential() const;
void update_last_draw_time();
int get_begin_time() const;
int get_end_time() const;
int time_to_tick(int animation_time) const { return unit_anim_.time_to_tick(animation_time); };
int get_animation_time() const{ return unit_anim_.get_animation_time() ; };
int get_animation_time_potential() const{ return unit_anim_.get_animation_time_potential() ; };
void start_animation(int start_time,const gamemap::location &src = gamemap::location::null_location, const gamemap::location &dst = gamemap::location::null_location , bool cycles=false, const std::string text="", const Uint32 text_color=0, double acceleration=1);
const int get_current_frame_begin_time() const{ return unit_anim_.get_current_frame_begin_time() ; };
void redraw();
@ -163,6 +164,7 @@ class unit_animator
bool would_end() const;
int get_animation_time() const;
int get_animation_time_potential() const;
int get_end_time() const;
void wait_for_end() const;
void wait_until( int animation_time) const;

View file

@ -78,10 +78,10 @@ static void move_unit_between(const gamemap::location& a, const gamemap::locatio
unit_animator animator;
animator.replace_anim_if_invalid(&temp_unit,"movement",a);
animator.start_animations();
int target_time = animator.get_animation_time();
int target_time = animator.get_animation_time_potential();
target_time += 150;
target_time -= target_time%150;
if( target_time - animator.get_animation_time() < 100 ) target_time +=150;
if( target_time - animator.get_animation_time_potential() < 100 ) target_time +=150;
disp->scroll_to_tiles(a,b,game_display::ONSCREEN);
animator.wait_until(target_time);
gamemap::location arr[6];
@ -132,7 +132,7 @@ void move_unit(const std::vector<gamemap::location>& path, unit& u, const std::v
unit temp_unit = u;
u.set_hidden(true);
temp_unit.set_hidden(false);
disp->draw();
for(size_t i = 0; i+1 < path.size(); ++i) {
bool invisible = teams[temp_unit.side()-1].is_enemy(int(disp->viewing_team()+1)) &&