Skip to content

Commit

Permalink
Removed animation invalidation code
Browse files Browse the repository at this point in the history
This no longer actually does anything now that location invalidation is removed. If you follow the code
animation_component::invalidate called unit_animation::invalidate which was responsible for generating
the overlaped_hex_ set. Previously, this is what locations were invalidated. Now it didn't do anything.
  • Loading branch information
Vultraz committed Aug 12, 2017
1 parent 1aa94cc commit 99faf30
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 115 deletions.
3 changes: 0 additions & 3 deletions src/actions/move.cpp
Expand Up @@ -516,9 +516,6 @@ namespace { // Private helpers for move_unit()
move_it_->set_movement(moves_left_.front(), true);
moves_left_.pop_front();

// Invalidate before moving so we invalidate neighbor hexes if needed.
move_it_->anim_comp().invalidate(disp);

// Attempt actually moving.
// (Fails if *step_to is occupied).
std::pair<unit_map::iterator, bool> move_result =
Expand Down
20 changes: 0 additions & 20 deletions src/display.cpp
Expand Up @@ -2409,26 +2409,6 @@ void display::invalidate_animations()
open_mp_list[i]->anim_comp().refresh();
}
#endif

bool new_inval;
do {
new_inval = false;

#ifndef _OPENMP
for(const unit& u : dc_->units()) {
new_inval |= u.anim_comp().invalidate(*this);
}

for(const unit* u : *fake_unit_man_) {
new_inval |= u->anim_comp().invalidate(*this);
}
#else
#pragma omp parallel for reduction(| : new_inval) shared(open_mp_list)
for(int i = 0; i < omp_iterations; i++) {
new_inval |= open_mp_list[i]->anim_comp().invalidate(*this);
}
#endif
} while(new_inval);
}

void display::add_arrow(arrow& arrow)
Expand Down
49 changes: 0 additions & 49 deletions src/units/animation.cpp
Expand Up @@ -267,9 +267,7 @@ unit_animation::unit_animation(int start_time,
, unit_anim_(start_time,builder)
, src_()
, dst_()
, invalidated_(false)
, play_offscreen_(true)
, overlaped_hex_()
{
add_frame(frame.duration(),frame,!frame.does_not_change());
}
Expand All @@ -291,9 +289,7 @@ unit_animation::unit_animation(const config& cfg,const std::string& frame_string
, unit_anim_(cfg,frame_string)
, src_()
, dst_()
, invalidated_(false)
, play_offscreen_(true)
, overlaped_hex_()
{
//if(!cfg["debug"].empty()) printf("DEBUG WML: FINAL\n%s\n\n",cfg.debug().c_str());

Expand Down Expand Up @@ -1081,9 +1077,6 @@ void unit_animation::restart_animation()

void unit_animation::redraw(frame_parameters& value, halo::manager& halo_man)
{
invalidated_ = false;
overlaped_hex_.clear();

value.primary_frame = true;
unit_anim_.redraw(value,src_,dst_, halo_man);

Expand All @@ -1102,48 +1095,6 @@ void unit_animation::clear_haloes()
}
}

// TODO: see if this function can be removed!
bool unit_animation::invalidate(frame_parameters& value)
{
if(invalidated_) return false;

display* disp = display::get_singleton();
const bool complete_redraw = disp->tile_nearly_on_screen(src_) || disp->tile_nearly_on_screen(dst_);

if(overlaped_hex_.empty()) {
if(complete_redraw) {
value.primary_frame = true;
overlaped_hex_ = unit_anim_.get_overlaped_hex(value, src_, dst_);
value.primary_frame = false;

for(auto& anim : sub_anims_) {
std::set<map_location> tmp = anim.second.get_overlaped_hex(value, src_, dst_);
overlaped_hex_.insert(tmp.begin(), tmp.end());
}
} else {
// Offscreen animations only invalidate their own hex, no propagation,
// but we still need this to play sounds
overlaped_hex_.insert(src_);
}
}

if(complete_redraw) {
if( need_update()) {
invalidated_ = true;
return true;
} else {
return invalidated_;
}
} else {
if(need_minimal_update()) {
invalidated_ = true;
return true;
} else {
return false;
}
}
}

std::string unit_animation::debug() const
{
std::ostringstream outstream;
Expand Down
4 changes: 1 addition & 3 deletions src/units/animation.hpp
Expand Up @@ -104,7 +104,7 @@ class unit_animation
}
void redraw(frame_parameters& value, halo::manager& halo_man);
void clear_haloes();
bool invalidate(frame_parameters& value );

std::string debug() const;
friend std::ostream& operator << (std::ostream& outstream, const unit_animation& u_animation);

Expand Down Expand Up @@ -187,9 +187,7 @@ class unit_animation
map_location src_;
map_location dst_;
// optimization
bool invalidated_;
bool play_offscreen_;
std::set<map_location> overlaped_hex_;
};

class unit_animator
Expand Down
28 changes: 0 additions & 28 deletions src/units/animation_component.cpp
Expand Up @@ -155,34 +155,6 @@ void unit_animation_component::clear_haloes ()
if(anim_ ) anim_->clear_haloes();
}

bool unit_animation_component::invalidate (const display & disp)
{
bool result = false;

// Very early calls, anim not initialized yet
if(get_animation()) {
frame_parameters params;
const gamemap & map = disp.get_map();
const t_translation::terrain_code terrain = map.get_terrain(u_.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 (u_.is_flying() && height_adjust < 0) {
height_adjust = 0;
}
params.y -= height_adjust;
params.halo_y -= height_adjust;
params.image_mod = u_.image_mods();
params.halo_mod = u_.TC_image_mods();
params.image= u_.default_anim_image();

result |= get_animation()->invalidate(params);
}

return result;

}

void unit_animation_component::reset_after_advance(const unit_type * newtype)
{
if (newtype) {
Expand Down
3 changes: 0 additions & 3 deletions src/units/animation_component.hpp
Expand Up @@ -86,9 +86,6 @@ class unit_animation_component
bool with_bars, const std::string &text = "",
color_t text_color = {}, STATE state = STATE_ANIM);

/** Invalidates an animation with respect to a display object, preparing it for redraw. */
bool invalidate(const display & disp);

/** Intermittently activates the idling animations in place of the standing animations. Used by display object. */
void refresh();

Expand Down
10 changes: 1 addition & 9 deletions src/whiteboard/manager.cpp
Expand Up @@ -724,7 +724,6 @@ void manager::create_temp_move()
}

unit_display::move_unit(path, fake_unit.get_unit_ptr(), false); //get facing right
fake_unit->anim_comp().invalidate(*game_display::get_singleton());
fake_unit->set_location(*curr_itor);
fake_unit->anim_comp().set_ghosted(true);
}
Expand All @@ -734,9 +733,7 @@ void manager::create_temp_move()
prev_itor = curr_itor;
}
}
//in case path shortens on next step and one ghosted unit has to be removed
int ind = fake_units_.size() - 1;
fake_units_[ind]->anim_comp().invalidate(*game_display::get_singleton());

//toss out old arrows and fake units
move_arrows_.resize(turn+1);
fake_units_.resize(turn+1);
Expand All @@ -745,11 +742,6 @@ void manager::create_temp_move()
void manager::erase_temp_move()
{
move_arrows_.clear();
for(fake_unit_ptr const& tmp : fake_units_) {
if(tmp) {
tmp->anim_comp().invalidate(*game_display::get_singleton());
}
}
fake_units_.clear();
route_.reset();
temp_move_unit_underlying_id_ = 0;
Expand Down

0 comments on commit 99faf30

Please sign in to comment.