Skip to content

Commit

Permalink
Rapidly changing light levels do not grant max vision to turrets (#51815
Browse files Browse the repository at this point in the history
)
  • Loading branch information
RoyBerube authored Sep 23, 2021
1 parent 2068418 commit 06ba8c6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ bool Creature::sees( const tripoint &t, bool is_avatar, int range_mod ) const
const int wanted_range = rl_dist( pos(), t );
if( wanted_range <= range_min ||
( wanted_range <= range_max &&
here.ambient_light_at( t ) > g->natural_light_level( t.z ) ) ) {
here.ambient_light_at( t ) > here.get_cache_ref( t.z ).natural_light_level_cache ) ) {
int range = 0;
if( here.ambient_light_at( t ) > g->natural_light_level( t.z ) ) {
if( here.ambient_light_at( t ) > here.get_cache_ref( t.z ).natural_light_level_cache ) {
range = MAX_VIEW_DISTANCE;
} else {
range = range_min;
Expand Down
3 changes: 3 additions & 0 deletions src/level_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ struct level_cache {
// This is only valid for the duration of generate_lightmap
float light_source_buffer[MAPSIZE_X][MAPSIZE_Y];

// Cache of natural light level is useful if it needs to be in sync with the light cache.
float natural_light_level_cache;

// if false, means tile is under the roof ("inside"), true means tile is "outside"
// "inside" tiles are protected from sun, rain, etc. (see ter_furn_flag::TFLAG_INDOORS flag)
bool outside_cache[MAPSIZE_X][MAPSIZE_Y];
Expand Down
1 change: 1 addition & 0 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ void map::build_sunlight_cache( int pzlev )
for( int zlev = zlev_max; zlev >= zlev_min; zlev-- ) {

level_cache &map_cache = get_cache( zlev );
map_cache.natural_light_level_cache = g->natural_light_level( zlev );
auto &lm = map_cache.lm;
// Grab illumination at ground level.
const float outside_light_level = g->natural_light_level( 0 );
Expand Down

0 comments on commit 06ba8c6

Please sign in to comment.