From 241fc807aa838616ee9b4505b13c899f763bd516 Mon Sep 17 00:00:00 2001 From: Kevin Granade Date: Mon, 23 Dec 2019 19:51:15 +0000 Subject: [PATCH] Overhaul map memory cache for tiles. --- src/cata_tiles.cpp | 19 +++++++++++-------- src/map.h | 8 ++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 766eccacfd0ef..9562a0d95d826 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1353,10 +1353,13 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int would_apply_vision_effects( g->m.get_visibility( ch.visibility_cache[np.x][np.y], cache ) ); } //calling draw to memorize everything. - draw_terrain( p, lighting, height_3d, invisible ); - draw_furniture( p, lighting, height_3d, invisible ); - draw_trap( p, lighting, height_3d, invisible ); - draw_vpart( p, lighting, height_3d, invisible ); + if( g->m.check_seen_cache( p ) ) { + draw_terrain( p, lighting, height_3d, invisible ); + draw_furniture( p, lighting, height_3d, invisible ); + draw_trap( p, lighting, height_3d, invisible ); + draw_vpart( p, lighting, height_3d, invisible ); + g->m.check_and_set_seen_cache( p ); + } } } @@ -2176,7 +2179,7 @@ bool cata_tiles::draw_terrain( const tripoint &p, const lit_level ll, int &heigh // do something to get other terrain orientation values } const std::string &tname = t.id().str(); - if( g->m.check_and_set_seen_cache( p ) ) { + if( g->m.check_seen_cache( p ) ) { g->u.memorize_tile( g->m.getabs( p ), tname, subtile, rotation ); } // draw the actual terrain if there's no override @@ -2340,7 +2343,7 @@ bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &hei int rotation = 0; get_tile_values( f, neighborhood, subtile, rotation ); const std::string &fname = f.id().str(); - if( g->m.check_and_set_seen_cache( p ) ) { + if( g->m.check_seen_cache( p ) ) { g->u.memorize_tile( g->m.getabs( p ), fname, subtile, rotation ); } // draw the actual furniture if there's no override @@ -2414,7 +2417,7 @@ bool cata_tiles::draw_trap( const tripoint &p, const lit_level ll, int &height_3 int rotation = 0; get_tile_values( tr, neighborhood, subtile, rotation ); const std::string trname = tr.id().str(); - if( g->m.check_and_set_seen_cache( p ) ) { + if( g->m.check_seen_cache( p ) ) { g->u.memorize_tile( g->m.getabs( p ), trname, subtile, rotation ); } // draw the actual trap if there's no override @@ -2580,7 +2583,7 @@ bool cata_tiles::draw_vpart( const tripoint &p, lit_level ll, int &height_3d, const int rotation = veh.face.dir(); const std::string vpname = "vp_" + vp_id.str(); if( !veh.forward_velocity() && !veh.player_in_control( g->u ) && - g->m.check_and_set_seen_cache( p ) ) { + g->m.check_seen_cache( p ) ) { g->u.memorize_tile( g->m.getabs( p ), vpname, subtile, rotation ); } if( !overridden ) { diff --git a/src/map.h b/src/map.h index c2a1ff55baef2..46eb2974dc121 100644 --- a/src/map.h +++ b/src/map.h @@ -265,6 +265,14 @@ class map } } + bool check_seen_cache( const tripoint &p ) const { + std::bitset &memory_seen_cache = + get_cache( p.z ).map_memory_seen_cache; + if( !memory_seen_cache[ static_cast( p.x + p.y * MAPSIZE_Y ) ] ) { + return true; + } + return false; + } bool check_and_set_seen_cache( const tripoint &p ) const { std::bitset &memory_seen_cache = get_cache( p.z ).map_memory_seen_cache;