Better tracking whether the unit was changed during movement.

Fixes #1565

Previosuly the anitmators fake unit was reset whenever any wml/lua was executed
causing animations issues ( #1565 ). Now we only reset it when the unit
appearance  was actually changed by wml.

appearance_changed_ is mutable because set_hidden() is const.
appearance_changed_ is initially true so that the code updates the unit in
case that the unit was completeley reset ( [unstore_unit] etc.)

EDIT: set_hidden() doesn't set appearance_changed_ anymore becasue it's also
called by the movement animation code which made appearance_changed_ always
true when we checked it at move.cpp
This commit is contained in:
gfgtdf 2017-08-01 17:58:56 +02:00
parent 3f287b9098
commit 62ec3b3951
3 changed files with 15 additions and 6 deletions

View file

@ -313,8 +313,6 @@ namespace { // Private helpers for move_unit()
team * current_team_; // Will default to the original team if the moving unit becomes invalid.
bool current_uses_fog_;
route_iterator move_loc_; // Will point to the last moved-to location (in case the moving unit disappears).
size_t do_move_track_; // Tracks whether or not do_move() needs to update the displayed (fake) unit. Should only be touched by do_move() and the constructor.
// Data accumulated while making the move.
map_location zoc_stop_;
map_location ambush_stop_; // Could be inaccurate if ambushed_ is false.
@ -368,7 +366,6 @@ namespace { // Private helpers for move_unit()
, current_team_(&resources::gameboard->get_team(current_side_))
, current_uses_fog_(current_team_->fog_or_shroud() && current_team_->auto_shroud_updates())
, move_loc_(begin_)
, do_move_track_(resources::game_events->pump().wml_tracking())
// The remaining fields are set to some sort of "zero state".
, zoc_stop_(map_location::null_location())
, ambush_stop_(map_location::null_location())
@ -543,10 +540,9 @@ namespace { // Private helpers for move_unit()
move_loc_ = step_to;
// Show this move.
const size_t current_tracking = resources::game_events->pump().wml_tracking();
animator.proceed_to(move_it_.get_shared_ptr(), step_to - begin_,
current_tracking != do_move_track_, false);
do_move_track_ = current_tracking;
move_it_->appearance_changed(), false);
move_it_->set_appearance_changed(false);
disp.redraw_minimap();
}

View file

@ -890,6 +890,7 @@ std::vector<std::string> unit::get_traits_list() const
*/
void unit::advance_to(const unit_type& u_type, bool use_traits)
{
appearance_changed_ = true;
// For reference, the type before this advancement.
const unit_type& old_type = type();
// Adjust the new type for gender and variation.
@ -1340,6 +1341,7 @@ std::map<std::string, unit::state_t> unit::known_boolean_state_names_ {
void unit::set_state(const std::string& state, bool value)
{
appearance_changed_ = true;
state_t known_boolean_state_id = get_known_boolean_state_id(state);
if(known_boolean_state_id != STATE_UNKNOWN) {
set_state(known_boolean_state_id, value);
@ -1513,6 +1515,7 @@ void unit::write(config& cfg) const
void unit::set_facing(map_location::DIRECTION dir) const
{
if(dir != map_location::NDIRECTIONS) {
appearance_changed_ = true;
facing_ = dir;
}
// Else look at yourself (not available so continue to face the same direction)
@ -1821,6 +1824,7 @@ std::string unit::describe_builtin_effect(std::string apply_to, const config& ef
void unit::apply_builtin_effect(std::string apply_to, const config& effect)
{
appearance_changed_ = true;
if(apply_to == "fearless") {
is_fearless_ = effect["set"].to_bool(true);
} else if(apply_to == "healthy") {
@ -2489,6 +2493,7 @@ void unit::remove_movement_ai()
void unit::set_hidden(bool state) const
{
// appearance_changed_ = true;
hidden_ = state;
if(!state) {
return;
@ -2500,6 +2505,7 @@ void unit::set_hidden(bool state) const
void unit::set_image_halo(const std::string& halo)
{
appearance_changed_ = true;
anim_comp_->clear_haloes();
halo_.reset(new std::string(halo));
}

View file

@ -1355,6 +1355,7 @@ public:
/** Set the unit's ellipse image. */
void set_image_ellipse(const std::string& ellipse)
{
appearance_changed_ = true;
ellipse_.reset(new std::string(ellipse));
}
@ -1562,6 +1563,9 @@ public:
friend void intrusive_ptr_add_ref(const unit*);
friend void intrusive_ptr_release(const unit*);
void set_appearance_changed(bool value) { appearance_changed_ = value; }
bool appearance_changed() const { return appearance_changed_; }
protected:
mutable long ref_count_; // used by intrusive_ptr
@ -1684,6 +1688,9 @@ private:
std::string profile_;
std::string small_profile_;
//Used to check whether the moving units during a move needs ot be updated
mutable bool appearance_changed_ = true;
void parse_upkeep(const config::attribute_value& upkeep);
void write_upkeep(config::attribute_value& upkeep) const;