Display: clean up whiteboard arrow rendering
The arrow class shouldn't be in charge of adding to the drawing buffer. Also it meant that in a case of multiple arrows padding through one hex, multiple buffer entries would be added. Now it will use one per hex.
This commit is contained in:
parent
4884561db7
commit
e7b3f59731
4 changed files with 18 additions and 17 deletions
|
@ -30,8 +30,7 @@ static lg::log_domain log_arrows("arrows");
|
|||
#define DBG_ARR LOG_STREAM(debug, log_arrows)
|
||||
|
||||
arrow::arrow(bool hidden)
|
||||
: layer_(drawing_layer::arrows)
|
||||
, color_("red")
|
||||
: color_("red")
|
||||
, style_(STYLE_STANDARD)
|
||||
, path_()
|
||||
, previous_path_()
|
||||
|
@ -136,12 +135,12 @@ bool arrow::path_contains(const map_location& hex) const
|
|||
return contains;
|
||||
}
|
||||
|
||||
void arrow::draw_hex(const map_location& hex)
|
||||
image::locator arrow::get_image_for_loc(const map_location& hex) const
|
||||
{
|
||||
if(path_contains(hex)) {
|
||||
display::get_singleton()->drawing_buffer_add(layer_, hex, [tex = image::get_texture(symbols_map_[hex])](const rect& dest) {
|
||||
draw::blit(tex, dest);
|
||||
});
|
||||
if(auto iter = symbols_map_.find(hex); iter != symbols_map_.end()) {
|
||||
return iter->second;
|
||||
} else {
|
||||
return {}; // TODO: optional<locator>? Practically I don't think this path gets hit
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
|
||||
bool path_contains(const map_location& hex) const;
|
||||
|
||||
virtual void draw_hex(const map_location& hex);
|
||||
image::locator get_image_for_loc(const map_location& hex) const;
|
||||
|
||||
/** Checks that the path is not of length 0 or 1 */
|
||||
static bool valid_path(const arrow_path_t& path);
|
||||
|
@ -91,8 +91,6 @@ protected:
|
|||
*/
|
||||
virtual void update_symbols();
|
||||
|
||||
drawing_layer layer_;
|
||||
|
||||
std::string color_;
|
||||
/** represents the subdirectory that holds images for this arrow style */
|
||||
std::string style_;
|
||||
|
|
|
@ -2702,11 +2702,17 @@ void display::draw_hex(const map_location& loc)
|
|||
}
|
||||
|
||||
// Paint arrows
|
||||
arrows_map_t::const_iterator arrows_in_hex = arrows_map_.find(loc);
|
||||
if(arrows_in_hex != arrows_map_.end()) {
|
||||
for (arrow* const a : arrows_in_hex->second) {
|
||||
a->draw_hex(loc);
|
||||
if(auto arrows_in_hex = arrows_map_.find(loc); arrows_in_hex != arrows_map_.end()) {
|
||||
std::vector<texture> to_draw;
|
||||
for(const arrow* a : arrows_in_hex->second) {
|
||||
to_draw.push_back(image::get_texture(a->get_image_for_loc(loc)));
|
||||
}
|
||||
|
||||
drawing_buffer_add(drawing_layer::arrows, loc, [to_draw = std::move(to_draw)](const rect& dest) {
|
||||
for(const texture& t : to_draw) {
|
||||
draw::blit(t, dest);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Apply shroud, fog and linger overlay
|
||||
|
|
|
@ -961,10 +961,8 @@ private:
|
|||
/** Currently set debug flags. */
|
||||
std::bitset<__NUM_DEBUG_FLAGS> debug_flags_;
|
||||
|
||||
typedef std::list<arrow*> arrows_list_t;
|
||||
typedef std::map<map_location, arrows_list_t > arrows_map_t;
|
||||
/** Maps the list of arrows for each location */
|
||||
arrows_map_t arrows_map_;
|
||||
std::map<map_location, std::list<arrow*>> arrows_map_;
|
||||
|
||||
tod_color color_adjust_;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue