From 00d1af0c1a81e7e0ec5d59b685db12223773e739 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Fri, 15 Dec 2023 01:27:12 +0800 Subject: [PATCH 01/26] disable ll invis cache --- src/cata_tiles.cpp | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 323836a81981a..d0cf2bc4d61e3 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1765,27 +1765,8 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int var = std::get_if( &p.var ) ) { // Get visibility variables - lit_level ll; - std::array invisible; - if( cur_zlevel == center.z ) { - // For the same z-level, use tile_render_info vars - ll = var->ll; - invisible = var->invisible; - } else { - // Otherwise, recalculate ll and invisible - if( here.ll_invis_cache.count( draw_loc ) == 0 ) { - const std::pair> ll_invis = calc_ll_invis( draw_loc ); - ll = ll_invis.first; - invisible = ll_invis.second; - // Only cache ll_invis if not in test mode - if( !test_mode ) { - here.ll_invis_cache[ draw_loc ] = ll_invis; - } - } else { - ll = here.ll_invis_cache[ draw_loc ].first; - invisible = here.ll_invis_cache[ draw_loc ].second; - } - } + lit_level ll = var->ll; + std::array invisible = var->invisible; if( f == &cata_tiles::draw_vpart_no_roof || f == &cata_tiles::draw_vpart_roof ) { int temp_height_3d = p.com.height_3d; From c9f39af86647267f464ec09551f55b471a672dbc Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Fri, 15 Dec 2023 14:44:25 +0800 Subject: [PATCH 02/26] remove old occlusion culling --- src/cata_tiles.cpp | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index d0cf2bc4d61e3..6d7ac0bd51308 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1232,10 +1232,9 @@ struct tile_render_info { const tripoint pos; // accumulator for 3d tallness of sprites rendered here so far; int height_3d = 0; - int draw_min_z = -OVERMAP_DEPTH; - common( const tripoint &pos, const int height_3d, const int draw_min_z ) - : pos( pos ), height_3d( height_3d ), draw_min_z( draw_min_z ) {} + common( const tripoint &pos, const int height_3d ) + : pos( pos ), height_3d( height_3d ) {} }; struct vision_effect { @@ -1475,7 +1474,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int invisible[0] = true; } else { if( would_apply_vision_effects( offscreen_type ) ) { - draw_points[row].emplace_back( tile_render_info::common{ pos, 0, pos.z }, + draw_points[row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::vision_effect{ offscreen_type } ); } continue; @@ -1653,7 +1652,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int || you.sees_with_specials( *critter ) ) ) ) { invisible[0] = true; } else { - draw_points[row].emplace_back( tile_render_info::common{ pos, 0, pos.z }, + draw_points[row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::vision_effect{ vis_type } ); continue; } @@ -1664,16 +1663,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int invisible[1 + i] = apply_visible( np, ch, here ); } - // Determine lowest z-level to draw for 3D vision. Some off-screen - // tiles are also considered here to simply the logic. - int draw_min_z; - tripoint p_temp = pos; - while( !here.dont_draw_lower_floor( p_temp ) && pos.z - p_temp.z < max_draw_depth ) { - p_temp.z -= 1; - } - draw_min_z = p_temp.z; - - draw_points[row].emplace_back( tile_render_info::common{ pos, 0, draw_min_z }, + draw_points[row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::sprite{ ll, invisible } ); } } @@ -1727,15 +1717,6 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // Start drawing from the lowest visible z-level (some off-screen tiles // are considered visible here to simplify the logic.) int cur_zlevel = center.z + 1; - for( const std::pair> &pts : draw_points ) { - for( const tile_render_info &p : pts.second ) { - cur_zlevel = std::min( cur_zlevel, p.com.draw_min_z ); - if( cur_zlevel <= center.z - max_draw_depth - || cur_zlevel <= -OVERMAP_DEPTH ) { - break; - } - } - } while( cur_zlevel <= center.z ) { const half_open_rectangle &cur_any_tile_range = is_isometric() ? z_any_tile_range[center.z - cur_zlevel] : top_any_tile_range; @@ -1749,11 +1730,6 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int for( auto f : drawing_layers ) { // For each tile for( tile_render_info &p : draw_points[row] ) { - // Skip if z-level less than draw_min_z - // Basically occlusion culling - if( cur_zlevel < p.com.draw_min_z ) { - continue; - } tripoint draw_loc = p.com.pos; draw_loc.z = cur_zlevel; if( const tile_render_info::vision_effect * const @@ -1779,8 +1755,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } } else if( f == &cata_tiles::draw_critter_at ) { // Draw - if( !( this->*f )( draw_loc, ll, p.com.height_3d, invisible, false ) && do_draw_shadow && - cur_zlevel == p.com.draw_min_z ) { + if( !( this->*f )( draw_loc, ll, p.com.height_3d, invisible, false ) && do_draw_shadow ) { //replace bottom detection // Draw shadow of flying critters on bottom-most tile if no other critter drawn draw_critter_above( draw_loc, ll, p.com.height_3d, invisible ); } From f0283b91f0184eb118215ac1768cb6a8733d1c77 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sat, 16 Dec 2023 15:36:57 +0800 Subject: [PATCH 03/26] multi z-level draw point generation --- src/cata_tiles.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 6d7ac0bd51308..2f1b1bbe7bf26 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1340,6 +1340,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int const int max_col = top_any_tile_range.p_max.x; const int min_row = bottom_any_tile_range.p_min.y; const int max_row = top_any_tile_range.p_max.y; + const int draw_min_z = std::max( center.z - fov_3d_z_range, -OVERMAP_DEPTH ); avatar &you = get_avatar(); //limit the render area to maximum view range (121x121 square centered on player) @@ -1446,15 +1447,16 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } creature_tracker &creatures = get_creature_tracker(); - std::map> draw_points; + std::map>> draw_points; for( int row = min_row; row < max_row; row ++ ) { - draw_points[row].reserve( std::max( 0, max_col - min_col ) ); + draw_points[center.z][row].reserve( std::max( 0, max_col - min_col ) ); for( int col = min_col; col < max_col; col ++ ) { const std::optional temp = tile_to_player( { col, row } ); + for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { if( !temp.has_value() ) { continue; } - const tripoint pos( temp.value(), center.z ); + const tripoint pos( temp.value(), zlevel ); const tripoint_abs_ms pos_global = here.getglobal( pos ); const int &x = pos.x; const int &y = pos.y; @@ -1474,7 +1476,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int invisible[0] = true; } else { if( would_apply_vision_effects( offscreen_type ) ) { - draw_points[row].emplace_back( tile_render_info::common{ pos, 0 }, + draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::vision_effect{ offscreen_type } ); } continue; @@ -1652,7 +1654,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int || you.sees_with_specials( *critter ) ) ) ) { invisible[0] = true; } else { - draw_points[row].emplace_back( tile_render_info::common{ pos, 0 }, + draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::vision_effect{ vis_type } ); continue; } @@ -1663,9 +1665,10 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int invisible[1 + i] = apply_visible( np, ch, here ); } - draw_points[row].emplace_back( tile_render_info::common{ pos, 0 }, + draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::sprite{ ll, invisible } ); } + } } // List all layers for a single z-level @@ -1699,7 +1702,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // Legacy draw mode for( int row = min_row; row < max_row; row ++ ) { for( auto f : drawing_layers_legacy ) { - for( tile_render_info &p : draw_points[row] ) { + for( tile_render_info &p : draw_points[center.z][row] ) { if( const tile_render_info::vision_effect * const var = std::get_if( &p.var ) ) { if( f == &cata_tiles::draw_terrain ) { @@ -1723,13 +1726,13 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // For each row for( int row = cur_any_tile_range.p_min.y; row < cur_any_tile_range.p_max.y; row ++ ) { // Set base height for each tile - for( tile_render_info &p : draw_points[row] ) { + for( tile_render_info &p : draw_points[cur_zlevel][row] ) { p.com.height_3d = ( cur_zlevel - center.z ) * zlevel_height; } // For each layer for( auto f : drawing_layers ) { // For each tile - for( tile_render_info &p : draw_points[row] ) { + for( tile_render_info &p : draw_points[cur_zlevel][row] ) { tripoint draw_loc = p.com.pos; draw_loc.z = cur_zlevel; if( const tile_render_info::vision_effect * const @@ -1773,7 +1776,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // display number of monsters to spawn in mapgen preview for( int row = top_any_tile_range.p_min.y; row < top_any_tile_range.p_max.y; row ++ ) { - for( const tile_render_info &p : draw_points[row] ) { + for( const tile_render_info &p : draw_points[center.z][row] ) { const tile_render_info::sprite *const var = std::get_if( &p.var ); if( !var ) { From 1399e5093f58dcffce65ddbf93804e588e867851 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sat, 16 Dec 2023 18:08:12 +0800 Subject: [PATCH 04/26] reserve draw points on every z-level --- src/cata_tiles.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 2f1b1bbe7bf26..2582ceddd4287 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1449,7 +1449,10 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int creature_tracker &creatures = get_creature_tracker(); std::map>> draw_points; for( int row = min_row; row < max_row; row ++ ) { - draw_points[center.z][row].reserve( std::max( 0, max_col - min_col ) ); + // Reserve columns on each row + for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { + draw_points[zlevel][row].reserve( std::max( 0, max_col - min_col ) ); + } for( int col = min_col; col < max_col; col ++ ) { const std::optional temp = tile_to_player( { col, row } ); for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { From fc69a564db8bc87383068907ae691c5bcd43107e Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sun, 17 Dec 2023 00:29:29 +0800 Subject: [PATCH 05/26] remove redundant check --- src/cata_tiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 2582ceddd4287..1e31aa07a2d96 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1455,10 +1455,10 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } for( int col = min_col; col < max_col; col ++ ) { const std::optional temp = tile_to_player( { col, row } ); - for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { if( !temp.has_value() ) { continue; } + for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { const tripoint pos( temp.value(), zlevel ); const tripoint_abs_ms pos_global = here.getglobal( pos ); const int &x = pos.x; From 1d6a0c9685b0bad45c3cc1727158d0708cfc13c0 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sun, 17 Dec 2023 13:30:27 +0800 Subject: [PATCH 06/26] add current z-level check --- src/cata_tiles.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 1e31aa07a2d96..1d289ce8d2f87 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1463,6 +1463,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int const tripoint_abs_ms pos_global = here.getglobal( pos ); const int &x = pos.x; const int &y = pos.y; + const bool is_center_z = ( zlevel == center.z ); // light level is used for choosing between grayscale filter and normal lit tiles. lit_level ll; @@ -1478,7 +1479,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int ll = lit_level::DARK; invisible[0] = true; } else { - if( would_apply_vision_effects( offscreen_type ) ) { + if( is_center_z && would_apply_vision_effects( offscreen_type ) ) { draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::vision_effect{ offscreen_type } ); } @@ -1657,8 +1658,10 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int || you.sees_with_specials( *critter ) ) ) ) { invisible[0] = true; } else { + if( is_center_z ) { draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::vision_effect{ vis_type } ); + } continue; } } From 013c80ad55bc261a1bdb451514a2284838d355d1 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sun, 17 Dec 2023 13:31:00 +0800 Subject: [PATCH 07/26] fix loop var --- src/cata_tiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 1d289ce8d2f87..24b1f01dc9902 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1725,7 +1725,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // Multi z-level draw mode // Start drawing from the lowest visible z-level (some off-screen tiles // are considered visible here to simplify the logic.) - int cur_zlevel = center.z + 1; + int cur_zlevel = draw_min_z; while( cur_zlevel <= center.z ) { const half_open_rectangle &cur_any_tile_range = is_isometric() ? z_any_tile_range[center.z - cur_zlevel] : top_any_tile_range; From cd490ea1ddd42346a8a1caa32e2f43ed2619b931 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sun, 17 Dec 2023 14:47:44 +0800 Subject: [PATCH 08/26] remove unneeded vars --- src/cata_tiles.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 24b1f01dc9902..53cbdbeb363de 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1739,12 +1739,10 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int for( auto f : drawing_layers ) { // For each tile for( tile_render_info &p : draw_points[cur_zlevel][row] ) { - tripoint draw_loc = p.com.pos; - draw_loc.z = cur_zlevel; if( const tile_render_info::vision_effect * const var = std::get_if( &p.var ) ) { if( f == &cata_tiles::draw_terrain ) { - apply_vision_effects( draw_loc, var->vis, p.com.height_3d ); + apply_vision_effects( p.com.pos, var->vis, p.com.height_3d ); } } else if( const tile_render_info::sprite * const var = std::get_if( &p.var ) ) { @@ -1758,19 +1756,19 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // Reset height_3d to base when drawing vehicles p.com.height_3d = ( cur_zlevel - center.z ) * zlevel_height; // Draw - if( !( this->*f )( draw_loc, ll, p.com.height_3d, invisible, false ) ) { + if( !( this->*f )( p.com.pos, ll, p.com.height_3d, invisible, false ) ) { // If no vpart drawn, revert height_3d changes p.com.height_3d = temp_height_3d; } } else if( f == &cata_tiles::draw_critter_at ) { // Draw - if( !( this->*f )( draw_loc, ll, p.com.height_3d, invisible, false ) && do_draw_shadow ) { //replace bottom detection + if( !( this->*f )( p.com.pos, ll, p.com.height_3d, invisible, false ) && do_draw_shadow ) { //replace bottom detection // Draw shadow of flying critters on bottom-most tile if no other critter drawn - draw_critter_above( draw_loc, ll, p.com.height_3d, invisible ); + draw_critter_above( p.com.pos, ll, p.com.height_3d, invisible ); } } else { // Draw - ( this->*f )( draw_loc, ll, p.com.height_3d, invisible, false ); + ( this->*f )( p.com.pos, ll, p.com.height_3d, invisible, false ); } } } From 796bb49b6d6559d02b0460f76e606e5e4ec65142 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sun, 17 Dec 2023 15:35:15 +0800 Subject: [PATCH 09/26] cache draw points --- src/cata_tiles.cpp | 56 +++++++++------------------------------------- src/cata_tiles.h | 3 --- src/map.h | 40 ++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 53cbdbeb363de..23f62d81f27ba 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1227,41 +1227,6 @@ void tileset_cache::loader::load_tile_spritelists( const JsonObject &entry, } } -struct tile_render_info { - struct common { - const tripoint pos; - // accumulator for 3d tallness of sprites rendered here so far; - int height_3d = 0; - - common( const tripoint &pos, const int height_3d ) - : pos( pos ), height_3d( height_3d ) {} - }; - - struct vision_effect { - visibility_type vis; - - explicit vision_effect( const visibility_type vis ) - : vis( vis ) {} - }; - - struct sprite { - lit_level ll; - std::array invisible; - - sprite( const lit_level ll, const std::array &inv ) - : ll( ll ), invisible( inv ) {} - }; - - common com; - std::variant var; - - tile_render_info( const common &com, const vision_effect &var ) - : com( com ), var( var ) {} - - tile_render_info( const common &com, const sprite &var ) - : com( com ), var( var ) {} -}; - static std::map display_npc_attack_potential() { avatar &you = get_avatar(); @@ -1447,11 +1412,10 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } creature_tracker &creatures = get_creature_tracker(); - std::map>> draw_points; for( int row = min_row; row < max_row; row ++ ) { // Reserve columns on each row for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { - draw_points[zlevel][row].reserve( std::max( 0, max_col - min_col ) ); + here.draw_points[zlevel][row].reserve( std::max( 0, max_col - min_col ) ); } for( int col = min_col; col < max_col; col ++ ) { const std::optional temp = tile_to_player( { col, row } ); @@ -1480,7 +1444,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int invisible[0] = true; } else { if( is_center_z && would_apply_vision_effects( offscreen_type ) ) { - draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::vision_effect{ offscreen_type } ); } continue; @@ -1659,7 +1623,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int invisible[0] = true; } else { if( is_center_z ) { - draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::vision_effect{ vis_type } ); } continue; @@ -1671,7 +1635,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int invisible[1 + i] = apply_visible( np, ch, here ); } - draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::sprite{ ll, invisible } ); } } @@ -1708,7 +1672,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // Legacy draw mode for( int row = min_row; row < max_row; row ++ ) { for( auto f : drawing_layers_legacy ) { - for( tile_render_info &p : draw_points[center.z][row] ) { + for( tile_render_info &p : here.draw_points[center.z][row] ) { if( const tile_render_info::vision_effect * const var = std::get_if( &p.var ) ) { if( f == &cata_tiles::draw_terrain ) { @@ -1732,13 +1696,13 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // For each row for( int row = cur_any_tile_range.p_min.y; row < cur_any_tile_range.p_max.y; row ++ ) { // Set base height for each tile - for( tile_render_info &p : draw_points[cur_zlevel][row] ) { + for( tile_render_info &p : here.draw_points[cur_zlevel][row] ) { p.com.height_3d = ( cur_zlevel - center.z ) * zlevel_height; } // For each layer for( auto f : drawing_layers ) { // For each tile - for( tile_render_info &p : draw_points[cur_zlevel][row] ) { + for( tile_render_info &p : here.draw_points[cur_zlevel][row] ) { if( const tile_render_info::vision_effect * const var = std::get_if( &p.var ) ) { if( f == &cata_tiles::draw_terrain ) { @@ -1780,7 +1744,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // display number of monsters to spawn in mapgen preview for( int row = top_any_tile_range.p_min.y; row < top_any_tile_range.p_max.y; row ++ ) { - for( const tile_render_info &p : draw_points[center.z][row] ) { + for( const tile_render_info &p : here.draw_points[center.z][row] ) { const tile_render_info::sprite *const var = std::get_if( &p.var ); if( !var ) { @@ -1981,7 +1945,7 @@ std::pair> cata_tiles::calc_ll_invis( const tripo void cata_tiles::clear_draw_caches() { - get_map().ll_invis_cache.clear(); + get_map().draw_points.clear(); } void cata_tiles::draw_minimap( const point &dest, const tripoint ¢er, int width, int height ) @@ -3025,7 +2989,7 @@ bool cata_tiles::draw_sprite_at( printErrorIf( ret != 0, "SDL_RenderCopyEx() failed" ); // this reference passes all the way back up the call chain back to - // cata_tiles::draw() draw_points[row][col].com.height_3d + // cata_tiles::draw() here.draw_points[row][col].com.height_3d // where we are accumulating the height of every sprite stacked up in a tile height_3d += tile.height_3d; return true; diff --git a/src/cata_tiles.h b/src/cata_tiles.h index b4ea1ab2458aa..a22eb2f2c31f3 100644 --- a/src/cata_tiles.h +++ b/src/cata_tiles.h @@ -809,9 +809,6 @@ class cata_tiles public: // Draw caches persist data between draws to avoid unnecessary recalculations - // Any event that would invalidate cached data should also clear it - // Currently only includes ll_invis_cache - // Performance gain from caching draw_points, overlay_strings and color_blocks is negligible void clear_draw_caches(); std::string memory_map_mode = "color_pixel_sepia"; diff --git a/src/map.h b/src/map.h index 39eb15545c3f2..9c24d7790cd39 100644 --- a/src/map.h +++ b/src/map.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "calendar.h" @@ -276,6 +277,41 @@ struct drawsq_params { //@} }; +struct tile_render_info { + struct common { + const tripoint pos; + // accumulator for 3d tallness of sprites rendered here so far; + int height_3d = 0; + + common( const tripoint &pos, const int height_3d ) + : pos( pos ), height_3d( height_3d ) {} + }; + + struct vision_effect { + visibility_type vis; + + explicit vision_effect( const visibility_type vis ) + : vis( vis ) {} + }; + + struct sprite { + lit_level ll; + std::array invisible; + + sprite( const lit_level ll, const std::array &inv ) + : ll( ll ), invisible( inv ) {} + }; + + common com; + std::variant var; + + tile_render_info( const common &com, const vision_effect &var ) + : com( com ), var( var ) {} + + tile_render_info( const common &com, const sprite &var ) + : com( com ), var( var ) {} +}; + /** * Manage and cache data about a part of the map. * @@ -2309,7 +2345,9 @@ class map bool has_haulable_items( const tripoint &pos ); std::vector get_haulable_items( const tripoint &pos ); - std::map>> ll_invis_cache; + + + std::map>> draw_points; }; map &get_map(); From 8a8e900dd8fcfedc89fe8498c890fa5a47e7f9a0 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sun, 17 Dec 2023 15:59:06 +0800 Subject: [PATCH 10/26] remove unused function --- src/cata_tiles.cpp | 59 ---------------------------------------------- src/cata_tiles.h | 3 --- 2 files changed, 62 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 23f62d81f27ba..5412aa9a16c03 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1884,65 +1884,6 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int "SDL_RenderSetClipRect failed" ); } -std::pair> cata_tiles::calc_ll_invis( const tripoint &draw_loc ) -{ - avatar &you = get_avatar(); - map &here = get_map(); - creature_tracker &creatures = get_creature_tracker(); - const visibility_variables &cache = here.get_visibility_variables_cache(); - const point min_visible( you.posx() % SEEX, you.posy() % SEEY ); - const point max_visible( ( you.posx() % SEEX ) + ( MAPSIZE - 1 ) * SEEX, - ( you.posy() % SEEY ) + ( MAPSIZE - 1 ) * SEEY ); - const level_cache &ch = here.access_cache( draw_loc.z ); - const auto apply_visible = [&]( const tripoint & np, const level_cache & ch, map & here ) { - return np.y < min_visible.y || np.y > max_visible.y || - np.x < min_visible.x || np.x > max_visible.x || - would_apply_vision_effects( here.get_visibility( ch.visibility_cache[np.x][np.y], - cache ) ); - }; - - lit_level ll = lit_level::DARK; - // invisible to normal eyes - std::array invisible; - invisible[0] = false; - tripoint pos = draw_loc; - tripoint_abs_ms pos_global = here.getglobal( pos ); - - if( draw_loc.y < min_visible.y || draw_loc.y > max_visible.y || draw_loc.x < min_visible.x || - draw_loc.x > max_visible.x ) { - if( has_memory_at( pos_global ) ) { - ll = lit_level::MEMORIZED; - invisible[0] = true; - } else if( has_draw_override( pos ) ) { - ll = lit_level::DARK; - invisible[0] = true; - } - } else { - ll = here.access_cache( draw_loc.z ).visibility_cache[draw_loc.x][draw_loc.y]; - } - - if( !invisible[0] ) { - const visibility_type vis_type = here.get_visibility( ll, cache ); - if( would_apply_vision_effects( vis_type ) ) { - const Creature *critter = creatures.creature_at( pos, true ); - if( has_draw_override( pos ) || has_memory_at( pos_global ) || - ( critter && - ( critter->has_flag( mon_flag_ALWAYS_VISIBLE ) - || you.sees_with_infrared( *critter ) - || you.sees_with_specials( *critter ) ) ) ) { - invisible[0] = true; - } - } - } - for( int i = 0; i < 4; i++ ) { - const tripoint np = pos + neighborhood[i]; - invisible[1 + i] = apply_visible( np, ch, here ); - } - - std::pair> ret( ll, invisible ); - return ret; -} - void cata_tiles::clear_draw_caches() { get_map().draw_points.clear(); diff --git a/src/cata_tiles.h b/src/cata_tiles.h index a22eb2f2c31f3..46c6ad8bc3b88 100644 --- a/src/cata_tiles.h +++ b/src/cata_tiles.h @@ -411,9 +411,6 @@ class cata_tiles void draw( const point &dest, const tripoint ¢er, int width, int height, std::multimap &overlay_strings, color_block_overlay_container &color_blocks ); - // Standalone version of the ll and invisible calculations normally done when accumulating draw_points - // Used to determine visibility of lower z-levels in 3D vision without generating extra draw_points and overlay_strings - std::pair> calc_ll_invis( const tripoint &draw_loc ); void draw_om( const point &dest, const tripoint_abs_omt ¢er_abs_omt, bool blink ); /** Minimap functionality */ From 5df264ce37f5cb14362d3a7cb1639d825f5c05e0 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sun, 17 Dec 2023 15:59:39 +0800 Subject: [PATCH 11/26] replace occlusion culling --- src/cata_tiles.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 5412aa9a16c03..311f4ec6e110b 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1637,6 +1637,10 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::sprite{ ll, invisible } ); + // Stop building draw points below when floor reached + if( here.dont_draw_lower_floor( pos ) ) { + break; + } } } } From e7d7bfa5a2a42ec8fd1454220a7cbbc28b6f9e1e Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sun, 17 Dec 2023 16:00:07 +0800 Subject: [PATCH 12/26] replace shadow floor check --- src/cata_tiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 311f4ec6e110b..b67756560b197 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1730,7 +1730,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } } else if( f == &cata_tiles::draw_critter_at ) { // Draw - if( !( this->*f )( p.com.pos, ll, p.com.height_3d, invisible, false ) && do_draw_shadow ) { //replace bottom detection + if( !( this->*f )( p.com.pos, ll, p.com.height_3d, invisible, false ) && do_draw_shadow && here.dont_draw_lower_floor( p.com.pos ) ) { // Draw shadow of flying critters on bottom-most tile if no other critter drawn draw_critter_above( p.com.pos, ll, p.com.height_3d, invisible ); } From 4958ca3132b4c57b2478555ceff1b3b39f82348d Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sun, 17 Dec 2023 16:32:47 +0800 Subject: [PATCH 13/26] remove unneeded include --- src/cata_tiles.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index b67756560b197..d86b5b7ec1c9a 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include "action.h" #include "avatar.h" From 3fa3c9cc3b85e83475e7bd0e16c835d1517a05a4 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Sun, 17 Dec 2023 16:34:53 +0800 Subject: [PATCH 14/26] cleanup and astyle --- src/cata_tiles.cpp | 383 +++++++++++++++++++++++---------------------- src/map.h | 4 +- 2 files changed, 193 insertions(+), 194 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index d86b5b7ec1c9a..0e912f62f21ea 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1412,8 +1412,8 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int creature_tracker &creatures = get_creature_tracker(); for( int row = min_row; row < max_row; row ++ ) { - // Reserve columns on each row - for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { + // Reserve columns on each row + for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { here.draw_points[zlevel][row].reserve( std::max( 0, max_col - min_col ) ); } for( int col = min_col; col < max_col; col ++ ) { @@ -1422,226 +1422,226 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int continue; } for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { - const tripoint pos( temp.value(), zlevel ); - const tripoint_abs_ms pos_global = here.getglobal( pos ); - const int &x = pos.x; - const int &y = pos.y; - const bool is_center_z = ( zlevel == center.z ); - - // light level is used for choosing between grayscale filter and normal lit tiles. - lit_level ll; - // invisible to normal eyes - std::array invisible; - invisible[0] = false; - - if( y < min_visible.y || y > max_visible.y || x < min_visible.x || x > max_visible.x ) { - if( has_memory_at( pos_global ) ) { - ll = lit_level::MEMORIZED; - invisible[0] = true; - } else if( has_draw_override( pos ) ) { - ll = lit_level::DARK; - invisible[0] = true; + const tripoint pos( temp.value(), zlevel ); + const tripoint_abs_ms pos_global = here.getglobal( pos ); + const int &x = pos.x; + const int &y = pos.y; + const bool is_center_z = ( zlevel == center.z ); + + // light level is used for choosing between grayscale filter and normal lit tiles. + lit_level ll; + // invisible to normal eyes + std::array invisible; + invisible[0] = false; + + if( y < min_visible.y || y > max_visible.y || x < min_visible.x || x > max_visible.x ) { + if( has_memory_at( pos_global ) ) { + ll = lit_level::MEMORIZED; + invisible[0] = true; + } else if( has_draw_override( pos ) ) { + ll = lit_level::DARK; + invisible[0] = true; + } else { + if( is_center_z && would_apply_vision_effects( offscreen_type ) ) { + here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + tile_render_info::vision_effect{ offscreen_type } ); + } + continue; + } } else { - if( is_center_z && would_apply_vision_effects( offscreen_type ) ) { - here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, - tile_render_info::vision_effect{ offscreen_type } ); + ll = ch.visibility_cache[x][y]; + } + + // Add scent value to the overlay_strings list for every visible tile when + // displaying scent + if( g->display_overlay_state( ACTION_DISPLAY_SCENT ) && !invisible[0] ) { + const int scent_value = get_scent().get( pos ); + if( scent_value > 0 ) { + overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, + formatted_text( std::to_string( scent_value ), + 8 + catacurses::yellow, direction::NORTH ) ); } - continue; } - } else { - ll = ch.visibility_cache[x][y]; - } - // Add scent value to the overlay_strings list for every visible tile when - // displaying scent - if( g->display_overlay_state( ACTION_DISPLAY_SCENT ) && !invisible[0] ) { - const int scent_value = get_scent().get( pos ); - if( scent_value > 0 ) { - overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, - formatted_text( std::to_string( scent_value ), - 8 + catacurses::yellow, direction::NORTH ) ); + // Add scent type to the overlay_strings list for every visible tile when + // displaying scent + if( g->display_overlay_state( ACTION_DISPLAY_SCENT_TYPE ) && !invisible[0] ) { + const scenttype_id scent_type = get_scent().get_type( pos ); + if( !scent_type.is_empty() ) { + overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, + formatted_text( scent_type.c_str(), + 8 + catacurses::yellow, direction::NORTH ) ); + } } - } - // Add scent type to the overlay_strings list for every visible tile when - // displaying scent - if( g->display_overlay_state( ACTION_DISPLAY_SCENT_TYPE ) && !invisible[0] ) { - const scenttype_id scent_type = get_scent().get_type( pos ); - if( !scent_type.is_empty() ) { - overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, - formatted_text( scent_type.c_str(), - 8 + catacurses::yellow, direction::NORTH ) ); + if( g->display_overlay_state( ACTION_DISPLAY_RADIATION ) ) { + const auto rad_override = radiation_override.find( pos ); + const bool rad_overridden = rad_override != radiation_override.end(); + if( rad_overridden || !invisible[0] ) { + const int rad_value = rad_overridden ? rad_override->second : + here.get_radiation( pos ); + catacurses::base_color col; + if( rad_value > 0 ) { + col = catacurses::green; + } else { + col = catacurses::cyan; + } + overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, + formatted_text( std::to_string( rad_value ), + 8 + col, direction::NORTH ) ); + } } - } - if( g->display_overlay_state( ACTION_DISPLAY_RADIATION ) ) { - const auto rad_override = radiation_override.find( pos ); - const bool rad_overridden = rad_override != radiation_override.end(); - if( rad_overridden || !invisible[0] ) { - const int rad_value = rad_overridden ? rad_override->second : - here.get_radiation( pos ); - catacurses::base_color col; - if( rad_value > 0 ) { - col = catacurses::green; - } else { - col = catacurses::cyan; + if( g->display_overlay_state( ACTION_DISPLAY_NPC_ATTACK_POTENTIAL ) ) { + if( npc_attack_rating_map.count( pos ) ) { + const int val = npc_attack_rating_map.at( pos ); + short color; + if( val <= 0 ) { + color = catacurses::red; + } else if( val == max_npc_effectiveness ) { + color = catacurses::cyan; + } else { + color = catacurses::white; + } + overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, + formatted_text( std::to_string( val ), color, + direction::NORTH ) ); } - overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, - formatted_text( std::to_string( rad_value ), - 8 + col, direction::NORTH ) ); } - } - if( g->display_overlay_state( ACTION_DISPLAY_NPC_ATTACK_POTENTIAL ) ) { - if( npc_attack_rating_map.count( pos ) ) { - const int val = npc_attack_rating_map.at( pos ); + // Add temperature value to the overlay_strings list for every visible tile when + // displaying temperature + if( g->display_overlay_state( ACTION_DISPLAY_TEMPERATURE ) && !invisible[0] ) { + const units::temperature temp_value = get_weather().get_temperature( pos ); + const float celsius_temp_value = units::to_celsius( temp_value ); short color; - if( val <= 0 ) { + const short bold = 8; + if( celsius_temp_value > 40 ) { color = catacurses::red; - } else if( val == max_npc_effectiveness ) { - color = catacurses::cyan; + } else if( celsius_temp_value > 25 ) { + color = catacurses::yellow + bold; + } else if( celsius_temp_value > 10 ) { + color = catacurses::green + bold; + } else if( celsius_temp_value > 0 ) { + color = catacurses::white + bold; + } else if( celsius_temp_value > -10 ) { + color = catacurses::cyan + bold; } else { - color = catacurses::white; + color = catacurses::blue + bold; } - overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, - formatted_text( std::to_string( val ), color, - direction::NORTH ) ); - } - } - // Add temperature value to the overlay_strings list for every visible tile when - // displaying temperature - if( g->display_overlay_state( ACTION_DISPLAY_TEMPERATURE ) && !invisible[0] ) { - const units::temperature temp_value = get_weather().get_temperature( pos ); - const float celsius_temp_value = units::to_celsius( temp_value ); - short color; - const short bold = 8; - if( celsius_temp_value > 40 ) { - color = catacurses::red; - } else if( celsius_temp_value > 25 ) { - color = catacurses::yellow + bold; - } else if( celsius_temp_value > 10 ) { - color = catacurses::green + bold; - } else if( celsius_temp_value > 0 ) { - color = catacurses::white + bold; - } else if( celsius_temp_value > -10 ) { - color = catacurses::cyan + bold; - } else { - color = catacurses::blue + bold; + std::string temp_str; + if( get_option( "USE_CELSIUS" ) == "celsius" ) { + temp_str = string_format( "%.0f", celsius_temp_value ); + } else if( get_option( "USE_CELSIUS" ) == "kelvin" ) { + temp_str = string_format( "%.0f", units::to_kelvin( temp_value ) ); + } else { + temp_str = string_format( "%.0f", units::to_fahrenheit( temp_value ) ); + } + overlay_strings.emplace( player_to_screen( point( x, y ) ), + formatted_text( temp_str, color, + text_alignment::left ) ); } - std::string temp_str; - if( get_option( "USE_CELSIUS" ) == "celsius" ) { - temp_str = string_format( "%.0f", celsius_temp_value ); - } else if( get_option( "USE_CELSIUS" ) == "kelvin" ) { - temp_str = string_format( "%.0f", units::to_kelvin( temp_value ) ); - } else { - temp_str = string_format( "%.0f", units::to_fahrenheit( temp_value ) ); + if( g->display_overlay_state( ACTION_DISPLAY_VISIBILITY ) && + g->displaying_visibility_creature && !invisible[0] ) { + const bool visibility = g->displaying_visibility_creature->sees( pos ); + + // color overlay. + SDL_Color block_color = visibility ? windowsPalette[catacurses::green] : + SDL_Color{ 192, 192, 192, 255 }; + block_color.a = 100; + color_blocks.first = SDL_BLENDMODE_BLEND; + color_blocks.second.emplace( player_to_screen( point( x, y ) ), block_color ); + + // overlay string + std::string visibility_str = visibility ? "+" : "-"; + overlay_strings.emplace( player_to_screen( point( x, y ) ) + quarter_tile, + formatted_text( visibility_str, catacurses::black, + direction::NORTH ) ); } - overlay_strings.emplace( player_to_screen( point( x, y ) ), - formatted_text( temp_str, color, - text_alignment::left ) ); - } - if( g->display_overlay_state( ACTION_DISPLAY_VISIBILITY ) && - g->displaying_visibility_creature && !invisible[0] ) { - const bool visibility = g->displaying_visibility_creature->sees( pos ); - - // color overlay. - SDL_Color block_color = visibility ? windowsPalette[catacurses::green] : - SDL_Color{ 192, 192, 192, 255 }; - block_color.a = 100; - color_blocks.first = SDL_BLENDMODE_BLEND; - color_blocks.second.emplace( player_to_screen( point( x, y ) ), block_color ); - - // overlay string - std::string visibility_str = visibility ? "+" : "-"; - overlay_strings.emplace( player_to_screen( point( x, y ) ) + quarter_tile, - formatted_text( visibility_str, catacurses::black, - direction::NORTH ) ); - } + static std::vector lighting_colors; + // color hue in the range of [0..10], 0 being white, 10 being blue + auto draw_debug_tile = [&]( const int color_hue, const std::string & text ) { + if( lighting_colors.empty() ) { + SDL_Color white = { 255, 255, 255, 255 }; + SDL_Color blue = { 0, 0, 255, 255 }; + lighting_colors = color_linear_interpolate( white, blue, 9 ); + } + point tile_pos = player_to_screen( point( x, y ) ); + + // color overlay + SDL_Color color = lighting_colors[std::min( std::max( 0, color_hue ), 10 )]; + color.a = 100; + color_blocks.first = SDL_BLENDMODE_BLEND; + color_blocks.second.emplace( tile_pos, color ); + + // string overlay + overlay_strings.emplace( + tile_pos + quarter_tile, + formatted_text( text, catacurses::black, direction::NORTH ) ); + }; - static std::vector lighting_colors; - // color hue in the range of [0..10], 0 being white, 10 being blue - auto draw_debug_tile = [&]( const int color_hue, const std::string & text ) { - if( lighting_colors.empty() ) { - SDL_Color white = { 255, 255, 255, 255 }; - SDL_Color blue = { 0, 0, 255, 255 }; - lighting_colors = color_linear_interpolate( white, blue, 9 ); + if( g->display_overlay_state( ACTION_DISPLAY_LIGHTING ) ) { + if( g->displaying_lighting_condition == 0 ) { + const float light = here.ambient_light_at( {x, y, center.z} ); + // note: lighting will be constrained in the [1.0, 11.0] range. + int intensity = + static_cast( std::max( 1.0, LIGHT_AMBIENT_LIT - light + 1.0 ) ) - 1; + draw_debug_tile( intensity, string_format( "%.1f", light ) ); + } } - point tile_pos = player_to_screen( point( x, y ) ); - // color overlay - SDL_Color color = lighting_colors[std::min( std::max( 0, color_hue ), 10 )]; - color.a = 100; - color_blocks.first = SDL_BLENDMODE_BLEND; - color_blocks.second.emplace( tile_pos, color ); - - // string overlay - overlay_strings.emplace( - tile_pos + quarter_tile, - formatted_text( text, catacurses::black, direction::NORTH ) ); - }; - - if( g->display_overlay_state( ACTION_DISPLAY_LIGHTING ) ) { - if( g->displaying_lighting_condition == 0 ) { - const float light = here.ambient_light_at( {x, y, center.z} ); - // note: lighting will be constrained in the [1.0, 11.0] range. - int intensity = - static_cast( std::max( 1.0, LIGHT_AMBIENT_LIT - light + 1.0 ) ) - 1; - draw_debug_tile( intensity, string_format( "%.1f", light ) ); + if( g->display_overlay_state( ACTION_DISPLAY_TRANSPARENCY ) ) { + const float tr = here.light_transparency( {x, y, center.z} ); + int intensity = tr <= LIGHT_TRANSPARENCY_SOLID ? 10 : static_cast + ( ( tr - LIGHT_TRANSPARENCY_OPEN_AIR ) * 8 ); + draw_debug_tile( intensity, string_format( "%.2f", tr ) ); } - } - - if( g->display_overlay_state( ACTION_DISPLAY_TRANSPARENCY ) ) { - const float tr = here.light_transparency( {x, y, center.z} ); - int intensity = tr <= LIGHT_TRANSPARENCY_SOLID ? 10 : static_cast - ( ( tr - LIGHT_TRANSPARENCY_OPEN_AIR ) * 8 ); - draw_debug_tile( intensity, string_format( "%.2f", tr ) ); - } - if( g->display_overlay_state( ACTION_DISPLAY_REACHABILITY_ZONES ) ) { - tripoint tile_pos( x, y, center.z ); - int value = here.reachability_cache_value( tile_pos, - g->debug_rz_display.r_cache_vertical, g->debug_rz_display.quadrant ); - // use color to denote reachability from you to the target tile according to the - // cache - bool reachable = here.has_potential_los( you.pos(), tile_pos ); - draw_debug_tile( reachable ? 0 : 6, std::to_string( value ) ); - } + if( g->display_overlay_state( ACTION_DISPLAY_REACHABILITY_ZONES ) ) { + tripoint tile_pos( x, y, center.z ); + int value = here.reachability_cache_value( tile_pos, + g->debug_rz_display.r_cache_vertical, g->debug_rz_display.quadrant ); + // use color to denote reachability from you to the target tile according to the + // cache + bool reachable = here.has_potential_los( you.pos(), tile_pos ); + draw_debug_tile( reachable ? 0 : 6, std::to_string( value ) ); + } - if( !invisible[0] ) { - const visibility_type vis_type = here.get_visibility( ll, cache ); - if( would_apply_vision_effects( vis_type ) ) { - const Creature *critter = creatures.creature_at( pos, true ); - if( has_draw_override( pos ) || has_memory_at( pos_global ) || - ( critter && - ( critter->has_flag( mon_flag_ALWAYS_VISIBLE ) - || you.sees_with_infrared( *critter ) - || you.sees_with_specials( *critter ) ) ) ) { - invisible[0] = true; - } else { - if( is_center_z ) { - here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, - tile_render_info::vision_effect{ vis_type } ); + if( !invisible[0] ) { + const visibility_type vis_type = here.get_visibility( ll, cache ); + if( would_apply_vision_effects( vis_type ) ) { + const Creature *critter = creatures.creature_at( pos, true ); + if( has_draw_override( pos ) || has_memory_at( pos_global ) || + ( critter && + ( critter->has_flag( mon_flag_ALWAYS_VISIBLE ) + || you.sees_with_infrared( *critter ) + || you.sees_with_specials( *critter ) ) ) ) { + invisible[0] = true; + } else { + if( is_center_z ) { + here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + tile_render_info::vision_effect{ vis_type } ); + } + continue; } - continue; } } - } - for( int i = 0; i < 4; i++ ) { - const tripoint np = pos + neighborhood[i]; - invisible[1 + i] = apply_visible( np, ch, here ); - } + for( int i = 0; i < 4; i++ ) { + const tripoint np = pos + neighborhood[i]; + invisible[1 + i] = apply_visible( np, ch, here ); + } - here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, - tile_render_info::sprite{ ll, invisible } ); - // Stop building draw points below when floor reached - if( here.dont_draw_lower_floor( pos ) ) { - break; + here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + tile_render_info::sprite{ ll, invisible } ); + // Stop building draw points below when floor reached + if( here.dont_draw_lower_floor( pos ) ) { + break; + } } } - } } // List all layers for a single z-level @@ -1729,7 +1729,8 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } } else if( f == &cata_tiles::draw_critter_at ) { // Draw - if( !( this->*f )( p.com.pos, ll, p.com.height_3d, invisible, false ) && do_draw_shadow && here.dont_draw_lower_floor( p.com.pos ) ) { + if( !( this->*f )( p.com.pos, ll, p.com.height_3d, invisible, false ) && do_draw_shadow && + here.dont_draw_lower_floor( p.com.pos ) ) { // Draw shadow of flying critters on bottom-most tile if no other critter drawn draw_critter_above( p.com.pos, ll, p.com.height_3d, invisible ); } diff --git a/src/map.h b/src/map.h index 9c24d7790cd39..03d19296a9089 100644 --- a/src/map.h +++ b/src/map.h @@ -311,7 +311,7 @@ struct tile_render_info { tile_render_info( const common &com, const sprite &var ) : com( com ), var( var ) {} }; - + /** * Manage and cache data about a part of the map. * @@ -2345,8 +2345,6 @@ class map bool has_haulable_items( const tripoint &pos ); std::vector get_haulable_items( const tripoint &pos ); - - std::map>> draw_points; }; From 85b1b2f2861ae28cb7ed48cb912f4ca7ddfeeb2e Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Mon, 18 Dec 2023 12:05:35 +0800 Subject: [PATCH 15/26] use correct level cache --- src/cata_tiles.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 0e912f62f21ea..3ff7fa59fa853 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1427,6 +1427,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int const int &x = pos.x; const int &y = pos.y; const bool is_center_z = ( zlevel == center.z ); + const level_cache &ch2 = here.access_cache( zlevel ); // light level is used for choosing between grayscale filter and normal lit tiles. lit_level ll; @@ -1449,7 +1450,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int continue; } } else { - ll = ch.visibility_cache[x][y]; + ll = ch2.visibility_cache[x][y]; } // Add scent value to the overlay_strings list for every visible tile when @@ -1631,7 +1632,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } for( int i = 0; i < 4; i++ ) { const tripoint np = pos + neighborhood[i]; - invisible[1 + i] = apply_visible( np, ch, here ); + invisible[1 + i] = apply_visible( np, ch2, here ); } here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, From f222e1ed6569b53c62cd99ed1af010e783bbbb38 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Mon, 18 Dec 2023 12:23:07 +0800 Subject: [PATCH 16/26] add cache dirty check --- src/cata_tiles.cpp | 24 ++++++++++++++---------- src/map.h | 3 ++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 3ff7fa59fa853..ec513da913083 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1410,11 +1410,14 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } } + if( here.draw_points_cache_dirty ) { + here.draw_points_cache_dirty = false; + here.draw_points_cache.clear(); creature_tracker &creatures = get_creature_tracker(); for( int row = min_row; row < max_row; row ++ ) { // Reserve columns on each row for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { - here.draw_points[zlevel][row].reserve( std::max( 0, max_col - min_col ) ); + here.draw_points_cache[zlevel][row].reserve( std::max( 0, max_col - min_col ) ); } for( int col = min_col; col < max_col; col ++ ) { const std::optional temp = tile_to_player( { col, row } ); @@ -1444,7 +1447,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int invisible[0] = true; } else { if( is_center_z && would_apply_vision_effects( offscreen_type ) ) { - here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::vision_effect{ offscreen_type } ); } continue; @@ -1623,7 +1626,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int invisible[0] = true; } else { if( is_center_z ) { - here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::vision_effect{ vis_type } ); } continue; @@ -1635,7 +1638,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int invisible[1 + i] = apply_visible( np, ch2, here ); } - here.draw_points[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::sprite{ ll, invisible } ); // Stop building draw points below when floor reached if( here.dont_draw_lower_floor( pos ) ) { @@ -1644,6 +1647,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } } } + } // List all layers for a single z-level const std::array drawing_layers = {{ @@ -1676,7 +1680,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // Legacy draw mode for( int row = min_row; row < max_row; row ++ ) { for( auto f : drawing_layers_legacy ) { - for( tile_render_info &p : here.draw_points[center.z][row] ) { + for( tile_render_info &p : here.draw_points_cache[center.z][row] ) { if( const tile_render_info::vision_effect * const var = std::get_if( &p.var ) ) { if( f == &cata_tiles::draw_terrain ) { @@ -1700,13 +1704,13 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // For each row for( int row = cur_any_tile_range.p_min.y; row < cur_any_tile_range.p_max.y; row ++ ) { // Set base height for each tile - for( tile_render_info &p : here.draw_points[cur_zlevel][row] ) { + for( tile_render_info &p : here.draw_points_cache[cur_zlevel][row] ) { p.com.height_3d = ( cur_zlevel - center.z ) * zlevel_height; } // For each layer for( auto f : drawing_layers ) { // For each tile - for( tile_render_info &p : here.draw_points[cur_zlevel][row] ) { + for( tile_render_info &p : here.draw_points_cache[cur_zlevel][row] ) { if( const tile_render_info::vision_effect * const var = std::get_if( &p.var ) ) { if( f == &cata_tiles::draw_terrain ) { @@ -1749,7 +1753,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // display number of monsters to spawn in mapgen preview for( int row = top_any_tile_range.p_min.y; row < top_any_tile_range.p_max.y; row ++ ) { - for( const tile_render_info &p : here.draw_points[center.z][row] ) { + for( const tile_render_info &p : here.draw_points_cache[center.z][row] ) { const tile_render_info::sprite *const var = std::get_if( &p.var ); if( !var ) { @@ -1891,7 +1895,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int void cata_tiles::clear_draw_caches() { - get_map().draw_points.clear(); + get_map().draw_points_cache_dirty = true; } void cata_tiles::draw_minimap( const point &dest, const tripoint ¢er, int width, int height ) @@ -2935,7 +2939,7 @@ bool cata_tiles::draw_sprite_at( printErrorIf( ret != 0, "SDL_RenderCopyEx() failed" ); // this reference passes all the way back up the call chain back to - // cata_tiles::draw() here.draw_points[row][col].com.height_3d + // cata_tiles::draw() here.draw_points_cache[row][col].com.height_3d // where we are accumulating the height of every sprite stacked up in a tile height_3d += tile.height_3d; return true; diff --git a/src/map.h b/src/map.h index 03d19296a9089..36a61e88eba57 100644 --- a/src/map.h +++ b/src/map.h @@ -2345,7 +2345,8 @@ class map bool has_haulable_items( const tripoint &pos ); std::vector get_haulable_items( const tripoint &pos ); - std::map>> draw_points; + bool draw_points_cache_dirty = true; + std::map>> draw_points_cache; }; map &get_map(); From 2f6110d59c46f4322b6b6befb3fb5f102077bfea Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Mon, 18 Dec 2023 13:14:28 +0800 Subject: [PATCH 17/26] only draw overlays for current z-level --- src/cata_tiles.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index ec513da913083..da0176eef63f1 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1456,6 +1456,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int ll = ch2.visibility_cache[x][y]; } + if( is_center_z ) { // Add scent value to the overlay_strings list for every visible tile when // displaying scent if( g->display_overlay_state( ACTION_DISPLAY_SCENT ) && !invisible[0] ) { @@ -1613,6 +1614,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int bool reachable = here.has_potential_los( you.pos(), tile_pos ); draw_debug_tile( reachable ? 0 : 6, std::to_string( value ) ); } + } if( !invisible[0] ) { const visibility_type vis_type = here.get_visibility( ll, cache ); From 6adf7c3943309c51bd5eb7590b1eac2249ffb936 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Tue, 19 Dec 2023 13:46:59 +0800 Subject: [PATCH 18/26] cache overlay_strings and color_blocks --- src/cata_tiles.cpp | 29 ++++++++++++++++++----------- src/map.h | 8 ++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index da0176eef63f1..82951d235bd2d 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1412,7 +1412,12 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int if( here.draw_points_cache_dirty ) { here.draw_points_cache_dirty = false; + // overlay_strings and color_blocks are generated with draw_points and thus are cleared together here.draw_points_cache.clear(); + here.overlay_strings_cache.clear(); + here.color_blocks_cache = {}; + + // Generate new draw points creature_tracker &creatures = get_creature_tracker(); for( int row = min_row; row < max_row; row ++ ) { // Reserve columns on each row @@ -1462,7 +1467,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int if( g->display_overlay_state( ACTION_DISPLAY_SCENT ) && !invisible[0] ) { const int scent_value = get_scent().get( pos ); if( scent_value > 0 ) { - overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, formatted_text( std::to_string( scent_value ), 8 + catacurses::yellow, direction::NORTH ) ); } @@ -1473,7 +1478,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int if( g->display_overlay_state( ACTION_DISPLAY_SCENT_TYPE ) && !invisible[0] ) { const scenttype_id scent_type = get_scent().get_type( pos ); if( !scent_type.is_empty() ) { - overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, formatted_text( scent_type.c_str(), 8 + catacurses::yellow, direction::NORTH ) ); } @@ -1491,7 +1496,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } else { col = catacurses::cyan; } - overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, formatted_text( std::to_string( rad_value ), 8 + col, direction::NORTH ) ); } @@ -1508,7 +1513,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } else { color = catacurses::white; } - overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, formatted_text( std::to_string( val ), color, direction::NORTH ) ); } @@ -1543,7 +1548,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } else { temp_str = string_format( "%.0f", units::to_fahrenheit( temp_value ) ); } - overlay_strings.emplace( player_to_screen( point( x, y ) ), + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ), formatted_text( temp_str, color, text_alignment::left ) ); } @@ -1556,12 +1561,12 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int SDL_Color block_color = visibility ? windowsPalette[catacurses::green] : SDL_Color{ 192, 192, 192, 255 }; block_color.a = 100; - color_blocks.first = SDL_BLENDMODE_BLEND; - color_blocks.second.emplace( player_to_screen( point( x, y ) ), block_color ); + here.color_blocks_cache.first = SDL_BLENDMODE_BLEND; + here.color_blocks_cache.second.emplace( player_to_screen( point( x, y ) ), block_color ); // overlay string std::string visibility_str = visibility ? "+" : "-"; - overlay_strings.emplace( player_to_screen( point( x, y ) ) + quarter_tile, + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + quarter_tile, formatted_text( visibility_str, catacurses::black, direction::NORTH ) ); } @@ -1579,11 +1584,11 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // color overlay SDL_Color color = lighting_colors[std::min( std::max( 0, color_hue ), 10 )]; color.a = 100; - color_blocks.first = SDL_BLENDMODE_BLEND; - color_blocks.second.emplace( tile_pos, color ); + here.color_blocks_cache.first = SDL_BLENDMODE_BLEND; + here.color_blocks_cache.second.emplace( tile_pos, color ); // string overlay - overlay_strings.emplace( + here.overlay_strings_cache.emplace( tile_pos + quarter_tile, formatted_text( text, catacurses::black, direction::NORTH ) ); }; @@ -1650,6 +1655,8 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } } } + overlay_strings = here.overlay_strings_cache; + color_blocks = here.color_blocks_cache; // List all layers for a single z-level const std::array drawing_layers = {{ diff --git a/src/map.h b/src/map.h index 36a61e88eba57..185a04ea69b4d 100644 --- a/src/map.h +++ b/src/map.h @@ -46,6 +46,10 @@ #include "units.h" #include "value_ptr.h" +#if defined(TILES) +#include "cata_tiles.h" +#endif + struct scent_block; namespace catacurses @@ -2345,8 +2349,12 @@ class map bool has_haulable_items( const tripoint &pos ); std::vector get_haulable_items( const tripoint &pos ); +#if defined(TILES) bool draw_points_cache_dirty = true; std::map>> draw_points_cache; + std::multimap overlay_strings_cache; + color_block_overlay_container color_blocks_cache; +#endif }; map &get_map(); From 046ccd5dc3542234cb2ca1faf414bfff8d65f762 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Tue, 19 Dec 2023 19:27:34 +0800 Subject: [PATCH 19/26] astyle --- src/cata_tiles.cpp | 440 ++++++++++++++++++++++----------------------- 1 file changed, 220 insertions(+), 220 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 82951d235bd2d..074e3410b70fa 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1411,250 +1411,250 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } if( here.draw_points_cache_dirty ) { - here.draw_points_cache_dirty = false; - // overlay_strings and color_blocks are generated with draw_points and thus are cleared together - here.draw_points_cache.clear(); - here.overlay_strings_cache.clear(); - here.color_blocks_cache = {}; - - // Generate new draw points - creature_tracker &creatures = get_creature_tracker(); - for( int row = min_row; row < max_row; row ++ ) { - // Reserve columns on each row - for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { - here.draw_points_cache[zlevel][row].reserve( std::max( 0, max_col - min_col ) ); - } - for( int col = min_col; col < max_col; col ++ ) { - const std::optional temp = tile_to_player( { col, row } ); - if( !temp.has_value() ) { - continue; - } + here.draw_points_cache_dirty = false; + // overlay_strings and color_blocks are generated with draw_points and thus are cleared together + here.draw_points_cache.clear(); + here.overlay_strings_cache.clear(); + here.color_blocks_cache = {}; + + // Generate new draw points + creature_tracker &creatures = get_creature_tracker(); + for( int row = min_row; row < max_row; row ++ ) { + // Reserve columns on each row for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { - const tripoint pos( temp.value(), zlevel ); - const tripoint_abs_ms pos_global = here.getglobal( pos ); - const int &x = pos.x; - const int &y = pos.y; - const bool is_center_z = ( zlevel == center.z ); - const level_cache &ch2 = here.access_cache( zlevel ); - - // light level is used for choosing between grayscale filter and normal lit tiles. - lit_level ll; - // invisible to normal eyes - std::array invisible; - invisible[0] = false; - - if( y < min_visible.y || y > max_visible.y || x < min_visible.x || x > max_visible.x ) { - if( has_memory_at( pos_global ) ) { - ll = lit_level::MEMORIZED; - invisible[0] = true; - } else if( has_draw_override( pos ) ) { - ll = lit_level::DARK; - invisible[0] = true; - } else { - if( is_center_z && would_apply_vision_effects( offscreen_type ) ) { - here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, - tile_render_info::vision_effect{ offscreen_type } ); - } - continue; - } - } else { - ll = ch2.visibility_cache[x][y]; + here.draw_points_cache[zlevel][row].reserve( std::max( 0, max_col - min_col ) ); + } + for( int col = min_col; col < max_col; col ++ ) { + const std::optional temp = tile_to_player( { col, row } ); + if( !temp.has_value() ) { + continue; } - - if( is_center_z ) { - // Add scent value to the overlay_strings list for every visible tile when - // displaying scent - if( g->display_overlay_state( ACTION_DISPLAY_SCENT ) && !invisible[0] ) { - const int scent_value = get_scent().get( pos ); - if( scent_value > 0 ) { - here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, - formatted_text( std::to_string( scent_value ), - 8 + catacurses::yellow, direction::NORTH ) ); + for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { + const tripoint pos( temp.value(), zlevel ); + const tripoint_abs_ms pos_global = here.getglobal( pos ); + const int &x = pos.x; + const int &y = pos.y; + const bool is_center_z = ( zlevel == center.z ); + const level_cache &ch2 = here.access_cache( zlevel ); + + // light level is used for choosing between grayscale filter and normal lit tiles. + lit_level ll; + // invisible to normal eyes + std::array invisible; + invisible[0] = false; + + if( y < min_visible.y || y > max_visible.y || x < min_visible.x || x > max_visible.x ) { + if( has_memory_at( pos_global ) ) { + ll = lit_level::MEMORIZED; + invisible[0] = true; + } else if( has_draw_override( pos ) ) { + ll = lit_level::DARK; + invisible[0] = true; + } else { + if( is_center_z && would_apply_vision_effects( offscreen_type ) ) { + here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + tile_render_info::vision_effect{ offscreen_type } ); + } + continue; + } + } else { + ll = ch2.visibility_cache[x][y]; } - } - // Add scent type to the overlay_strings list for every visible tile when - // displaying scent - if( g->display_overlay_state( ACTION_DISPLAY_SCENT_TYPE ) && !invisible[0] ) { - const scenttype_id scent_type = get_scent().get_type( pos ); - if( !scent_type.is_empty() ) { - here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, - formatted_text( scent_type.c_str(), - 8 + catacurses::yellow, direction::NORTH ) ); - } - } + if( is_center_z ) { + // Add scent value to the overlay_strings list for every visible tile when + // displaying scent + if( g->display_overlay_state( ACTION_DISPLAY_SCENT ) && !invisible[0] ) { + const int scent_value = get_scent().get( pos ); + if( scent_value > 0 ) { + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, + formatted_text( std::to_string( scent_value ), + 8 + catacurses::yellow, direction::NORTH ) ); + } + } - if( g->display_overlay_state( ACTION_DISPLAY_RADIATION ) ) { - const auto rad_override = radiation_override.find( pos ); - const bool rad_overridden = rad_override != radiation_override.end(); - if( rad_overridden || !invisible[0] ) { - const int rad_value = rad_overridden ? rad_override->second : - here.get_radiation( pos ); - catacurses::base_color col; - if( rad_value > 0 ) { - col = catacurses::green; - } else { - col = catacurses::cyan; + // Add scent type to the overlay_strings list for every visible tile when + // displaying scent + if( g->display_overlay_state( ACTION_DISPLAY_SCENT_TYPE ) && !invisible[0] ) { + const scenttype_id scent_type = get_scent().get_type( pos ); + if( !scent_type.is_empty() ) { + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, + formatted_text( scent_type.c_str(), + 8 + catacurses::yellow, direction::NORTH ) ); + } } - here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, - formatted_text( std::to_string( rad_value ), - 8 + col, direction::NORTH ) ); - } - } - if( g->display_overlay_state( ACTION_DISPLAY_NPC_ATTACK_POTENTIAL ) ) { - if( npc_attack_rating_map.count( pos ) ) { - const int val = npc_attack_rating_map.at( pos ); - short color; - if( val <= 0 ) { - color = catacurses::red; - } else if( val == max_npc_effectiveness ) { - color = catacurses::cyan; - } else { - color = catacurses::white; + if( g->display_overlay_state( ACTION_DISPLAY_RADIATION ) ) { + const auto rad_override = radiation_override.find( pos ); + const bool rad_overridden = rad_override != radiation_override.end(); + if( rad_overridden || !invisible[0] ) { + const int rad_value = rad_overridden ? rad_override->second : + here.get_radiation( pos ); + catacurses::base_color col; + if( rad_value > 0 ) { + col = catacurses::green; + } else { + col = catacurses::cyan; + } + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, + formatted_text( std::to_string( rad_value ), + 8 + col, direction::NORTH ) ); + } } - here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, - formatted_text( std::to_string( val ), color, - direction::NORTH ) ); - } - } - // Add temperature value to the overlay_strings list for every visible tile when - // displaying temperature - if( g->display_overlay_state( ACTION_DISPLAY_TEMPERATURE ) && !invisible[0] ) { - const units::temperature temp_value = get_weather().get_temperature( pos ); - const float celsius_temp_value = units::to_celsius( temp_value ); - short color; - const short bold = 8; - if( celsius_temp_value > 40 ) { - color = catacurses::red; - } else if( celsius_temp_value > 25 ) { - color = catacurses::yellow + bold; - } else if( celsius_temp_value > 10 ) { - color = catacurses::green + bold; - } else if( celsius_temp_value > 0 ) { - color = catacurses::white + bold; - } else if( celsius_temp_value > -10 ) { - color = catacurses::cyan + bold; - } else { - color = catacurses::blue + bold; - } + if( g->display_overlay_state( ACTION_DISPLAY_NPC_ATTACK_POTENTIAL ) ) { + if( npc_attack_rating_map.count( pos ) ) { + const int val = npc_attack_rating_map.at( pos ); + short color; + if( val <= 0 ) { + color = catacurses::red; + } else if( val == max_npc_effectiveness ) { + color = catacurses::cyan; + } else { + color = catacurses::white; + } + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile, + formatted_text( std::to_string( val ), color, + direction::NORTH ) ); + } + } - std::string temp_str; - if( get_option( "USE_CELSIUS" ) == "celsius" ) { - temp_str = string_format( "%.0f", celsius_temp_value ); - } else if( get_option( "USE_CELSIUS" ) == "kelvin" ) { - temp_str = string_format( "%.0f", units::to_kelvin( temp_value ) ); - } else { - temp_str = string_format( "%.0f", units::to_fahrenheit( temp_value ) ); - } - here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ), - formatted_text( temp_str, color, - text_alignment::left ) ); - } + // Add temperature value to the overlay_strings list for every visible tile when + // displaying temperature + if( g->display_overlay_state( ACTION_DISPLAY_TEMPERATURE ) && !invisible[0] ) { + const units::temperature temp_value = get_weather().get_temperature( pos ); + const float celsius_temp_value = units::to_celsius( temp_value ); + short color; + const short bold = 8; + if( celsius_temp_value > 40 ) { + color = catacurses::red; + } else if( celsius_temp_value > 25 ) { + color = catacurses::yellow + bold; + } else if( celsius_temp_value > 10 ) { + color = catacurses::green + bold; + } else if( celsius_temp_value > 0 ) { + color = catacurses::white + bold; + } else if( celsius_temp_value > -10 ) { + color = catacurses::cyan + bold; + } else { + color = catacurses::blue + bold; + } - if( g->display_overlay_state( ACTION_DISPLAY_VISIBILITY ) && - g->displaying_visibility_creature && !invisible[0] ) { - const bool visibility = g->displaying_visibility_creature->sees( pos ); - - // color overlay. - SDL_Color block_color = visibility ? windowsPalette[catacurses::green] : - SDL_Color{ 192, 192, 192, 255 }; - block_color.a = 100; - here.color_blocks_cache.first = SDL_BLENDMODE_BLEND; - here.color_blocks_cache.second.emplace( player_to_screen( point( x, y ) ), block_color ); - - // overlay string - std::string visibility_str = visibility ? "+" : "-"; - here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + quarter_tile, - formatted_text( visibility_str, catacurses::black, - direction::NORTH ) ); - } + std::string temp_str; + if( get_option( "USE_CELSIUS" ) == "celsius" ) { + temp_str = string_format( "%.0f", celsius_temp_value ); + } else if( get_option( "USE_CELSIUS" ) == "kelvin" ) { + temp_str = string_format( "%.0f", units::to_kelvin( temp_value ) ); + } else { + temp_str = string_format( "%.0f", units::to_fahrenheit( temp_value ) ); + } + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ), + formatted_text( temp_str, color, + text_alignment::left ) ); + } - static std::vector lighting_colors; - // color hue in the range of [0..10], 0 being white, 10 being blue - auto draw_debug_tile = [&]( const int color_hue, const std::string & text ) { - if( lighting_colors.empty() ) { - SDL_Color white = { 255, 255, 255, 255 }; - SDL_Color blue = { 0, 0, 255, 255 }; - lighting_colors = color_linear_interpolate( white, blue, 9 ); - } - point tile_pos = player_to_screen( point( x, y ) ); - - // color overlay - SDL_Color color = lighting_colors[std::min( std::max( 0, color_hue ), 10 )]; - color.a = 100; - here.color_blocks_cache.first = SDL_BLENDMODE_BLEND; - here.color_blocks_cache.second.emplace( tile_pos, color ); - - // string overlay - here.overlay_strings_cache.emplace( - tile_pos + quarter_tile, - formatted_text( text, catacurses::black, direction::NORTH ) ); - }; + if( g->display_overlay_state( ACTION_DISPLAY_VISIBILITY ) && + g->displaying_visibility_creature && !invisible[0] ) { + const bool visibility = g->displaying_visibility_creature->sees( pos ); + + // color overlay. + SDL_Color block_color = visibility ? windowsPalette[catacurses::green] : + SDL_Color{ 192, 192, 192, 255 }; + block_color.a = 100; + here.color_blocks_cache.first = SDL_BLENDMODE_BLEND; + here.color_blocks_cache.second.emplace( player_to_screen( point( x, y ) ), block_color ); + + // overlay string + std::string visibility_str = visibility ? "+" : "-"; + here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + quarter_tile, + formatted_text( visibility_str, catacurses::black, + direction::NORTH ) ); + } - if( g->display_overlay_state( ACTION_DISPLAY_LIGHTING ) ) { - if( g->displaying_lighting_condition == 0 ) { - const float light = here.ambient_light_at( {x, y, center.z} ); - // note: lighting will be constrained in the [1.0, 11.0] range. - int intensity = - static_cast( std::max( 1.0, LIGHT_AMBIENT_LIT - light + 1.0 ) ) - 1; - draw_debug_tile( intensity, string_format( "%.1f", light ) ); - } - } + static std::vector lighting_colors; + // color hue in the range of [0..10], 0 being white, 10 being blue + auto draw_debug_tile = [&]( const int color_hue, const std::string & text ) { + if( lighting_colors.empty() ) { + SDL_Color white = { 255, 255, 255, 255 }; + SDL_Color blue = { 0, 0, 255, 255 }; + lighting_colors = color_linear_interpolate( white, blue, 9 ); + } + point tile_pos = player_to_screen( point( x, y ) ); + + // color overlay + SDL_Color color = lighting_colors[std::min( std::max( 0, color_hue ), 10 )]; + color.a = 100; + here.color_blocks_cache.first = SDL_BLENDMODE_BLEND; + here.color_blocks_cache.second.emplace( tile_pos, color ); + + // string overlay + here.overlay_strings_cache.emplace( + tile_pos + quarter_tile, + formatted_text( text, catacurses::black, direction::NORTH ) ); + }; + + if( g->display_overlay_state( ACTION_DISPLAY_LIGHTING ) ) { + if( g->displaying_lighting_condition == 0 ) { + const float light = here.ambient_light_at( {x, y, center.z} ); + // note: lighting will be constrained in the [1.0, 11.0] range. + int intensity = + static_cast( std::max( 1.0, LIGHT_AMBIENT_LIT - light + 1.0 ) ) - 1; + draw_debug_tile( intensity, string_format( "%.1f", light ) ); + } + } - if( g->display_overlay_state( ACTION_DISPLAY_TRANSPARENCY ) ) { - const float tr = here.light_transparency( {x, y, center.z} ); - int intensity = tr <= LIGHT_TRANSPARENCY_SOLID ? 10 : static_cast - ( ( tr - LIGHT_TRANSPARENCY_OPEN_AIR ) * 8 ); - draw_debug_tile( intensity, string_format( "%.2f", tr ) ); - } + if( g->display_overlay_state( ACTION_DISPLAY_TRANSPARENCY ) ) { + const float tr = here.light_transparency( {x, y, center.z} ); + int intensity = tr <= LIGHT_TRANSPARENCY_SOLID ? 10 : static_cast + ( ( tr - LIGHT_TRANSPARENCY_OPEN_AIR ) * 8 ); + draw_debug_tile( intensity, string_format( "%.2f", tr ) ); + } - if( g->display_overlay_state( ACTION_DISPLAY_REACHABILITY_ZONES ) ) { - tripoint tile_pos( x, y, center.z ); - int value = here.reachability_cache_value( tile_pos, - g->debug_rz_display.r_cache_vertical, g->debug_rz_display.quadrant ); - // use color to denote reachability from you to the target tile according to the - // cache - bool reachable = here.has_potential_los( you.pos(), tile_pos ); - draw_debug_tile( reachable ? 0 : 6, std::to_string( value ) ); - } - } + if( g->display_overlay_state( ACTION_DISPLAY_REACHABILITY_ZONES ) ) { + tripoint tile_pos( x, y, center.z ); + int value = here.reachability_cache_value( tile_pos, + g->debug_rz_display.r_cache_vertical, g->debug_rz_display.quadrant ); + // use color to denote reachability from you to the target tile according to the + // cache + bool reachable = here.has_potential_los( you.pos(), tile_pos ); + draw_debug_tile( reachable ? 0 : 6, std::to_string( value ) ); + } + } - if( !invisible[0] ) { - const visibility_type vis_type = here.get_visibility( ll, cache ); - if( would_apply_vision_effects( vis_type ) ) { - const Creature *critter = creatures.creature_at( pos, true ); - if( has_draw_override( pos ) || has_memory_at( pos_global ) || - ( critter && - ( critter->has_flag( mon_flag_ALWAYS_VISIBLE ) - || you.sees_with_infrared( *critter ) - || you.sees_with_specials( *critter ) ) ) ) { - invisible[0] = true; - } else { - if( is_center_z ) { - here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, - tile_render_info::vision_effect{ vis_type } ); + if( !invisible[0] ) { + const visibility_type vis_type = here.get_visibility( ll, cache ); + if( would_apply_vision_effects( vis_type ) ) { + const Creature *critter = creatures.creature_at( pos, true ); + if( has_draw_override( pos ) || has_memory_at( pos_global ) || + ( critter && + ( critter->has_flag( mon_flag_ALWAYS_VISIBLE ) + || you.sees_with_infrared( *critter ) + || you.sees_with_specials( *critter ) ) ) ) { + invisible[0] = true; + } else { + if( is_center_z ) { + here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + tile_render_info::vision_effect{ vis_type } ); + } + continue; } - continue; } } - } - for( int i = 0; i < 4; i++ ) { - const tripoint np = pos + neighborhood[i]; - invisible[1 + i] = apply_visible( np, ch2, here ); - } + for( int i = 0; i < 4; i++ ) { + const tripoint np = pos + neighborhood[i]; + invisible[1 + i] = apply_visible( np, ch2, here ); + } - here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, - tile_render_info::sprite{ ll, invisible } ); - // Stop building draw points below when floor reached - if( here.dont_draw_lower_floor( pos ) ) { - break; + here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + tile_render_info::sprite{ ll, invisible } ); + // Stop building draw points below when floor reached + if( here.dont_draw_lower_floor( pos ) ) { + break; + } } } } } - } overlay_strings = here.overlay_strings_cache; color_blocks = here.color_blocks_cache; From 7f6ff845fac69059cb3c8ead43f56fe2554e1e2d Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Wed, 20 Dec 2023 02:44:07 +0800 Subject: [PATCH 20/26] appease clang --- src/cata_tiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 074e3410b70fa..539b72fe66380 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1434,7 +1434,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int const tripoint_abs_ms pos_global = here.getglobal( pos ); const int &x = pos.x; const int &y = pos.y; - const bool is_center_z = ( zlevel == center.z ); + const bool is_center_z = zlevel == center.z; const level_cache &ch2 = here.access_cache( zlevel ); // light level is used for choosing between grayscale filter and normal lit tiles. From 8b490b07580c32ab6be8b1a89a58960bd85f741e Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:57:28 +0800 Subject: [PATCH 21/26] fix wrong z-level range --- src/cata_tiles.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 539b72fe66380..b99da1579754b 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1304,13 +1304,13 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int const int max_col = top_any_tile_range.p_max.x; const int min_row = bottom_any_tile_range.p_min.y; const int max_row = top_any_tile_range.p_max.y; - const int draw_min_z = std::max( center.z - fov_3d_z_range, -OVERMAP_DEPTH ); avatar &you = get_avatar(); //limit the render area to maximum view range (121x121 square centered on player) const point min_visible( you.posx() % SEEX, you.posy() % SEEY ); const point max_visible( ( you.posx() % SEEX ) + ( MAPSIZE - 1 ) * SEEX, ( you.posy() % SEEY ) + ( MAPSIZE - 1 ) * SEEY ); + const int draw_min_z = std::max( you.posz() - fov_3d_z_range, -OVERMAP_DEPTH ); const level_cache &ch = here.access_cache( center.z ); @@ -1421,7 +1421,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int creature_tracker &creatures = get_creature_tracker(); for( int row = min_row; row < max_row; row ++ ) { // Reserve columns on each row - for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { + for( int zlevel = center.z; zlevel >= draw_min_z; zlevel -- ) { here.draw_points_cache[zlevel][row].reserve( std::max( 0, max_col - min_col ) ); } for( int col = min_col; col < max_col; col ++ ) { @@ -1429,7 +1429,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int if( !temp.has_value() ) { continue; } - for( int zlevel = center.z; zlevel > draw_min_z; zlevel -- ) { + for( int zlevel = center.z; zlevel >= draw_min_z; zlevel -- ) { const tripoint pos( temp.value(), zlevel ); const tripoint_abs_ms pos_global = here.getglobal( pos ); const int &x = pos.x; From 73a035d58040aba21d07f07a9387b1f3dd8b9c87 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Thu, 21 Dec 2023 02:48:54 +0800 Subject: [PATCH 22/26] fix draw_points not updating --- src/handle_action.cpp | 4 ++++ src/map.cpp | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 3140283ab0279..504ae545433d2 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -263,6 +263,10 @@ input_context game::get_player_input( std::string &action ) const visibility_variables &cache = m.get_visibility_variables_cache(); const level_cache &map_cache = m.get_cache_ref( u.posz() ); const auto &visibility_cache = map_cache.visibility_cache; +#if defined(TILES) + // Mark cata_tiles draw caches as dirty + tilecontext->clear_draw_caches(); +#endif user_turn current_turn; diff --git a/src/map.cpp b/src/map.cpp index e892177ff7366..f911f6bb4dbdf 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -6695,7 +6695,7 @@ void map::update_visibility_cache( const int zlev ) } #if defined(TILES) - // clear previously cached visibility variables from cata_tiles + // Mark cata_tiles draw caches as dirty tilecontext->clear_draw_caches(); #endif @@ -9393,6 +9393,10 @@ void map::build_map_cache( const int zlev, bool skip_lightmap ) player_prev_pos = p; player_prev_range = sr; camera_cache_dirty = true; +#if defined(TILES) + // Mark cata_tiles draw caches as dirty + tilecontext->clear_draw_caches(); +#endif } if( camera_cache_dirty ) { u.moncam_cache = mcache; From 83ce1ac4e451ec32196c5aca77e1960aa06371fe Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Thu, 21 Dec 2023 03:20:35 +0800 Subject: [PATCH 23/26] change function name --- src/cata_tiles.cpp | 2 +- src/cata_tiles.h | 4 ++-- src/handle_action.cpp | 2 +- src/map.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index b99da1579754b..00b8ebd3b989e 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1902,7 +1902,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int "SDL_RenderSetClipRect failed" ); } -void cata_tiles::clear_draw_caches() +void cata_tiles::set_draw_cache_dirty() { get_map().draw_points_cache_dirty = true; } diff --git a/src/cata_tiles.h b/src/cata_tiles.h index 46c6ad8bc3b88..730749dabed69 100644 --- a/src/cata_tiles.h +++ b/src/cata_tiles.h @@ -805,8 +805,8 @@ class cata_tiles pimpl minimap; public: - // Draw caches persist data between draws to avoid unnecessary recalculations - void clear_draw_caches(); + // Draw caches persist data between draws and are only recalculated when dirty + void set_draw_cache_dirty(); std::string memory_map_mode = "color_pixel_sepia"; }; diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 504ae545433d2..4d303deb35580 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -265,7 +265,7 @@ input_context game::get_player_input( std::string &action ) const auto &visibility_cache = map_cache.visibility_cache; #if defined(TILES) // Mark cata_tiles draw caches as dirty - tilecontext->clear_draw_caches(); + tilecontext->set_draw_cache_dirty(); #endif user_turn current_turn; diff --git a/src/map.cpp b/src/map.cpp index f911f6bb4dbdf..9ad7b451e5b02 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -6696,7 +6696,7 @@ void map::update_visibility_cache( const int zlev ) #if defined(TILES) // Mark cata_tiles draw caches as dirty - tilecontext->clear_draw_caches(); + tilecontext->set_draw_cache_dirty(); #endif visibility_variables_cache.last_pos = player_character.pos(); @@ -9395,7 +9395,7 @@ void map::build_map_cache( const int zlev, bool skip_lightmap ) camera_cache_dirty = true; #if defined(TILES) // Mark cata_tiles draw caches as dirty - tilecontext->clear_draw_caches(); + tilecontext->set_draw_cache_dirty(); #endif } if( camera_cache_dirty ) { From e9bc68742351112624204c86816cb3aed3b43008 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:02:09 +0800 Subject: [PATCH 24/26] apply review suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Jianxiang Wang (王健翔) --- src/cata_tiles.cpp | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 00b8ebd3b989e..521bdfcdca5b9 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1381,20 +1381,6 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } const point half_tile( tile_width / 2, 0 ); const point quarter_tile( tile_width / 4, tile_height / 4 ); - if( g->display_overlay_state( ACTION_DISPLAY_VEHICLE_AI ) ) { - for( const wrapped_vehicle &elem : here.get_vehicles() ) { - const vehicle &veh = *elem.v; - const point veh_pos = veh.global_pos3().xy(); - for( const auto &overlay_data : veh.get_debug_overlay_data() ) { - const point pt = veh_pos + std::get<0>( overlay_data ); - const int color = std::get<1>( overlay_data ); - const std::string &text = std::get<2>( overlay_data ); - overlay_strings.emplace( player_to_screen( pt ), - formatted_text( text, color, - text_alignment::left ) ); - } - } - } const auto apply_visible = [&]( const tripoint & np, const level_cache & ch, map & here ) { return np.y < min_visible.y || np.y > max_visible.y || np.x < min_visible.x || np.x > max_visible.x || @@ -1417,6 +1403,21 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int here.overlay_strings_cache.clear(); here.color_blocks_cache = {}; + if( g->display_overlay_state( ACTION_DISPLAY_VEHICLE_AI ) ) { + for( const wrapped_vehicle &elem : here.get_vehicles() ) { + const vehicle &veh = *elem.v; + const point veh_pos = veh.global_pos3().xy(); + for( const auto &overlay_data : veh.get_debug_overlay_data() ) { + const point pt = veh_pos + std::get<0>( overlay_data ); + const int color = std::get<1>( overlay_data ); + const std::string &text = std::get<2>( overlay_data ); + overlay_strings.emplace( player_to_screen( pt ), + formatted_text( text, color, + text_alignment::left ) ); + } + } + } + // Generate new draw points creature_tracker &creatures = get_creature_tracker(); for( int row = min_row; row < max_row; row ++ ) { @@ -1451,11 +1452,11 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int ll = lit_level::DARK; invisible[0] = true; } else { - if( is_center_z && would_apply_vision_effects( offscreen_type ) ) { + if( would_apply_vision_effects( offscreen_type ) ) { here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, tile_render_info::vision_effect{ offscreen_type } ); } - continue; + break; } } else { ll = ch2.visibility_cache[x][y]; @@ -1632,11 +1633,9 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int || you.sees_with_specials( *critter ) ) ) ) { invisible[0] = true; } else { - if( is_center_z ) { - here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, - tile_render_info::vision_effect{ vis_type } ); - } - continue; + here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 }, + tile_render_info::vision_effect{ vis_type } ); + break; } } } From e662ecf437840aebeb9bece62fca0753678be28b Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:03:42 +0800 Subject: [PATCH 25/26] Update src/cata_tiles.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jianxiang Wang (王健翔) --- src/cata_tiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 521bdfcdca5b9..c44d0f14b3123 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1310,7 +1310,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int const point min_visible( you.posx() % SEEX, you.posy() % SEEY ); const point max_visible( ( you.posx() % SEEX ) + ( MAPSIZE - 1 ) * SEEX, ( you.posy() % SEEY ) + ( MAPSIZE - 1 ) * SEEY ); - const int draw_min_z = std::max( you.posz() - fov_3d_z_range, -OVERMAP_DEPTH ); + const int draw_min_z = std::max( you.posz() - max_draw_depth, -OVERMAP_DEPTH ); const level_cache &ch = here.access_cache( center.z ); From 0ad491182288a1a1ffd7b8a6004ae17e16728193 Mon Sep 17 00:00:00 2001 From: Rewryte <129854247+Rewryte@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:03:50 +0800 Subject: [PATCH 26/26] Update src/cata_tiles.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jianxiang Wang (王健翔) --- src/cata_tiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index c44d0f14b3123..0c39342de131d 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -2947,7 +2947,7 @@ bool cata_tiles::draw_sprite_at( printErrorIf( ret != 0, "SDL_RenderCopyEx() failed" ); // this reference passes all the way back up the call chain back to - // cata_tiles::draw() here.draw_points_cache[row][col].com.height_3d + // cata_tiles::draw() here.draw_points_cache[z][row][col].com.height_3d // where we are accumulating the height of every sprite stacked up in a tile height_3d += tile.height_3d; return true;