Skip to content

Commit

Permalink
Only recalculate seen cache when necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade committed Jun 11, 2019
1 parent a30c173 commit 70d51a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
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 @@ -7781,11 +7781,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 @@ -7811,6 +7811,7 @@ void map::build_floor_cache( const int zlev )
}

ch.floor_cache_dirty = false;
return zlevels;
}

void map::build_floor_caches()
Expand All @@ -7826,10 +7827,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 @@ -7876,10 +7878,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

0 comments on commit 70d51a1

Please sign in to comment.