Skip to content

Commit

Permalink
Handle overmap editor place terrain/special lag
Browse files Browse the repository at this point in the history
  • Loading branch information
Procyonae committed Dec 20, 2024
1 parent 243c86b commit cdeb995
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/overmap_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -543,28 +544,34 @@ static bool get_and_assign_los( int &los, avatar &player_character, const tripoi
return los;
}

static std::unordered_set<point_abs_omt> generated_omts;
static std::unordered_map<point_abs_omt, bool> generated_omts;

static void build_generated_omts()
{
const int om_map_width = OVERMAP_WINDOW_WIDTH;
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<coords::sm>( 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<coords::sm>( 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<coords::sm>( 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;
Expand Down Expand Up @@ -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 );
}
}
Expand Down Expand Up @@ -1485,6 +1494,15 @@ static void place_ter_or_special( const ui_adaptor &om_ui, tripoint_abs_omt &cur
std::vector<const overmap_special *> 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() ) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -2592,6 +2607,7 @@ std::optional<city> 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;
}

0 comments on commit cdeb995

Please sign in to comment.