mail[Wesnoth-commits] r13977 - in /trunk/src: animated.cpp animated.hpp builder.cpp halo.cpp


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

Header


Content

Posted by jeremy . rosen on October 15, 2006 - 23:21:
Author: boucman
Date: Sun Oct 15 23:20:55 2006
New Revision: 13977

URL: http://svn.gna.org/viewcvs/wesnoth?rev=13977&view=rev
Log:
remove a high maintainance cost/low benefit feature of animation, no user 
impact

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

Modified: trunk/src/animated.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/animated.cpp?rev=13977&r1=13976&r2=13977&view=diff
==============================================================================
--- trunk/src/animated.cpp (original)
+++ trunk/src/animated.cpp Sun Oct 15 23:20:55 2006
@@ -38,7 +38,7 @@
 }
 
 template<typename T,  typename T_void_value>
-animated<T,T_void_value>::animated(const std::string &cfg,int start_time, 
const string_initializer& init):
+animated<T,T_void_value>::animated(const std::vector<std::pair<int,T> > 
&cfg, int start_time, bool force_change ):
        starting_frame_time_(start_time),
        does_not_change_(true),
        started_(false),
@@ -48,23 +48,11 @@
        last_update_tick_(0),
        current_frame_key_(start_time)
 {
-       std::vector<std::string> items = utils::split(cfg);
-
-       std::vector<std::string>::const_iterator itor = items.begin();
-       for(; itor != items.end(); ++itor) {
-               const std::vector<std::string>& items = utils::split(*itor, 
':');
-               std::string str;
-               int time;
-
-               if(items.size() > 1) {
-                       str = items.front();
-                       time = atoi(items.back().c_str());
-               } else {
-                       str = *itor;
-                       time = 100;
-               }
-
-               add_frame(time,init(str),false);
+
+       typename std::vector< std::pair<int,T> >::const_iterator itor = 
cfg.begin();
+       for(; itor != cfg.end(); ++itor) {
+
+               add_frame(itor->first,itor->second,force_change);
        }
 }
 

Modified: trunk/src/animated.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/animated.hpp?rev=13977&r1=13976&r2=13977&view=diff
==============================================================================
--- trunk/src/animated.hpp (original)
+++ trunk/src/animated.hpp Sun Oct 15 23:20:55 2006
@@ -16,6 +16,7 @@
 
 #include <string>
 #include <map>
+#include <vector>
 
 template<typename T>
 class void_value
@@ -28,22 +29,14 @@
 class animated
 {
 public:
-       class string_initializer
-       {
-       public:
-               virtual T operator()(const std::string& s) const { return 
T(s); }
-               virtual ~string_initializer(){};
-       };
 
        animated(int start_time=0);
        virtual ~animated(){};
 
-       //if T can be constructed from a string, you may use this constructor
-       // animated(const std::string& cfg);
-       //if T cannot, you may provide a custom (subclassed) 
string_initializer
-       //to do the job
 
-       animated(const std::string &cfg, int start_time = 0, const 
string_initializer& init=string_initializer());
+       typedef  std::pair<int,T> frame_description;
+       typedef  std::vector<frame_description> anim_description;
+       animated(const std::vector<frame_description> &cfg, int start_time = 
0,bool force_change =false);
 
 
        // Adds a frame

Modified: trunk/src/builder.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/builder.cpp?rev=13977&r1=13976&r2=13977&view=diff
==============================================================================
--- trunk/src/builder.cpp (original)
+++ trunk/src/builder.cpp Sun Oct 15 23:20:55 2006
@@ -25,30 +25,6 @@
 
 #define ERR_NG LOG_STREAM(err, engine)
 
-namespace {
-
-class locator_string_initializer : public 
animated<image::locator>::string_initializer
-{
-public:
-       locator_string_initializer() : no_loc_(true) {}
-       locator_string_initializer(const gamemap::location& loc): 
no_loc_(false), loc_(loc)  {}
-       image::locator operator()(const std::string &s) const;
-
-private:
-       bool no_loc_;
-       gamemap::location loc_;
-};
-
-image::locator locator_string_initializer::operator()(const std::string &s) 
const
-{
-       if(no_loc_) {
-               return image::locator("terrain/" + s + ".png");
-       } else {
-               return image::locator("terrain/" + s + ".png", loc_);
-       }
-}
-
-}
 
 const int terrain_builder::rule_image::TILEWIDTH = 72;
 const int terrain_builder::rule_image::UNITPOS = 36 + 18;
@@ -214,7 +190,8 @@
                btile.images_background.clear();
                const std::string filename =
                        
map_.get_terrain_info(map_.get_terrain(loc)).symbol_image();
-               animated<image::locator> img_loc("terrain/" + filename + 
".png");
+               animated<image::locator> img_loc;
+               img_loc.add_frame(100,image::locator("terrain/" + filename + 
".png"));
                img_loc.start_animation(0, true);
                btile.images_background.push_back(img_loc);
        }
@@ -274,14 +251,30 @@
 
                        for(variant = image->variants.begin(); variant != 
image->variants.end(); ++variant) {
 
-                               locator_string_initializer initializer;
-
-                               if(image->global_image) {
-                                       initializer = 
locator_string_initializer(constraint->second.loc);
+                               animated<image::locator>::anim_description 
image_vector;
+                               std::vector<std::string> items = 
utils::split(variant->second.image_string);
+                               std::vector<std::string>::const_iterator itor 
= items.begin();
+                               for(; itor != items.end(); ++itor) {
+                                       const std::vector<std::string>& items 
= utils::split(*itor, ':');
+                                       std::string str;
+                                       int time;
+
+                                       if(items.size() > 1) {
+                                               str = items.front();
+                                               time = 
atoi(items.back().c_str());
+                                       } else {
+                                               str = *itor;
+                                               time = 100;
+                                       }
+                                       if(image->global_image) {
+                                               
image_vector.push_back(animated<image::locator>::frame_description(time,image::locator("terrain/"
 + str + ".png",constraint->second.loc)));
+                                       } else {
+                                               
image_vector.push_back(animated<image::locator>::frame_description(time,image::locator("terrain/"
 + str + ".png")));
+                                       }
+
                                }
 
-                               animated<image::locator> 
th(variant->second.image_string,0,
-                                               initializer);
+                               animated<image::locator> th(image_vector);
 
                                variant->second.image = th;
                                variant->second.image.start_animation(0, 
true);

Modified: trunk/src/halo.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/halo.cpp?rev=13977&r1=13976&r2=13977&view=diff
==============================================================================
--- trunk/src/halo.cpp (original)
+++ trunk/src/halo.cpp Sun Oct 15 23:20:55 2006
@@ -35,7 +35,7 @@
 class effect
 {
 public:
-       effect(int xpos, int ypos, const std::string& img, ORIENTATION 
orientation,bool infinite);
+       effect(int xpos, int ypos, const 
animated<std::string>::anim_description& img, ORIENTATION orientation,bool 
infinite);
 
        void set_location(int x, int y);
 
@@ -66,7 +66,7 @@
 bool hide_halo = false;
 
 
-effect::effect(int xpos, int ypos, const std::string& img, ORIENTATION 
orientation,bool infinite)
+effect::effect(int xpos, int ypos, const 
animated<std::string>::anim_description& img, ORIENTATION orientation,bool 
infinite)
 : images_(img), orientation_(orientation), origx_(xpos), origy_(ypos), 
x_(xpos), y_(ypos),
   origzoom_(disp->zoom()), zoom_(disp->zoom()), surf_(NULL), buffer_(NULL), 
rect_(empty_rect)
 {
@@ -221,7 +221,25 @@
 int add(int x, int y, const std::string& image, ORIENTATION orientation, 
bool infinite)
 {
        const int id = halo_id++;
-       
haloes.insert(std::pair<int,effect>(id,effect(x,y,image,orientation,infinite)));
+       animated<std::string>::anim_description image_vector;
+       std::vector<std::string> items = utils::split(image);
+       std::vector<std::string>::const_iterator itor = items.begin();
+       for(; itor != items.end(); ++itor) {
+               const std::vector<std::string>& items = utils::split(*itor, 
':');
+               std::string str;
+               int time;
+
+               if(items.size() > 1) {
+                       str = items.front();
+                       time = atoi(items.back().c_str());
+               } else {
+                       str = *itor;
+                       time = 100;
+               }
+               
image_vector.push_back(animated<std::string>::frame_description(time,std::string(str)));
+
+       }
+       
haloes.insert(std::pair<int,effect>(id,effect(x,y,image_vector,orientation,infinite)));
        return id;
 }
 




Related Messages


Powered by MHonArc, Updated Mon Oct 16 01:00:21 2006