have frame parameters returned as a big struct,
...so future changes are waaaay simpler
This commit is contained in:
parent
6384d3b1f3
commit
219b163fc9
6 changed files with 150 additions and 214 deletions
43
src/unit.cpp
43
src/unit.cpp
|
@ -155,7 +155,6 @@ unit::unit(const unit& o):
|
|||
anim_(NULL),
|
||||
|
||||
frame_begin_time_(o.frame_begin_time_),
|
||||
offset_(o.offset_),
|
||||
unit_halo_(o.unit_halo_),
|
||||
unit_anim_halo_(o.unit_anim_halo_),
|
||||
getsHit_(o.getsHit_),
|
||||
|
@ -202,7 +201,6 @@ unit::unit(const game_data* gamedata, unit_map* unitmap, const gamemap* map,
|
|||
end_turn_ = false;
|
||||
refreshing_ = false;
|
||||
hidden_ = false;
|
||||
offset_ = 0;
|
||||
game_config::add_color_info(cfg);
|
||||
}
|
||||
|
||||
|
@ -218,7 +216,6 @@ unit::unit(const game_data& gamedata,const config& cfg,bool use_traits) : moveme
|
|||
end_turn_ = false;
|
||||
refreshing_ = false;
|
||||
hidden_ = false;
|
||||
offset_ = 0;
|
||||
}
|
||||
|
||||
void unit::clear_status_caches()
|
||||
|
@ -287,7 +284,6 @@ unit::unit(const game_data* gamedata, unit_map* unitmap, const gamemap* map,
|
|||
getsHit_=0;
|
||||
end_turn_ = false;
|
||||
hold_position_ = false;
|
||||
offset_ = 0;
|
||||
next_idling_ = 0;
|
||||
frame_begin_time_ = 0;
|
||||
unit_halo_ = halo::NO_HALO;
|
||||
|
@ -331,7 +327,6 @@ unit::unit(const unit_type* t, int side, bool use_traits, bool dummy_unit, unit_
|
|||
getsHit_=0;
|
||||
end_turn_ = false;
|
||||
hold_position_ = false;
|
||||
offset_ = 0;
|
||||
}
|
||||
|
||||
unit::~unit()
|
||||
|
@ -1623,7 +1618,6 @@ void unit::start_animation(const int start_time, const gamemap::location &loc,co
|
|||
}
|
||||
state_ =state;
|
||||
draw_bars_ = with_bars;
|
||||
offset_=0;
|
||||
if(anim_) delete anim_;
|
||||
anim_ = new unit_animation(*animation);
|
||||
const int real_start_time = start_time == INT_MAX ? anim_->get_begin_time() : start_time;
|
||||
|
@ -1688,21 +1682,22 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
set_standing(loc);
|
||||
}
|
||||
anim_->update_last_draw_time();
|
||||
const frame_parameters params = anim_->get_current_params();
|
||||
|
||||
if(frame_begin_time_ != anim_->get_current_frame_begin_time()) {
|
||||
frame_begin_time_ = anim_->get_current_frame_begin_time();
|
||||
if(!anim_->sound().empty()) {
|
||||
sound::play_sound(anim_->sound());
|
||||
if(!params.sound.empty()) {
|
||||
sound::play_sound(params.sound);
|
||||
}
|
||||
if(!anim_->text().first.empty() ) {
|
||||
game_display::get_singleton()->float_label(loc,anim_->text().first,
|
||||
(anim_->text().second & 0x00FF0000) >> 16,
|
||||
(anim_->text().second & 0x0000FF00) >> 8,
|
||||
(anim_->text().second & 0x000000FF) >> 0);
|
||||
if(!params.text.empty() ) {
|
||||
game_display::get_singleton()->float_label(loc,params.text,
|
||||
(params.text_color & 0x00FF0000) >> 16,
|
||||
(params.text_color & 0x0000FF00) >> 8,
|
||||
(params.text_color & 0x000000FF) >> 0);
|
||||
}
|
||||
}
|
||||
|
||||
double tmp_offset = anim_->offset(offset_);
|
||||
const double tmp_offset = params.offset;
|
||||
int d2 = disp.hex_size() / 2;
|
||||
const int x = static_cast<int>(tmp_offset * xdst + (1.0-tmp_offset) * xsrc) + d2;
|
||||
const int y = static_cast<int>(tmp_offset * ydst + (1.0-tmp_offset) * ysrc) + d2 - height_adjust;
|
||||
|
@ -1719,19 +1714,19 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
halo::remove(unit_anim_halo_);
|
||||
unit_anim_halo_ = halo::NO_HALO;
|
||||
}
|
||||
if(!anim_->halo().empty()) {
|
||||
int dx = static_cast<int>(anim_->halo_x() * disp.get_zoom_factor());
|
||||
int dy = static_cast<int>(anim_->halo_y() * disp.get_zoom_factor());
|
||||
if(!params.halo.empty()) {
|
||||
int dx = static_cast<int>(params.halo_x * disp.get_zoom_factor());
|
||||
int dy = static_cast<int>(params.halo_y * disp.get_zoom_factor());
|
||||
if (facing_west) dx = -dx;
|
||||
unit_anim_halo_ = halo::add(x + dx, y + dy,
|
||||
anim_->halo(), gamemap::location(-1, -1),
|
||||
params.halo, gamemap::location(-1, -1),
|
||||
facing_west ? halo::HREVERSE : halo::NORMAL);
|
||||
}
|
||||
|
||||
|
||||
image::locator image_loc;
|
||||
#ifndef LOW_MEM
|
||||
image_loc = anim_->image();
|
||||
image_loc = params.image;
|
||||
if(image_loc.is_void()) {
|
||||
image_loc = absolute_image();
|
||||
}
|
||||
|
@ -1753,7 +1748,7 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
|
||||
bool stoned = utils::string_bool(get_state("stoned"));
|
||||
|
||||
fixed_t highlight_ratio = minimum<fixed_t>(alpha(),anim_->highlight_ratio());
|
||||
fixed_t highlight_ratio = minimum<fixed_t>(alpha(),ftofxp(params.highlight_ratio));
|
||||
if(invisible(loc,disp.get_units(),disp.get_teams()) &&
|
||||
highlight_ratio > ftofxp(0.5)) {
|
||||
highlight_ratio = ftofxp(0.5);
|
||||
|
@ -1762,8 +1757,8 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
highlight_ratio = ftofxp(1.5);
|
||||
}
|
||||
|
||||
Uint32 blend_with = anim_->blend_with();
|
||||
double blend_ratio = anim_->blend_ratio();
|
||||
Uint32 blend_with = params.blend_with;
|
||||
double blend_ratio = params.blend_ratio;
|
||||
//if(blend_ratio == 0) { blend_with = disp.rgb(0,0,0); }
|
||||
if (utils::string_bool(get_state("poisoned")) && blend_ratio == 0){
|
||||
blend_with = disp.rgb(0,255,0);
|
||||
|
@ -1941,8 +1936,8 @@ std::set<gamemap::location> unit::overlaps(const gamemap::location &loc) const
|
|||
}
|
||||
|
||||
// Very early calls, anim not initialized yet
|
||||
double tmp_offset=offset_;
|
||||
if(anim_)tmp_offset= anim_->offset(offset_);
|
||||
double tmp_offset=0;
|
||||
if(anim_)tmp_offset= anim_->get_current_params().offset;
|
||||
|
||||
// Invalidate adjacent neighbours if we don't stay in our hex
|
||||
if(tmp_offset != 0) {
|
||||
|
|
|
@ -184,7 +184,6 @@ public:
|
|||
void set_idling(const game_display& disp,const gamemap::location& loc);
|
||||
void set_selecting(const game_display& disp,const gamemap::location& loc);
|
||||
const unit_animation* get_animation() const { return anim_;};
|
||||
void set_offset(double offset){offset_ = offset;}
|
||||
void set_facing(gamemap::location::DIRECTION dir);
|
||||
gamemap::location::DIRECTION facing() const { return facing_; }
|
||||
|
||||
|
@ -365,7 +364,6 @@ private:
|
|||
int frame_begin_time_;
|
||||
|
||||
|
||||
double offset_;
|
||||
int unit_halo_;
|
||||
int unit_anim_halo_;
|
||||
bool getsHit_;
|
||||
|
|
|
@ -501,7 +501,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
|
|||
animations.push_back(unit_animation(**anim_itor));
|
||||
if(atoi((**anim_itor)["value"].c_str()) != 0) {
|
||||
animations.back().add_frame(100,frame_builder()
|
||||
.image(animations.back().get_last_frame().image())
|
||||
.image(animations.back().get_last_frame().parameters(0).image)
|
||||
.duration(100)
|
||||
.blend("0.5:50,0.0:50",game_display::rgb(255,0,0)));
|
||||
}
|
||||
|
@ -511,7 +511,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
|
|||
(**anim_itor)["value"]="";
|
||||
animations.push_back(unit_animation(**anim_itor));
|
||||
animations.back().add_frame(100,frame_builder()
|
||||
.image(animations.back().get_last_frame().image())
|
||||
.image(animations.back().get_last_frame().parameters(0).image)
|
||||
.duration(100)
|
||||
.blend("0.5:50,0.0:50",game_display::rgb(255,0,0)));
|
||||
}
|
||||
|
@ -539,7 +539,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
|
|||
for(anim_itor = deaths.begin(); anim_itor != deaths.end(); ++anim_itor) {
|
||||
(**anim_itor)["apply_to"] ="death";
|
||||
animations.push_back(unit_animation(**anim_itor));
|
||||
image::locator image_loc = animations.back().get_last_frame().image();
|
||||
image::locator image_loc = animations.back().get_last_frame().parameters(0).image;
|
||||
animations.back().add_frame(600,frame_builder().image(image_loc).duration(600).highlight("1~0:600"));
|
||||
if(!cfg["die_sound"].empty()) {
|
||||
animations.back().sub_anims_["_death_sound"] = particule();
|
||||
|
@ -577,68 +577,18 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
|
|||
void unit_animation::particule::override( int start_time,const std::string highlight,const std::string blend_ratio ,Uint32 blend_color ,const std::string offset)
|
||||
{
|
||||
set_begin_time(start_time);
|
||||
if(!highlight.empty()) highlight_ratio_ = progressive_double(highlight,get_animation_duration());
|
||||
if(!offset.empty()) offset_ = progressive_double(offset,get_animation_duration());
|
||||
if(!blend_ratio.empty()) {
|
||||
blend_ratio_ = progressive_double(blend_ratio,get_animation_duration());
|
||||
blend_with_ = blend_color;
|
||||
}
|
||||
if(!highlight.empty()) parameters_.highlight(highlight);
|
||||
if(!offset.empty()) parameters_.offset(offset);
|
||||
if(!blend_ratio.empty()) parameters_.blend(blend_ratio,blend_color);
|
||||
|
||||
|
||||
}
|
||||
const std::string &unit_animation::particule::halo(const std::string&default_val ) const
|
||||
{
|
||||
return get_current_frame().halo(get_current_frame_time(),halo_.get_current_element(get_animation_time() - get_begin_time(),default_val));
|
||||
}
|
||||
|
||||
int unit_animation::particule::halo_x(const int default_val) const
|
||||
{
|
||||
return get_current_frame().halo_x(get_current_frame_time(),halo_x_.get_current_element(get_animation_time() - get_begin_time(),default_val));
|
||||
}
|
||||
int unit_animation::particule::halo_y(const int default_val) const
|
||||
{
|
||||
return get_current_frame().halo_y(get_current_frame_time(),halo_y_.get_current_element(get_animation_time() - get_begin_time(),default_val));
|
||||
}
|
||||
double unit_animation::particule::blend_ratio(const double default_val) const
|
||||
{
|
||||
|
||||
return get_current_frame().blend_ratio(
|
||||
get_current_frame_time(),
|
||||
blend_ratio_.get_current_element(get_animation_time() - get_begin_time(),default_val));
|
||||
}
|
||||
|
||||
Uint32 unit_animation::particule::blend_with(const Uint32 default_val) const
|
||||
{
|
||||
return get_current_frame().blend_with(blend_with_?blend_with_:default_val);
|
||||
}
|
||||
|
||||
fixed_t unit_animation::particule::highlight_ratio(const float default_val) const
|
||||
{
|
||||
return get_current_frame().highlight_ratio(get_current_frame_time(),highlight_ratio_.get_current_element(get_animation_time() - get_begin_time(),default_val));
|
||||
}
|
||||
|
||||
double unit_animation::particule::offset(double default_val) const
|
||||
{
|
||||
return get_current_frame().offset(get_current_frame_time(),offset_.get_current_element(get_animation_time() - get_begin_time(),default_val)) ;
|
||||
}
|
||||
|
||||
std::pair<std::string,Uint32> unit_animation::particule::text() const
|
||||
{
|
||||
return get_current_frame().text();
|
||||
}
|
||||
|
||||
bool unit_animation::particule::need_update() const
|
||||
{
|
||||
if(animated<unit_frame>::need_update()) return true;
|
||||
if(get_current_frame().need_update()) return true;
|
||||
if(!halo_.does_not_change() ||
|
||||
!halo_x_.does_not_change() ||
|
||||
!halo_y_.does_not_change() ||
|
||||
!blend_ratio_.does_not_change() ||
|
||||
!highlight_ratio_.does_not_change() ||
|
||||
!offset_.does_not_change() ) {
|
||||
return true;
|
||||
}
|
||||
if(parameters_.need_update()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -646,13 +596,7 @@ unit_animation::particule::particule(
|
|||
const config& cfg, const std::string frame_string ) :
|
||||
animated<unit_frame>(),
|
||||
accelerate(true),
|
||||
offset_(),
|
||||
halo_(),
|
||||
halo_x_(),
|
||||
halo_y_(),
|
||||
blend_with_(0),
|
||||
blend_ratio_(),
|
||||
highlight_ratio_(),
|
||||
parameters_(cfg,frame_string),
|
||||
src_(),
|
||||
dst_(),
|
||||
halo_id_(0),
|
||||
|
@ -673,20 +617,8 @@ unit_animation::particule::particule(
|
|||
unit_frame tmp_frame(**range.first);
|
||||
add_frame(tmp_frame.duration(),tmp_frame,!tmp_frame.does_not_change());
|
||||
}
|
||||
halo_ = progressive_string(cfg[frame_string+"halo"],get_animation_duration());
|
||||
halo_x_ = progressive_int(cfg[frame_string+"halo_x"],get_animation_duration());
|
||||
halo_y_ = progressive_int(cfg[frame_string+"halo_y"],get_animation_duration());
|
||||
std::vector<std::string> tmp_blend=utils::split(cfg[frame_string+"blend_color"]);
|
||||
if(tmp_blend.size() ==3) {blend_with_= display::rgb(atoi(tmp_blend[0].c_str()),atoi(tmp_blend[1].c_str()),atoi(tmp_blend[2].c_str()));};
|
||||
blend_ratio_ = progressive_double(cfg[frame_string+"blend_ratio"],get_animation_duration());
|
||||
highlight_ratio_ = progressive_double(cfg[frame_string+"alpha"],get_animation_duration());
|
||||
offset_ = progressive_double(cfg[frame_string+"offset"],get_animation_duration());
|
||||
if(!halo_.does_not_change() ||
|
||||
!halo_x_.does_not_change() ||
|
||||
!halo_y_.does_not_change() ||
|
||||
!blend_ratio_.does_not_change() ||
|
||||
!highlight_ratio_.does_not_change() ||
|
||||
!offset_.does_not_change() ) {
|
||||
parameters_.duration(get_animation_duration());
|
||||
if(!parameters_.does_not_change() ) {
|
||||
force_change();
|
||||
}
|
||||
}
|
||||
|
@ -778,11 +710,12 @@ void unit_animation::redraw()
|
|||
void unit_animation::particule::redraw()
|
||||
{
|
||||
const unit_frame& current_frame= get_current_frame();
|
||||
const frame_parameters default_val = parameters_.parameters(get_animation_time() -get_begin_time());
|
||||
if(get_current_frame_begin_time() != last_frame_begin_time_ ) {
|
||||
last_frame_begin_time_ = get_current_frame_begin_time();
|
||||
current_frame.redraw(get_current_frame_time(),true,src_,dst_,&halo_id_);
|
||||
current_frame.redraw(get_current_frame_time(),true,src_,dst_,&halo_id_,default_val);
|
||||
} else {
|
||||
current_frame.redraw(get_current_frame_time(),false,src_,dst_,&halo_id_);
|
||||
current_frame.redraw(get_current_frame_time(),false,src_,dst_,&halo_id_,default_val);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,18 +58,7 @@ class unit_animation
|
|||
friend class unit;
|
||||
protected:
|
||||
// reserved to class unit, for the special case of redrawing the unit base frame
|
||||
image::locator image() const { return unit_anim_.get_current_frame().image() ; }
|
||||
image::locator image_diagonal() const { return unit_anim_.get_current_frame().image_diagonal() ; }
|
||||
std::string sound() const { return unit_anim_.get_current_frame().sound() ; };
|
||||
Uint32 blend_with(const Uint32 default_val=0) const{ return unit_anim_.blend_with(default_val) ; };
|
||||
const std::string &halo(const std::string&default_val ="") const{ return unit_anim_.halo(default_val); };
|
||||
int halo_x(const int default_val = 0) const{ return unit_anim_.halo_x(default_val); };
|
||||
int halo_y(const int default_val = 0) const{ return unit_anim_.halo_y(default_val); };
|
||||
double blend_ratio(const double default_val = 0.0) const{ return unit_anim_.blend_ratio(default_val); };
|
||||
fixed_t highlight_ratio(const float default_val = 1.0) const{ return unit_anim_.highlight_ratio(default_val); };
|
||||
public:
|
||||
double offset(double default_val =0.0) const{ return unit_anim_.offset(default_val); };
|
||||
std::pair<std::string,Uint32> text() const { return unit_anim_.text() ; };
|
||||
const frame_parameters get_current_params(const frame_parameters & default_val = frame_parameters()) const { return unit_anim_.parameters(default_val); };
|
||||
private:
|
||||
static config prepare_animation(const config &cfg,const std::string animation_tag);
|
||||
explicit unit_animation(const config& cfg,const std::string frame_string ="");
|
||||
|
@ -80,13 +69,7 @@ class unit_animation
|
|||
explicit particule(int start_time=0) :
|
||||
animated<unit_frame>(start_time),
|
||||
accelerate(true),
|
||||
offset_(),
|
||||
halo_(),
|
||||
halo_x_(),
|
||||
halo_y_(),
|
||||
blend_with_(0),
|
||||
blend_ratio_(),
|
||||
highlight_ratio_(),
|
||||
parameters_(),
|
||||
src_(),
|
||||
dst_(),
|
||||
halo_id_(0),
|
||||
|
@ -96,27 +79,14 @@ class unit_animation
|
|||
virtual ~particule();
|
||||
bool need_update() const;
|
||||
void override(int start_time,const std::string highlight="", const std::string blend_ratio ="",Uint32 blend_color = 0,const std::string offset="");
|
||||
const std::string &halo(const std::string&default_val ="") const;
|
||||
int halo_x(const int default_val = 0) const;
|
||||
int halo_y(const int default_val = 0) const;
|
||||
double blend_ratio(const double default_val = 0.0) const;
|
||||
Uint32 blend_with(const Uint32 default_val = 0) const;
|
||||
fixed_t highlight_ratio(const float default_val = 1.0) const;
|
||||
double offset(double default_val =0.0) const;
|
||||
std::pair<std::string,Uint32> text() const ;
|
||||
void redraw( );
|
||||
void start_animation(int start_time,const gamemap::location& src,const gamemap::location& dst, bool cycles=false);
|
||||
const frame_parameters parameters(const frame_parameters & default_val) const { return get_current_frame().parameters(get_current_frame_time(),parameters_.parameters(get_animation_time()-get_begin_time(),default_val)); };
|
||||
bool accelerate;
|
||||
private:
|
||||
|
||||
//animation params that can be locally overridden by frames
|
||||
progressive_double offset_;
|
||||
progressive_string halo_;
|
||||
progressive_int halo_x_;
|
||||
progressive_int halo_y_;
|
||||
Uint32 blend_with_;
|
||||
progressive_double blend_ratio_;
|
||||
progressive_double highlight_ratio_;
|
||||
frame_builder parameters_;
|
||||
gamemap::location src_;
|
||||
gamemap::location dst_;
|
||||
int halo_id_;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
progressive_string::progressive_string(const std::string & data,int duration)
|
||||
{
|
||||
const std::vector<std::string> first_pass = utils::split(data);
|
||||
input_ = data;
|
||||
const int time_chunk = maximum<int>(duration / (first_pass.size()?first_pass.size():1),1);
|
||||
|
||||
std::vector<std::string>::const_iterator tmp;
|
||||
|
@ -70,6 +71,7 @@ const std::string& progressive_string::get_current_element(int current_time,cons
|
|||
template <class T>
|
||||
progressive_<T>::progressive_(const std::string &data, int duration)
|
||||
{
|
||||
input_ = data;
|
||||
const std::vector<std::string> first_split = utils::split(data);
|
||||
const int time_chunk = maximum<int>(duration / (first_split.size()?first_split.size():1),1);
|
||||
|
||||
|
@ -154,66 +156,77 @@ template class progressive_<double>;
|
|||
|
||||
|
||||
|
||||
frame_builder::frame_builder(const config& cfg)
|
||||
frame_builder::frame_builder(const config& cfg,const std::string& frame_string)
|
||||
{
|
||||
initialization_finished=false;
|
||||
image(image::locator(cfg["image"]));
|
||||
image_diagonal(image::locator(cfg["image_diagonal"]));
|
||||
sound(cfg["sound"]);
|
||||
std::vector<std::string> tmp_string_vect=utils::split(cfg["text_color"]);
|
||||
image(image::locator(cfg[frame_string+"image"]));
|
||||
image_diagonal(image::locator(cfg[frame_string+"image_diagonal"]));
|
||||
sound(cfg[frame_string+"sound"]);
|
||||
std::vector<std::string> tmp_string_vect=utils::split(cfg[frame_string+"text_color"]);
|
||||
if(tmp_string_vect.size() ==3) {
|
||||
text(cfg["text"],
|
||||
text(cfg[frame_string+"text"],
|
||||
display::rgb(atoi(tmp_string_vect[0].c_str()),atoi(tmp_string_vect[1].c_str()),atoi(tmp_string_vect[2].c_str())));
|
||||
} else {
|
||||
text(cfg["text"],0);
|
||||
text(cfg[frame_string+"text"],0);
|
||||
}
|
||||
|
||||
if(!cfg["duration"].empty()) {
|
||||
duration(atoi(cfg["duration"].c_str()));
|
||||
if(!cfg[frame_string+"duration"].empty()) {
|
||||
duration(atoi(cfg[frame_string+"duration"].c_str()));
|
||||
} else {
|
||||
duration(atoi(cfg["end"].c_str()) - atoi(cfg["begin"].c_str()));
|
||||
duration(atoi(cfg[frame_string+"end"].c_str()) - atoi(cfg[frame_string+"begin"].c_str()));
|
||||
}
|
||||
halo(cfg["halo"],cfg["halo_x"],cfg["halo_y"]);
|
||||
tmp_string_vect=utils::split(cfg["blend_color"]);
|
||||
halo(cfg[frame_string+"halo"],cfg[frame_string+"halo_x"],cfg[frame_string+"halo_y"]);
|
||||
tmp_string_vect=utils::split(cfg[frame_string+"blend_color"]);
|
||||
if(tmp_string_vect.size() ==3) {
|
||||
blend(cfg["blend_ratio"],display::rgb(atoi(tmp_string_vect[0].c_str()),atoi(tmp_string_vect[1].c_str()),atoi(tmp_string_vect[2].c_str())));
|
||||
blend(cfg[frame_string+"blend_ratio"],display::rgb(atoi(tmp_string_vect[0].c_str()),atoi(tmp_string_vect[1].c_str()),atoi(tmp_string_vect[2].c_str())));
|
||||
} else {
|
||||
blend(cfg["blend_ratio"],0);
|
||||
blend(cfg[frame_string+"blend_ratio"],0);
|
||||
}
|
||||
highlight(cfg["alpha"]);
|
||||
offset(cfg["offset"]);
|
||||
initialization_finished=true;
|
||||
highlight(cfg[frame_string+"alpha"]);
|
||||
offset(cfg[frame_string+"offset"]);
|
||||
|
||||
}
|
||||
|
||||
const frame_parameters frame_builder::parameters(int current_time, const frame_parameters & default_val) const
|
||||
{
|
||||
frame_parameters result;
|
||||
result.duration = duration_ == 0?default_val.duration:duration_;
|
||||
result.image = image_.is_void()?default_val.image:image_;
|
||||
result.image_diagonal = image_diagonal_.is_void()?default_val.image_diagonal:image_diagonal_;
|
||||
result.halo = halo_.get_current_element(current_time,default_val.halo);
|
||||
result.sound = sound_.empty()?default_val.sound:sound_;
|
||||
result.text = text_.empty()?default_val.text:text_;
|
||||
result.text_color = text_color_ == 0?default_val.text_color:text_color_;
|
||||
result.halo_x = halo_x_.get_current_element(current_time,default_val.halo_x);
|
||||
result.halo_y = halo_y_.get_current_element(current_time,default_val.halo_y);
|
||||
result.blend_with = blend_with_ == 0?default_val.blend_with:blend_with_;
|
||||
result.blend_ratio = blend_ratio_.get_current_element(current_time,default_val.blend_ratio);
|
||||
result.highlight_ratio = highlight_ratio_.get_current_element(current_time,default_val.highlight_ratio);
|
||||
result.offset = offset_.get_current_element(current_time,default_val.offset);
|
||||
return result;
|
||||
}
|
||||
frame_builder & frame_builder::image(const image::locator image )
|
||||
{
|
||||
assert(!initialization_finished);
|
||||
image_ = image;
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::image_diagonal(const image::locator image_diagonal)
|
||||
{
|
||||
assert(!initialization_finished);
|
||||
image_diagonal_ = image_diagonal;
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::sound(const std::string& sound)
|
||||
{
|
||||
assert(!initialization_finished);
|
||||
sound_=sound;
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::text(const std::string& text,const Uint32 text_color)
|
||||
{
|
||||
assert(!initialization_finished);
|
||||
text_=text;
|
||||
text_color_=text_color;
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::halo(const std::string &halo, const std::string &halo_x, const std::string& halo_y)
|
||||
{
|
||||
assert(!initialization_finished);
|
||||
halo_ = progressive_string(halo,duration_);
|
||||
halo_x_ = progressive_int(halo_x,duration_);
|
||||
halo_y_ = progressive_int(halo_y,duration_);
|
||||
|
@ -221,27 +234,29 @@ frame_builder & frame_builder::halo(const std::string &halo, const std::string &
|
|||
}
|
||||
frame_builder & frame_builder::duration(const int duration)
|
||||
{
|
||||
assert(!initialization_finished);
|
||||
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_);
|
||||
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_);
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::blend(const std::string& blend_ratio,const Uint32 blend_color)
|
||||
{
|
||||
assert(!initialization_finished);
|
||||
blend_with_=blend_color;
|
||||
blend_ratio_=progressive_double(blend_ratio,duration_);
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::highlight(const std::string& highlight)
|
||||
{
|
||||
assert(!initialization_finished);
|
||||
highlight_ratio_=progressive_double(highlight,duration_);
|
||||
return *this;
|
||||
}
|
||||
frame_builder & frame_builder::offset(const std::string& offset)
|
||||
{
|
||||
assert(!initialization_finished);
|
||||
offset_=progressive_double(offset);
|
||||
offset_=progressive_double(offset,duration_);
|
||||
return *this;
|
||||
}
|
||||
bool frame_builder::does_not_change() const
|
||||
|
@ -266,7 +281,7 @@ bool frame_builder::need_update() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void unit_frame::redraw(const int frame_time,bool first_time,const gamemap::location & src,const gamemap::location & dst,int*halo_id)const
|
||||
void unit_frame::redraw(const int frame_time,bool first_time,const gamemap::location & src,const gamemap::location & dst,int*halo_id,const frame_parameters & default_val)const
|
||||
{
|
||||
const int xsrc = game_display::get_singleton()->get_location_x(src);
|
||||
const int ysrc = game_display::get_singleton()->get_location_y(src);
|
||||
|
@ -274,27 +289,28 @@ void unit_frame::redraw(const int frame_time,bool first_time,const gamemap::loca
|
|||
const int ydst = game_display::get_singleton()->get_location_y(dst);
|
||||
const gamemap::location::DIRECTION direction = src.get_relative_dir(dst);
|
||||
|
||||
double tmp_offset = offset(frame_time);
|
||||
const frame_parameters current_data = builder_.parameters(frame_time,default_val);
|
||||
double tmp_offset = current_data.offset;
|
||||
int d2 = game_display::get_singleton()->hex_size() / 2;
|
||||
|
||||
if(first_time ) {
|
||||
// stuff sthat should be done only once per frame
|
||||
if(!sound().empty() ) {
|
||||
sound::play_sound(sound());
|
||||
if(!current_data.sound.empty() ) {
|
||||
sound::play_sound(current_data.sound);
|
||||
}
|
||||
if(!text().first.empty() ) {
|
||||
game_display::get_singleton()->float_label(src,text().first,
|
||||
(text().second & 0x00FF0000) >> 16,
|
||||
(text().second & 0x0000FF00) >> 8,
|
||||
(text().second & 0x000000FF) >> 0);
|
||||
if(!current_data.text.empty() ) {
|
||||
game_display::get_singleton()->float_label(src,current_data.text,
|
||||
(current_data.text_color & 0x00FF0000) >> 16,
|
||||
(current_data.text_color & 0x0000FF00) >> 8,
|
||||
(current_data.text_color & 0x000000FF) >> 0);
|
||||
}
|
||||
}
|
||||
image::locator image_loc;
|
||||
if(direction != gamemap::location::NORTH && direction != gamemap::location::SOUTH) {
|
||||
image_loc = image_diagonal();
|
||||
image_loc = current_data.image_diagonal;
|
||||
}
|
||||
if(image_loc.is_void()) { // invalid diag image, or not diagonal
|
||||
image_loc = image();
|
||||
image_loc = current_data.image;
|
||||
}
|
||||
|
||||
surface image;
|
||||
|
@ -310,11 +326,11 @@ void unit_frame::redraw(const int frame_time,bool first_time,const gamemap::loca
|
|||
bool facing_west = direction == gamemap::location::NORTH_WEST || direction == gamemap::location::SOUTH_WEST;
|
||||
bool facing_north = direction == gamemap::location::NORTH_WEST || direction == gamemap::location::NORTH || direction == gamemap::location::NORTH_EAST;
|
||||
game_display::get_singleton()->render_unit_image(x- image->w/2, y - image->h/2, false, gamemap::get_drawing_order(src), image, facing_west, false,
|
||||
highlight_ratio(frame_time), blend_with(0), blend_ratio(frame_time),0,!facing_north);
|
||||
ftofxp(current_data.highlight_ratio), current_data.blend_with, current_data.blend_ratio,0,!facing_north);
|
||||
}
|
||||
halo::remove(*halo_id);
|
||||
*halo_id = halo::NO_HALO;
|
||||
if(!halo(frame_time).empty()) {
|
||||
if(!current_data.halo.empty()) {
|
||||
halo::ORIENTATION orientation;
|
||||
switch(direction)
|
||||
{
|
||||
|
@ -338,15 +354,15 @@ void unit_frame::redraw(const int frame_time,bool first_time,const gamemap::loca
|
|||
break;
|
||||
}
|
||||
if(direction != gamemap::location::SOUTH_WEST && direction != gamemap::location::NORTH_WEST) {
|
||||
*halo_id = halo::add(x+halo_x(frame_time),
|
||||
y+halo_y(frame_time),
|
||||
halo(frame_time),
|
||||
*halo_id = halo::add(x+current_data.halo_x,
|
||||
y+current_data.halo_y,
|
||||
current_data.halo,
|
||||
gamemap::location(-1, -1),
|
||||
orientation);
|
||||
} else {
|
||||
*halo_id = halo::add(x-halo_x(frame_time),
|
||||
y+halo_y(frame_time),
|
||||
halo(frame_time),
|
||||
*halo_id = halo::add(x-current_data.halo_x,
|
||||
y+current_data.halo_y,
|
||||
current_data.halo,
|
||||
gamemap::location(-1, -1),
|
||||
orientation);
|
||||
}
|
||||
|
|
|
@ -36,19 +36,23 @@ class progressive_string {
|
|||
int duration() const;
|
||||
const std::string & get_current_element(int time,const std::string& default_val="") const;
|
||||
bool does_not_change() const { return data_.size() <= 1; }
|
||||
std::string get_original(){return input_;}
|
||||
private:
|
||||
std::vector<std::pair<std::string,int> > data_;
|
||||
std::string input_;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class progressive_
|
||||
{
|
||||
std::vector<std::pair<std::pair<T, T>, int> > data_;
|
||||
std::string input_;
|
||||
public:
|
||||
progressive_(const std::string& data = "", int duration = 0);
|
||||
int duration() const;
|
||||
const T get_current_element(int time, const T default_val = 0) const;
|
||||
bool does_not_change() const;
|
||||
std::string get_original(){return input_;}
|
||||
};
|
||||
|
||||
typedef progressive_<int> progressive_int;
|
||||
|
@ -58,7 +62,39 @@ typedef progressive_<double> progressive_double;
|
|||
// This hack prevents MSVC++ 6 to issue several warnings
|
||||
#ifndef UNIT_FRAME_H_PART2
|
||||
#define UNIT_FRAME_H_PART2
|
||||
//! All parameters from a frame at a given instant
|
||||
class frame_parameters{
|
||||
public:
|
||||
frame_parameters():
|
||||
image(""),
|
||||
image_diagonal(""),
|
||||
halo(""),
|
||||
sound(""),
|
||||
text(""),
|
||||
text_color(0),
|
||||
halo_x(0),
|
||||
halo_y(0),
|
||||
duration(0),
|
||||
blend_with(0),
|
||||
blend_ratio(0.0),
|
||||
highlight_ratio(1.0),
|
||||
offset(0)
|
||||
{};
|
||||
|
||||
image::locator image;
|
||||
image::locator image_diagonal;
|
||||
std::string halo;
|
||||
std::string sound;
|
||||
std::string text;
|
||||
Uint32 text_color;
|
||||
int halo_x;
|
||||
int halo_y;
|
||||
int duration;
|
||||
Uint32 blend_with;
|
||||
double blend_ratio;
|
||||
double highlight_ratio;
|
||||
double offset;
|
||||
} ;
|
||||
//! keep most parameters in a separate class to simplify handling of large number of parameters
|
||||
class frame_builder {
|
||||
public:
|
||||
|
@ -76,9 +112,9 @@ class frame_builder {
|
|||
blend_with_(0),
|
||||
blend_ratio_(""),
|
||||
highlight_ratio_(""),
|
||||
offset_(""),
|
||||
initialization_finished(false) {};
|
||||
frame_builder(const config& cfg);
|
||||
offset_("")
|
||||
{};
|
||||
frame_builder(const config& cfg,const std::string &frame_string = "");
|
||||
//! allow easy chained modifications will raised assert if used after initialization
|
||||
frame_builder & image(const image::locator image );
|
||||
frame_builder & image_diagonal(const image::locator image_diagonal);
|
||||
|
@ -90,26 +126,9 @@ class frame_builder {
|
|||
frame_builder & highlight(const std::string& highlight);
|
||||
frame_builder & offset(const std::string& offset);
|
||||
//! getters for the different parameters
|
||||
const image::locator image() const { return image_ ;}
|
||||
const image::locator image_diagonal() const { return image_diagonal_ ; }
|
||||
const std::string &halo(int current_time,const std::string& default_val="") const
|
||||
{ return halo_.get_current_element(current_time,default_val); }
|
||||
|
||||
const std::string sound() const { return sound_ ; };
|
||||
const std::pair<std::string,Uint32> text() const { return std::pair<std::string,Uint32>(text_,text_color_) ; };
|
||||
const int halo_x(int current_time,const int default_val=0) const { return halo_x_.get_current_element(current_time,default_val); }
|
||||
const int halo_y(int current_time,const int default_val=0) const { return halo_y_.get_current_element(current_time,default_val); }
|
||||
const int duration() const { return duration_; }
|
||||
const Uint32 blend_with(const Uint32 default_val) const { return blend_with_?blend_with_:default_val; }
|
||||
const double blend_ratio(int current_time,const double default_val=0.0) const
|
||||
{ return blend_ratio_.get_current_element(current_time,default_val); }
|
||||
|
||||
const fixed_t highlight_ratio(int current_time,double default_val =0.0) const
|
||||
{ return ftofxp(highlight_ratio_.get_current_element(current_time,default_val)); }
|
||||
|
||||
double offset(int current_time,double default_val =0.0) const
|
||||
{ return offset_.get_current_element(current_time,default_val) ; }
|
||||
const frame_parameters parameters(int current_time, const frame_parameters & default_val = frame_parameters()) const;
|
||||
|
||||
int duration() const{ return duration_;};
|
||||
bool does_not_change() const;
|
||||
bool need_update() const;
|
||||
private:
|
||||
|
@ -126,16 +145,21 @@ class frame_builder {
|
|||
progressive_double blend_ratio_;
|
||||
progressive_double highlight_ratio_;
|
||||
progressive_double offset_;
|
||||
protected:
|
||||
bool initialization_finished;
|
||||
|
||||
};
|
||||
//! Describe a unit's animation sequence.
|
||||
class unit_frame: public frame_builder{
|
||||
class unit_frame {
|
||||
public:
|
||||
// Constructors
|
||||
unit_frame(const frame_builder builder=frame_builder()):frame_builder(builder){initialization_finished=true;};
|
||||
void redraw(const int frame_time,bool first_time,const gamemap::location & src,const gamemap::location & dst,int*halo_id)const;
|
||||
unit_frame(const frame_builder builder=frame_builder()):builder_(builder){};
|
||||
void redraw(const int frame_time,bool first_time,const gamemap::location & src,const gamemap::location & dst,int*halo_id,const frame_parameters & default_val)const;
|
||||
const frame_parameters parameters(int current_time, const frame_parameters & default_val = frame_parameters()) const{return builder_.parameters(current_time,default_val); } ;
|
||||
|
||||
int duration() const { return builder_.duration();};
|
||||
bool does_not_change() const{ return builder_.does_not_change();};
|
||||
bool need_update() const{ return builder_.need_update();};
|
||||
private:
|
||||
frame_builder builder_;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue