Skip to content

Commit

Permalink
Merge pull request #41238 from jbytheway/combine_locals_into_points
Browse files Browse the repository at this point in the history
Clang-tidy check to combine locals into points
  • Loading branch information
kevingranade authored Jun 13, 2020
2 parents 8fa42ac + 92516f7 commit c2b5b38
Show file tree
Hide file tree
Showing 74 changed files with 1,556 additions and 1,222 deletions.
10 changes: 4 additions & 6 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,8 @@ int advanced_inventory::print_header( advanced_inventory_pane &pane, aim_locatio
}

const std::string key = get_location_key( static_cast<aim_location>( i ) );
const int x = squares[i].hscreen.x + ofs;
const int y = squares[i].hscreen.y;
mvwprintz( window, point( x, y ), bcolor, "%c", bracket[0] );
const point p( squares[i].hscreen + point( ofs, 0 ) );
mvwprintz( window, p, bcolor, "%c", bracket[0] );
wprintz( window, kcolor, "%s", in_vehicle && sel != AIM_DRAGGED ? "V" : key );
wprintz( window, bcolor, "%c", bracket[1] );
}
Expand Down Expand Up @@ -1614,9 +1613,8 @@ void query_destination_callback::draw_squares( const uilist *menu )
bool canputitems = menu->entries[i - 1].enabled && square.canputitems();
nc_color bcolor = canputitems ? sel == loc ? h_white : c_light_gray : c_dark_gray;
nc_color kcolor = canputitems ? sel == loc ? h_white : c_light_gray : c_dark_gray;
const int x = square.hscreen.x + ofs;
const int y = square.hscreen.y + 5;
mvwprintz( menu->window, point( x, y ), bcolor, "%c", bracket[0] );
const point p( square.hscreen + point( ofs, 5 ) );
mvwprintz( menu->window, p, bcolor, "%c", bracket[0] );
wprintz( menu->window, kcolor, "%s", key );
wprintz( menu->window, bcolor, "%c", bracket[1] );
}
Expand Down
19 changes: 9 additions & 10 deletions src/armor_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,7 @@ void player::sort_armor()

int win_h = 0;
int win_w = 0;
int win_x = 0;
int win_y = 0;
point win;

int cont_h = 0;
int left_w = 0;
Expand Down Expand Up @@ -500,22 +499,22 @@ void player::sort_armor()
ui.on_screen_resize( [&]( ui_adaptor & ui ) {
win_h = std::min( TERMY, std::max( { FULL_SCREEN_HEIGHT, req_right_h, req_mid_h } ) );
win_w = FULL_SCREEN_WIDTH + ( TERMX - FULL_SCREEN_WIDTH ) * 3 / 4;
win_x = TERMX / 2 - win_w / 2;
win_y = TERMY / 2 - win_h / 2;
win.x = TERMX / 2 - win_w / 2;
win.y = TERMY / 2 - win_h / 2;
cont_h = win_h - 4;
left_w = ( win_w - 4 ) / 3;
right_w = left_w;
middle_w = ( win_w - 4 ) - left_w - right_w;
leftListLines = rightListLines = cont_h - 2;
w_sort_armor = catacurses::newwin( win_h, win_w, point( win_x, win_y ) );
w_sort_cat = catacurses::newwin( 1, win_w - 4, point( win_x + 2, win_y + 1 ) );
w_sort_left = catacurses::newwin( cont_h, left_w, point( win_x + 1, win_y + 3 ) );
w_sort_armor = catacurses::newwin( win_h, win_w, win );
w_sort_cat = catacurses::newwin( 1, win_w - 4, win + point( 2, 1 ) );
w_sort_left = catacurses::newwin( cont_h, left_w, win + point( 1, 3 ) );
w_sort_middle = catacurses::newwin( cont_h - num_bp - 1, middle_w,
point( win_x + left_w + 2, win_y + 3 ) );
win + point( 2 + left_w, 3 ) );
w_sort_right = catacurses::newwin( cont_h, right_w,
point( win_x + left_w + middle_w + 3, win_y + 3 ) );
win + point( 3 + left_w + middle_w, 3 ) );
w_encumb = catacurses::newwin( num_bp + 1, middle_w,
point( win_x + left_w + 2, win_y + 3 + cont_h - num_bp - 1 ) );
win + point( 2 + left_w, -1 + 3 + cont_h - num_bp ) );
ui.position_from_window( w_sort_armor );
} );
ui.mark_resize();
Expand Down
10 changes: 5 additions & 5 deletions src/auto_note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,17 @@ void auto_note_manager_gui::show()
ui.on_screen_resize( [&]( ui_adaptor & ui ) {
iContentHeight = FULL_SCREEN_HEIGHT - 2 - iHeaderHeight;

const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0;
const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0;
const point iOffset( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0,
TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 );

w_border = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH,
point( iOffsetX, iOffsetY ) );
iOffset );

