From cdeb995a4112950c128f83dfdb8fc70a8eebd36a Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 19 Dec 2024 20:16:41 +0000 Subject: [PATCH] Handle overmap editor place terrain/special lag --- src/overmap_ui.cpp | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index 4d14464f08809..6f611980237b2 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -55,6 +55,7 @@ #include "overmap_types.h" #include "overmapbuffer.h" #include "point.h" +#include "popup.h" #include "regional_settings.h" #include "rng.h" #include "sounds.h" @@ -543,7 +544,7 @@ static bool get_and_assign_los( int &los, avatar &player_character, const tripoi return los; } -static std::unordered_set generated_omts; +static std::unordered_map generated_omts; static void build_generated_omts() { @@ -551,20 +552,26 @@ static void build_generated_omts() const int om_map_height = OVERMAP_WINDOW_HEIGHT; const int om_half_width = om_map_width / 2; const int om_half_height = om_map_height / 2; - const tripoint_abs_omt corner = g->overmap_data.cursor_pos - point_rel_omt( om_half_width, - om_half_height ); + const point_abs_omt corner = g->overmap_data.cursor_pos.xy() - point_rel_omt( om_half_width, + om_half_height ); for( int i = 0; i < om_map_width; ++i ) { for( int j = 0; j < om_map_height; ++j ) { - const tripoint_abs_omt omp = corner + point_rel_omt( i, j ); - if( MAPBUFFER.submap_exists( project_to( omp ) ) ) { - generated_omts.insert( omp.xy() ); - } + const point_abs_omt omp = corner + point_rel_omt( i, j ); + generated_omts.insert( { omp, MAPBUFFER.submap_exists( { project_to( omp ), 0 } ) } ); } } } -static void draw_ascii( - const catacurses::window &w, overmap_draw_data_t &data ) +static bool update_generated_omts( const point_abs_omt &omp ) +{ + if( generated_omts.find( omp ) == generated_omts.end() ) { + generated_omts.insert( { omp, MAPBUFFER.submap_exists( { project_to( omp ), 0 } ) } ); + return true; + } + return false; +} + +static void draw_ascii( const catacurses::window &w, overmap_draw_data_t &data ) { const tripoint_abs_omt &orig = data.origin_pos; const tripoint_abs_omt &cursor_pos = data.cursor_pos; @@ -816,7 +823,9 @@ static void draw_ascii( } } // Highlight areas that already have been generated - if( generated_omts.find( omp.xy() ) != generated_omts.end() ) { + const auto it = generated_omts.find( omp.xy() ); + const bool found = it != generated_omts.end(); + if( ( found && it->second ) || ( !found && update_generated_omts( omp.xy() ) ) ) { ter_color = red_background( ter_color ); } } @@ -1485,6 +1494,15 @@ static void place_ter_or_special( const ui_adaptor &om_ui, tripoint_abs_omt &cur std::vector oslist; const bool terrain = om_action == "PLACE_TERRAIN"; + //add_msg( m_info, _( "Hang on a bit…" ) ); + // + //static_popup popup; + //popup.message( "%s", _( "Hang on a bit…" ) ); + //ui_manager::redraw(); + //refresh_display(); + + build_generated_omts(); + if( terrain ) { pmenu.title = _( "Select terrain to place:" ); for( const oter_t &oter : overmap_terrains::get_all() ) { @@ -1589,8 +1607,6 @@ static void place_ter_or_special( const ui_adaptor &om_ui, tripoint_abs_omt &cur wnoutrefresh( w_editor ); } ); - build_generated_omts(); - std::string action; do { om_ui.invalidate_ui(); @@ -1630,7 +1646,6 @@ static void place_ter_or_special( const ui_adaptor &om_ui, tripoint_abs_omt &cur } } while( action != "CONFIRM" && action != "QUIT" ); - generated_omts.clear(); uistate.place_terrain = nullptr; uistate.place_special = nullptr; } @@ -2592,6 +2607,7 @@ std::optional ui::omap::select_city( uilist &cities_menu, void ui::omap::force_quit() { + overmap_ui::generated_omts.clear(); g->overmap_data.ui.reset(); g->overmap_data.fast_traveling = false; }