Skip to content

Commit

Permalink
Merge pull request #77193 from PatrikLundell/lightmap
Browse files Browse the repository at this point in the history
Addressed light map adjustments resulting in no net change dirtying c…
  • Loading branch information
Maleclypse authored Oct 22, 2024
2 parents b246d05 + 9806ed7 commit 8f226e5
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,57 +191,59 @@ bool map::build_transparency_cache( const int zlev )
return true;
}

bool map::build_vision_transparency_cache( const int zlev )
bool map::build_vision_transparency_cache( int zlev )
{
level_cache &map_cache = get_cache( zlev );
auto &transparency_cache = map_cache.transparency_cache;
auto &vision_transparency_cache = map_cache.vision_transparency_cache;

memcpy( &vision_transparency_cache, &transparency_cache, sizeof( transparency_cache ) );
cata::mdarray<float, point_bub_ms> &transparency_cache = map_cache.transparency_cache;
cata::mdarray<float, point_bub_ms> &vision_transparency_cache = map_cache.vision_transparency_cache;

Character &player_character = get_player_character();
const tripoint_bub_ms p = player_character.pos_bub();

if( p.z() != zlev ) {
// Just copy the transparency cache and be done with it.
memcpy( &vision_transparency_cache, &transparency_cache, sizeof( transparency_cache ) );
return false;
}

bool dirty = false;

std::vector<tripoint_bub_ms> solid_tiles;

// This segment handles vision when the player is crouching or prone. It only checks adjacent tiles.
// If you change this, also consider creature::sees and map::obstacle_coverage.
bool is_crouching = player_character.is_crouching();
bool low_profile = player_character.has_effect( effect_quadruped_full ) &&
player_character.is_running();
bool is_prone = player_character.is_prone();
static move_mode_id previous_move_mode = player_character.current_movement_mode();

for( const tripoint_bub_ms &loc : points_in_radius( p, 1 ) ) {
if( loc == p ) {
// The tile player is standing on should always be visible
vision_transparency_cache[p.x()][p.y()] = LIGHT_TRANSPARENCY_OPEN_AIR;
} else if( ( is_crouching || is_prone || low_profile ) && coverage( loc ) >= 30 ) {
// If we're crouching or prone behind an obstacle, we can't see past it.
if( vision_transparency_cache[loc.x()][loc.y()] != LIGHT_TRANSPARENCY_SOLID ||
previous_move_mode != player_character.current_movement_mode() ) {
previous_move_mode = player_character.current_movement_mode();
vision_transparency_cache[loc.x()][loc.y()] = LIGHT_TRANSPARENCY_SOLID;
dirty = true;
const bool is_crouching = player_character.is_crouching();
const bool low_profile = player_character.has_effect( effect_quadruped_full ) &&
player_character.is_running();
const bool is_prone = player_character.is_prone();

if( is_crouching || is_prone || low_profile ) {
for( const tripoint_bub_ms &loc : points_in_radius( p, 1 ) ) {
if( loc != p && coverage( loc ) >= 30 ) {
// If we're crouching or prone behind an obstacle, we can't see past it.
dirty |= vision_transparency_cache[loc.x()][loc.y()] != LIGHT_TRANSPARENCY_SOLID;
solid_tiles.emplace_back( loc );
}
}
}

// This segment handles blocking vision through TRANSLUCENT flagged terrain.
for( const tripoint_bub_ms &loc : points_in_radius( p, MAX_VIEW_DISTANCE ) ) {
if( loc == p ) {
// The tile player is standing on should always be visible
vision_transparency_cache[p.x()][p.y()] = LIGHT_TRANSPARENCY_OPEN_AIR;
} else if( map::ter( loc ).obj().has_flag( ter_furn_flag::TFLAG_TRANSLUCENT ) ) {
vision_transparency_cache[loc.x()][loc.y()] = LIGHT_TRANSPARENCY_SOLID;
dirty = true;
if( map::ter( loc ).obj().has_flag( ter_furn_flag::TFLAG_TRANSLUCENT ) && loc != p ) {
dirty |= vision_transparency_cache[loc.x()][loc.y()] != LIGHT_TRANSPARENCY_SOLID;
solid_tiles.emplace_back( loc );
}
}

memcpy( &vision_transparency_cache, &transparency_cache, sizeof( transparency_cache ) );

// The tile player is standing on should always be visible
vision_transparency_cache[p.x()][p.y()] = LIGHT_TRANSPARENCY_OPEN_AIR;

for( const tripoint_bub_ms loc : solid_tiles ) {
vision_transparency_cache[loc.x()][loc.y()] = LIGHT_TRANSPARENCY_SOLID;
}

return dirty;
}

Expand Down

0 comments on commit 8f226e5

Please sign in to comment.