Skip to content

Commit

Permalink
fix performance of the map view after reading a map
Browse files Browse the repository at this point in the history
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 CleverRaven#70540
  • Loading branch information
db48x committed Jan 1, 2024
1 parent 0e820db commit 0e7ff3d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ class Character : public Creature, public visitable
// route for overmap-scale traveling
std::vector<tripoint_abs_omt> omt_path;
// Container of OMTs to highlight as having been revealed
std::vector<tripoint_abs_omt> map_revealed_omts;
std::unordered_set<tripoint_abs_omt> map_revealed_omts;
bool is_using_bionic_weapon() const;
bionic_uid get_weapon_bionic_uid() const;

Expand Down
2 changes: 1 addition & 1 deletion src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ void reveal_map_actor::reveal_targets( const tripoint_abs_omt &center,
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 );
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/overmap_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,7 @@ static void draw_ascii(
size_t count = 0;
};
std::unordered_set<tripoint_abs_omt> npc_path_route;
std::unordered_set<tripoint_abs_omt> newly_revealed( player_character.map_revealed_omts.begin(),
player_character.map_revealed_omts.end() ) ;
std::unordered_set<tripoint_abs_omt> &revealed_highlights = get_avatar().map_revealed_omts;
std::unordered_map<point_abs_omt, int> player_path_route;
std::unordered_map<tripoint_abs_omt, npc_coloring> npc_color;
auto npcs_near_player = overmap_buffer.get_npcs_near_player( sight_points );
Expand Down Expand Up @@ -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 &&
Expand Down
10 changes: 6 additions & 4 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_
100;
const bool showhordes = uistate.overmap_show_hordes;
const bool show_map_revealed = uistate.overmap_show_revealed_omts;
std::unordered_set<tripoint_abs_omt> &revealed_highlights = get_avatar().map_revealed_omts;
const bool viewing_weather = uistate.overmap_debug_weather || uistate.overmap_visible_weather;
o = origin.raw().xy();

Expand Down Expand Up @@ -925,10 +926,11 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_
0, 0, ll, false );
}

std::vector<tripoint_abs_omt> &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 ) {
Expand Down

0 comments on commit 0e7ff3d

Please sign in to comment.