MCPcopy Create free account
hub / github.com/CleverRaven/Cataclysm-DDA / update_visibility_cache

Method update_visibility_cache

src/map.cpp:5852–5896  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5850}
5851
5852void map::update_visibility_cache( const int zlev )
5853{
5854 Character &player_character = get_player_character();
5855 visibility_variables_cache.variables_set = true; // Not used yet
5856 visibility_variables_cache.g_light_level = static_cast<int>( g->light_level( zlev ) );
5857 visibility_variables_cache.vision_threshold = player_character.get_vision_threshold(
5858 get_cache_ref(
5859 player_character.posz() ).lm[player_character.posx()][player_character.posy()].max() );
5860
5861 visibility_variables_cache.u_clairvoyance = player_character.clairvoyance();
5862 visibility_variables_cache.u_sight_impaired = player_character.sight_impaired();
5863 visibility_variables_cache.u_is_boomered = player_character.has_effect( effect_boomered );
5864 visibility_variables_cache.clairvoyance_field.reset();
5865 if( field_fd_clairvoyant.is_valid() ) {
5866 visibility_variables_cache.clairvoyance_field = field_fd_clairvoyant;
5867 }
5868
5869 int sm_squares_seen[MAPSIZE][MAPSIZE];
5870 std::memset( sm_squares_seen, 0, sizeof( sm_squares_seen ) );
5871
5872 auto &visibility_cache = get_cache( zlev ).visibility_cache;
5873
5874 tripoint p;
5875 p.z = zlev;
5876 int &x = p.x;
5877 int &y = p.y;
5878 for( x = 0; x < MAPSIZE_X; x++ ) {
5879 for( y = 0; y < MAPSIZE_Y; y++ ) {
5880 lit_level ll = apparent_light_at( p, visibility_variables_cache );
5881 visibility_cache[x][y] = ll;
5882 sm_squares_seen[ x / SEEX ][ y / SEEY ] += ( ll == lit_level::BRIGHT || ll == lit_level::LIT );
5883 }
5884 }
5885
5886 for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) {
5887 for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) {
5888 if( sm_squares_seen[gridx][gridy] > 36 ) { // 25% of the submap is visible
5889 const tripoint sm( gridx, gridy, 0 );
5890 const tripoint_abs_sm abs_sm = map::abs_sub + sm;
5891 const tripoint_abs_omt abs_omt = project_to<coords::omt>( abs_sm );
5892 overmap_buffer.set_seen( abs_omt, true );
5893 }
5894 }
5895 }
5896}
5897
5898const visibility_variables &map::get_visibility_variables_cache() const
5899{

Callers 8

drawMethod · 0.80
look_aroundMethod · 0.80
get_player_inputMethod · 0.80
test_allMethod · 0.80
update_cacheFunction · 0.80
reset_cachesFunction · 0.80
set_timeFunction · 0.80

Calls 12

light_levelMethod · 0.80
get_vision_thresholdMethod · 0.80
clairvoyanceMethod · 0.80
sight_impairedMethod · 0.80
set_seenMethod · 0.80
maxMethod · 0.45
poszMethod · 0.45
posxMethod · 0.45
posyMethod · 0.45
has_effectMethod · 0.45
resetMethod · 0.45
is_validMethod · 0.45

Tested by 3

test_allMethod · 0.64
update_cacheFunction · 0.64
reset_cachesFunction · 0.64