mail[Wesnoth-commits] r14100 - in /trunk/src: animated.cpp animated.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by jeremy . rosen on October 28, 2006 - 13:59:
Author: boucman
Date: Sat Oct 28 13:59:17 2006
New Revision: 14100

URL: http://svn.gna.org/viewcvs/wesnoth?rev=14100&view=rev
Log:
make animation use vect instead of map, first step for random durations

Modified:
    trunk/src/animated.cpp
    trunk/src/animated.hpp

Modified: trunk/src/animated.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/animated.cpp?rev=14100&r1=14099&r2=14100&view=diff
==============================================================================
--- trunk/src/animated.cpp (original)
+++ trunk/src/animated.cpp Sat Oct 28 13:59:17 2006
@@ -62,15 +62,12 @@
 void animated<T,T_void_value>::add_frame(int duration, const T& value,bool 
force_change)
 {
        if(frames_.empty() ) {
-               frames_[starting_frame_time_] =
-                       frame(duration,value);
                does_not_change_=!force_change;
-               return;
-       }
-       typename std::map<int,frame>::reverse_iterator last_frame = 
frames_.rbegin();
-       does_not_change_=false;
-       frames_[last_frame->first +last_frame->second.duration_] =
-               frame(duration,value);
+               frames_.push_back( 
frame(duration,value,starting_frame_time_));
+       } else {
+               does_not_change_=false;
+               frames_.push_back( 
frame(duration,value,frames_.back().start_time_+frames_.back().duration_));
+       }
 }
 
 template<typename T,  typename T_void_value>
@@ -82,7 +79,7 @@
        cycles_ = cycles;
        acceleration_ = acceleration;
        if(acceleration_ <=0) acceleration_ = 1;
-       current_frame_key_= frames_.begin()->first;
+       current_frame_key_= 0;
        update_last_draw_time();
 }
 
@@ -109,11 +106,9 @@
                        current_frame_key_ =starting_frame_time_;
                }
        }
-       typename std::map<int,frame>::iterator current_frame = 
frames_.find(current_frame_key_);
        while(get_current_frame_end_time() < get_animation_time() &&  // 
catch up
                        get_current_frame_end_time() < get_end_time()) {// 
don't go after the end
-               current_frame++;
-               current_frame_key_ = current_frame->first;
+               current_frame_key_++;
        }
 }
 
@@ -173,7 +168,7 @@
 {
        if(frames_.empty() )
                return void_value_;
-       return frames_.find(current_frame_key_)->second.value_;
+       return frames_[current_frame_key_].value_;
 }
 
 template<typename T,  typename T_void_value>
@@ -181,7 +176,7 @@
 {
        if(frames_.empty() )
                return starting_frame_time_;
-       return frames_.find(current_frame_key_)->first;
+       return frames_[current_frame_key_].start_time_;
 }
 
 template<typename T,  typename T_void_value>
@@ -197,7 +192,7 @@
 {
        if(frames_.empty() )
                return 0;
-       return frames_.find(current_frame_key_)->second.duration_;
+       return frames_[current_frame_key_].duration_;
 }
 
 template<typename T,  typename T_void_value>
@@ -213,7 +208,7 @@
 {
        if(frames_.empty() )
                return void_value_;
-       return frames_.begin()->second.value_;
+       return frames_[0].value_;
 }
 
 template<typename T,  typename T_void_value>
@@ -221,8 +216,7 @@
 {
        if(frames_.empty() )
                return void_value_;
-       typename std::map<int,frame>::const_reverse_iterator last_frame = 
frames_.rbegin();
-       return last_frame->second.value_;
+       return frames_.back().value_;
 }
 
 template<typename T, typename T_void_value>
@@ -242,8 +236,7 @@
 {
        if(frames_.empty())
                return starting_frame_time_;
-       typename std::map<int,frame>::const_reverse_iterator last_frame = 
frames_.rbegin();
-       return (last_frame->first +last_frame->second.duration_);
+       return frames_.back().start_time_ + frames_.back().duration_;
 }
 
 // Force compilation of the following template instantiations

Modified: trunk/src/animated.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/animated.hpp?rev=14100&r1=14099&r2=14100&view=diff
==============================================================================
--- trunk/src/animated.hpp (original)
+++ trunk/src/animated.hpp Sat Oct 28 13:59:17 2006
@@ -76,21 +76,22 @@
        struct frame
        {
 
-               frame(int duration , const T& value) :
-                       duration_(duration),value_(value)
+               frame(int duration , const T& value,int start_time) :
+                       
duration_(duration),value_(value),start_time_(start_time)
                {};
                frame():
-                       duration_(0),value_(void_value_)
+                       duration_(0),value_(void_value_),start_time_(0)
                {};
 
                // Represents the timestamp of the frame start
                int duration_;
                T value_;
+               int start_time_;
        };
 
        bool does_not_change_;  // optimization for 1-frame permanent 
animations
        bool started_;
-       std::map<int,frame> frames_;
+       std::vector<frame> frames_;
 
        //these are only valid when anim is started
        int start_tick_; // time at which we started




Related Messages


Powered by MHonArc, Updated Sat Oct 28 14:21:17 2006