diff --git a/src/fake_unit_ptr.cpp b/src/fake_unit_ptr.cpp index af9537f87f62..bddb7a8e2a20 100644 --- a/src/fake_unit_ptr.cpp +++ b/src/fake_unit_ptr.cpp @@ -26,7 +26,17 @@ fake_unit_ptr::fake_unit_ptr(const internal_ptr & u, fake_unit_manager * mgr) : { place_on_fake_unit_manager(mgr); } -fake_unit_ptr::fake_unit_ptr(const fake_unit_ptr & ptr) : unit_(ptr.unit_), my_manager_(nullptr) {} +fake_unit_ptr::fake_unit_ptr(const fake_unit_ptr & ptr) + : unit_(ptr.unit_) + , my_manager_(nullptr) +{} + +fake_unit_ptr::fake_unit_ptr(fake_unit_ptr && ptr) + : unit_(std::move(ptr.unit_)) + , my_manager_(ptr.my_manager_) +{ + ptr.my_manager_ = nullptr; +} void fake_unit_ptr::swap (fake_unit_ptr & o) { boost::swap(unit_, o.unit_); diff --git a/src/fake_unit_ptr.hpp b/src/fake_unit_ptr.hpp index 209c11bf3e9f..3ba3b0dd890f 100644 --- a/src/fake_unit_ptr.hpp +++ b/src/fake_unit_ptr.hpp @@ -37,6 +37,7 @@ class fake_unit_ptr { explicit fake_unit_ptr(const internal_ptr & u); //!< Construct a fake unit pointer wrapping a normal unit pointer, marking it as a fake unit. fake_unit_ptr(const internal_ptr & u, fake_unit_manager * mgr); //!< Construct a fake unit pointer, and simultaenously register with a manager. fake_unit_ptr(const fake_unit_ptr & ptr); //!< Copy construct a fake unit pointer. Does not reallocate the underlying unit. + fake_unit_ptr(fake_unit_ptr && ptr); void swap (fake_unit_ptr & o); //!< Pointer swap. diff --git a/src/whiteboard/attack.cpp b/src/whiteboard/attack.cpp index 8ab7aa66678f..96f3b6f28409 100644 --- a/src/whiteboard/attack.cpp +++ b/src/whiteboard/attack.cpp @@ -54,7 +54,7 @@ std::ostream& attack::print(std::ostream& s) const attack::attack(std::size_t team_index, bool hidden, unit& u, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route, arrow_ptr arrow, fake_unit_ptr fake_unit) - : move(team_index, hidden, u, route, arrow, fake_unit), + : move(team_index, hidden, u, route, arrow, std::move(fake_unit)), target_hex_(target_hex), weapon_choice_(weapon_choice), attack_movement_cost_(get_unit()->attacks()[weapon_choice_].movement_used()), diff --git a/src/whiteboard/manager.cpp b/src/whiteboard/manager.cpp index e07bdd06ef5d..6d94c52c00ae 100644 --- a/src/whiteboard/manager.cpp +++ b/src/whiteboard/manager.cpp @@ -782,7 +782,6 @@ void manager::save_temp_move() continue; std::size_t turn = first_turn + i; - fake_unit_ptr fake_unit = fake_units_[i]; //@todo Using a marked_route here is wrong, since right now it's not marked //either switch over to a plain route for planned moves, or mark it correctly @@ -790,7 +789,7 @@ void manager::save_temp_move() route.steps = move_arrow->get_path(); route.move_cost = path_cost(route.steps,*u); - sa.queue_move(turn,*u,route,move_arrow,fake_unit); + sa.queue_move(turn, *u, route, move_arrow, std::move(fake_units_[i])); } erase_temp_move(); @@ -811,7 +810,7 @@ void manager::save_temp_attack(const map_location& attacker_loc, const map_locat assert(weapon_choice >= 0); arrow_ptr move_arrow; - fake_unit_ptr fake_unit; + fake_unit_ptr* fake_unit = nullptr; map_location source_hex; if (route_ && !route_->steps.empty()) @@ -820,12 +819,12 @@ void manager::save_temp_attack(const map_location& attacker_loc, const map_locat assert(move_arrows_.size() == 1); assert(fake_units_.size() == 1); move_arrow = move_arrows_.front(); - fake_unit = fake_units_.front(); + fake_unit = &fake_units_.front(); assert(route_->steps.back() == attacker_loc); source_hex = route_->steps.front(); - fake_unit->anim_comp().set_disabled_ghosted(true); + (**fake_unit).anim_comp().set_disabled_ghosted(true); } else { @@ -843,7 +842,7 @@ void manager::save_temp_attack(const map_location& attacker_loc, const map_locat validate_viewer_actions(); side_actions& sa = *viewer_actions(); - sa.queue_attack(sa.get_turn_num_of(*attacking_unit),*attacking_unit,defender_loc,weapon_choice,*route_,move_arrow,fake_unit); + sa.queue_attack(sa.get_turn_num_of(*attacking_unit), *attacking_unit, defender_loc, weapon_choice, *route_, move_arrow, fake_unit ? std::move(*fake_unit) : fake_unit_ptr()); print_help_once(); diff --git a/src/whiteboard/move.cpp b/src/whiteboard/move.cpp index edb510ec7fcf..ec4b8612f9c9 100644 --- a/src/whiteboard/move.cpp +++ b/src/whiteboard/move.cpp @@ -71,7 +71,7 @@ move::move(std::size_t team_index, bool hidden, unit& u, const pathfind::marked_ movement_cost_(0), turn_number_(0), arrow_(arrow), - fake_unit_(fake_unit), + fake_unit_(std::move(fake_unit)), arrow_brightness_(), arrow_texture_(), mover_(), diff --git a/src/whiteboard/side_actions.cpp b/src/whiteboard/side_actions.cpp index c6955a590106..008eacf59475 100644 --- a/src/whiteboard/side_actions.cpp +++ b/src/whiteboard/side_actions.cpp @@ -674,13 +674,13 @@ side_actions::iterator side_actions::safe_erase(const iterator& itor) } side_actions::iterator side_actions::queue_move(std::size_t turn, unit& mover, const pathfind::marked_route& route, arrow_ptr arrow, fake_unit_ptr fake_unit) { - move_ptr new_move(std::make_shared(team_index(), hidden_, std::ref(mover), route, arrow, fake_unit)); + move_ptr new_move(std::make_shared(team_index(), hidden_, std::ref(mover), route, arrow, std::move(fake_unit))); return queue_action(turn, new_move); } side_actions::iterator side_actions::queue_attack(std::size_t turn, unit& mover, const map_location& target_hex, int weapon_choice, const pathfind::marked_route& route, arrow_ptr arrow, fake_unit_ptr fake_unit) { - attack_ptr new_attack(std::make_shared(team_index(), hidden_, std::ref(mover), target_hex, weapon_choice, route, arrow, fake_unit)); + attack_ptr new_attack(std::make_shared(team_index(), hidden_, std::ref(mover), target_hex, weapon_choice, route, arrow, std::move(fake_unit))); return queue_action(turn, new_attack); }