Extensive cleanup of unit animation frame code
The majority of which consists of code formatting, but also a few small semantic changes (tristate -> boost::tribool, etc).
This commit is contained in:
parent
a3c2f027c4
commit
42f087abb3
4 changed files with 998 additions and 729 deletions
|
@ -1084,10 +1084,10 @@ void unit_animation::redraw(frame_parameters& value, halo::manager& halo_man)
|
||||||
invalidated_ = false;
|
invalidated_ = false;
|
||||||
overlaped_hex_.clear();
|
overlaped_hex_.clear();
|
||||||
|
|
||||||
value.primary_frame = t_true;
|
value.primary_frame = true;
|
||||||
unit_anim_.redraw(value,src_,dst_, halo_man);
|
unit_anim_.redraw(value,src_,dst_, halo_man);
|
||||||
|
|
||||||
value.primary_frame = t_false;
|
value.primary_frame = false;
|
||||||
for(auto& anim : sub_anims_) {
|
for(auto& anim : sub_anims_) {
|
||||||
anim.second.redraw(value, src_, dst_, halo_man);
|
anim.second.redraw(value, src_, dst_, halo_man);
|
||||||
}
|
}
|
||||||
|
@ -1111,9 +1111,9 @@ bool unit_animation::invalidate(frame_parameters& value)
|
||||||
|
|
||||||
if(overlaped_hex_.empty()) {
|
if(overlaped_hex_.empty()) {
|
||||||
if(complete_redraw) {
|
if(complete_redraw) {
|
||||||
value.primary_frame = t_true;
|
value.primary_frame = true;
|
||||||
overlaped_hex_ = unit_anim_.get_overlaped_hex(value, src_, dst_);
|
overlaped_hex_ = unit_anim_.get_overlaped_hex(value, src_, dst_);
|
||||||
value.primary_frame = t_false;
|
value.primary_frame = false;
|
||||||
|
|
||||||
for(auto& anim : sub_anims_) {
|
for(auto& anim : sub_anims_) {
|
||||||
std::set<map_location> tmp = anim.second.get_overlaped_hex(value, src_, dst_);
|
std::set<map_location> tmp = anim.second.get_overlaped_hex(value, src_, dst_);
|
||||||
|
|
|
@ -147,7 +147,7 @@ void unit_drawer::redraw_unit (const unit & u) const
|
||||||
|
|
||||||
|
|
||||||
if(u.incapacitated()) params.image_mod +="~GS()";
|
if(u.incapacitated()) params.image_mod +="~GS()";
|
||||||
params.primary_frame = t_true;
|
params.primary_frame = true;
|
||||||
|
|
||||||
|
|
||||||
const frame_parameters adjusted_params = ac.anim_->get_current_params(params);
|
const frame_parameters adjusted_params = ac.anim_->get_current_params(params);
|
||||||
|
|
1319
src/units/frame.cpp
1319
src/units/frame.cpp
File diff suppressed because it is too large
Load diff
|
@ -23,203 +23,297 @@
|
||||||
#include "halo.hpp"
|
#include "halo.hpp"
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
|
|
||||||
|
#include <boost/logic/tribool.hpp>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
class config;
|
class config;
|
||||||
|
|
||||||
class progressive_string {
|
/* FIXME: these 'progressive_' classes are all mostly equivalent except for the exact type of the
|
||||||
public:
|
* data_ vector and the interactions with it. Need to figure how to reduce the code duplication -
|
||||||
progressive_string(const std::string& data = "",int duration = 0);
|
* perhaps inherit from progressive_base? Though do note the string/image functions are only
|
||||||
int duration() const;
|
* unique since they don't store a pair of pairs.
|
||||||
const std::string & get_current_element(int time) const;
|
*/
|
||||||
bool does_not_change() const { return data_.size() <= 1; }
|
template<typename T>
|
||||||
std::string get_original() const { return input_; }
|
class progressive_base
|
||||||
private:
|
|
||||||
std::vector<std::pair<std::string,int> > data_;
|
|
||||||
std::string input_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class progressive_image {
|
|
||||||
public:
|
|
||||||
progressive_image(const std::string& data = "",int duration = 0);
|
|
||||||
int duration() const;
|
|
||||||
const image::locator & get_current_element(int time) const;
|
|
||||||
bool does_not_change() const { return data_.size() <= 1; }
|
|
||||||
std::string get_original() const { return input_; }
|
|
||||||
private:
|
|
||||||
std::vector<std::pair<image::locator,int> > data_;
|
|
||||||
std::string input_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class progressive_
|
|
||||||
{
|
{
|
||||||
std::vector<std::pair<std::pair<T, T>, int> > data_;
|
|
||||||
std::string input_;
|
|
||||||
public:
|
public:
|
||||||
progressive_(const std::string& data = "", int duration = 0);
|
progressive_base(const std::string& data = "", int duration = 0);
|
||||||
int duration() const;
|
int duration() const;
|
||||||
const T get_current_element(int time,T default_val=0) const;
|
const T get_current_element(int time, T default_val = 0) const;
|
||||||
bool does_not_change() const;
|
bool does_not_change() const;
|
||||||
std::string get_original() const { return input_; }
|
|
||||||
|
std::string get_original() const
|
||||||
|
{
|
||||||
|
return input_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::pair<std::pair<T, T>, int>> data_;
|
||||||
|
std::string input_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef progressive_<int> progressive_int;
|
class progressive_string
|
||||||
typedef progressive_<double> progressive_double;
|
{
|
||||||
|
public:
|
||||||
|
progressive_string(const std::string& data = "", int duration = 0);
|
||||||
|
int duration() const;
|
||||||
|
const std::string& get_current_element(int time) const;
|
||||||
|
|
||||||
|
bool does_not_change() const
|
||||||
|
{
|
||||||
|
return data_.size() <= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string get_original() const
|
||||||
|
{
|
||||||
|
return input_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::pair<std::string,int>> data_;
|
||||||
|
std::string input_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class progressive_image
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
progressive_image(const std::string& data = "", int duration = 0);
|
||||||
|
int duration() const;
|
||||||
|
const image::locator& get_current_element(int time) const;
|
||||||
|
|
||||||
|
bool does_not_change() const
|
||||||
|
{
|
||||||
|
return data_.size() <= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string get_original() const
|
||||||
|
{
|
||||||
|
return input_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::pair<image::locator,int>> data_;
|
||||||
|
std::string input_;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef progressive_base<int> progressive_int;
|
||||||
|
typedef progressive_base<double> progressive_double;
|
||||||
|
|
||||||
enum tristate {t_false,t_true,t_unset};
|
|
||||||
bool tristate_to_bool(tristate tri, bool def);
|
|
||||||
/** All parameters from a frame at a given instant */
|
/** All parameters from a frame at a given instant */
|
||||||
class frame_parameters{
|
struct frame_parameters
|
||||||
public:
|
{
|
||||||
frame_parameters();
|
frame_parameters();
|
||||||
|
|
||||||
int duration;
|
int duration;
|
||||||
|
|
||||||
image::locator image;
|
image::locator image;
|
||||||
image::locator image_diagonal;
|
image::locator image_diagonal;
|
||||||
|
|
||||||
std::string image_mod;
|
std::string image_mod;
|
||||||
std::string halo;
|
std::string halo;
|
||||||
|
|
||||||
int halo_x;
|
int halo_x;
|
||||||
int halo_y;
|
int halo_y;
|
||||||
|
|
||||||
std::string halo_mod;
|
std::string halo_mod;
|
||||||
std::string sound;
|
std::string sound;
|
||||||
std::string text;
|
std::string text;
|
||||||
|
|
||||||
boost::optional<color_t> text_color;
|
boost::optional<color_t> text_color;
|
||||||
boost::optional<color_t> blend_with;
|
boost::optional<color_t> blend_with;
|
||||||
|
|
||||||
double blend_ratio;
|
double blend_ratio;
|
||||||
double highlight_ratio;
|
double highlight_ratio;
|
||||||
double offset;
|
double offset;
|
||||||
double submerge;
|
double submerge;
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int directional_x;
|
int directional_x;
|
||||||
int directional_y;
|
int directional_y;
|
||||||
tristate auto_vflip;
|
|
||||||
tristate auto_hflip;
|
boost::tribool auto_vflip;
|
||||||
tristate primary_frame;
|
boost::tribool auto_hflip;
|
||||||
|
boost::tribool primary_frame;
|
||||||
|
|
||||||
int drawing_layer;
|
int drawing_layer;
|
||||||
} ;
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* easily build frame parameters with the serialized constructors
|
* Easily build frame parameters with the serialized constructors
|
||||||
*/
|
*/
|
||||||
class frame_parsed_parameters;
|
class frame_parsed_parameters;
|
||||||
class frame_builder {
|
class frame_builder
|
||||||
public:
|
{
|
||||||
frame_builder();
|
public:
|
||||||
frame_builder(const config& cfg,const std::string &frame_string = "");
|
frame_builder();
|
||||||
/** allow easy chained modifications will raised assert if used after initialization */
|
frame_builder(const config& cfg, const std::string& frame_string = "");
|
||||||
frame_builder & duration(const int duration);
|
|
||||||
frame_builder & image(const std::string& image ,const std::string & image_mod="");
|
/** Allow easy chained modifications. Will raised assert if used after initialization */
|
||||||
frame_builder & image_diagonal(const std::string& image_diagonal,const std::string & image_mod="");
|
frame_builder& duration(const int duration);
|
||||||
frame_builder & sound(const std::string& sound);
|
frame_builder& image(const std::string& image, const std::string& image_mod = "");
|
||||||
frame_builder & text(const std::string& text,const color_t text_color);
|
frame_builder& image_diagonal(const std::string& image_diagonal, const std::string& image_mod = "");
|
||||||
frame_builder & halo(const std::string &halo, const std::string &halo_x, const std::string& halo_y,const std::string& halo_mod);
|
frame_builder& sound(const std::string& sound);
|
||||||
frame_builder & blend(const std::string& blend_ratio,const color_t blend_color);
|
frame_builder& text(const std::string& text, const color_t text_color);
|
||||||
frame_builder & highlight(const std::string& highlight);
|
frame_builder& halo(const std::string& halo, const std::string& halo_x, const std::string& halo_y, const std::string& halo_mod);
|
||||||
frame_builder & offset(const std::string& offset);
|
frame_builder& blend(const std::string& blend_ratio, const color_t blend_color);
|
||||||
frame_builder & submerge(const std::string& submerge);
|
frame_builder& highlight(const std::string& highlight);
|
||||||
frame_builder & x(const std::string& x);
|
frame_builder& offset(const std::string& offset);
|
||||||
frame_builder & y(const std::string& y);
|
frame_builder& submerge(const std::string& submerge);
|
||||||
frame_builder & directional_x(const std::string& directional_x);
|
frame_builder& x(const std::string& x);
|
||||||
frame_builder & directional_y(const std::string& directional_y);
|
frame_builder& y(const std::string& y);
|
||||||
frame_builder & auto_vflip(const bool auto_vflip);
|
frame_builder& directional_x(const std::string& directional_x);
|
||||||
frame_builder & auto_hflip(const bool auto_hflip);
|
frame_builder& directional_y(const std::string& directional_y);
|
||||||
frame_builder & primary_frame(const bool primary_frame);
|
frame_builder& auto_vflip(const bool auto_vflip);
|
||||||
frame_builder & drawing_layer(const std::string& drawing_layer);
|
frame_builder& auto_hflip(const bool auto_hflip);
|
||||||
/** getters for the different parameters */
|
frame_builder& primary_frame(const bool primary_frame);
|
||||||
private:
|
frame_builder& drawing_layer(const std::string& drawing_layer);
|
||||||
friend class frame_parsed_parameters;
|
|
||||||
int duration_;
|
private:
|
||||||
std::string image_;
|
friend class frame_parsed_parameters;
|
||||||
std::string image_diagonal_;
|
|
||||||
std::string image_mod_;
|
int duration_;
|
||||||
std::string halo_;
|
|
||||||
std::string halo_x_;
|
std::string image_;
|
||||||
std::string halo_y_;
|
std::string image_diagonal_;
|
||||||
std::string halo_mod_;
|
std::string image_mod_;
|
||||||
std::string sound_;
|
std::string halo_;
|
||||||
std::string text_;
|
std::string halo_x_;
|
||||||
boost::optional<color_t> text_color_;
|
std::string halo_y_;
|
||||||
boost::optional<color_t> blend_with_;
|
std::string halo_mod_;
|
||||||
std::string blend_ratio_;
|
std::string sound_;
|
||||||
std::string highlight_ratio_;
|
std::string text_;
|
||||||
std::string offset_;
|
|
||||||
std::string submerge_;
|
boost::optional<color_t> text_color_;
|
||||||
std::string x_;
|
boost::optional<color_t> blend_with_;
|
||||||
std::string y_;
|
|
||||||
std::string directional_x_;
|
std::string blend_ratio_;
|
||||||
std::string directional_y_;
|
std::string highlight_ratio_;
|
||||||
tristate auto_vflip_;
|
std::string offset_;
|
||||||
tristate auto_hflip_;
|
std::string submerge_;
|
||||||
tristate primary_frame_;
|
std::string x_;
|
||||||
std::string drawing_layer_;
|
std::string y_;
|
||||||
|
std::string directional_x_;
|
||||||
|
std::string directional_y_;
|
||||||
|
|
||||||
|
boost::tribool auto_vflip_;
|
||||||
|
boost::tribool auto_hflip_;
|
||||||
|
boost::tribool primary_frame_;
|
||||||
|
|
||||||
|
std::string drawing_layer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* keep most parameters in a separate class to simplify handling of large
|
* Keep most parameters in a separate class to simplify the handling of the large
|
||||||
* number of parameters handling is common for frame level and animation level
|
* number of parameters between the frame level and animation level.
|
||||||
*/
|
*/
|
||||||
class frame_parsed_parameters {
|
class frame_parsed_parameters
|
||||||
public:
|
{
|
||||||
frame_parsed_parameters(const frame_builder& builder=frame_builder(),int override_duration = 0);
|
public:
|
||||||
/** allow easy chained modifications will raised assert if used after initialization */
|
frame_parsed_parameters(const frame_builder& builder = frame_builder(), int override_duration = 0);
|
||||||
void override( int duration
|
|
||||||
, const std::string& highlight = ""
|
|
||||||
, const std::string& blend_ratio =""
|
|
||||||
, color_t blend_color = {0,0,0}
|
|
||||||
, const std::string& offset = ""
|
|
||||||
, const std::string& layer = ""
|
|
||||||
, const std::string& modifiers = "");
|
|
||||||
/** getters for the different parameters */
|
|
||||||
const frame_parameters parameters(int current_time) const ;
|
|
||||||
|
|
||||||
int duration() const{ return duration_;}
|
void override(int duration,
|
||||||
bool does_not_change() const;
|
const std::string& highlight = "",
|
||||||
bool need_update() const;
|
const std::string& blend_ratio = "",
|
||||||
std::vector<std::string> debug_strings() const; //contents of frame in strings
|
color_t blend_color = {0,0,0},
|
||||||
private:
|
const std::string& offset = "",
|
||||||
int duration_;
|
const std::string& layer = "",
|
||||||
progressive_image image_;
|
const std::string& modifiers = "");
|
||||||
progressive_image image_diagonal_;
|
|
||||||
std::string image_mod_;
|
/** Getters for the different parameters */
|
||||||
progressive_string halo_;
|
const frame_parameters parameters(int current_time) const;
|
||||||
progressive_int halo_x_;
|
|
||||||
progressive_int halo_y_;
|
int duration() const{ return duration_;}
|
||||||
std::string halo_mod_;
|
bool does_not_change() const;
|
||||||
std::string sound_;
|
bool need_update() const;
|
||||||
std::string text_;
|
|
||||||
boost::optional<color_t> text_color_;
|
/** Contents of frame in strings */
|
||||||
boost::optional<color_t> blend_with_;
|
std::vector<std::string> debug_strings() const;
|
||||||
progressive_double blend_ratio_;
|
|
||||||
progressive_double highlight_ratio_;
|
private:
|
||||||
progressive_double offset_;
|
int duration_;
|
||||||
progressive_double submerge_;
|
|
||||||
progressive_int x_;
|
progressive_image image_;
|
||||||
progressive_int y_;
|
progressive_image image_diagonal_;
|
||||||
progressive_int directional_x_;
|
|
||||||
progressive_int directional_y_;
|
std::string image_mod_;
|
||||||
tristate auto_vflip_;
|
|
||||||
tristate auto_hflip_;
|
progressive_string halo_;
|
||||||
tristate primary_frame_;
|
progressive_int halo_x_;
|
||||||
progressive_int drawing_layer_;
|
progressive_int halo_y_;
|
||||||
|
|
||||||
|
std::string halo_mod_;
|
||||||
|
std::string sound_;
|
||||||
|
std::string text_;
|
||||||
|
|
||||||
|
boost::optional<color_t> text_color_;
|
||||||
|
boost::optional<color_t> blend_with_;
|
||||||
|
|
||||||
|
progressive_double blend_ratio_;
|
||||||
|
progressive_double highlight_ratio_;
|
||||||
|
progressive_double offset_;
|
||||||
|
progressive_double submerge_;
|
||||||
|
progressive_int x_;
|
||||||
|
progressive_int y_;
|
||||||
|
progressive_int directional_x_;
|
||||||
|
progressive_int directional_y_;
|
||||||
|
|
||||||
|
boost::tribool auto_vflip_;
|
||||||
|
boost::tribool auto_hflip_;
|
||||||
|
boost::tribool primary_frame_;
|
||||||
|
|
||||||
|
progressive_int drawing_layer_;
|
||||||
};
|
};
|
||||||
/** Describe a unit's animation sequence. */
|
|
||||||
class unit_frame {
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
unit_frame(const frame_builder& builder=frame_builder()):builder_(builder){}
|
|
||||||
void redraw(const int frame_time,bool on_start_time,bool in_scope_of_frame,const map_location & src,const map_location & dst,halo::handle & halo_id, halo::manager & halo_man, const frame_parameters & animation_val,const frame_parameters & engine_val)const;
|
|
||||||
const frame_parameters merge_parameters(int current_time,const frame_parameters & animation_val,const frame_parameters & engine_val=frame_parameters()) const;
|
|
||||||
const frame_parameters parameters(int current_time) const {return builder_.parameters(current_time);}
|
|
||||||
const frame_parameters end_parameters() const {return builder_.parameters(duration());}
|
|
||||||
|
|
||||||
int duration() const { return builder_.duration();}
|
/** Describes a unit's animation sequence. */
|
||||||
bool does_not_change() const{ return builder_.does_not_change();}
|
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;
|
public:
|
||||||
std::vector<std::string> debug_strings() const { return builder_.debug_strings();} //contents of frame in strings
|
// Constructors
|
||||||
private:
|
unit_frame(const frame_builder& builder = frame_builder()) : builder_(builder) {}
|
||||||
frame_parsed_parameters builder_;
|
|
||||||
|
|
||||||
|
void redraw(const int frame_time, bool on_start_time, bool in_scope_of_frame, const map_location& src, const map_location& dst,
|
||||||
|
halo::handle& halo_id, halo::manager& halo_man, const frame_parameters& animation_val, const frame_parameters& engine_val) const;
|
||||||
|
|
||||||
|
const frame_parameters merge_parameters(int current_time, const frame_parameters& animation_val,
|
||||||
|
const frame_parameters& engine_val = frame_parameters()) const;
|
||||||
|
|
||||||
|
const frame_parameters parameters(int current_time) const
|
||||||
|
{
|
||||||
|
return builder_.parameters(current_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
const frame_parameters end_parameters() const
|
||||||
|
{
|
||||||
|
return builder_.parameters(duration());
|
||||||
|
}
|
||||||
|
|
||||||
|
int duration() const
|
||||||
|
{
|
||||||
|
return builder_.duration();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool does_not_change() const
|
||||||
|
{
|
||||||
|
return builder_.does_not_change();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool need_update() const
|
||||||
|
{
|
||||||
|
return builder_.need_update();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> debug_strings() const
|
||||||
|
{
|
||||||
|
// Contents of frame in strings
|
||||||
|
return builder_.debug_strings();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
private:
|
||||||
|
frame_parsed_parameters builder_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue