From 9806ed794a8ae064107449123a5f0cabb174db50 Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Sun, 20 Oct 2024 13:39:00 +0200 Subject: [PATCH] Addressed light map adjustments resulting in no net change dirtying cache --- src/lightmap.cpp | 58 +++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/lightmap.cpp b/src/lightmap.cpp index 0b4d529e9c370..cf86c8cfe4b18 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -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 &transparency_cache = map_cache.transparency_cache; + cata::mdarray &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 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; }