Skip to content

Commit

Permalink
Merge pull request #36392 from kevingranade/overhaul-tiles-map-memory
Browse files Browse the repository at this point in the history
Overhaul map memory cache for tiles.
  • Loading branch information
ZhilkinSerg authored Dec 24, 2019
2 parents 03c1b4c + 241fc80 commit 62c50b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,10 +1353,13 @@ void cata_tiles::draw( const point &dest, const tripoint &center, 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 );
}
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ) {
Expand Down
8 changes: 8 additions & 0 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ class map
}
}

bool check_seen_cache( const tripoint &p ) const {
std::bitset<MAPSIZE_X *MAPSIZE_Y> &memory_seen_cache =
get_cache( p.z ).map_memory_seen_cache;
if( !memory_seen_cache[ static_cast<size_t>( p.x + p.y * MAPSIZE_Y ) ] ) {
return true;
}
return false;
}
bool check_and_set_seen_cache( const tripoint &p ) const {
std::bitset<MAPSIZE_X *MAPSIZE_Y> &memory_seen_cache =
get_cache( p.z ).map_memory_seen_cache;
Expand Down

0 comments on commit 62c50b3

Please sign in to comment.