Skip to content

Commit

Permalink
Add FOV_3D_Z_RANGE option to limit the vertical range of 3D vision (#…
Browse files Browse the repository at this point in the history
…31802)

* * add FOV_3D_Z_RANGE option. Minimum 0, maximum OVERMAP_LAYERS,
default 4.
* add logic to cast_zlight_segment that allows us to stop casting light
segments beyond FOV_3D_Z_RANGE levels. Decent speedup!
  • Loading branch information
kristleifur authored and kevingranade committed Sep 27, 2019
1 parent 2d7e5c2 commit f561e51
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6639,6 +6639,8 @@ look_around_result game::look_around( catacurses::window w_info, tripoint &cente
ctxt.register_action( "zoom_in" );

const int old_levz = get_levz();
const int min_levz = std::max( old_levz - fov_3d_z_range, -OVERMAP_DEPTH );
const int max_levz = std::min( old_levz + fov_3d_z_range, OVERMAP_HEIGHT );

m.update_visibility_cache( old_levz );
const visibility_variables &cache = g->m.get_visibility_variables_cache();
Expand Down Expand Up @@ -6729,8 +6731,8 @@ look_around_result game::look_around( catacurses::window w_info, tripoint &cente
}

const int dz = ( action == "LEVEL_UP" ? 1 : -1 );
lz = clamp( lz + dz, -OVERMAP_DEPTH, OVERMAP_HEIGHT );
center.z = clamp( center.z + dz, -OVERMAP_DEPTH, OVERMAP_HEIGHT );
lz = clamp( lz + dz, min_levz, max_levz );
center.z = clamp( center.z + dz, min_levz, max_levz );

add_msg( m_debug, "levx: %d, levy: %d, levz :%d", get_levx(), get_levy(), center.z );
u.view_offset.z = center.z - u.posz();
Expand Down
1 change: 1 addition & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern std::unique_ptr<game> g;
extern bool trigdist;
extern bool use_tiles;
extern bool fov_3d;
extern int fov_3d_z_range;
extern bool tile_iso;

extern const int core_version;
Expand Down
2 changes: 1 addition & 1 deletion src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ void cast_zlight_segment(
T current_transparency = 0.0f;

// TODO: Precalculate min/max delta.z based on start/end and distance
for( delta.z = 0; delta.z <= distance; delta.z++ ) {
for( delta.z = 0; delta.z <= std::min( fov_3d_z_range, distance ); delta.z++ ) {
float trailing_edge_major = ( delta.z - 0.5f ) / ( delta.y + 0.5f );
float leading_edge_major = ( delta.z + 0.5f ) / ( delta.y - 0.5f );
current.z = offset.z + delta.x * 00 + delta.y * 00 + delta.z * zz;
Expand Down
11 changes: 11 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ bool log_from_top;
int message_ttl;
int message_cooldown;
bool fov_3d;
int fov_3d_z_range;
bool tile_iso;

std::map<std::string, std::string> TILESETS; // All found tilesets: <name, tileset_dir>
Expand Down Expand Up @@ -1872,6 +1873,14 @@ void options_manager::add_options_debug()
false
);

add( "FOV_3D_Z_RANGE", "debug", translate_marker( "Vertical range of 3D field of vision" ),
translate_marker( "How many levels up and down the experimental 3D field of vision reaches. (This many levels up, this many levels down.) 3D vision of the full height of the world can slow the game down a lot. Seeing fewer Z-levels is faster." ),
0, OVERMAP_LAYERS, 4
);

get_option( "FOV_3D_Z_RANGE" ).setPrerequisite( "FOV_3D" );


add( "ENCODING_CONV", "debug", translate_marker( "Experimental path name encoding conversion" ),
translate_marker( "If true, file path names are going to be transcoded from system encoding to UTF-8 when reading and will be transcoded back when writing. Mainly for CJK Windows users." ),
true
Expand Down Expand Up @@ -2809,6 +2818,7 @@ bool options_manager::save()
message_ttl = ::get_option<int>( "MESSAGE_TTL" );
message_cooldown = ::get_option<int>( "MESSAGE_COOLDOWN" );
fov_3d = ::get_option<bool>( "FOV_3D" );
fov_3d_z_range = ::get_option<int>( "FOV_3D_Z_RANGE" );

update_music_volume();

Expand Down Expand Up @@ -2841,6 +2851,7 @@ void options_manager::load()
message_ttl = ::get_option<int>( "MESSAGE_TTL" );
message_cooldown = ::get_option<int>( "MESSAGE_COOLDOWN" );
fov_3d = ::get_option<bool>( "FOV_3D" );
fov_3d_z_range = ::get_option<int>( "FOV_3D_Z_RANGE" );
#if defined(SDL_SOUND)
sounds::sound_enabled = ::get_option<bool>( "SOUND_ENABLED" );
#endif
Expand Down

0 comments on commit f561e51

Please sign in to comment.