rework the animation parameters logic to avoid...
...multiple useless parsing of WML fix bug #14824
This commit is contained in:
parent
a7d4c3a815
commit
c275f68f82
4 changed files with 154 additions and 72 deletions
|
@ -705,13 +705,8 @@ void unit_animation::particule::override(int start_time
|
|||
, const std::string& layer)
|
||||
{
|
||||
set_begin_time(start_time);
|
||||
if(!highlight.empty()) parameters_.highlight(highlight);
|
||||
if(!offset.empty()) parameters_.offset(offset);
|
||||
if(!blend_ratio.empty()) parameters_.blend(blend_ratio,blend_color);
|
||||
if(!layer.empty()) parameters_.drawing_layer(layer);
|
||||
parameters_.override(duration,highlight,blend_ratio,blend_color,offset,layer);
|
||||
|
||||
|
||||
parameters_.duration(duration);
|
||||
if(get_animation_duration() < duration) {
|
||||
const unit_frame & last_frame = get_last_frame();
|
||||
add_frame(duration -get_animation_duration(), last_frame);
|
||||
|
@ -719,7 +714,6 @@ void unit_animation::particule::override(int start_time
|
|||
remove_frames_after(duration);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool unit_animation::particule::need_update() const
|
||||
|
@ -742,7 +736,7 @@ unit_animation::particule::particule(
|
|||
const config& cfg, const std::string& frame_string ) :
|
||||
animated<unit_frame>(),
|
||||
accelerate(true),
|
||||
parameters_(cfg,frame_string),
|
||||
parameters_(),
|
||||
halo_id_(0),
|
||||
last_frame_begin_time_(0)
|
||||
{
|
||||
|
@ -761,7 +755,7 @@ unit_animation::particule::particule(
|
|||
unit_frame tmp_frame(frame);
|
||||
add_frame(tmp_frame.duration(),tmp_frame,!tmp_frame.does_not_change());
|
||||
}
|
||||
parameters_.duration(get_animation_duration());
|
||||
parameters_ = frame_parsed_parameters(frame_builder(cfg,frame_string),get_animation_duration());
|
||||
if(!parameters_.does_not_change() ) {
|
||||
force_change();
|
||||
}
|
||||
|
@ -970,7 +964,7 @@ void unit_animation::particule::start_animation(int start_time, bool cycles)
|
|||
{
|
||||
halo::remove(halo_id_);
|
||||
halo_id_ = halo::NO_HALO;
|
||||
parameters_.duration(get_animation_duration());
|
||||
parameters_.override(get_animation_duration());
|
||||
animated<unit_frame>::start_animation(start_time,cycles);
|
||||
last_frame_begin_time_ = get_begin_time() -1;
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ class unit_animation
|
|||
private:
|
||||
|
||||
//animation params that can be locally overridden by frames
|
||||
frame_builder parameters_;
|
||||
frame_parsed_parameters parameters_;
|
||||
int halo_id_;
|
||||
int last_frame_begin_time_;
|
||||
|
||||
|
|
|
@ -146,6 +146,7 @@ template class progressive_<double>;
|
|||
#undef UNIT_FRAME_H_PART2
|
||||
|
||||
frame_parameters::frame_parameters() :
|
||||
duration(0),
|
||||
image(),
|
||||
image_diagonal(),
|
||||
image_mod(""),
|
||||
|
@ -156,7 +157,6 @@ frame_parameters::frame_parameters() :
|
|||
sound(""),
|
||||
text(""),
|
||||
text_color(0),
|
||||
duration(0),
|
||||
blend_with(0),
|
||||
blend_ratio(0.0),
|
||||
highlight_ratio(1.0),
|
||||
|
@ -170,6 +170,7 @@ frame_parameters::frame_parameters() :
|
|||
{}
|
||||
|
||||
frame_builder::frame_builder() :
|
||||
duration_(1),
|
||||
image_(),
|
||||
image_diagonal_(),
|
||||
image_mod_(""),
|
||||
|
@ -180,7 +181,6 @@ frame_builder::frame_builder() :
|
|||
sound_(""),
|
||||
text_(""),
|
||||
text_color_(0),
|
||||
duration_(1),
|
||||
blend_with_(0),
|
||||
blend_ratio_(""),
|
||||
highlight_ratio_(""),
|
||||
|
@ -192,6 +192,7 @@ frame_builder::frame_builder() :
|
|||
{}
|
||||
|
||||
frame_builder::frame_builder(const config& cfg,const std::string& frame_string) :
|
||||
duration_(1),
|
||||
image_(),
|
||||
image_diagonal_(),
|
||||
image_mod_(""),
|
||||
|
@ -202,7 +203,6 @@ frame_builder::frame_builder(const config& cfg,const std::string& frame_string)
|
|||
sound_(""),
|
||||
text_(""),
|
||||
text_color_(0),
|
||||
duration_(1),
|
||||
blend_with_(0),
|
||||
blend_ratio_(""),
|
||||
highlight_ratio_(""),
|
||||
|
@ -243,30 +243,6 @@ frame_builder::frame_builder(const config& cfg,const std::string& frame_string)
|
|||
drawing_layer(cfg[frame_string+"layer"]);
|
||||
}
|
||||
|
||||
const frame_parameters frame_builder::parameters(int current_time) const
|
||||
{
|
||||
frame_parameters result;
|
||||
result.duration = duration_;
|
||||
result.image = image_;
|
||||
result.image_diagonal = image_diagonal_;
|
||||
result.image_mod = image_mod_;
|
||||
result.halo = halo_.get_current_element(current_time);
|
||||
result.halo_x = halo_x_.get_current_element(current_time);
|
||||
result.halo_y = halo_y_.get_current_element(current_time);
|
||||
result.halo_mod = halo_mod_;
|
||||
result.sound = sound_;
|
||||
result.text = text_;
|
||||
result.text_color = text_color_;
|
||||
result.blend_with = blend_with_;
|
||||
result.blend_ratio = blend_ratio_.get_current_element(current_time);
|
||||
result.highlight_ratio = highlight_ratio_.get_current_element(current_time,1.0);
|
||||
result.offset = offset_.get_current_element(current_time,-1000);
|
||||
result.submerge = submerge_.get_current_element(current_time);
|
||||
result.x = x_.get_current_element(current_time);
|
||||
result.y = y_.get_current_element(current_time);
|
||||
result.drawing_layer = drawing_layer_.get_current_element(current_time,display::LAYER_UNIT_DEFAULT-display::LAYER_UNIT_FIRST);
|
||||
return result;
|
||||
}
|
||||
frame_builder & frame_builder::image(const image::locator& image ,const std::string & image_mod)
|
||||
{
|
||||
image_ = image;
|
||||
|
@ -292,69 +268,79 @@ frame_builder & frame_builder::text(const std::string& text,const Uint32 text_c
|
|||
}
|
||||
frame_builder & frame_builder::halo(const std::string &halo, const std::string &halo_x, const std::string& halo_y,const std::string & halo_mod)
|
||||
{
|
||||
halo_ = progressive_string(halo,duration_);
|
||||
halo_x_ = progressive_int(halo_x,duration_);
|
||||
halo_y_ = progressive_int(halo_y,duration_);
|
||||
halo_ = halo;
|
||||
halo_x_ = halo_x;
|
||||
halo_y_ = halo_y;
|
||||
halo_mod_= halo_mod;
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::duration(const int duration)
|
||||
{
|
||||
duration_= duration;
|
||||
recalculate_duration();
|
||||
return *this;
|
||||
}
|
||||
void frame_builder::recalculate_duration()
|
||||
{
|
||||
halo_ = progressive_string(halo_.get_original(),duration_);
|
||||
halo_x_ = progressive_int(halo_x_.get_original(),duration_);
|
||||
halo_y_ = progressive_int(halo_y_.get_original(),duration_);
|
||||
blend_ratio_=progressive_double(blend_ratio_.get_original(),duration_);
|
||||
highlight_ratio_=progressive_double(highlight_ratio_.get_original(),duration_);
|
||||
offset_=progressive_double(offset_.get_original(),duration_);
|
||||
submerge_=progressive_double(submerge_.get_original(),duration_);
|
||||
x_=progressive_int(x_.get_original(),duration_);
|
||||
y_=progressive_int(y_.get_original(),duration_);
|
||||
drawing_layer_=progressive_int(drawing_layer_.get_original(),duration_);
|
||||
}
|
||||
frame_builder & frame_builder::blend(const std::string& blend_ratio,const Uint32 blend_color)
|
||||
{
|
||||
blend_with_=blend_color;
|
||||
blend_ratio_=progressive_double(blend_ratio,duration_);
|
||||
blend_ratio_=blend_ratio;
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::highlight(const std::string& highlight)
|
||||
{
|
||||
highlight_ratio_=progressive_double(highlight,duration_);
|
||||
highlight_ratio_=highlight;
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::offset(const std::string& offset)
|
||||
{
|
||||
offset_=progressive_double(offset,duration_);
|
||||
offset_=offset;
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::submerge(const std::string& submerge)
|
||||
{
|
||||
submerge_=progressive_double(submerge,duration_);
|
||||
submerge_=submerge;
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::x(const std::string& x)
|
||||
{
|
||||
x_=progressive_int(x,duration_);
|
||||
x_=x;
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::y(const std::string& y)
|
||||
{
|
||||
y_=progressive_int(y,duration_);
|
||||
y_=y;
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::drawing_layer(const std::string& drawing_layer)
|
||||
{
|
||||
drawing_layer_=progressive_int(drawing_layer,duration_);
|
||||
drawing_layer_=drawing_layer;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool frame_builder::does_not_change() const
|
||||
|
||||
frame_parsed_parameters::frame_parsed_parameters(const frame_builder & builder, int duration) :
|
||||
duration_(duration ? duration :builder.duration_),
|
||||
image_(builder.image_),
|
||||
image_diagonal_(builder.image_diagonal_),
|
||||
image_mod_(builder.image_mod_),
|
||||
halo_(builder.halo_,duration_),
|
||||
halo_x_(builder.halo_x_,duration_),
|
||||
halo_y_(builder.halo_y_,duration_),
|
||||
halo_mod_(builder.halo_mod_),
|
||||
sound_(builder.sound_),
|
||||
text_(builder.text_),
|
||||
text_color_(builder.text_color_),
|
||||
blend_with_(builder.blend_with_),
|
||||
blend_ratio_(builder.blend_ratio_,duration_),
|
||||
highlight_ratio_(builder.highlight_ratio_,duration_),
|
||||
offset_(builder.offset_,duration_),
|
||||
submerge_(builder.submerge_,duration_),
|
||||
x_(builder.x_,duration_),
|
||||
y_(builder.y_,duration_),
|
||||
drawing_layer_(builder.drawing_layer_,duration_)
|
||||
{}
|
||||
|
||||
|
||||
bool frame_parsed_parameters::does_not_change() const
|
||||
{
|
||||
return halo_.does_not_change() &&
|
||||
halo_x_.does_not_change() &&
|
||||
|
@ -367,7 +353,7 @@ bool frame_builder::does_not_change() const
|
|||
y_.does_not_change() &&
|
||||
drawing_layer_.does_not_change();
|
||||
}
|
||||
bool frame_builder::need_update() const
|
||||
bool frame_parsed_parameters::need_update() const
|
||||
{
|
||||
if(!halo_.does_not_change() ||
|
||||
!halo_x_.does_not_change() ||
|
||||
|
@ -384,6 +370,73 @@ bool frame_builder::need_update() const
|
|||
return false;
|
||||
}
|
||||
|
||||
const frame_parameters frame_parsed_parameters::parameters(int current_time) const
|
||||
{
|
||||
frame_parameters result;
|
||||
result.duration = duration_;
|
||||
result.image = image_;
|
||||
result.image_diagonal = image_diagonal_;
|
||||
result.image_mod = image_mod_;
|
||||
result.halo = halo_.get_current_element(current_time);
|
||||
result.halo_x = halo_x_.get_current_element(current_time);
|
||||
result.halo_y = halo_y_.get_current_element(current_time);
|
||||
result.halo_mod = halo_mod_;
|
||||
result.sound = sound_;
|
||||
result.text = text_;
|
||||
result.text_color = text_color_;
|
||||
result.blend_with = blend_with_;
|
||||
result.blend_ratio = blend_ratio_.get_current_element(current_time);
|
||||
result.highlight_ratio = highlight_ratio_.get_current_element(current_time,1.0);
|
||||
result.offset = offset_.get_current_element(current_time,-1000);
|
||||
result.submerge = submerge_.get_current_element(current_time);
|
||||
result.x = x_.get_current_element(current_time);
|
||||
result.y = y_.get_current_element(current_time);
|
||||
result.drawing_layer = drawing_layer_.get_current_element(current_time,display::LAYER_UNIT_DEFAULT-display::LAYER_UNIT_FIRST);
|
||||
return result;
|
||||
}
|
||||
|
||||
void frame_parsed_parameters::override( int duration
|
||||
, const std::string& highlight
|
||||
, const std::string& blend_ratio
|
||||
, Uint32 blend_color
|
||||
, const std::string& offset
|
||||
, const std::string& layer)
|
||||
{
|
||||
|
||||
if(!highlight.empty()) {
|
||||
highlight_ratio_ = progressive_double(highlight,duration);
|
||||
} else if(duration != duration_){
|
||||
highlight_ratio_=progressive_double(highlight_ratio_.get_original(),duration);
|
||||
}
|
||||
if(!offset.empty()) {
|
||||
offset_= progressive_double(offset,duration);
|
||||
} else if(duration != duration_){
|
||||
offset_=progressive_double(offset_.get_original(),duration);
|
||||
}
|
||||
if(!blend_ratio.empty()) {
|
||||
blend_ratio_ = progressive_double(blend_ratio,duration);
|
||||
blend_with_ = blend_color;
|
||||
} else if(duration != duration_){
|
||||
blend_ratio_=progressive_double(blend_ratio_.get_original(),duration);
|
||||
}
|
||||
if(!layer.empty()) {
|
||||
drawing_layer_ = progressive_int(layer,duration);
|
||||
} else if(duration != duration_){
|
||||
drawing_layer_=progressive_int(drawing_layer_.get_original(),duration);
|
||||
}
|
||||
|
||||
if(duration != duration_) {
|
||||
halo_ = progressive_string(halo_.get_original(),duration);
|
||||
halo_x_ = progressive_int(halo_x_.get_original(),duration);
|
||||
halo_y_ = progressive_int(halo_y_.get_original(),duration);
|
||||
submerge_=progressive_double(submerge_.get_original(),duration);
|
||||
x_=progressive_int(x_.get_original(),duration);
|
||||
y_=progressive_int(y_.get_original(),duration);
|
||||
duration_ = duration;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void unit_frame::redraw(const int frame_time,bool first_time,const map_location & src,const map_location & dst,int*halo_id,const frame_parameters & animation_val,const frame_parameters & engine_val,const bool primary)const
|
||||
{
|
||||
const int xsrc = game_display::get_singleton()->get_location_x(src);
|
||||
|
|
|
@ -68,6 +68,7 @@ class frame_parameters{
|
|||
public:
|
||||
frame_parameters();
|
||||
|
||||
int duration;
|
||||
image::locator image;
|
||||
image::locator image_diagonal;
|
||||
std::string image_mod;
|
||||
|
@ -78,7 +79,6 @@ class frame_parameters{
|
|||
std::string sound;
|
||||
std::string text;
|
||||
Uint32 text_color;
|
||||
int duration;
|
||||
Uint32 blend_with;
|
||||
double blend_ratio;
|
||||
double highlight_ratio;
|
||||
|
@ -91,20 +91,20 @@ class frame_parameters{
|
|||
bool diagonal_in_hex;
|
||||
} ;
|
||||
/**
|
||||
* keep most parameters in a separate class to simplify handling of large
|
||||
* number of parameters
|
||||
* easily build frame parameters with the serialized constructors
|
||||
*/
|
||||
class frame_parsed_parameters;
|
||||
class frame_builder {
|
||||
public:
|
||||
frame_builder();
|
||||
frame_builder(const config& cfg,const std::string &frame_string = "");
|
||||
/** allow easy chained modifications will raised assert if used after initialization */
|
||||
frame_builder & duration(const int duration);
|
||||
frame_builder & image(const image::locator& image ,const std::string & image_mod="");
|
||||
frame_builder & image_diagonal(const image::locator& image_diagonal,const std::string & image_mod="");
|
||||
frame_builder & sound(const std::string& sound);
|
||||
frame_builder & text(const std::string& text,const Uint32 text_color);
|
||||
frame_builder & halo(const std::string &halo, const std::string &halo_x, const std::string& halo_y,const std::string& halo_mod);
|
||||
frame_builder & duration(const int duration);
|
||||
frame_builder & blend(const std::string& blend_ratio,const Uint32 blend_color);
|
||||
frame_builder & highlight(const std::string& highlight);
|
||||
frame_builder & offset(const std::string& offset);
|
||||
|
@ -113,13 +113,50 @@ class frame_builder {
|
|||
frame_builder & y(const std::string& y);
|
||||
frame_builder & drawing_layer(const std::string& drawing_layer);
|
||||
/** getters for the different parameters */
|
||||
private:
|
||||
friend class frame_parsed_parameters;
|
||||
int duration_;
|
||||
image::locator image_;
|
||||
image::locator image_diagonal_;
|
||||
std::string image_mod_;
|
||||
std::string halo_;
|
||||
std::string halo_x_;
|
||||
std::string halo_y_;
|
||||
std::string halo_mod_;
|
||||
std::string sound_;
|
||||
std::string text_;
|
||||
Uint32 text_color_;
|
||||
Uint32 blend_with_;
|
||||
std::string blend_ratio_;
|
||||
std::string highlight_ratio_;
|
||||
std::string offset_;
|
||||
std::string submerge_;
|
||||
std::string x_;
|
||||
std::string y_;
|
||||
std::string drawing_layer_;
|
||||
};
|
||||
/**
|
||||
* keep most parameters in a separate class to simplify handling of large
|
||||
* number of parameters hanling is common for frame level and animation level
|
||||
*/
|
||||
class frame_parsed_parameters {
|
||||
public:
|
||||
frame_parsed_parameters(const frame_builder& builder=frame_builder(),int override_duration = 0);
|
||||
/** allow easy chained modifications will raised assert if used after initialization */
|
||||
void override( int duration
|
||||
, const std::string& highlight = ""
|
||||
, const std::string& blend_ratio =""
|
||||
, Uint32 blend_color = 0
|
||||
, const std::string& offset = ""
|
||||
, const std::string& layer = "");
|
||||
/** getters for the different parameters */
|
||||
const frame_parameters parameters(int current_time) const ;
|
||||
|
||||
int duration() const{ return duration_;};
|
||||
void recalculate_duration();
|
||||
bool does_not_change() const;
|
||||
bool need_update() const;
|
||||
private:
|
||||
int duration_;
|
||||
image::locator image_;
|
||||
image::locator image_diagonal_;
|
||||
std::string image_mod_;
|
||||
|
@ -130,7 +167,6 @@ class frame_builder {
|
|||
std::string sound_;
|
||||
std::string text_;
|
||||
Uint32 text_color_;
|
||||
int duration_;
|
||||
Uint32 blend_with_;
|
||||
progressive_double blend_ratio_;
|
||||
progressive_double highlight_ratio_;
|
||||
|
@ -140,7 +176,6 @@ class frame_builder {
|
|||
progressive_int y_;
|
||||
progressive_int drawing_layer_;
|
||||
};
|
||||
|
||||
/** Describe a unit's animation sequence. */
|
||||
class unit_frame {
|
||||
public:
|
||||
|
@ -155,7 +190,7 @@ class unit_frame {
|
|||
bool need_update() const{ return builder_.need_update();};
|
||||
std::set<map_location> get_overlaped_hex(const int frame_time,const map_location & src,const map_location & dst,const frame_parameters & animation_val,const frame_parameters & engine_val,const bool primary) const;
|
||||
private:
|
||||
frame_builder builder_;
|
||||
frame_parsed_parameters builder_;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue