From e7b3f59731119a639be6bdd86d863e84893c4967 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sat, 31 Aug 2024 15:29:41 -0400 Subject: [PATCH] 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. --- src/arrow.cpp | 13 ++++++------- src/arrow.hpp | 4 +--- src/display.cpp | 14 ++++++++++---- src/display.hpp | 4 +--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/arrow.cpp b/src/arrow.cpp index 7e615c0f259..8b8b46bc8c3 100644 --- a/src/arrow.cpp +++ b/src/arrow.cpp @@ -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? Practically I don't think this path gets hit } } diff --git a/src/arrow.hpp b/src/arrow.hpp index d90e119b7d0..52fbc0efab1 100644 --- a/src/arrow.hpp +++ b/src/arrow.hpp @@ -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_; diff --git a/src/display.cpp b/src/display.cpp index ff540f7c747..5f3e9df7437 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -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 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 diff --git a/src/display.hpp b/src/display.hpp index 1eb3d922702..616075db36d 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -961,10 +961,8 @@ private: /** Currently set debug flags. */ std::bitset<__NUM_DEBUG_FLAGS> debug_flags_; - typedef std::list arrows_list_t; - typedef std::map arrows_map_t; /** Maps the list of arrows for each location */ - arrows_map_t arrows_map_; + std::map> arrows_map_; tod_color color_adjust_;