w_header = catacurses::newwin( iHeaderHeight, FULL_SCREEN_WIDTH - 2,
point( 1 + iOffsetX, 1 + iOffsetY ) );
iOffset + point_south_east );

w = catacurses::newwin( iContentHeight, FULL_SCREEN_WIDTH - 2,
point( 1 + iOffsetX, iHeaderHeight + 1 + iOffsetY ) );
iOffset + point( 1, iHeaderHeight + 1 ) );

ui.position_from_window( w_border );
} );
Expand Down
26 changes: 13 additions & 13 deletions src/auto_pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ void user_interface::show()

const auto init_windows = [&]( ui_adaptor & ui ) {
iContentHeight = FULL_SCREEN_HEIGHT - 2 - iHeaderHeight;
const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0;
const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0;
const point iOffset( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0,
TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 );

w_border = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH,
point( iOffsetX, iOffsetY ) );
iOffset );
w_header = catacurses::newwin( iHeaderHeight, FULL_SCREEN_WIDTH - 2,
point( 1 + iOffsetX, 1 + iOffsetY ) );
iOffset + point_south_east );
w = catacurses::newwin( iContentHeight, FULL_SCREEN_WIDTH - 2,
point( 1 + iOffsetX, iHeaderHeight + 1 + iOffsetY ) );
iOffset + point( 1, iHeaderHeight + 1 ) );

ui.position_from_window( w_border );
};
Expand Down Expand Up @@ -283,11 +283,11 @@ void user_interface::show()
ui_adaptor help_ui;
catacurses::window w_help;
const auto init_help_window = [&]( ui_adaptor & help_ui ) {
const int iOffsetX = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0;
const int iOffsetY = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0;
const point iOffset( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0,
TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 );
w_help = catacurses::newwin( FULL_SCREEN_HEIGHT / 2 + 2,
FULL_SCREEN_WIDTH * 3 / 4,
point( iOffsetX + 19 / 2, 7 + iOffsetY + FULL_SCREEN_HEIGHT / 2 / 2 ) );
iOffset + point( 19 / 2, 7 + FULL_SCREEN_HEIGHT / 2 / 2 ) );
help_ui.position_from_window( w_help );
};
init_help_window( help_ui );
Expand Down Expand Up @@ -438,17 +438,17 @@ void rule::test_pattern() const
ui_adaptor ui;

const auto init_windows = [&]( ui_adaptor & ui ) {
const int iOffsetX = 15 + ( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 );
const int iOffsetY = 5 + ( TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 :
0 );
const point iOffset( 15 + ( TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 ),
5 + ( TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 :
0 ) );
iContentHeight = FULL_SCREEN_HEIGHT - 8;
iContentWidth = FULL_SCREEN_WIDTH - 30;

w_test_rule_border = catacurses::newwin( iContentHeight + 2, iContentWidth,
point( iOffsetX, iOffsetY ) );
iOffset );
w_test_rule_content = catacurses::newwin( iContentHeight,
iContentWidth - 2,
point( 1 + iOffsetX, 1 + iOffsetY ) );
iOffset + point_south_east );

