potential fix for the jumpiness when moving units and scrolling...
...at the same time. I had trouble reproducing the bug reliably, so if you see it again, please report to me
This commit is contained in:
parent
0ac0a900f8
commit
de873197d7
6 changed files with 55 additions and 8 deletions
|
@ -54,6 +54,8 @@ public:
|
|||
//! The first frame of the animation to start may be set
|
||||
//! to any value by using a start_time different to 0.
|
||||
void start_animation(int start_time, bool cycles=false);
|
||||
void pause_animation(){ started_ =false;};
|
||||
void restart_animation(){if(start_tick_) started_ = true;};
|
||||
|
||||
int get_begin_time() const;
|
||||
int get_end_time() const;
|
||||
|
|
|
@ -115,6 +115,10 @@ void animated<T,T_void_value>::update_last_draw_time(double acceleration)
|
|||
start_tick_ = last_update_tick_ +
|
||||
static_cast<int>(( starting_frame_time_ - tmp)/acceleration_);
|
||||
}
|
||||
if(!started_ && start_tick_ != 0) {
|
||||
// animation is paused
|
||||
start_tick_ +=current_ticks -last_update_tick_;
|
||||
}
|
||||
last_update_tick_ = current_ticks;
|
||||
if (need_first_update_) {
|
||||
need_first_update_ = false;
|
||||
|
@ -156,7 +160,7 @@ bool animated<T,T_void_value>::need_update() const
|
|||
if(frames_.empty()) {
|
||||
return false;
|
||||
}
|
||||
if(!started_) {
|
||||
if(!started_ && start_tick_ == 0) {
|
||||
return false;
|
||||
}
|
||||
if(current_ticks >
|
||||
|
@ -173,7 +177,7 @@ bool animated<T,T_void_value>::animation_finished_potential() const
|
|||
{
|
||||
if(frames_.empty())
|
||||
return true;
|
||||
if(!started_)
|
||||
if(!started_ && start_tick_ == 0)
|
||||
return true;
|
||||
if(cycles_ )
|
||||
return true;
|
||||
|
@ -187,7 +191,7 @@ bool animated<T,T_void_value>::animation_finished() const
|
|||
{
|
||||
if(frames_.empty())
|
||||
return true;
|
||||
if(!started_)
|
||||
if(!started_ && start_tick_ == 0)
|
||||
return true;
|
||||
if(cycles_)
|
||||
return true;
|
||||
|
@ -200,7 +204,7 @@ bool animated<T,T_void_value>::animation_finished() const
|
|||
template<typename T, typename T_void_value>
|
||||
int animated<T,T_void_value>::get_animation_time_potential() const
|
||||
{
|
||||
if(!started_ ) return starting_frame_time_;
|
||||
if(!started_ && start_tick_ == 0 ) return starting_frame_time_;
|
||||
|
||||
return tick_to_time(current_ticks);
|
||||
}
|
||||
|
@ -208,7 +212,7 @@ int animated<T,T_void_value>::get_animation_time_potential() const
|
|||
template<typename T, typename T_void_value>
|
||||
int animated<T,T_void_value>::get_animation_time() const
|
||||
{
|
||||
if(!started_ ) return starting_frame_time_;
|
||||
if(!started_ && start_tick_ == 0 ) return starting_frame_time_;
|
||||
|
||||
return tick_to_time(last_update_tick_);
|
||||
}
|
||||
|
@ -291,13 +295,13 @@ int animated<T,T_void_value>::get_begin_time() const
|
|||
template<typename T, typename T_void_value>
|
||||
int animated<T,T_void_value>::time_to_tick(int animation_time) const
|
||||
{
|
||||
if(!started_) return 0;
|
||||
if(!started_ && start_tick_ == 0) return 0;
|
||||
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
|
||||
{
|
||||
if(!started_) return 0;
|
||||
if(!started_ && start_tick_ == 0) return 0;
|
||||
return static_cast<int>(
|
||||
(static_cast<double>(animation_tick - start_tick_) *
|
||||
acceleration_) + starting_frame_time_);
|
||||
|
|
|
@ -184,6 +184,7 @@ public:
|
|||
void set_standing(const gamemap::location& loc, bool with_bars = true);
|
||||
void set_idling(const game_display& disp,const gamemap::location& loc);
|
||||
void set_selecting(const game_display& disp,const gamemap::location& loc);
|
||||
unit_animation* get_animation() { return anim_;};
|
||||
const unit_animation* get_animation() const { return anim_;};
|
||||
void set_facing(gamemap::location::DIRECTION dir);
|
||||
gamemap::location::DIRECTION facing() const { return facing_; }
|
||||
|
|
|
@ -700,6 +700,24 @@ void unit_animation::start_animation(int start_time,const gamemap::location &src
|
|||
anim_itor->second.start_animation(start_time,src,dst,cycles);
|
||||
}
|
||||
}
|
||||
void unit_animation::pause_animation()
|
||||
{
|
||||
|
||||
std::map<std::string,particule>::iterator anim_itor =sub_anims_.begin();
|
||||
unit_anim_.pause_animation();
|
||||
for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
|
||||
anim_itor->second.pause_animation();
|
||||
}
|
||||
}
|
||||
void unit_animation::restart_animation()
|
||||
{
|
||||
|
||||
std::map<std::string,particule>::iterator anim_itor =sub_anims_.begin();
|
||||
unit_anim_.restart_animation();
|
||||
for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
|
||||
anim_itor->second.restart_animation();
|
||||
}
|
||||
}
|
||||
void unit_animation::redraw()
|
||||
{
|
||||
|
||||
|
@ -881,3 +899,19 @@ int unit_animator::get_end_time() const
|
|||
}
|
||||
return end_time;
|
||||
}
|
||||
void unit_animator::pause_animation()
|
||||
{
|
||||
for(std::vector<anim_elem>::iterator anim = animated_units_.begin(); anim != animated_units_.end();anim++) {
|
||||
if(anim->my_unit->get_animation()) {
|
||||
anim->my_unit->get_animation()->pause_animation();
|
||||
}
|
||||
}
|
||||
}
|
||||
void unit_animator::restart_animation()
|
||||
{
|
||||
for(std::vector<anim_elem>::iterator anim = animated_units_.begin(); anim != animated_units_.end();anim++) {
|
||||
if(anim->my_unit->get_animation()) {
|
||||
anim->my_unit->get_animation()->restart_animation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,8 @@ class unit_animation
|
|||
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,const bool accelerate = true);
|
||||
void pause_animation();
|
||||
void restart_animation();
|
||||
int get_current_frame_begin_time() const{ return unit_anim_.get_current_frame_begin_time() ; };
|
||||
void redraw();
|
||||
void invalidate( ) const;
|
||||
|
@ -130,6 +132,8 @@ class unit_animator
|
|||
const attack_type* attack=NULL, const attack_type* second_attack = NULL,
|
||||
int swing_num =0);
|
||||
void start_animations();
|
||||
void pause_animation();
|
||||
void restart_animation();
|
||||
void empty(){start_time_ = INT_MIN ; animated_units_.clear();};
|
||||
|
||||
|
||||
|
|
|
@ -78,11 +78,13 @@ 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();
|
||||
animator.pause_animation();
|
||||
disp->scroll_to_tiles(a,b,game_display::ONSCREEN);
|
||||
animator.restart_animation();
|
||||
int target_time = animator.get_animation_time_potential();
|
||||
target_time += 150;
|
||||
target_time -= 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];
|
||||
get_adjacent_tiles(a, arr);
|
||||
|
|
Loading…
Add table
Reference in a new issue