Author: boucman
Date: Sat Apr  5 23:16:10 2008
New Revision: 25602

URL: http://svn.gna.org/viewcvs/wesnoth?rev=25602&view=rev
Log:
potential fix for the jumpyness 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

Modified:
    trunk/src/animated.hpp
    trunk/src/animated.i
    trunk/src/unit.hpp
    trunk/src/unit_animation.cpp
    trunk/src/unit_animation.hpp
    trunk/src/unit_display.cpp

Modified: trunk/src/animated.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/animated.hpp?rev=25602&r1=25601&r2=25602&view=diff
==============================================================================
--- trunk/src/animated.hpp (original)
+++ trunk/src/animated.hpp Sat Apr  5 23:16:10 2008
@@ -54,6 +54,8 @@
        //! 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;

Modified: trunk/src/animated.i
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/animated.i?rev=25602&r1=25601&r2=25602&view=diff
==============================================================================
--- trunk/src/animated.i (original)
+++ trunk/src/animated.i Sat Apr  5 23:16:10 2008
@@ -115,6 +115,10 @@
                 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 @@
        if(frames_.empty()) {
                return false;
        }
-       if(!started_) {
+       if(!started_ && start_tick_ == 0) {
                return false;
        }
        if(current_ticks >
@@ -173,7 +177,7 @@
 {
        if(frames_.empty())
                return true;
-       if(!started_)
+       if(!started_ && start_tick_ == 0)
                return true;
        if(cycles_ )
                 return true;
@@ -187,7 +191,7 @@
 {
        if(frames_.empty())
                return true;
-       if(!started_)
+       if(!started_ && start_tick_ == 0)
                return true;
         if(cycles_)
                 return true;
@@ -200,7 +204,7 @@
 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 @@
 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 @@
 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_);

Modified: trunk/src/unit.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=25602&r1=25601&r2=25602&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Sat Apr  5 23:16:10 2008
@@ -184,6 +184,7 @@
        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_; }

Modified: trunk/src/unit_animation.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_animation.cpp?rev=25602&r1=25601&r2=25602&view=diff
==============================================================================
--- trunk/src/unit_animation.cpp (original)
+++ trunk/src/unit_animation.cpp Sat Apr  5 23:16:10 2008
@@ -700,6 +700,24 @@
                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 @@
         }
         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();
+              }
+        }
+}

Modified: trunk/src/unit_animation.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_animation.hpp?rev=25602&r1=25601&r2=25602&view=diff
==============================================================================
--- trunk/src/unit_animation.hpp (original)
+++ trunk/src/unit_animation.hpp Sat Apr  5 23:16:10 2008
@@ -52,6 +52,8 @@
                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 @@
                                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();};
 
 

Modified: trunk/src/unit_display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_display.cpp?rev=25602&r1=25601&r2=25602&view=diff
==============================================================================
--- trunk/src/unit_display.cpp (original)
+++ trunk/src/unit_display.cpp Sat Apr  5 23:16:10 2008
@@ -78,11 +78,13 @@
        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);


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to