From faf0ed76d26846e9dee240891d273e5c1ac41918 Mon Sep 17 00:00:00 2001 From: redpenguiney <119638232+redpenguiney@users.noreply.github.com> Date: Fri, 1 Mar 2024 22:47:18 -0800 Subject: [PATCH 1/3] yay it works --- src/cata_tiles.cpp | 57 +++++++++++++++++++++++----------------------- src/submap.h | 29 +++++++++++++++++++++++ 2 files changed, 58 insertions(+), 28 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index a2d974d021a2b..64c8dcb39628b 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -472,7 +472,7 @@ void tileset_cache::loader::create_textures_from_tile_atlas( const SDL_Surface_P for( tiles_pixel_color_entry &entry : tile_values_data ) { std::vector *tile_values = std::get<0>( entry ); color_pixel_function_pointer color_pixel_function = get_color_pixel_function( std::get<1> - ( entry ) ); + ( entry ) ); if( !color_pixel_function ) { // TODO: Move it inside apply_color_filter. copy_surface_to_texture( tile_atlas, offset, *tile_values ); @@ -934,26 +934,26 @@ void tileset_cache::loader::process_variations_after_loading( for( auto &v : vs ) { // in a given variation, erase any invalid sprite ids v.obj.erase( - std::remove_if( - v.obj.begin(), - v.obj.end(), + std::remove_if( + v.obj.begin(), + v.obj.end(), [&]( int id ) { return id >= offset || id < 0; } ), v.obj.end() - ); + ); } // erase any variations with no valid sprite ids left vs.erase( - std::remove_if( - vs.begin(), - vs.end(), + std::remove_if( + vs.begin(), + vs.end(), [&]( const weighted_object> &o ) { return o.obj.empty(); } - ), + ), vs.end() - ); + ); // populate the bookkeeping table used for selecting sprite variations vs.precalc(); } @@ -1365,9 +1365,9 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int here.prev_o = o; you.prepare_map_memory_region( - here.getglobal( tripoint( min_mm_reg, center.z ) ), - here.getglobal( tripoint( max_mm_reg, center.z ) ) - ); + here.getglobal( tripoint( min_mm_reg, center.z ) ), + here.getglobal( tripoint( max_mm_reg, center.z ) ) + ); //set up a default tile for the edges outside the render area visibility_type offscreen_type = visibility_type::HIDDEN; @@ -1601,8 +1601,8 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // string overlay here.overlay_strings_cache.emplace( - tile_pos + quarter_tile, - formatted_text( text, catacurses::black, direction::NORTH ) ); + tile_pos + quarter_tile, + formatted_text( text, catacurses::black, direction::NORTH ) ); }; if( g->display_overlay_state( ACTION_DISPLAY_LIGHTING ) ) { @@ -1709,7 +1709,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int 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; + ? z_any_tile_range[center.z - cur_zlevel] : top_any_tile_range; // 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 @@ -3276,7 +3276,7 @@ bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &hei const auto furn = [&]( const tripoint & q, const bool invis ) -> furn_id { const auto it = furniture_override.find( q ); return it != furniture_override.end() ? it->second : - ( !overridden || !invis ) ? here.furn( q ) : f_null; + ( !overridden || !invis ) ? here.furn( q ) : f_null; }; const std::array neighborhood = { static_cast( furn( p + point_south, invisible[1] ) ), @@ -3370,7 +3370,7 @@ bool cata_tiles::draw_trap( const tripoint &p, const lit_level ll, int &height_3 const auto tr_at = [&]( const tripoint & q, const bool invis ) -> trap_id { const auto it = trap_override.find( q ); return it != trap_override.end() ? it->second : - ( !overridden || !invis ) ? here.tr_at( q ).loadid : tr_null; + ( !overridden || !invis ) ? here.tr_at( q ).loadid : tr_null; }; const std::array neighborhood = { static_cast( tr_at( p + point_south, invisible[1] ) ), @@ -3473,8 +3473,7 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int auto has_field = [&]( field_type_id fld, const tripoint & q, const bool invis ) -> field_type_id { // go through the fields and see if they are equal field_type_id found = fd_null; - for( std::pair &this_fld : here.field_at( q ) ) - { + for( std::pair &this_fld : here.field_at( q ) ) { if( this_fld.first == fld ) { found = fld; } @@ -3579,7 +3578,7 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int auto field_at = [&]( const tripoint & q, const bool invis ) -> field_type_id { const auto it = field_override.find( q ); return it != field_override.end() ? it->second : - ( !fld_overridden || !invis ) ? here.field_at( q ).displayed_field_type() : fd_null; + ( !fld_overridden || !invis ) ? here.field_at( q ).displayed_field_type() : fd_null; }; // for rotation information const std::array neighborhood = { @@ -3648,7 +3647,7 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int 0, layer_lit, layer_nv, height_3d, 0, variant, layer_var.offset ); // if the top item is already being layered don't draw it later - if( i.typeId() == tile.get_uppermost_item().typeId() ) { + if( i.typeId() == tile.get_most_visible_item().typeId() ) { drawtop = false; } @@ -3693,7 +3692,7 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int 0, layer_lit, layer_nv, height_3d, 0, variant, layer_var.offset ); // if the top item is already being layered don't draw it later - if( i.typeId() == tile.get_uppermost_item().typeId() ) { + if( i.typeId() == tile.get_most_visible_item().typeId() ) { drawtop = false; } @@ -3715,7 +3714,9 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int hilite = std::get<2>( it_override->second ); it_type = item::find_type( it_id ); } else if( !invisible[0] && here.sees_some_items( p, get_player_character() ) ) { - const item &itm = tile.get_uppermost_item(); + // instead of just drawing the uppermost item, we draw the uppermost favorite item, and if there is none, we draw the item with the greatest volume. + const item &itm = tile.get_most_visible_item(); + if( itm.has_itype_variant() ) { variant = itm.itype_variant().id; } @@ -4717,8 +4718,8 @@ void cata_tiles::draw_sct_frame( std::multimap &overlay_s full_text_length / 2; overlay_strings.emplace( - player_to_screen( iD + point( direction_offset, 0 ) ), - formatted_text( sText, FG, direction ) ); + player_to_screen( iD + point( direction_offset, 0 ) ), + formatted_text( sText, FG, direction ) ); } else { for( char &it : sText ) { const std::string generic_id = get_ascii_tile_id( it, FG, -1 ); @@ -4818,7 +4819,7 @@ void cata_tiles::get_terrain_orientation( const tripoint &p, int &rota, int &sub const auto ter = [&]( const tripoint & q, const bool invis ) -> ter_id { const auto override = ter_override.find( q ); return override != ter_override.end() ? override->second : - ( !overridden || !invis ) ? here.ter( q ) : t_null; + ( !overridden || !invis ) ? here.ter( q ) : t_null; }; // get terrain at x,y @@ -5238,7 +5239,7 @@ void cata_tiles::do_tile_loading_report() std::vector map_extra_ids = MapExtras::get_all_function_names(); map_extra_ids.erase( - std::remove_if( map_extra_ids.begin(), map_extra_ids.end(), + std::remove_if( map_extra_ids.begin(), map_extra_ids.end(), []( const map_extra_id & id ) { return !id->autonote; } ), map_extra_ids.end() ); diff --git a/src/submap.h b/src/submap.h index 9aa6584ca1f48..d6a22cfee4bc2 100644 --- a/src/submap.h +++ b/src/submap.h @@ -418,6 +418,35 @@ class maptile_impl return *std::prev( sm->get_items( pos() ).cend() ); } + /** Returns the uppermost favorite item if there is a favorite item. Otherwise, returns the item with the greatest volume. + * + * Assumes there is at least one item. + * Used to decide which item to render. + * TODO: might be slow enough to justify storing the most visible item for each tile? + */ + const item &get_most_visible_item() const { + + const item *biggest_item = nullptr; + units::volume biggest_volume = 0_ml; + + // uppermost item is at end of the list, so iterate backwards so uppermost item is preferred + auto items = get_items(); + // unsigned int i = get_items().size(); + for( auto it = items.rbegin(); it != items.rend(); it++ ) { + const auto &item = *it; + + if( item.is_favorite ) { + return item; + } + + if( item.base_volume() > biggest_volume ) { + biggest_item = &item; + biggest_volume = item.base_volume(); + } + } + return *biggest_item; + } + // Gets all items const cata::colony &get_items() const { return sm->get_items( pos() ); From 7b3ae8f6f3891bbbd077d4ea96ce9b4b83d6bd17 Mon Sep 17 00:00:00 2001 From: redpenguiney <119638232+redpenguiney@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:16:56 -0800 Subject: [PATCH 2/3] address some complaints in pr --- src/submap.cpp | 2 ++ src/submap.h | 31 ++++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/submap.cpp b/src/submap.cpp index 21124576852b6..90c9f09e81e16 100644 --- a/src/submap.cpp +++ b/src/submap.cpp @@ -296,6 +296,8 @@ void submap::rotate( int turns ) computers = rot_comp; } + + void submap::mirror( bool horizontally ) { if( is_uniform() ) { diff --git a/src/submap.h b/src/submap.h index d6a22cfee4bc2..d028fc51c3556 100644 --- a/src/submap.h +++ b/src/submap.h @@ -420,30 +420,35 @@ class maptile_impl /** Returns the uppermost favorite item if there is a favorite item. Otherwise, returns the item with the greatest volume. * - * Assumes there is at least one item. + * Requires that there is at least one item, otherwise throws. * Used to decide which item to render. - * TODO: might be slow enough to justify storing the most visible item for each tile? */ - const item &get_most_visible_item() const { + const item& get_most_visible_item() const { + + const cata::colony & items = get_items(); - const item *biggest_item = nullptr; + // make sure there is at least one item + if( items.size() == 0 ) { + throw std::runtime_error("Call to get_most_visible_item() with no visible item!\n"); + } + + const item *biggest_item = &*items.begin(); units::volume biggest_volume = 0_ml; - // uppermost item is at end of the list, so iterate backwards so uppermost item is preferred - auto items = get_items(); - // unsigned int i = get_items().size(); + // uppermost item is at end of the list, so iterate backwards so uppermost (last dropped) item is preferred for( auto it = items.rbegin(); it != items.rend(); it++ ) { - const auto &item = *it; + const item ¤t_item = *it; - if( item.is_favorite ) { - return item; + if( current_item.is_favorite ) { + return current_item; } - if( item.base_volume() > biggest_volume ) { - biggest_item = &item; - biggest_volume = item.base_volume(); + if( current_item.base_volume() > biggest_volume ) { + biggest_item = ¤t_item; + biggest_volume = current_item.base_volume(); } } + return *biggest_item; } From f0d5733677955dcfa797df0bd22ef9e428a76c28 Mon Sep 17 00:00:00 2001 From: redpenguiney <119638232+redpenguiney@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:20:16 -0800 Subject: [PATCH 3/3] address some complaints in the pr --- src/submap.cpp | 2 -- src/submap.h | 31 +++++++++++++------------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/submap.cpp b/src/submap.cpp index 90c9f09e81e16..21124576852b6 100644 --- a/src/submap.cpp +++ b/src/submap.cpp @@ -296,8 +296,6 @@ void submap::rotate( int turns ) computers = rot_comp; } - - void submap::mirror( bool horizontally ) { if( is_uniform() ) { diff --git a/src/submap.h b/src/submap.h index d028fc51c3556..d6a22cfee4bc2 100644 --- a/src/submap.h +++ b/src/submap.h @@ -420,35 +420,30 @@ class maptile_impl /** Returns the uppermost favorite item if there is a favorite item. Otherwise, returns the item with the greatest volume. * - * Requires that there is at least one item, otherwise throws. + * Assumes there is at least one item. * Used to decide which item to render. + * TODO: might be slow enough to justify storing the most visible item for each tile? */ - const item& get_most_visible_item() const { - - const cata::colony & items = get_items(); + const item &get_most_visible_item() const { - // make sure there is at least one item - if( items.size() == 0 ) { - throw std::runtime_error("Call to get_most_visible_item() with no visible item!\n"); - } - - const item *biggest_item = &*items.begin(); + const item *biggest_item = nullptr; units::volume biggest_volume = 0_ml; - // uppermost item is at end of the list, so iterate backwards so uppermost (last dropped) item is preferred + // uppermost item is at end of the list, so iterate backwards so uppermost item is preferred + auto items = get_items(); + // unsigned int i = get_items().size(); for( auto it = items.rbegin(); it != items.rend(); it++ ) { - const item ¤t_item = *it; + const auto &item = *it; - if( current_item.is_favorite ) { - return current_item; + if( item.is_favorite ) { + return item; } - if( current_item.base_volume() > biggest_volume ) { - biggest_item = ¤t_item; - biggest_volume = current_item.base_volume(); + if( item.base_volume() > biggest_volume ) { + biggest_item = &item; + biggest_volume = item.base_volume(); } } - return *biggest_item; }