Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix map cache invalidation #31295

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,6 @@ 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.
m.invalidate_map_cache( get_levz() );
m.build_map_cache( get_levz(), true );
monmove();
if( calendar::once_every( 3_minutes ) ) {
Expand Down Expand Up @@ -3148,7 +3147,6 @@ void game::draw()

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

Expand Down
1 change: 0 additions & 1 deletion src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,6 @@ bool game::handle_action()
add_msg( m_info, _( "You can't disassemble items while you're riding." ) );
} else {
u.disassemble();
g->m.invalidate_map_cache( g->get_levz() );
refresh_all();
}
break;
Expand Down
5 changes: 3 additions & 2 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ void map::add_light_from_items( const tripoint &p, std::list<item>::iterator beg
}

// TODO: Consider making this just clear the cache and dynamically fill it in as trans() is called
void map::build_transparency_cache( const int zlev )
bool map::build_transparency_cache( const int zlev )
{
auto &map_cache = get_cache( zlev );
auto &transparency_cache = map_cache.transparency_cache;
auto &outside_cache = map_cache.outside_cache;

if( !map_cache.transparency_cache_dirty ) {
return;
return false;
}

// Default to just barely not transparent.
Expand Down Expand Up @@ -167,6 +167,7 @@ void map::build_transparency_cache( const int zlev )
}
}
map_cache.transparency_cache_dirty = false;
return true;
}

void map::apply_character_light( player &p )
Expand Down
18 changes: 12 additions & 6 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7782,11 +7782,11 @@ void map::build_obstacle_cache( const tripoint &start, const tripoint &end,
}
}

void map::build_floor_cache( const int zlev )
bool map::build_floor_cache( const int zlev )
{
auto &ch = get_cache( zlev );
if( !ch.floor_cache_dirty ) {
return;
return false;
}

auto &floor_cache = ch.floor_cache;
Expand All @@ -7812,6 +7812,7 @@ void map::build_floor_cache( const int zlev )
}

ch.floor_cache_dirty = false;
return zlevels;
}

void map::build_floor_caches()
Expand All @@ -7827,10 +7828,11 @@ void map::build_map_cache( const int zlev, bool skip_lightmap )
{
const int minz = zlevels ? -OVERMAP_DEPTH : zlev;
const int maxz = zlevels ? OVERMAP_HEIGHT : zlev;
bool seen_cache_dirty = false;
for( int z = minz; z <= maxz; z++ ) {
build_outside_cache( z );
build_transparency_cache( z );
build_floor_cache( z );
seen_cache_dirty |= build_transparency_cache( z );
seen_cache_dirty |= build_floor_cache( z );
}

tripoint start( 0, 0, minz );
Expand Down Expand Up @@ -7877,10 +7879,14 @@ void map::build_map_cache( const int zlev, bool skip_lightmap )
const tripoint &p = g->u.pos();
if( ( has_furn( p ) && !furn( p ).obj().transparent ) || !ter( p ).obj().transparent ) {
get_cache( p.z ).transparency_cache[p.x][p.y] = LIGHT_TRANSPARENCY_CLEAR;
set_transparency_cache_dirty( p.z );
}

build_seen_cache( g->u.pos(), zlev );
// Initial value is illegal player position.
static tripoint player_prev_pos = tripoint_zero;
if( seen_cache_dirty || player_prev_pos != p ) {
build_seen_cache( g->u.pos(), zlev );
player_prev_pos = p;
}
if( !skip_lightmap ) {
generate_lightmap( zlev );
}
Expand Down
8 changes: 6 additions & 2 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1463,11 +1463,15 @@ class map
void draw_connections( const oter_id &terrain_type, mapgendata &dat, const time_point &when,
const float density );

void build_transparency_cache( int zlev );
// Builds a transparency cache and returns true if the cache was invalidated.
// Used to determine if seen cache should be rebuilt.
bool build_transparency_cache( int zlev );
void build_sunlight_cache( int zlev );
public:
void build_outside_cache( int zlev );
void build_floor_cache( int zlev );
// Builds a floor cache and returns true if the cache was invalidated.
// Used to determine if seen cache should be rebuilt.
bool build_floor_cache( int zlev );
// We want this visible in `game`, because we want it built earlier in the turn than the rest
void build_floor_caches();

Expand Down