diff --git a/src/animated.hpp b/src/animated.hpp index 61084db3dd3..9ecef666cfe 100644 --- a/src/animated.hpp +++ b/src/animated.hpp @@ -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; diff --git a/src/animated.i b/src/animated.i index 98ddff1389f..1dc893b5105 100644 --- a/src/animated.i +++ b/src/animated.i @@ -115,6 +115,10 @@ void animated::update_last_draw_time(double acceleration) start_tick_ = last_update_tick_ + static_cast(( 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::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::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::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::animation_finished() const template int animated::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::get_animation_time_potential() const template int animated::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::get_begin_time() const template int animated::time_to_tick(int animation_time) const { - if(!started_) return 0; + if(!started_ && start_tick_ == 0) return 0; return start_tick_ + static_cast((animation_time-starting_frame_time_)/acceleration_); } template int animated::tick_to_time(int animation_tick) const { - if(!started_) return 0; + if(!started_ && start_tick_ == 0) return 0; return static_cast( (static_cast(animation_tick - start_tick_) * acceleration_) + starting_frame_time_); diff --git a/src/unit.hpp b/src/unit.hpp index 08c69d1990b..5544e91e40c 100644 --- a/src/unit.hpp +++ b/src/unit.hpp @@ -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_; } diff --git a/src/unit_animation.cpp b/src/unit_animation.cpp index 18f104c2747..df85f02d159 100644 --- a/src/unit_animation.cpp +++ b/src/unit_animation.cpp @@ -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::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::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::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::iterator anim = animated_units_.begin(); anim != animated_units_.end();anim++) { + if(anim->my_unit->get_animation()) { + anim->my_unit->get_animation()->restart_animation(); + } + } +} diff --git a/src/unit_animation.hpp b/src/unit_animation.hpp index 6b254572fac..7e5319322f6 100644 --- a/src/unit_animation.hpp +++ b/src/unit_animation.hpp @@ -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();}; diff --git a/src/unit_display.cpp b/src/unit_display.cpp index eabb68c2739..10e884d554a 100644 --- a/src/unit_display.cpp +++ b/src/unit_display.cpp @@ -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);