Skip to content

Commit

Permalink
Only cast down if there's a chance of revealing something.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade authored Sep 30, 2020
1 parent f08120b commit 58d6d54
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 128 deletions.
6 changes: 5 additions & 1 deletion src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ void map::build_seen_cache( const tripoint &origin, const int target_z )
array_of_grids_of<const float> transparency_caches;
array_of_grids_of<float> seen_caches;
array_of_grids_of<const bool> floor_caches;
vertical_direction directions_to_cast = vertical_direction::BOTH;
for( int z = -OVERMAP_DEPTH; z <= OVERMAP_HEIGHT; z++ ) {
auto &cur_cache = get_cache( z );
transparency_caches[z + OVERMAP_DEPTH] = &cur_cache.vision_transparency_cache;
Expand All @@ -994,12 +995,15 @@ void map::build_seen_cache( const tripoint &origin, const int target_z )
std::uninitialized_fill_n(
&cur_cache.seen_cache[0][0], map_dimensions, light_transparency_solid );
cur_cache.seen_cache_dirty = false;
if( origin.z == z && cur_cache.no_floor_gaps ) {
directions_to_cast = vertical_direction::UP;
}
}
if( origin.z == target_z ) {
get_cache( origin.z ).seen_cache[origin.x][origin.y] = VISIBILITY_FULL;
}
cast_zlight<float, sight_calc, sight_check, accumulate_transparency>(
seen_caches, transparency_caches, floor_caches, origin, 0, 1.0 );
seen_caches, transparency_caches, floor_caches, origin, 0, 1.0, directions_to_cast );
}

const optional_vpart_position vp = veh_at( origin );
Expand Down
254 changes: 128 additions & 126 deletions src/shadowcasting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,131 +494,131 @@ void cast_zlight(
const array_of_grids_of<T> &output_caches,
const array_of_grids_of<const T> &input_arrays,
const array_of_grids_of<const bool> &floor_caches,
const tripoint &origin, const int offset_distance, const T numerator )
const tripoint &origin, const int offset_distance, const T numerator, vertical_direction dir )
{
// Down lateral

// @..
// ..
// .
cast_horizontal_zlight_segment < 0, 1, 1, 0, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// @
// ..
// ...
cast_horizontal_zlight_segment < 1, 0, 0, 1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .
// ..
// @..
cast_horizontal_zlight_segment < 0, -1, 1, 0, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ...
// ..
// @
cast_horizontal_zlight_segment < -1, 0, 0, 1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..@
// ..
// .
cast_horizontal_zlight_segment < 0, 1, -1, 0, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// @
// ..
// ...
cast_horizontal_zlight_segment < 1, 0, 0, -1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .
// ..
// ..@
cast_horizontal_zlight_segment < 0, -1, -1, 0, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ...
// ..
// @
cast_horizontal_zlight_segment < -1, 0, 0, -1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );

// Up lateral

// @..
// ..
// .
cast_horizontal_zlight_segment < 0, 1, 1, 0, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// @
// ..
// ...
cast_horizontal_zlight_segment < 1, 0, 0, 1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..@
// ..
// .
cast_horizontal_zlight_segment < 0, -1, 1, 0, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// @
// ..
// ...
cast_horizontal_zlight_segment < -1, 0, 0, 1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .
// ..
// @..
cast_horizontal_zlight_segment < 0, 1, -1, 0, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ...
// ..
// @
cast_horizontal_zlight_segment < 1, 0, 0, -1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .
// ..
// ..@
cast_horizontal_zlight_segment < 0, -1, -1, 0, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ...
// ..
// @
cast_horizontal_zlight_segment < -1, 0, 0, -1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );

// Straight up

// @.
// ..
cast_vertical_zlight_segment < 1, 1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..
// @.
cast_vertical_zlight_segment < 1, -1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .@
// ..
cast_vertical_zlight_segment < -1, 1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..
// .@
cast_vertical_zlight_segment < -1, -1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );

// Straight down