ui.position_from_window( w_test_rule_border );
};
Expand Down
11 changes: 5 additions & 6 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,15 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
}

// If the player is *attempting to* move on the X axis, update facing direction of their sprite to match.
int new_dx = dest_loc.x - you.posx();
int new_dy = dest_loc.y - you.posy();
point new_d( dest_loc.xy() + point( -you.posx(), -you.posy() ) );

if( !tile_iso ) {
if( new_dx > 0 ) {
if( new_d.x > 0 ) {
you.facing = FacingDirection::RIGHT;
if( is_riding ) {
you.mounted_creature->facing = FacingDirection::RIGHT;
}
} else if( new_dx < 0 ) {
} else if( new_d.x < 0 ) {
you.facing = FacingDirection::LEFT;
if( is_riding ) {
you.mounted_creature->facing = FacingDirection::LEFT;
Expand Down Expand Up @@ -197,14 +196,14 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
// y: left-up key => __ -y FacingDirection::LEFT
// down key => -x +y ______
//
if( new_dx >= 0 && new_dy >= 0 ) {
if( new_d.x >= 0 && new_d.y >= 0 ) {
you.facing = FacingDirection::RIGHT;
if( is_riding ) {
auto mons = you.mounted_creature.get();
mons->facing = FacingDirection::RIGHT;
}
}
if( new_dy <= 0 && new_dx <= 0 ) {
if( new_d.y <= 0 && new_d.x <= 0 ) {
you.facing = FacingDirection::LEFT;
if( is_riding ) {
auto mons = you.mounted_creature.get();
Expand Down
2 changes: 1 addition & 1 deletion src/basecamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extern const std::map<point, direction_data> all_directions;

point direction_from_id( const std::string &id );

const point base_dir = point_zero;
const point base_dir{};
const std::string prefix = "faction_base_";
const std::string id = "FACTION_CAMP";
const int prefix_len = 13;
Expand Down
16 changes: 7 additions & 9 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,30 +459,28 @@ void player::power_bionics()
TITLE_HEIGHT + TITLE_TAB_HEIGHT +
static_cast<int>( my_bionics->size() ) + 2 ) );
WIDTH = FULL_SCREEN_WIDTH + ( TERMX - FULL_SCREEN_WIDTH ) / 2;
const int START_X = ( TERMX - WIDTH ) / 2;
const int START_Y = ( TERMY - HEIGHT ) / 2;
const point START( ( TERMX - WIDTH ) / 2, ( TERMY - HEIGHT ) / 2 );
//wBio is the entire bionic window
wBio = catacurses::newwin( HEIGHT, WIDTH, point( START_X, START_Y ) );
wBio = catacurses::newwin( HEIGHT, WIDTH, START );

LIST_HEIGHT = HEIGHT - TITLE_HEIGHT - TITLE_TAB_HEIGHT - 2;

const int DESCRIPTION_WIDTH = WIDTH - 2 - 40;
const int DESCRIPTION_START_Y = START_Y + TITLE_HEIGHT + TITLE_TAB_HEIGHT + 1;
const int DESCRIPTION_START_X = START_X + 1 + 40;
const int DESCRIPTION_START_Y = START.y + TITLE_HEIGHT + TITLE_TAB_HEIGHT + 1;
const int DESCRIPTION_START_X = START.x + 1 + 40;
//w_description is the description panel that is controlled with ! key
w_description = catacurses::newwin( LIST_HEIGHT, DESCRIPTION_WIDTH,
point( DESCRIPTION_START_X, DESCRIPTION_START_Y ) );

// Title window
const int TITLE_START_Y = START_Y + 1;
const int TITLE_START_Y = START.y + 1;
const int HEADER_LINE_Y = TITLE_HEIGHT + TITLE_TAB_HEIGHT;
w_title = catacurses::newwin( TITLE_HEIGHT, WIDTH - 2, point( START_X + 1,
START_Y ) );
w_title = catacurses::newwin( TITLE_HEIGHT, WIDTH - 2, START + point_east );

const int TAB_START_Y = TITLE_START_Y + 3;
//w_tabs is the tab bar for passive and active bionic groups
w_tabs = catacurses::newwin( TITLE_TAB_HEIGHT, WIDTH,
point( START_X, TAB_START_Y ) );
point( START.x, TAB_START_Y ) );

// offset for display: bionic with index i is drawn at y=list_start_y+i
// drawing the bionics starts with bionic[scroll_position]
Expand Down
56 changes: 26 additions & 30 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ void tileset_loader::load_tile_spritelists( const JsonObject &entry,
}

struct tile_render_info {
const tripoint pos;
const tripoint pos{};
// accumulator for 3d tallness of sprites rendered here so far;
int height_3d = 0;
lit_level ll;
Expand Down Expand Up @@ -1007,9 +1007,8 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
render_fill_rect( renderer, clipRect, 0, 0, 0 );
}

int sx = 0;
int sy = 0;
get_window_tile_counts( width, height, sx, sy );
point s;
get_window_tile_counts( width, height, s.x, s.y );

init_light();
g->m.update_visibility_cache( center.z );
Expand All @@ -1025,9 +1024,9 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
screentile_height = divide_round_up( height, tile_height );

const int min_col = 0;
const int max_col = sx;
const int max_col = s.x;
const int min_row = 0;
const int max_row = sy;
const int max_row = s.y;

//limit the render area to maximum view range (121x121 square centered on player)
const int min_visible_x = g->u.posx() % SEEX;
Expand Down Expand Up @@ -1092,11 +1091,11 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
if( iso_mode ) {
//in isometric, rows and columns represent a checkerboard screen space, and we place
//the appropriate tile in valid squares by getting position relative to the screen center.
if( modulo( row - sy / 2, 2 ) != modulo( col - sx / 2, 2 ) ) {
if( modulo( row - s.y / 2, 2 ) != modulo( col - s.x / 2, 2 ) ) {
continue;
}
temp_x = divide_round_down( col - row - sx / 2 + sy / 2, 2 ) + o.x;
temp_y = divide_round_down( row + col - sy / 2 - sx / 2, 2 ) + o.y;
temp_x = divide_round_down( col - row - s.x / 2 + s.y / 2, 2 ) + o.x;
temp_y = divide_round_down( row + col - s.y / 2 - s.x / 2, 2 ) + o.y;
} else {
temp_x = col + o.x;
temp_y = row + o.y;
Expand Down Expand Up @@ -1317,8 +1316,8 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
// ( col - sx / 2 ) % 2 = ( row - sy / 2 ) % 2
// ||
// \/
const int col = mem_y + mem_x + sx / 2 - o.y - o.x;
const int row = mem_y - mem_x + sy / 2 - o.y + o.x;
const int col = mem_y + mem_x + s.x / 2 - o.y - o.x;
const int row = mem_y - mem_x + s.y / 2 - o.y + o.x;
if( already_drawn.contains( point( col, row ) ) ) {
continue;
}
Expand Down Expand Up @@ -2150,22 +2149,21 @@ bool cata_tiles::draw_terrain_below( const tripoint &p, const lit_level, int &,
belowRect.w = ( belowRect.w * 3 ) / 4;
}
// translate from player-relative to screen relative tile position
int screen_x = 0;
int screen_y = 0;
point screen;
if( tile_iso ) {
screen_x = ( ( pbelow.x - o.x ) - ( o.y - pbelow.y ) + screentile_width - 2 ) * tile_width / 2 +
screen.x = ( ( pbelow.x - o.x ) - ( o.y - pbelow.y ) + screentile_width - 2 ) * tile_width / 2 +
op.x;
// y uses tile_width because width is definitive for iso tiles
// tile footprints are half as tall as wide, arbitrarily tall
screen_y = ( ( pbelow.y - o.y ) - ( pbelow.x - o.x ) - 4 ) * tile_width / 4 +
screen.y = ( ( pbelow.y - o.y ) - ( pbelow.x - o.x ) - 4 ) * tile_width / 4 +
screentile_height * tile_height / 2 + // TODO: more obvious centering math
op.y;
} else {
screen_x = ( pbelow.x - o.x ) * tile_width + op.x;
screen_y = ( pbelow.y - o.y ) * tile_height + op.y;
screen.x = ( pbelow.x - o.x ) * tile_width + op.x;
screen.y = ( pbelow.y - o.y ) * tile_height + op.y;
}
belowRect.x = screen_x + ( tile_width - belowRect.w ) / 2;
belowRect.y = screen_y + ( tile_height - belowRect.h ) / 2;
belowRect.x = screen.x + ( tile_width - belowRect.w ) / 2;
belowRect.y = screen.y + ( tile_height - belowRect.h ) / 2;
if( tile_iso ) {
belowRect.y += tile_height / 8;
}
Expand Down Expand Up @@ -3298,8 +3296,7 @@ void cata_tiles::draw_sct_frame( std::multimap<point, formatted_text> &overlay_s
const bool use_font = get_option<bool>( "ANIMATION_SCT_USE_FONT" );

for( auto iter = SCT.vSCT.begin(); iter != SCT.vSCT.end(); ++iter ) {
const int iDX = iter->getPosX();
const int iDY = iter->getPosY();
const point iD( iter->getPosX(), iter->getPosY() );
const int full_text_length = utf8_width( iter->getText() );

int iOffsetX = 0;
Expand All @@ -3317,15 +3314,15 @@ void cata_tiles::draw_sct_frame( std::multimap<point, formatted_text> &overlay_s
const int direction_offset = ( -direction_XY( direction ).x + 1 ) * full_text_length / 2;

overlay_strings.emplace(
player_to_screen( point( iDX + direction_offset, iDY ) ),
player_to_screen( iD + point( direction_offset, 0 ) ),
formatted_text( sText, FG, direction ) );
} else {
for( auto &it : sText ) {
const std::string generic_id = get_ascii_tile_id( it, FG, -1 );

if( tileset_ptr->find_tile_type( generic_id ) ) {
draw_from_id_string( generic_id, C_NONE, empty_string,
{ iDX + iOffsetX, iDY + iOffsetY, g->u.pos().z }, 0, 0, lit_level::LIT, false );
iD + tripoint( iOffsetX, iOffsetY, g->u.pos().z ), 0, 0, lit_level::LIT, false );
}

if( tile_iso ) {
Expand Down Expand Up @@ -3529,21 +3526,20 @@ void cata_tiles::do_tile_loading_report()

point cata_tiles::player_to_screen( const point &p ) const
{
int screen_x = 0;
int screen_y = 0;
point screen;
if( tile_iso ) {
screen_x = ( ( p.x - o.x ) - ( o.y - p.y ) + screentile_width - 2 ) * tile_width / 2 +
screen.x = ( ( p.x - o.x ) - ( o.y - p.y ) + screentile_width - 2 ) * tile_width / 2 +
op.x;
// y uses tile_width because width is definitive for iso tiles
// tile footprints are half as tall as wide, arbitrarily tall
screen_y = ( ( p.y - o.y ) - ( p.x - o.x ) - 4 ) * tile_width / 4 +
screen.y = ( ( p.y - o.y ) - ( p.x - o.x ) - 4 ) * tile_width / 4 +
screentile_height * tile_height / 2 + // TODO: more obvious centering math
op.y;
} else {
screen_x = ( p.x - o.x ) * tile_width + op.x;
screen_y = ( p.y - o.y ) * tile_height + op.y;
screen.x = ( p.x - o.x ) * tile_width + op.x;
screen.y = ( p.y - o.y ) * tile_height + op.y;
}
return {screen_x, screen_y};
return {screen};
}

template<typename Iter, typename Func>
Expand Down
Loading

0 comments on commit c2b5b38

Please sign in to comment.