mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-19 10:08:57 +00:00
Display: clean up exclusive draw stuff
This commit is contained in:
parent
6d40872de0
commit
c5891ef7fe
@ -372,28 +372,27 @@ void display::set_playing_team_index(std::size_t teamindex)
|
|||||||
invalidate_game_status();
|
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()) {
|
if(!loc.valid()) return false;
|
||||||
exclusive_unit_draw_requests_[loc] = unit.id();
|
auto [iter, success] = exclusive_unit_draw_requests_.emplace(loc, unit.id());
|
||||||
return true;
|
return success;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string display::remove_exclusive_draw(const map_location& loc)
|
std::string display::remove_exclusive_draw(const map_location& loc)
|
||||||
{
|
{
|
||||||
std::string id = "";
|
if(!loc.valid()) return {};
|
||||||
if(loc.valid())
|
std::string id = exclusive_unit_draw_requests_[loc];
|
||||||
{
|
|
||||||
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);
|
exclusive_unit_draw_requests_.erase(loc);
|
||||||
}
|
|
||||||
return id;
|
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)
|
void display::update_tod(const time_of_day* tod_override)
|
||||||
{
|
{
|
||||||
const time_of_day* tod = tod_override;
|
const time_of_day* tod = tod_override;
|
||||||
@ -2630,9 +2629,7 @@ void display::draw_invalidated()
|
|||||||
|
|
||||||
if(drawer) {
|
if(drawer) {
|
||||||
const auto u_it = context().units().find(loc);
|
const auto u_it = context().units().find(loc);
|
||||||
const auto request = exclusive_unit_draw_requests_.find(loc);
|
if(u_it != context().units().end() && unit_can_draw_here(loc, *u_it)) {
|
||||||
|
|
||||||
if(u_it != context().units().end() && (request == exclusive_unit_draw_requests_.end() || request->second == u_it->id())) {
|
|
||||||
drawer->redraw_unit(*u_it);
|
drawer->redraw_unit(*u_it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,8 @@ public:
|
|||||||
* @param unit The unit requesting exclusivity.
|
* @param unit The unit requesting exclusivity.
|
||||||
* @return false if there's already an exclusive draw request for this location.
|
* @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.
|
* Cancels an exclusive draw request.
|
||||||
* @return The id of the unit whose exclusive draw request was canceled, or else
|
* @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);
|
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.
|
* Functions to add and remove overlays from locations.
|
||||||
*
|
*
|
||||||
|
@ -200,13 +200,12 @@ void game_display::draw_invalidated()
|
|||||||
}
|
}
|
||||||
unit_drawer drawer = unit_drawer(*this);
|
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();
|
const map_location& loc = temp_unit->get_location();
|
||||||
exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc);
|
if(utils::contains(invalidated_, loc) && unit_can_draw_here(loc, *temp_unit)) {
|
||||||
if (invalidated_.find(loc) != invalidated_.end()
|
|
||||||
&& (request == exclusive_unit_draw_requests_.end() || request->second == temp_unit->id()))
|
|
||||||
drawer.redraw_unit(*temp_unit);
|
drawer.redraw_unit(*temp_unit);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user