// @.
// ..
cast_vertical_zlight_segment < 1, 1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..
// @.
cast_vertical_zlight_segment < 1, -1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .@
// ..
cast_vertical_zlight_segment < -1, 1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..
// .@
cast_vertical_zlight_segment < -1, -1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
if( dir == vertical_direction::DOWN || dir == vertical_direction::BOTH ) {
// Down lateral
// @..
// ..
// .
cast_horizontal_zlight_segment < 0, 1, 1, 0, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// @
// ..
// ...
cast_horizontal_zlight_segment < 1, 0, 0, 1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .
// ..
// @..
cast_horizontal_zlight_segment < 0, -1, 1, 0, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ...
// ..
// @
cast_horizontal_zlight_segment < -1, 0, 0, 1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..@
// ..
// .
cast_horizontal_zlight_segment < 0, 1, -1, 0, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// @
// ..
// ...
cast_horizontal_zlight_segment < 1, 0, 0, -1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .
// ..
// ..@
cast_horizontal_zlight_segment < 0, -1, -1, 0, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ...
// ..
// @
cast_horizontal_zlight_segment < -1, 0, 0, -1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );

// Straight down
// @.
// ..
cast_vertical_zlight_segment < 1, 1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..
// @.
cast_vertical_zlight_segment < 1, -1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .@
// ..
cast_vertical_zlight_segment < -1, 1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..
// .@
cast_vertical_zlight_segment < -1, -1, -1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
}

if( dir == vertical_direction::UP || dir == vertical_direction::BOTH ) {
// Up lateral
// @..
// ..
// .
cast_horizontal_zlight_segment < 0, 1, 1, 0, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// @
// ..
// ...
cast_horizontal_zlight_segment < 1, 0, 0, 1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..@
// ..
// .
cast_horizontal_zlight_segment < 0, -1, 1, 0, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// @
// ..
// ...
cast_horizontal_zlight_segment < -1, 0, 0, 1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .
// ..
// @..
cast_horizontal_zlight_segment < 0, 1, -1, 0, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ...
// ..
// @
cast_horizontal_zlight_segment < 1, 0, 0, -1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .
// ..
// ..@
cast_horizontal_zlight_segment < 0, -1, -1, 0, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ...
// ..
// @
cast_horizontal_zlight_segment < -1, 0, 0, -1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );

// Straight up
// @.
// ..
cast_vertical_zlight_segment < 1, 1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..
// @.
cast_vertical_zlight_segment < 1, -1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// .@
// ..
cast_vertical_zlight_segment < -1, 1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
// ..
// .@
cast_vertical_zlight_segment < -1, -1, 1, T, calc, is_transparent, accumulate > (
output_caches, input_arrays, floor_caches, origin, offset_distance, numerator );
}
}

// I can't figure out how to make implicit instantiation work when the parameters of
Expand All @@ -627,11 +627,13 @@ template void cast_zlight<float, sight_calc, sight_check, accumulate_transparenc
const std::array<float ( * )[MAPSIZE_X][MAPSIZE_Y], OVERMAP_LAYERS> &output_caches,
const std::array<const float ( * )[MAPSIZE_X][MAPSIZE_Y], OVERMAP_LAYERS> &input_arrays,
const std::array<const bool ( * )[MAPSIZE_X][MAPSIZE_Y], OVERMAP_LAYERS> &floor_caches,
const tripoint &origin, const int offset_distance, const float numerator );
const tripoint &origin, const int offset_distance, const float numerator,
vertical_direction dir );

template void cast_zlight<fragment_cloud, shrapnel_calc, shrapnel_check, accumulate_fragment_cloud>(
const std::array<fragment_cloud( * )[MAPSIZE_X][MAPSIZE_Y], OVERMAP_LAYERS> &output_caches,
const std::array<const fragment_cloud( * )[MAPSIZE_X][MAPSIZE_Y], OVERMAP_LAYERS>
&input_arrays,
const std::array<const bool ( * )[MAPSIZE_X][MAPSIZE_Y], OVERMAP_LAYERS> &floor_caches,
const tripoint &origin, const int offset_distance, const fragment_cloud numerator );
const tripoint &origin, const int offset_distance, const fragment_cloud numerator,
vertical_direction dir );
9 changes: 8 additions & 1 deletion src/shadowcasting.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ enum class quadrant : int {
default_ = NE
};

enum class vertical_direction {
UP,
DOWN,
BOTH
};

struct four_quadrants {
four_quadrants() = default;
explicit constexpr four_quadrants( float v ) : values{{v, v, v, v}} {}
Expand Down Expand Up @@ -127,6 +133,7 @@ void cast_zlight(
const array_of_grids_of<T> &output_caches,
const array_of_grids_of<const T> &input_arrays,
const array_of_grids_of<const bool> &floor_caches,
const tripoint &origin, int offset_distance, T numerator );
const tripoint &origin, int offset_distance, T numerator,
vertical_direction dir = vertical_direction::BOTH );

#endif // CATA_SRC_SHADOWCASTING_H

0 comments on commit 58d6d54

Please sign in to comment.