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

Addressed light map adjustments resulting in no net change dirtying c… #77193

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
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
Loading