remove a high maintainance cost/low benefit feature of animation, no user impact
This commit is contained in:
parent
f5ebed8a80
commit
939259648a
4 changed files with 52 additions and 60 deletions
|
@ -38,7 +38,7 @@ animated<T,T_void_value>::animated(int start_time) :
|
|||
}
|
||||
|
||||
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 @@ animated<T,T_void_value>::animated(const std::string &cfg,int start_time, const
|
|||
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;
|
||||
typename std::vector< std::pair<int,T> >::const_iterator itor = cfg.begin();
|
||||
for(; itor != cfg.end(); ++itor) {
|
||||
|
||||
if(items.size() > 1) {
|
||||
str = items.front();
|
||||
time = atoi(items.back().c_str());
|
||||
} else {
|
||||
str = *itor;
|
||||
time = 100;
|
||||
}
|
||||
|
||||
add_frame(time,init(str),false);
|
||||
add_frame(itor->first,itor->second,force_change);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
template<typename T>
|
||||
class void_value
|
||||
|
@ -28,22 +29,14 @@ template<typename T, typename T_void_value=void_value<T> >
|
|||
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
|
||||
|
|
|
@ -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 @@ void terrain_builder::rebuild_terrain(const gamemap::location &loc)
|
|||
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 @@ bool terrain_builder::start_animation(building_rule &rule)
|
|||
|
||||
for(variant = image->variants.begin(); variant != image->variants.end(); ++variant) {
|
||||
|
||||
locator_string_initializer initializer;
|
||||
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")));
|
||||
}
|
||||
|
||||
if(image->global_image) {
|
||||
initializer = locator_string_initializer(constraint->second.loc);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
24
src/halo.cpp
24
src/halo.cpp
|
@ -35,7 +35,7 @@ display* disp = NULL;
|
|||
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 @@ int halo_id = 1;
|
|||
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 @@ halo_hider::~halo_hider()
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue