Skip to content

Commit

Permalink
Map cache invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg committed Apr 20, 2019
1 parent 3fae041 commit b75c702
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,7 @@ void activity_handlers::vehicle_finish( player_activity *act, player *p )
act->values.size() );
} else {
if( vp ) {
g->invalidate_map_cache();
g->refresh_all();
// TODO: Z (and also where the activity is queued)
// Or not, because the vehicle coordinates are dropped anyway
Expand Down Expand Up @@ -2512,6 +2513,7 @@ void activity_handlers::meditate_finish( player_activity *act, player *p )
void activity_handlers::aim_do_turn( player_activity *act, player * )
{
if( act->index == 0 ) {
g->invalidate_map_cache();
g->m.build_map_cache( g->get_levz() );
g->plfire();
}
Expand Down
2 changes: 2 additions & 0 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ bool player::uninstall_bionic( const bionic_id &b_id, player &installer, bool au
}
bionics_uninstall_failure( installer, difficulty, success, adjusted_skill );
}
g->invalidate_map_cache();
g->refresh_all();
return true;
}
Expand Down Expand Up @@ -1133,6 +1134,7 @@ bool player::install_bionics( const itype &type, player &installer, bool autodoc
}
bionics_install_failure( installer, difficult, success, adjusted_skill );
}
g->invalidate_map_cache();
g->refresh_all();
return true;
}
Expand Down
62 changes: 35 additions & 27 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ void game::init_ui( const bool resized )
// Only refresh if we are in-game, otherwise all resources are not initialized
// and this refresh will crash the game.
if( resized && u.getID() != -1 ) {
refresh_all();
g->refresh_all();
}
}

Expand All @@ -533,10 +533,10 @@ void game::toggle_fullscreen()
#if !defined(TILES)
fullscreen = !fullscreen;
init_ui();
refresh_all();
g->refresh_all();
#else
toggle_fullscreen_window();
refresh_all();
g->refresh_all();
#endif
}

Expand All @@ -548,7 +548,7 @@ void game::toggle_pixel_minimap()
}
pixel_minimap_option = !pixel_minimap_option;
init_ui();
refresh_all();
g->refresh_all();
#endif // TILES
}

Expand Down Expand Up @@ -699,10 +699,12 @@ bool game::start_game()
lev.y -= HALF_MAPSIZE;
load_map( lev );

g->invalidate_map_cache();
m.build_map_cache( get_levz() );
// Do this after the map cache has been built!
start_loc.place_player( u );
// ...but then rebuild it, because we want visibility cache to avoid spawning monsters in sight
g->invalidate_map_cache();
m.build_map_cache( get_levz() );
// Start the overmap with out immediate neighborhood visible, this needs to be after place_player
overmap_buffer.reveal( point( u.global_omt_location().x, u.global_omt_location().y ),
Expand Down Expand Up @@ -1460,6 +1462,7 @@ bool game::do_turn()
sounds::process_sounds();
// Update vision caches for monsters. If this turns out to be expensive,
// consider a stripped down cache just for monsters.
g->invalidate_map_cache();
m.build_map_cache( get_levz(), true );
monmove();
if( calendar::once_every( 3_minutes ) ) {
Expand Down Expand Up @@ -1922,13 +1925,12 @@ void game::handle_key_blocking_activity()
cancel_activity_query( _( "Confirm:" ) );
} else if( action == "player_data" ) {
u.disp_info();
refresh_all();
} else if( action == "messages" ) {
Messages::display_messages();
refresh_all();
g->refresh_all();
} else if( action == "help" ) {
get_help().display_help();
refresh_all();
g->refresh_all();
}
}
}
Expand Down Expand Up @@ -2923,7 +2925,7 @@ void game::debug()
_( "Toggle NPC pathfinding on map" ), // 37
_( "Quit to Main Menu" ), // 38
} );
refresh_all();
g->refresh_all();
switch( action ) {
case 0:
debug_menu::wishitem( &u );
Expand Down Expand Up @@ -3354,7 +3356,8 @@ void game::debug()
break;
}
catacurses::erase();
refresh_all();
g->invalidate_map_cache();
g->refresh_all();
}

void game::disp_kills()
Expand Down Expand Up @@ -3411,7 +3414,7 @@ void game::disp_kills()
}
display_table( w, buffer.str(), 3, data );

refresh_all();
g->refresh_all();
}

void game::disp_NPC_epilogues()
Expand All @@ -3434,7 +3437,7 @@ void game::disp_NPC_epilogues()
multipage( w, txt, "", 2 );
}

refresh_all();
g->refresh_all();
}

void game::disp_faction_ends()
Expand Down Expand Up @@ -3533,7 +3536,7 @@ there was nothing left to fight for... just endless cities full of the dead." )
data.clear();
}

refresh_all();
g->refresh_all();
}

struct npc_dist_to_player {
Expand Down Expand Up @@ -3596,6 +3599,7 @@ void game::draw()

//temporary fix for updating visibility for minimap
ter_view_z = ( u.pos() + u.view_offset ).z;
g->invalidate_map_cache();
m.build_map_cache( ter_view_z );
m.update_visibility_cache( ter_view_z );

Expand Down Expand Up @@ -5059,7 +5063,7 @@ void game::use_computer( const tripoint &p )

used->use();

refresh_all();
g->refresh_all();
}

void game::resonance_cascade( const tripoint &p )
Expand Down Expand Up @@ -5695,7 +5699,7 @@ void game::use_item( int pos )
}
}

