reimplement parameter passing between the different layers of animation.
as a side efffect fix bug #10820 (poisoned unit don't display select anim) and fix bug #10890 (projectiles don't follow unit_height_adjust)
This commit is contained in:
parent
7de759aff4
commit
fe4445d4dc
6 changed files with 206 additions and 111 deletions
|
@ -166,6 +166,8 @@ Version 1.5.0-svn:
|
|||
* new progressive parameter for animations : x and y
|
||||
* image_diagonal now also works with normal [frame]
|
||||
* fix sub-optimal multi-turns pathfinding which avoided ZoC too much
|
||||
* sub-frames now obey terrain height
|
||||
* selecting a poisoned unit now does the selection anim properly
|
||||
|
||||
Version 1.4:
|
||||
* language and i18n:
|
||||
|
|
157
src/unit.cpp
157
src/unit.cpp
|
@ -1621,6 +1621,39 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
}
|
||||
refreshing_ = true;
|
||||
|
||||
|
||||
if(!anim_) {
|
||||
set_standing(loc);
|
||||
}
|
||||
anim_->update_last_draw_time();
|
||||
frame_parameters params;
|
||||
const t_translation::t_terrain terrain = map.get_terrain(loc);
|
||||
const terrain_type& terrain_info = map.get_terrain_info(terrain);
|
||||
// do not set to 0 so we can distinguih the flying from the "not on submerge terrain"
|
||||
params.submerge= is_flying() ? 0.01 : terrain_info.unit_submerge();
|
||||
|
||||
if(invisible(loc,disp.get_units(),disp.get_teams()) &&
|
||||
params.highlight_ratio > 0.5) {
|
||||
params.highlight_ratio = 0.5;
|
||||
}
|
||||
if(loc == disp.selected_hex() && params.highlight_ratio == 1.0) {
|
||||
params.highlight_ratio = 1.5;
|
||||
}
|
||||
int height_adjust = static_cast<int>(terrain_info.unit_height_adjust() * disp.get_zoom_factor());
|
||||
if (is_flying() && height_adjust < 0) {
|
||||
height_adjust = 0;
|
||||
}
|
||||
params.y -= height_adjust;
|
||||
params.halo_y -= height_adjust;
|
||||
if (utils::string_bool(get_state("poisoned")) ){
|
||||
params.blend_with = disp.rgb(0,255,0);
|
||||
params.blend_ratio = 0.25;
|
||||
}
|
||||
|
||||
const frame_parameters adjusted_params = anim_->get_current_params(params,true);
|
||||
|
||||
|
||||
|
||||
#ifndef LOW_MEM
|
||||
bool facing_west = facing_ == gamemap::location::NORTH_WEST || facing_ == gamemap::location::SOUTH_WEST;
|
||||
#else
|
||||
|
@ -1633,39 +1666,23 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
const int ydst = disp.get_location_y(dst);
|
||||
const int drawing_order = gamemap::get_drawing_order(loc);
|
||||
|
||||
const t_translation::t_terrain terrain = map.get_terrain(loc);
|
||||
const terrain_type& terrain_info = map.get_terrain_info(terrain);
|
||||
int height_adjust = static_cast<int>(terrain_info.unit_height_adjust() * disp.get_zoom_factor());
|
||||
if (is_flying() && height_adjust < 0) {
|
||||
height_adjust = 0;
|
||||
}
|
||||
const int ysrc_adjusted = ysrc - height_adjust;
|
||||
|
||||
if(!anim_) {
|
||||
set_standing(loc);
|
||||
}
|
||||
anim_->update_last_draw_time();
|
||||
const frame_parameters params = anim_->get_current_params();
|
||||
double submerge = params.submerge;
|
||||
if(!submerge) submerge= is_flying() ? 0.0 : terrain_info.unit_submerge();
|
||||
|
||||
if(frame_begin_time_ != anim_->get_current_frame_begin_time()) {
|
||||
frame_begin_time_ = anim_->get_current_frame_begin_time();
|
||||
if(!params.sound.empty()) {
|
||||
sound::play_sound(params.sound);
|
||||
if(!adjusted_params.sound.empty()) {
|
||||
sound::play_sound(adjusted_params.sound);
|
||||
}
|
||||
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);
|
||||
if(!adjusted_params.text.empty() ) {
|
||||
game_display::get_singleton()->float_label(loc,adjusted_params.text,
|
||||
(adjusted_params.text_color & 0x00FF0000) >> 16,
|
||||
(adjusted_params.text_color & 0x0000FF00) >> 8,
|
||||
(adjusted_params.text_color & 0x000000FF) >> 0);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
const int x = static_cast<int>(adjusted_params.offset * xdst + (1.0-adjusted_params.offset) * xsrc) + d2;
|
||||
const int y = static_cast<int>(adjusted_params.offset * ydst + (1.0-adjusted_params.offset) * ysrc) + d2;
|
||||
|
||||
|
||||
if(unit_halo_ == halo::NO_HALO && !image_halo().empty()) {
|
||||
|
@ -1679,12 +1696,12 @@ 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(!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(!adjusted_params.halo.empty()) {
|
||||
int dx = static_cast<int>(adjusted_params.halo_x * disp.get_zoom_factor());
|
||||
int dy = static_cast<int>(adjusted_params.halo_y * disp.get_zoom_factor());
|
||||
if (facing_west) dx = -dx;
|
||||
unit_anim_halo_ = halo::add(x + dx, y+ dy,
|
||||
params.halo, gamemap::location(-1, -1),
|
||||
adjusted_params.halo, gamemap::location(-1, -1),
|
||||
facing_west ? halo::HREVERSE : halo::NORMAL);
|
||||
}
|
||||
|
||||
|
@ -1692,12 +1709,12 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
image::locator image_loc = image::locator();
|
||||
#ifndef LOW_MEM
|
||||
if(facing_ != gamemap::location::NORTH && facing_ != gamemap::location::SOUTH) {
|
||||
image_loc = params.image_diagonal;
|
||||
image_loc = adjusted_params.image_diagonal;
|
||||
}
|
||||
if(image_loc.is_void()|| image_loc.get_filename() == "") { // invalid diag image, or not diagonal
|
||||
image_loc = params.image;
|
||||
image_loc = adjusted_params.image;
|
||||
}
|
||||
if(image_loc.is_void()) {
|
||||
if(image_loc.is_void()|| image_loc.get_filename() == "") {
|
||||
image_loc = absolute_image();
|
||||
}
|
||||
std::string mod=image_mods();
|
||||
|
@ -1718,28 +1735,13 @@ 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(),ftofxp(params.highlight_ratio));
|
||||
if(invisible(loc,disp.get_units(),disp.get_teams()) &&
|
||||
highlight_ratio > ftofxp(0.5)) {
|
||||
highlight_ratio = ftofxp(0.5);
|
||||
}
|
||||
if(loc == disp.selected_hex() && highlight_ratio == ftofxp(1.0)) {
|
||||
highlight_ratio = ftofxp(1.5);
|
||||
}
|
||||
|
||||
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);
|
||||
blend_ratio = 0.25;
|
||||
}
|
||||
|
||||
// We draw bars only if wanted, visible on the map view and not a fake unit
|
||||
bool draw_bars = draw_bars_ && !fake;
|
||||
if (draw_bars) {
|
||||
const int d = disp.hex_size();
|
||||
SDL_Rect unit_rect = {xsrc, ysrc_adjusted, d, d};
|
||||
SDL_Rect unit_rect = {xsrc, ysrc +adjusted_params.y, d, d};
|
||||
draw_bars = rects_overlap(unit_rect, disp.map_outside_area());
|
||||
}
|
||||
|
||||
|
@ -1750,7 +1752,7 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
// The division by 2 seems to have no real meaning,
|
||||
// It just works fine with the current center of ellipse
|
||||
// and prevent a too large adjust if submerge = 1.0
|
||||
ellipse_floating = static_cast<int>(submerge * disp.hex_size() / 2);
|
||||
ellipse_floating = static_cast<int>(adjusted_params.submerge * disp.hex_size() / 2);
|
||||
|
||||
std::string ellipse=image_ellipse();
|
||||
if(ellipse.empty()){
|
||||
|
@ -1772,19 +1774,19 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
|
||||
if (ellipse_back != NULL) {
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BG, drawing_order,
|
||||
display::tblit(xsrc, ysrc_adjusted-ellipse_floating, ellipse_back));
|
||||
display::tblit(xsrc, ysrc +adjusted_params.y-ellipse_floating, ellipse_back));
|
||||
}
|
||||
|
||||
if (image != NULL) {
|
||||
const int tmp_x = params.x +x - image->w/2;
|
||||
const int tmp_y = params.y +y - image->h/2;
|
||||
const int tmp_x = adjusted_params.x +x - image->w/2;
|
||||
const int tmp_y = adjusted_params.y +y - image->h/2;
|
||||
disp.render_unit_image(tmp_x, tmp_y, fake, drawing_order, image, facing_west, stoned,
|
||||
highlight_ratio, blend_with, blend_ratio, submerge);
|
||||
ftofxp(adjusted_params.highlight_ratio), adjusted_params.blend_with, adjusted_params.blend_ratio, adjusted_params.submerge);
|
||||
}
|
||||
|
||||
if (ellipse_front != NULL) {
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_FG, drawing_order,
|
||||
display::tblit(xsrc, ysrc_adjusted-ellipse_floating, ellipse_front));
|
||||
display::tblit(xsrc, ysrc +adjusted_params.y-ellipse_floating, ellipse_front));
|
||||
}
|
||||
|
||||
if(draw_bars) {
|
||||
|
@ -1813,7 +1815,7 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
surface orb(image::get_image(*movement_file,image::SCALED_TO_ZOOM));
|
||||
if (orb != NULL) {
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BAR,
|
||||
drawing_order, display::tblit(xsrc, ysrc_adjusted, orb));
|
||||
drawing_order, display::tblit(xsrc, ysrc +adjusted_params.y, orb));
|
||||
}
|
||||
|
||||
double unit_energy = 0.0;
|
||||
|
@ -1829,7 +1831,7 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
|
||||
const fixed_t bar_alpha = (loc == disp.mouseover_hex() || loc == disp.selected_hex()) ? ftofxp(1.0): ftofxp(0.8);
|
||||
|
||||
disp.draw_bar(*energy_file, xsrc+bar_shift, ysrc_adjusted,
|
||||
disp.draw_bar(*energy_file, xsrc+bar_shift, ysrc +adjusted_params.y,
|
||||
drawing_order, hp_bar_height, unit_energy,hp_color(), bar_alpha);
|
||||
|
||||
if(experience() > 0 && can_advance()) {
|
||||
|
@ -1838,7 +1840,7 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
const int xp_bar_height = static_cast<int>(max_experience()*game_config::xp_bar_scaling / maximum<int>(level_,1));
|
||||
|
||||
SDL_Color colour=xp_color();
|
||||
disp.draw_bar(*energy_file, xsrc, ysrc_adjusted,
|
||||
disp.draw_bar(*energy_file, xsrc, ysrc +adjusted_params.y,
|
||||
drawing_order, xp_bar_height, filled, colour, bar_alpha);
|
||||
}
|
||||
|
||||
|
@ -1849,7 +1851,7 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
// crown = adjust_surface_alpha(crown, bar_alpha);
|
||||
//}
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BAR,
|
||||
drawing_order, display::tblit(xsrc, ysrc_adjusted, crown));
|
||||
drawing_order, display::tblit(xsrc, ysrc +adjusted_params.y, crown));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1857,12 +1859,12 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc, const b
|
|||
const surface ov_img(image::get_image(*ov, image::SCALED_TO_ZOOM));
|
||||
if(ov_img != NULL) {
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BAR,
|
||||
drawing_order, display::tblit(xsrc, ysrc_adjusted, ov_img));
|
||||
drawing_order, display::tblit(xsrc, ysrc +adjusted_params.y, ov_img));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
anim_->redraw();
|
||||
anim_->redraw(params);
|
||||
refreshing_ = false;
|
||||
}
|
||||
|
||||
|
@ -1906,12 +1908,37 @@ std::set<gamemap::location> unit::overlaps(const gamemap::location &loc) const
|
|||
}
|
||||
|
||||
// Very early calls, anim not initialized yet
|
||||
double tmp_offset=0;
|
||||
if(anim_)tmp_offset= anim_->get_current_params().offset;
|
||||
frame_parameters params;
|
||||
game_display * disp = game_display::get_singleton();
|
||||
const gamemap & map = disp->get_map();
|
||||
const t_translation::t_terrain terrain = map.get_terrain(loc);
|
||||
const terrain_type& terrain_info = map.get_terrain_info(terrain);
|
||||
if(!params.submerge) params.submerge= is_flying() ? 0.0 : terrain_info.unit_submerge();
|
||||
|
||||
if(invisible(loc,disp->get_units(),disp->get_teams()) &&
|
||||
params.highlight_ratio > 0.5) {
|
||||
params.highlight_ratio = 0.5;
|
||||
}
|
||||
if(loc == disp->selected_hex() && params.highlight_ratio == 1.0) {
|
||||
params.highlight_ratio = 1.5;
|
||||
}
|
||||
int height_adjust = static_cast<int>(terrain_info.unit_height_adjust() * disp->get_zoom_factor());
|
||||
if (is_flying() && height_adjust < 0) {
|
||||
height_adjust = 0;
|
||||
}
|
||||
params.y -= height_adjust;
|
||||
params.halo_y -= height_adjust;
|
||||
if (utils::string_bool(get_state("poisoned")) ){
|
||||
params.blend_with = disp->rgb(0,255,0);
|
||||
params.blend_ratio = 0.25;
|
||||
}
|
||||
|
||||
frame_parameters adjusted_params;
|
||||
if(anim_) adjusted_params = anim_->get_current_params(params);
|
||||
|
||||
// Invalidate adjacent neighbours if we don't stay in our hex
|
||||
if(tmp_offset != 0) {
|
||||
gamemap::location::DIRECTION dir = (tmp_offset > 0) ? facing_ : loc.get_opposite_dir(facing_);
|
||||
if(adjusted_params.offset != 0) {
|
||||
gamemap::location::DIRECTION dir = (adjusted_params.offset > 0) ? facing_ : loc.get_opposite_dir(facing_);
|
||||
gamemap::location adj_loc = loc.get_direction(dir);
|
||||
over.insert(adj_loc);
|
||||
gamemap::location arr[6];
|
||||
|
@ -1929,7 +1956,7 @@ std::set<gamemap::location> unit::overlaps(const gamemap::location &loc) const
|
|||
over.insert(arr[i]);
|
||||
}
|
||||
}
|
||||
if(get_animation()) get_animation()->invalidate();
|
||||
if(get_animation()) get_animation()->invalidate(params);
|
||||
|
||||
return over;
|
||||
}
|
||||
|
|
|
@ -734,38 +734,38 @@ void unit_animation::restart_animation()
|
|||
anim_itor->second.restart_animation();
|
||||
}
|
||||
}
|
||||
void unit_animation::redraw()
|
||||
void unit_animation::redraw(const frame_parameters& value)
|
||||
{
|
||||
|
||||
std::map<std::string,particule>::iterator anim_itor =sub_anims_.begin();
|
||||
for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
|
||||
anim_itor->second.redraw();
|
||||
anim_itor->second.redraw( value);
|
||||
}
|
||||
}
|
||||
void unit_animation::invalidate() const
|
||||
void unit_animation::invalidate(const frame_parameters& value) const
|
||||
{
|
||||
|
||||
std::map<std::string,particule>::const_iterator anim_itor =sub_anims_.begin();
|
||||
for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
|
||||
anim_itor->second.invalidate();
|
||||
anim_itor->second.invalidate(value);
|
||||
}
|
||||
}
|
||||
void unit_animation::particule::redraw()
|
||||
void unit_animation::particule::redraw(const frame_parameters& value)
|
||||
{
|
||||
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_,default_val);
|
||||
current_frame.redraw(get_current_frame_time(),true,src_,dst_,&halo_id_,default_val,value);
|
||||
} else {
|
||||
current_frame.redraw(get_current_frame_time(),false,src_,dst_,&halo_id_,default_val);
|
||||
current_frame.redraw(get_current_frame_time(),false,src_,dst_,&halo_id_,default_val,value);
|
||||
}
|
||||
}
|
||||
void unit_animation::particule::invalidate() const
|
||||
void unit_animation::particule::invalidate(const frame_parameters& value) const
|
||||
{
|
||||
const unit_frame& current_frame= get_current_frame();
|
||||
const frame_parameters default_val = parameters_.parameters(get_animation_time() -get_begin_time());
|
||||
current_frame.invalidate(get_current_frame_time(),src_,dst_,default_val);
|
||||
current_frame.invalidate(get_current_frame_time(),src_,dst_,default_val,value);
|
||||
}
|
||||
|
||||
unit_animation::particule::~particule()
|
||||
|
|
|
@ -55,13 +55,13 @@ class unit_animation
|
|||
void pause_animation();
|
||||
void restart_animation();
|
||||
int get_current_frame_begin_time() const{ return unit_anim_.get_current_frame_begin_time() ; };
|
||||
void redraw();
|
||||
void invalidate( ) const;
|
||||
void redraw(const frame_parameters& value);
|
||||
void invalidate(const frame_parameters& value ) const;
|
||||
|
||||
friend class unit;
|
||||
protected:
|
||||
// reserved to class unit, for the special case of redrawing the unit base frame
|
||||
const frame_parameters get_current_params(const frame_parameters & default_val = frame_parameters()) const { return unit_anim_.parameters(default_val); };
|
||||
const frame_parameters get_current_params(const frame_parameters & default_val = frame_parameters(),bool primary = true) const { return unit_anim_.parameters(default_val,primary); };
|
||||
private:
|
||||
static config prepare_animation(const config &cfg,const std::string animation_tag);
|
||||
explicit unit_animation(const config& cfg,const std::string frame_string ="");
|
||||
|
@ -82,10 +82,10 @@ 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="");
|
||||
void redraw( );
|
||||
void invalidate( ) const;
|
||||
void redraw( const frame_parameters& value);
|
||||
void invalidate(const frame_parameters& value ) const;
|
||||
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)); };
|
||||
const frame_parameters parameters(const frame_parameters & default_val,bool primary) const { return get_current_frame().merge_parameters(get_current_frame_time(),parameters_.parameters(get_animation_time()-get_begin_time()),default_val,primary); };
|
||||
bool accelerate;
|
||||
private:
|
||||
|
||||
|
|
|
@ -52,12 +52,12 @@ int progressive_string::duration() const
|
|||
return total;
|
||||
|
||||
}
|
||||
|
||||
const std::string& progressive_string::get_current_element(int current_time,const std::string& default_val)const
|
||||
static const std::string empty_string ="";
|
||||
const std::string& progressive_string::get_current_element(int current_time)const
|
||||
{
|
||||
int time = 0;
|
||||
unsigned int sub_halo = 0;
|
||||
if(data_.empty()) return default_val;
|
||||
if(data_.empty()) return empty_string;
|
||||
while(time < current_time&& sub_halo < data_.size()) {
|
||||
time += data_[sub_halo].second;
|
||||
sub_halo++;
|
||||
|
@ -98,7 +98,7 @@ progressive_<T>::progressive_(const std::string &data, int duration)
|
|||
}
|
||||
|
||||
template <class T>
|
||||
const T progressive_<T>::get_current_element(int current_time,const T default_val) const
|
||||
const T progressive_<T>::get_current_element(int current_time, T default_val) const
|
||||
{
|
||||
int time = 0;
|
||||
unsigned int sub_halo = 0;
|
||||
|
@ -189,25 +189,25 @@ frame_builder::frame_builder(const config& cfg,const std::string& frame_string)
|
|||
|
||||
}
|
||||
|
||||
const frame_parameters frame_builder::parameters(int current_time, const frame_parameters & default_val) const
|
||||
const frame_parameters frame_builder::parameters(int current_time) 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);
|
||||
result.submerge = submerge_.get_current_element(current_time,default_val.submerge);
|
||||
result.x = x_.get_current_element(current_time,default_val.x);
|
||||
result.y = y_.get_current_element(current_time,default_val.y);
|
||||
result.duration = duration_;
|
||||
result.image = image_;
|
||||
result.image_diagonal = image_diagonal_;
|
||||
result.halo = halo_.get_current_element(current_time);
|
||||
result.sound = sound_;
|
||||
result.text = text_;
|
||||
result.text_color = text_color_;
|
||||
result.halo_x = halo_x_.get_current_element(current_time);
|
||||
result.halo_y = halo_y_.get_current_element(current_time);
|
||||
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);
|
||||
result.submerge = submerge_.get_current_element(current_time);
|
||||
result.x = x_.get_current_element(current_time);
|
||||
result.y = y_.get_current_element(current_time);
|
||||
return result;
|
||||
}
|
||||
frame_builder & frame_builder::image(const image::locator image )
|
||||
|
@ -315,7 +315,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 frame_parameters & default_val)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 & animation_val,const frame_parameters & engine_val)const
|
||||
{
|
||||
const int xsrc = game_display::get_singleton()->get_location_x(src);
|
||||
const int ysrc = game_display::get_singleton()->get_location_y(src);
|
||||
|
@ -323,7 +323,7 @@ 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);
|
||||
|
||||
const frame_parameters current_data = builder_.parameters(frame_time,default_val);
|
||||
const frame_parameters current_data = merge_parameters(frame_time,animation_val,engine_val);
|
||||
double tmp_offset = current_data.offset;
|
||||
int d2 = game_display::get_singleton()->hex_size() / 2;
|
||||
|
||||
|
@ -405,7 +405,7 @@ void unit_frame::redraw(const int frame_time,bool first_time,const gamemap::loca
|
|||
}
|
||||
}
|
||||
}
|
||||
void unit_frame::invalidate(const int frame_time,const gamemap::location & src,const gamemap::location & dst,const frame_parameters & default_val) const
|
||||
void unit_frame::invalidate(const int frame_time,const gamemap::location & src,const gamemap::location & dst,const frame_parameters & animation_val,const frame_parameters & engine_val) const
|
||||
{
|
||||
const int xsrc = game_display::get_singleton()->get_location_x(src);
|
||||
const int ysrc = game_display::get_singleton()->get_location_y(src);
|
||||
|
@ -413,7 +413,7 @@ void unit_frame::invalidate(const int frame_time,const gamemap::location & src,c
|
|||
const int ydst = game_display::get_singleton()->get_location_y(dst);
|
||||
const gamemap::location::DIRECTION direction = src.get_relative_dir(dst);
|
||||
|
||||
const frame_parameters current_data = builder_.parameters(frame_time,default_val);
|
||||
const frame_parameters current_data = merge_parameters(frame_time,animation_val,engine_val);
|
||||
double tmp_offset = current_data.offset;
|
||||
//unused var - int d2 = game_display::get_singleton()->hex_size() / 2;
|
||||
|
||||
|
@ -439,3 +439,68 @@ void unit_frame::invalidate(const int frame_time,const gamemap::location & src,c
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const frame_parameters unit_frame::merge_parameters(int current_time,const frame_parameters & animation_val,const frame_parameters & engine_val, bool primary) const
|
||||
{
|
||||
/*! this function merges the value provided by
|
||||
* * the frame
|
||||
* * the engine (poison, flying unit...)
|
||||
* * the animation as a whole
|
||||
* there is no absolute rule for merging, so creativity is the rule
|
||||
* if a value is never provided by the engine, assert. (this way if it becomes used, people will easily find the right place to look)
|
||||
*
|
||||
* */
|
||||
frame_parameters result;
|
||||
const frame_parameters & current_value = builder_.parameters(current_time);
|
||||
assert(engine_val.image.is_void() || engine_val.image.get_filename() == "");
|
||||
result.image = current_value.image.is_void() || current_value.image.get_filename() == ""?animation_val.image:current_value.image;
|
||||
|
||||
assert(engine_val.image_diagonal.is_void() || engine_val.image_diagonal.get_filename() == "");
|
||||
result.image_diagonal = current_value.image_diagonal.is_void()|| current_value.image_diagonal.get_filename() == ""?animation_val.image_diagonal:current_value.image_diagonal;
|
||||
|
||||
assert(engine_val.halo.empty());
|
||||
result.halo = current_value.halo.empty()?animation_val.halo:current_value.halo;
|
||||
|
||||
assert(engine_val.sound.empty());
|
||||
result.sound = current_value.sound.empty()?animation_val.sound:current_value.sound;
|
||||
|
||||
assert(engine_val.text.empty());
|
||||
result.text = current_value.text.empty()?animation_val.text:current_value.text;
|
||||
|
||||
assert(engine_val.text_color == 0);
|
||||
result.text_color = current_value.text_color?current_value.text_color:animation_val.text_color;
|
||||
|
||||
assert(engine_val.halo_x == 0);
|
||||
result.halo_x = current_value.halo_x?current_value.halo_x:animation_val.halo_x;
|
||||
|
||||
result.halo_y = current_value.halo_y?current_value.halo_y:animation_val.halo_y;
|
||||
result.halo_y += engine_val.halo_y;
|
||||
|
||||
assert(engine_val.duration == 0);
|
||||
result.duration = current_value.duration;
|
||||
|
||||
result.blend_with = current_value.blend_with?current_value.blend_with:animation_val.blend_with;
|
||||
if(primary&& engine_val.blend_with) result.blend_with = engine_val.blend_with;
|
||||
|
||||
result.blend_ratio = current_value.blend_ratio?current_value.blend_ratio:animation_val.blend_ratio;
|
||||
if(primary && engine_val.blend_ratio) result.blend_ratio += engine_val.blend_ratio;
|
||||
|
||||
result.highlight_ratio = current_value.highlight_ratio!=0.0?current_value.highlight_ratio:animation_val.highlight_ratio;
|
||||
if(primary && engine_val.highlight_ratio != 1.0) result.highlight_ratio = result.highlight_ratio +engine_val.highlight_ratio - 1.0; // selected unit
|
||||
|
||||
assert(engine_val.offset == 0);
|
||||
result.offset = current_value.offset?current_value.offset:animation_val.offset;
|
||||
|
||||
result.submerge = current_value.submerge?current_value.submerge:animation_val.submerge;
|
||||
if(primary && engine_val.submerge) result.submerge = engine_val.submerge;
|
||||
|
||||
assert(engine_val.x == 0);
|
||||
result.x = current_value.x?current_value.x:animation_val.x;
|
||||
|
||||
result.y = current_value.y?current_value.y:animation_val.y;
|
||||
result.y += engine_val.y;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class progressive_string {
|
|||
public:
|
||||
progressive_string(const std::string& data = "",int duration = 0);
|
||||
int duration() const;
|
||||
const std::string & get_current_element(int time,const std::string& default_val="") const;
|
||||
const std::string & get_current_element(int time) const;
|
||||
bool does_not_change() const { return data_.size() <= 1; }
|
||||
std::string get_original(){return input_;}
|
||||
private:
|
||||
|
@ -50,7 +50,7 @@ class progressive_
|
|||
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;
|
||||
const T get_current_element(int time,T default_val=0) const;
|
||||
bool does_not_change() const;
|
||||
std::string get_original(){return input_;}
|
||||
};
|
||||
|
@ -138,7 +138,7 @@ class frame_builder {
|
|||
frame_builder & x(const std::string& x);
|
||||
frame_builder & y(const std::string& y);
|
||||
//! getters for the different parameters
|
||||
const frame_parameters parameters(int current_time, const frame_parameters & default_val = frame_parameters()) const;
|
||||
const frame_parameters parameters(int current_time) const ;
|
||||
|
||||
int duration() const{ return duration_;};
|
||||
void recalculate_duration();
|
||||
|
@ -168,13 +168,14 @@ class unit_frame {
|
|||
public:
|
||||
// Constructors
|
||||
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); } ;
|
||||
void redraw(const int frame_time,bool first_time,const gamemap::location & src,const gamemap::location & dst,int*halo_id,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(),bool primary=false) const;
|
||||
const frame_parameters parameters(int current_time) const {return builder_.parameters(current_time);};
|
||||
|
||||
int duration() const { return builder_.duration();};
|
||||
bool does_not_change() const{ return builder_.does_not_change();};
|
||||
bool need_update() const{ return builder_.need_update();};
|
||||
void invalidate(const int frame_time,const gamemap::location & src,const gamemap::location & dst,const frame_parameters & default_val) const;
|
||||
void invalidate(const int frame_time,const gamemap::location & src,const gamemap::location & dst,const frame_parameters & animation_val,const frame_parameters & engine_val) const;
|
||||
private:
|
||||
frame_builder builder_;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue