From 0e7ff3dbb9a660793c861a7b3b93bd3f3b291a42 Mon Sep 17 00:00:00 2001 From: Daniel Brooks Date: Sun, 31 Dec 2023 23:58:17 -0800 Subject: [PATCH] fix performance of the map view after reading a map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When you read a map, we now keep track of what overmap tiles the map revealed to you, so that we can blink them in the map view. I’ve changed it from a vector of coordinates to an unordered_set, so that membership testing is O(1), greatly improving performance. fixes #70540 --- src/character.h | 2 +- src/iuse_actor.cpp | 2 +- src/overmap_ui.cpp | 7 +++---- src/sdltiles.cpp | 10 ++++++---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/character.h b/src/character.h index 7b3b1d58dafe9..88c02952e66ec 100644 --- a/src/character.h +++ b/src/character.h @@ -1657,7 +1657,7 @@ class Character : public Creature, public visitable // route for overmap-scale traveling std::vector omt_path; // Container of OMTs to highlight as having been revealed - std::vector map_revealed_omts; + std::unordered_set map_revealed_omts; bool is_using_bionic_weapon() const; bionic_uid get_weapon_bionic_uid() const; diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index ad164c6cd8f87..f5cc976da8fb0 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -1193,7 +1193,7 @@ void reveal_map_actor::reveal_targets( const tripoint_abs_omt ¢er, for( const tripoint_abs_omt &place : places ) { overmap_buffer.reveal( place, reveal_distance ); // Should be replaced with the character using the item passed as an argument if NPCs ever learn to use maps - get_avatar().map_revealed_omts.emplace_back( place ); + get_avatar().map_revealed_omts.emplace( place ); } } diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index d86e00065e298..4be77076fb9ee 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -646,8 +646,7 @@ static void draw_ascii( size_t count = 0; }; std::unordered_set npc_path_route; - std::unordered_set newly_revealed( player_character.map_revealed_omts.begin(), - player_character.map_revealed_omts.end() ) ; + std::unordered_set &revealed_highlights = get_avatar().map_revealed_omts; std::unordered_map player_path_route; std::unordered_map npc_color; auto npcs_near_player = overmap_buffer.get_npcs_near_player( sight_points ); @@ -786,8 +785,8 @@ static void draw_ascii( ter_color = c_red; ter_sym = "!"; } else if( blink && show_map_revealed && - newly_revealed.find( omp ) != newly_revealed.end() ) { - // Revealed maps + revealed_highlights.find( omp ) != revealed_highlights.end() ) { + // Revealed map tiles ter_color = c_magenta; ter_sym = "&"; } else if( blink && showhordes && diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 629328a28c3a9..67ae517317e59 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -880,6 +880,7 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ 100; const bool showhordes = uistate.overmap_show_hordes; const bool show_map_revealed = uistate.overmap_show_revealed_omts; + std::unordered_set &revealed_highlights = get_avatar().map_revealed_omts; const bool viewing_weather = uistate.overmap_debug_weather || uistate.overmap_visible_weather; o = origin.raw().xy(); @@ -925,10 +926,11 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_ 0, 0, ll, false ); } - std::vector &revealed_highlights = get_avatar().map_revealed_omts; - auto it = std::find( revealed_highlights.begin(), revealed_highlights.end(), omp ); - if( blink && show_map_revealed && it != revealed_highlights.end() ) { - draw_from_id_string( "highlight", omp.raw(), 0, 0, lit_level::LIT, false ); + if( blink && show_map_revealed ) { + auto it = revealed_highlights.find( omp ); + if( it != revealed_highlights.end() ) { + draw_from_id_string( "highlight", omp.raw(), 0, 0, lit_level::LIT, false ); + } } if( see ) {