refresh_all();
g->refresh_all();

if( use_loc ) {
update_lum( loc.clone(), false );
Expand Down Expand Up @@ -6214,7 +6218,7 @@ void game::peek()
{
const cata::optional<tripoint> p = choose_direction( _( "Peek where?" ), true );
if( !p ) {
refresh_all();
g->refresh_all();
return;
}

Expand Down Expand Up @@ -7091,7 +7095,7 @@ void game::zones_manager()
u.view_offset = stored_view_offset;
pixel_minimap_option = stored_pm_opt;

refresh_all();
g->refresh_all();
}

void game::pre_print_all_tile_info( const tripoint &lp, const catacurses::window &w_info,
Expand Down Expand Up @@ -7287,7 +7291,8 @@ look_around_result game::look_around( catacurses::window w_info, tripoint &cente

add_msg( m_debug, "levx: %d, levy: %d, levz :%d", get_levx(), get_levy(), center.z );
u.view_offset.z = center.z - u.posz();
refresh_all();
g->invalidate_map_cache();
g->refresh_all();
if( select_zone && has_first_point ) { // is blinking
blink = true; // Always draw blink symbols when moving cursor
}
Expand Down Expand Up @@ -7399,6 +7404,7 @@ look_around_result game::look_around( catacurses::window w_info, tripoint &cente
action != "throw_blind" );

if( m.has_zlevels() && center.z != old_levz ) {
g->invalidate_map_cache();
m.build_map_cache( old_levz );
u.view_offset.z = 0;
}
Expand Down Expand Up @@ -7643,7 +7649,7 @@ void game::reset_item_list_state( const catacurses::window &window, int height,
xpos += shortcut_print( window, ypos, xpos, c_white, c_light_green, tokens[i] ) + gap_spaces;
}

refresh_all();
g->refresh_all();
}

void game::list_items_monsters()
Expand Down Expand Up @@ -7685,7 +7691,7 @@ void game::list_items_monsters()
}
}

refresh_all();
g->refresh_all();
if( ret == game::vmenu_ret::FIRE ) {
plfire( u.weapon );
}
Expand Down Expand Up @@ -7773,7 +7779,7 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
if( action == "COMPARE" ) {
game_menus::inv::compare( u, active_pos );
reset = true;
refresh_all();
g->refresh_all();
} else if( action == "FILTER" ) {
draw_item_filter_rules( w_item_info, 0, iInfoHeight - 1, item_filter_type::FILTER );
string_input_popup()
Expand Down Expand Up @@ -8543,7 +8549,7 @@ bool game::get_liquid_target( item &liquid, item *const source, const int radius

const std::string liqstr = string_format( _( "Pour %s where?" ), liquid_name );

refresh_all();
g->refresh_all();
const cata::optional<tripoint> target_pos_ = choose_adjacent( liqstr );
if( !target_pos_ ) {
return;
Expand Down Expand Up @@ -8571,7 +8577,7 @@ bool game::get_liquid_target( item &liquid, item *const source, const int radius
}

menu.query();
refresh_all();
g->refresh_all();
if( menu.ret < 0 || static_cast<size_t>( menu.ret ) >= actions.size() ) {
add_msg( _( "Never mind." ) );
// Explicitly canceled all options (container, drink, pour).
Expand Down Expand Up @@ -8707,7 +8713,7 @@ void game::drop()
void game::drop_in_direction()
{
if( const cata::optional<tripoint> pnt = choose_adjacent( _( "Drop where?" ) ) ) {
refresh_all();
g->refresh_all();
u.drop( game_menus::inv::multidrop( u ), *pnt );
}
}
Expand All @@ -8721,7 +8727,7 @@ void game::plthrow( int pos, const cata::optional<tripoint> &blind_throw_from_po

if( pos == INT_MIN ) {
pos = inv_for_all( _( "Throw item" ), _( "You don't have any items to throw." ) );
refresh_all();
g->refresh_all();
}

if( pos == INT_MIN ) {
Expand Down Expand Up @@ -8948,7 +8954,7 @@ bool game::plfire()
args.ammo = gun->ammo_data();
u.set_targeting_data( args );

refresh_all();
g->refresh_all();
}
}

Expand Down Expand Up @@ -9615,7 +9621,7 @@ void game::reload( item_location &loc, bool prompt, bool empty )
u.activity.targets.push_back( std::move( opt.ammo ) );
}

refresh_all();
g->refresh_all();
}


Expand Down Expand Up @@ -11672,7 +11678,8 @@ void game::vertical_move( int movez, bool force )
}
}

refresh_all();
g->invalidate_map_cache();
g->refresh_all();
// Upon force movement, traps can not be avoided.
m.creature_on_trap( u, !force );
}
Expand Down Expand Up @@ -11948,6 +11955,7 @@ point game::update_map( int &x, int &y )
load_npcs();

// Make sure map cache is consistent since it may have shifted.
g->invalidate_map_cache();
m.build_map_cache( get_levz() );

// Spawn monsters if appropriate
Expand Down
4 changes: 4 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ class game
int assign_npc_id();
Creature *is_hostile_nearby();
Creature *is_hostile_very_close();
bool is_map_cache_valid = false;
inline void invalidate_map_cache() {
g->is_map_cache_valid = false;
}
void refresh_all();
// Handles shifting coordinates transparently when moving between submaps.
// Helper to make calling with a player pointer less verbose.
Expand Down
Loading

0 comments on commit b75c702

Please sign in to comment.