Display: clean up exclusive draw stuff
This commit is contained in:
parent
6d40872de0
commit
c5891ef7fe
3 changed files with 22 additions and 22 deletions
|
@ -372,28 +372,27 @@ void display::set_playing_team_index(std::size_t teamindex)
|
|||
invalidate_game_status();
|
||||
}
|
||||
|
||||
bool display::add_exclusive_draw(const map_location& loc, unit& unit)
|
||||
bool display::add_exclusive_draw(const map_location& loc, const unit& unit)
|
||||
{
|
||||
if(loc.valid() && exclusive_unit_draw_requests_.find(loc) == exclusive_unit_draw_requests_.end()) {
|
||||
exclusive_unit_draw_requests_[loc] = unit.id();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if(!loc.valid()) return false;
|
||||
auto [iter, success] = exclusive_unit_draw_requests_.emplace(loc, unit.id());
|
||||
return success;
|
||||
}
|
||||
|
||||
std::string display::remove_exclusive_draw(const map_location& loc)
|
||||
{
|
||||
std::string id = "";
|
||||
if(loc.valid())
|
||||
{
|
||||
id = exclusive_unit_draw_requests_[loc];
|
||||
//id will be set to the default "" string by the [] operator if the map doesn't have anything for that loc.
|
||||
exclusive_unit_draw_requests_.erase(loc);
|
||||
}
|
||||
if(!loc.valid()) return {};
|
||||
std::string id = exclusive_unit_draw_requests_[loc];
|
||||
exclusive_unit_draw_requests_.erase(loc);
|
||||
return id;
|
||||
}
|
||||
|
||||
bool display::unit_can_draw_here(const map_location& loc, const unit& unit) const
|
||||
{
|
||||
auto request = exclusive_unit_draw_requests_.find(loc);
|
||||
return request == exclusive_unit_draw_requests_.end() || request->second == unit.id();
|
||||
}
|
||||
|
||||
void display::update_tod(const time_of_day* tod_override)
|
||||
{
|
||||
const time_of_day* tod = tod_override;
|
||||
|
@ -2630,9 +2629,7 @@ void display::draw_invalidated()
|
|||
|
||||
if(drawer) {
|
||||
const auto u_it = context().units().find(loc);
|
||||
const auto request = exclusive_unit_draw_requests_.find(loc);
|
||||
|
||||
if(u_it != context().units().end() && (request == exclusive_unit_draw_requests_.end() || request->second == u_it->id())) {
|
||||
if(u_it != context().units().end() && unit_can_draw_here(loc, *u_it)) {
|
||||
drawer->redraw_unit(*u_it);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,7 +156,8 @@ public:
|
|||
* @param unit The unit requesting exclusivity.
|
||||
* @return false if there's already an exclusive draw request for this location.
|
||||
*/
|
||||
bool add_exclusive_draw(const map_location& loc, unit& unit);
|
||||
bool add_exclusive_draw(const map_location& loc, const unit& unit);
|
||||
|
||||
/**
|
||||
* Cancels an exclusive draw request.
|
||||
* @return The id of the unit whose exclusive draw request was canceled, or else
|
||||
|
@ -164,6 +165,9 @@ public:
|
|||
*/
|
||||
std::string remove_exclusive_draw(const map_location& loc);
|
||||
|
||||
/** Returns true if there is no exclusive draw request for @a loc, or if there is, that it's for @a unit */
|
||||
bool unit_can_draw_here(const map_location& loc, const unit& unit) const;
|
||||
|
||||
/**
|
||||
* Functions to add and remove overlays from locations.
|
||||
*
|
||||
|
|
|
@ -200,12 +200,11 @@ void game_display::draw_invalidated()
|
|||
}
|
||||
unit_drawer drawer = unit_drawer(*this);
|
||||
|
||||
for (const unit* temp_unit : *fake_unit_man_) {
|
||||
for(const unit* temp_unit : *fake_unit_man_) {
|
||||
const map_location& loc = temp_unit->get_location();
|
||||
exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc);
|
||||
if (invalidated_.find(loc) != invalidated_.end()
|
||||
&& (request == exclusive_unit_draw_requests_.end() || request->second == temp_unit->id()))
|
||||
if(utils::contains(invalidated_, loc) && unit_can_draw_here(loc, *temp_unit)) {
|
||||
drawer.redraw_unit(*temp_unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue