progessive parameter (internal use only for the moment, soon usable in WML)
This commit is contained in:
parent
7edfee7d7a
commit
14cf410be7
4 changed files with 116 additions and 78 deletions
74
src/unit.cpp
74
src/unit.cpp
|
@ -1540,11 +1540,10 @@ void unit::set_defending(const display &disp,const gamemap::location& loc, int d
|
|||
int anim_time = anim_->get_last_frame_time();
|
||||
const std::string my_image = anim_->get_last_frame().image();
|
||||
if(damage) {
|
||||
anim_->add_frame(anim_time,unit_frame(my_image,"",anim_time,anim_time+30,display::rgb(255,0,0),0.5));
|
||||
anim_time += 50;
|
||||
anim_->add_frame(anim_time,unit_frame(my_image,"",anim_time,anim_time+30,display::rgb(255,0,0),0.0));
|
||||
anim_time += 50;
|
||||
anim_->add_frame(anim_time,unit_frame(my_image,"",anim_time,anim_time+100,display::rgb(255,0,0),"0.5:50,0.0:50"));
|
||||
anim_time+=100;
|
||||
}
|
||||
anim_->add_frame(anim_time);
|
||||
anim_->start_animation(anim_->get_first_frame_time(),1,disp.turbo()?5:1);
|
||||
frame_begin_time = anim_->get_first_frame_time() -1;
|
||||
anim_->update_current_frame();
|
||||
|
@ -1608,13 +1607,8 @@ void unit::set_leveling_in(const display &disp,const gamemap::location& /*loc*/)
|
|||
my_image = absolute_image();
|
||||
anim_ = new unit_animation();
|
||||
// add a fade in effect
|
||||
double blend_ratio =1;
|
||||
int anim_time =0;
|
||||
while(blend_ratio > 0) {
|
||||
anim_->add_frame(anim_time,unit_frame(my_image,"",anim_time,anim_time+10,display::rgb(255,255,255),blend_ratio));
|
||||
blend_ratio -=0.015;
|
||||
anim_time += 10;
|
||||
}
|
||||
anim_->add_frame(0,unit_frame(my_image,"",0,600,display::rgb(255,255,255),"1~0:600"));
|
||||
anim_->add_frame(600);
|
||||
|
||||
anim_->start_animation(anim_->get_first_frame_time(),1,disp.turbo()?5:1);
|
||||
frame_begin_time = anim_->get_first_frame_time() -1;
|
||||
|
@ -1632,13 +1626,8 @@ void unit::set_leveling_out(const display &disp,const gamemap::location& /*loc*/
|
|||
my_image = absolute_image();
|
||||
anim_ = new unit_animation();
|
||||
// add a fade out effect
|
||||
double blend_ratio =0;
|
||||
int anim_time =0;
|
||||
while(blend_ratio < 1) {
|
||||
anim_->add_frame(anim_time,unit_frame(my_image,"",anim_time,anim_time+10,display::rgb(255,255,255),blend_ratio));
|
||||
blend_ratio +=0.015;
|
||||
anim_time += 10;
|
||||
}
|
||||
anim_->add_frame(0,unit_frame(my_image,"",0,600,display::rgb(255,255,255),"0~1:600"));
|
||||
anim_->add_frame(600);
|
||||
|
||||
anim_->start_animation(anim_->get_first_frame_time(),1,disp.turbo()?5:1);
|
||||
frame_begin_time = anim_->get_first_frame_time() -1;
|
||||
|
@ -1654,18 +1643,13 @@ void unit::set_recruited(const display &disp,const gamemap::location& /*loc*/)
|
|||
}
|
||||
anim_ = new unit_animation();
|
||||
// add a fade in effect
|
||||
double blend_ratio =0;
|
||||
int anim_time =0;
|
||||
while(blend_ratio < 1) {
|
||||
anim_->add_frame(anim_time,unit_frame(absolute_image(),"",anim_time,anim_time+10,0,0,ftofxp(blend_ratio)));
|
||||
blend_ratio +=0.015;
|
||||
anim_time += 10;
|
||||
}
|
||||
anim_->add_frame(0,unit_frame(absolute_image(),"",0,600,0,"","0~1:600"));
|
||||
anim_->add_frame(600);
|
||||
anim_->start_animation(anim_->get_first_frame_time(),1,disp.turbo()?5:1);
|
||||
frame_begin_time = anim_->get_first_frame_time() -1;
|
||||
anim_->update_current_frame();
|
||||
}
|
||||
void unit::set_healed(const display &disp,const gamemap::location& /*loc*/, int healing)
|
||||
void unit::set_healed(const display &disp,const gamemap::location& /*loc*/, int /*healing*/)
|
||||
{
|
||||
state_ = STATE_HEALED;
|
||||
draw_bars_ = true;
|
||||
|
@ -1675,22 +1659,14 @@ void unit::set_healed(const display &disp,const gamemap::location& /*loc*/, int
|
|||
}
|
||||
anim_ = new unit_animation(absolute_image());
|
||||
// add a blink on heal effect
|
||||
int anim_time = anim_->get_last_frame_time();
|
||||
int heal_left = healing;
|
||||
const std::string my_image = anim_->get_last_frame().image();
|
||||
while(anim_time < 1000 && heal_left > 0 ) {
|
||||
anim_->add_frame(anim_time,unit_frame(my_image,"",anim_time,anim_time+30,display::rgb(255,255,255),0.5));
|
||||
anim_time += 30;
|
||||
heal_left --;
|
||||
anim_->add_frame(anim_time,unit_frame(my_image,"",anim_time,anim_time+30,display::rgb(255,255,255),0.0));
|
||||
anim_time += 30;
|
||||
heal_left --;
|
||||
}
|
||||
anim_->add_frame(0,unit_frame(my_image,"",0,240,display::rgb(255,255,255),"0:30,0.5:30,0:30,0.5:30,0:30,0.5:30,0:30,0.5:30"));
|
||||
anim_->add_frame(240);
|
||||
anim_->start_animation(anim_->get_first_frame_time(),1,disp.turbo()?5:1);
|
||||
frame_begin_time = anim_->get_first_frame_time() -1;
|
||||
anim_->update_current_frame();
|
||||
}
|
||||
void unit::set_poisoned(const display &disp,const gamemap::location& /*loc*/, int damage)
|
||||
void unit::set_poisoned(const display &disp,const gamemap::location& /*loc*/, int /*damage*/)
|
||||
{
|
||||
state_ = STATE_POISONED;
|
||||
draw_bars_ = true;
|
||||
|
@ -1700,17 +1676,9 @@ void unit::set_poisoned(const display &disp,const gamemap::location& /*loc*/, in
|
|||
}
|
||||
anim_ = new unit_animation(absolute_image());
|
||||
// add a blink on damage effect
|
||||
int anim_time = anim_->get_last_frame_time();
|
||||
int damage_left = damage;
|
||||
const std::string my_image = anim_->get_last_frame().image();
|
||||
while(anim_time < 1000 && damage_left > 0 ) {
|
||||
anim_->add_frame(anim_time,unit_frame(my_image,"",anim_time,anim_time+30,display::rgb(0,255,0),0.5));
|
||||
anim_time += 30;
|
||||
damage_left --;
|
||||
anim_->add_frame(anim_time,unit_frame(my_image,"",anim_time,anim_time+30,display::rgb(0,255,0),0.0));
|
||||
anim_time += 30;
|
||||
damage_left --;
|
||||
}
|
||||
anim_->add_frame(0,unit_frame(my_image,"",0,240,display::rgb(0,255,0),"0:30,0.5:30,0:30,0.5:30,0:30,0.5:30,0:30,0.5:30"));
|
||||
anim_->add_frame(240);
|
||||
anim_->start_animation(anim_->get_first_frame_time(),1,disp.turbo()?5:1);
|
||||
frame_begin_time = anim_->get_first_frame_time() -1;
|
||||
anim_->update_current_frame();
|
||||
|
@ -1739,14 +1707,10 @@ void unit::set_dying(const display &disp,const gamemap::location& loc,const atta
|
|||
anim_ = NULL;
|
||||
}
|
||||
anim_ = new death_animation(die_animation(disp.get_map().underlying_union_terrain(loc),fighting_animation::KILL,attack));
|
||||
double blend_ratio = 1.0;
|
||||
std::string tmp_image = anim_->get_last_frame().image();
|
||||
int anim_time =anim_->get_last_frame_time();
|
||||
while(blend_ratio > 0.0) {
|
||||
anim_->add_frame(anim_time,unit_frame(tmp_image,"",anim_time,anim_time+10,0,0,ftofxp(blend_ratio)));
|
||||
blend_ratio -=0.015;
|
||||
anim_time += 10;
|
||||
}
|
||||
anim_->add_frame(0,unit_frame(tmp_image,"",anim_time,anim_time+600,0,"","1~0:600"));
|
||||
anim_->add_frame(anim_time+600);
|
||||
anim_->start_animation(anim_->get_first_frame_time(),1,disp.turbo()?5:1);
|
||||
frame_begin_time = anim_->get_first_frame_time() -1;
|
||||
anim_->update_current_frame();
|
||||
|
@ -1877,9 +1841,9 @@ void unit::redraw_unit(display& disp,gamemap::location hex)
|
|||
}
|
||||
|
||||
Uint32 blend_with = current_frame.blend_with();
|
||||
double blend_ratio = current_frame.blend_ratio();
|
||||
double blend_ratio = current_frame.blend_ratio(anim_->get_animation_time());
|
||||
if(blend_ratio == 0) { blend_with = disp.rgb(0,0,0); }
|
||||
fixed_t highlight_ratio = minimum<fixed_t>(alpha(),current_frame.highlight_ratio());
|
||||
fixed_t highlight_ratio = minimum<fixed_t>(alpha(),current_frame.highlight_ratio(anim_->get_animation_time()));
|
||||
if(invisible(hex,disp.get_units(),disp.get_teams()) &&
|
||||
highlight_ratio > ftofxp(0.5)) {
|
||||
highlight_ratio = ftofxp(0.5);
|
||||
|
|
|
@ -118,7 +118,7 @@ unit_animation::unit_animation(const config& cfg,const std::string frame_string
|
|||
|
||||
unit_animation::unit_animation(const std::string image, int begin_at, int end_at, const std::string image_diagonal,const std::string halo,int halo_x,int halo_y)
|
||||
{
|
||||
add_frame(begin_at, unit_frame(image,image_diagonal,begin_at,end_at,0,0.0,ftofxp(1),halo,halo_x,halo_y));
|
||||
add_frame(begin_at, unit_frame(image,image_diagonal,begin_at,end_at,0,"0.0","1.0",halo,halo_x,halo_y));
|
||||
if (end_at != begin_at) {
|
||||
add_frame(end_at);
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ unit_animation::unit_animation(const std::string image, int begin_at, int end_at
|
|||
|
||||
unit_animation::unit_animation(const std::string image, const std::string halo,int halo_x,int halo_y)
|
||||
{
|
||||
add_frame(0, unit_frame(image,"",0,0,0,0.0,ftofxp(1),halo,halo_x,halo_y));
|
||||
add_frame(0, unit_frame(image,"",0,0,0,"0.0","1.0",halo,halo_x,halo_y));
|
||||
if (!halo.empty()) {
|
||||
add_frame();
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@ std::vector<std::pair<std::string,int> > prepare_timed_list(const std::string &
|
|||
{
|
||||
const std::vector<std::string> first_pass = utils::split(data);
|
||||
const int time_chunk = maximum<int>(duration / (first_pass.size()?first_pass.size():1),1);
|
||||
std::vector<std::pair<std::string,int> > result;
|
||||
|
||||
std::vector<std::string>::const_iterator tmp;
|
||||
std::vector<std::pair<std::string,int> > result;
|
||||
for(tmp=first_pass.begin();tmp != first_pass.end() ; tmp++) {
|
||||
std::vector<std::string> second_pass = utils::split(*tmp,':');
|
||||
if(second_pass.size() > 1) {
|
||||
|
@ -32,7 +32,7 @@ std::vector<std::pair<std::string,int> > prepare_timed_list(const std::string &
|
|||
return result;
|
||||
}
|
||||
|
||||
const std::string get_current_element(const std::vector<std::pair<std::string,int> > &data, int current_time)
|
||||
const std::string get_current_element_string(const std::vector<std::pair<std::string,int> > &data, int current_time)
|
||||
{
|
||||
int time = 0;
|
||||
unsigned int sub_halo = 0;
|
||||
|
@ -47,7 +47,52 @@ const std::string get_current_element(const std::vector<std::pair<std::string,in
|
|||
return data[sub_halo].first;
|
||||
}
|
||||
|
||||
int duration(const std::vector<std::pair<std::string,int> > &data)
|
||||
|
||||
std::vector<std::pair<std::pair<double,double>,int> > prepare_progressive_double(const std::string &data, int duration)
|
||||
{
|
||||
std::vector<std::pair<std::string,int> > first_pass = prepare_timed_list(data,duration);
|
||||
std::vector<std::pair<std::string,int> >::const_iterator tmp;
|
||||
std::vector<std::pair<std::pair<double,double>,int> > result;
|
||||
for(tmp=first_pass.begin();tmp != first_pass.end() ; tmp++) {
|
||||
std::vector<std::string> range = utils::split(tmp->first,'~');
|
||||
result.push_back(std::pair<std::pair<double,double>,int> (
|
||||
std::pair<double,double>(
|
||||
atof(range[0].c_str()),
|
||||
atof(range.size()>1?range[1].c_str():range[0].c_str())),
|
||||
tmp->second));
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
const double get_current_element_double(const std::vector<std::pair<std::pair<double,double>,int> > &data, int current_time)
|
||||
{
|
||||
int time = 0;
|
||||
unsigned int sub_halo = 0;
|
||||
if(data.empty()) return 0;
|
||||
while(time < current_time&& sub_halo < data.size()) {
|
||||
time += data[sub_halo].second;
|
||||
sub_halo++;
|
||||
|
||||
}
|
||||
if(sub_halo > 0) {
|
||||
sub_halo--;
|
||||
time -= data[sub_halo].second;
|
||||
}
|
||||
if(sub_halo >= data.size()) {
|
||||
sub_halo = data.size();
|
||||
time = current_time; // never more than max allowed
|
||||
}
|
||||
|
||||
const double first = data[sub_halo].first.first;
|
||||
const double second = data[sub_halo].first.second;
|
||||
|
||||
return ( double(current_time - time)/(double)(data[sub_halo].second))*(second - first)+ first;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int duration_string(const std::vector<std::pair<std::string,int> > &data)
|
||||
{
|
||||
int total =0;
|
||||
std::vector<std::pair<std::string,int> >::const_iterator cur_halo;
|
||||
|
@ -56,31 +101,49 @@ int duration(const std::vector<std::pair<std::string,int> > &data)
|
|||
}
|
||||
return total;
|
||||
|
||||
}
|
||||
int duration_double(const std::vector<std::pair<std::pair<double,double>,int> > &data)
|
||||
{
|
||||
int total =0;
|
||||
std::vector<std::pair<std::pair<double,double>,int> >::const_iterator cur_halo;
|
||||
for(cur_halo = data.begin() ; cur_halo != data.end() ; cur_halo++) {
|
||||
total += cur_halo->second;
|
||||
}
|
||||
return total;
|
||||
|
||||
}
|
||||
unit_frame::unit_frame() :
|
||||
xoffset_(0), image_(), image_diagonal_(),halo_(), sound_(),
|
||||
halo_x_(0), halo_y_(0), begin_time_(0), end_time_(0),
|
||||
blend_with_(0),blend_ratio_(0),
|
||||
highlight_ratio_(ftofxp(1))
|
||||
{}
|
||||
blend_with_(0),blend_ratio_(),
|
||||
highlight_ratio_()
|
||||
{
|
||||
highlight_ratio_ = prepare_progressive_double("1.0",0);
|
||||
}
|
||||
|
||||
|
||||
unit_frame::unit_frame(const std::string& str, const std::string & diag,
|
||||
int begin,int end,
|
||||
Uint32 blend_color, double blend_rate,
|
||||
fixed_t highlight,
|
||||
Uint32 blend_color, const std::string& blend_rate,
|
||||
const std::string& highlight,
|
||||
std::string in_halo, int halox, int haloy) :
|
||||
xoffset_(0), image_(str),image_diagonal_(diag),
|
||||
halo_(),halo_x_(halox), halo_y_(haloy),
|
||||
begin_time_(begin), end_time_(end),
|
||||
blend_with_(blend_color), blend_ratio_(blend_rate),
|
||||
highlight_ratio_(highlight)
|
||||
blend_with_(blend_color)
|
||||
{
|
||||
// let's decide of duration ourselves
|
||||
if(begin == end) {
|
||||
end_time_ = begin_time_ + minimum<int>(200,duration(halo_));
|
||||
halo_ = prepare_timed_list(in_halo,0);
|
||||
blend_ratio_ = prepare_progressive_double(blend_rate,0);
|
||||
highlight_ratio_ = prepare_progressive_double(highlight,0);
|
||||
end_time_ = maximum<int>(duration_double(blend_ratio_),duration_string(halo_));
|
||||
end_time_ = maximum<int>(end_time_,duration_double(highlight_ratio_));
|
||||
end_time_ += begin_time_;
|
||||
}
|
||||
halo_ = prepare_timed_list(in_halo,end_time_ - begin_time_);
|
||||
blend_ratio_ = prepare_progressive_double(blend_rate,end_time_ - begin_time_);
|
||||
highlight_ratio_ = prepare_progressive_double(highlight,end_time_ - begin_time_);
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,16 +158,26 @@ unit_frame::unit_frame(const config& cfg)
|
|||
sound_ = cfg["sound"];
|
||||
begin_time_ = atoi(cfg["begin"].c_str());
|
||||
end_time_ = atoi(cfg["end"].c_str());
|
||||
highlight_ratio_ = ftofxp(1);
|
||||
halo_ = prepare_timed_list(cfg["halo"],end_time_-begin_time_);
|
||||
blend_with_= 0;
|
||||
blend_ratio_ = 0;
|
||||
blend_ratio_ = prepare_progressive_double(cfg["blend_ratio"],end_time_-begin_time_);
|
||||
highlight_ratio_ = prepare_progressive_double(cfg["highlight"].empty()?"1.0":cfg["highlight"],end_time_-begin_time_);
|
||||
|
||||
}
|
||||
|
||||
|
||||
const std::string unit_frame::halo(int current_time) const
|
||||
{
|
||||
return get_current_element(halo_,current_time - begin_time_);
|
||||
return get_current_element_string(halo_,current_time - begin_time_);
|
||||
}
|
||||
|
||||
double unit_frame::blend_ratio(int current_time) const
|
||||
{
|
||||
return get_current_element_double(blend_ratio_,current_time - begin_time_);
|
||||
}
|
||||
|
||||
fixed_t unit_frame::highlight_ratio(int current_time) const
|
||||
{
|
||||
return ftofxp(get_current_element_double(highlight_ratio_,current_time - begin_time_));
|
||||
}
|
||||
|
||||
|
|
|
@ -23,29 +23,30 @@
|
|||
#include <vector>
|
||||
|
||||
//a class to describe a unit's animation sequence
|
||||
extern std::string grr(const char*);
|
||||
class unit_frame {
|
||||
public:
|
||||
// constructors
|
||||
unit_frame();
|
||||
explicit unit_frame(const std::string& str, const std::string & diag ="",
|
||||
int begin=0,int end = 0,
|
||||
Uint32 blend_color = 0, double blend_rate = 0.0,
|
||||
fixed_t highlight = ftofxp(1),
|
||||
Uint32 blend_color = 0, const std::string& blend_rate = "",
|
||||
const std::string& highlight="1.0",
|
||||
std::string in_halo = "",int halox = 0,int haloy = 0);
|
||||
explicit unit_frame(const config& cfg);
|
||||
|
||||
int xoffset() const { return xoffset_ ; }
|
||||
std::string image() const { return image_ ;}
|
||||
std::string image_diagonal() const { return image_diagonal_ ; }
|
||||
const std::string halo(int current_time) const ;
|
||||
const std::string halo(int current_time) const;
|
||||
std::string sound() const { return sound_ ; };
|
||||
int halo_x() const { return halo_x_; }
|
||||
int halo_y() const { return halo_y_; }
|
||||
int begin_time() const { return begin_time_; }
|
||||
int end_time() const { return end_time_ ; }
|
||||
Uint32 blend_with() const { return blend_with_; }
|
||||
double blend_ratio() const { return blend_ratio_; }
|
||||
fixed_t highlight_ratio() const { return highlight_ratio_ ; }
|
||||
double blend_ratio(int current_time) const;
|
||||
fixed_t highlight_ratio(int current_time) const;
|
||||
private:
|
||||
int xoffset_;
|
||||
std::string image_;
|
||||
|
@ -55,8 +56,8 @@ class unit_frame {
|
|||
int halo_x_, halo_y_;
|
||||
int begin_time_, end_time_;
|
||||
Uint32 blend_with_;
|
||||
double blend_ratio_;
|
||||
fixed_t highlight_ratio_;
|
||||
std::vector<std::pair<std::pair<double,double>,int> > blend_ratio_;
|
||||
std::vector<std::pair<std::pair<double,double>,int> > highlight_ratio_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue