From 3e5d61c2e978832b99358d9579214d2e60a3cb7d Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sun, 24 Jul 2022 03:31:07 +0200 Subject: [PATCH] Remove the write_to_screen parameter of refresh* functions It isn't up to the caller to determine when the update should be performed. We'll always do it at the next opportunity, i.e. whenever the queued connection fires. --- client/climisc.cpp | 4 ++-- client/control.cpp | 10 ++++---- client/editor.cpp | 2 +- client/mapview_common.cpp | 49 ++++++++++++++------------------------- client/mapview_common.h | 7 +++--- client/packhand.cpp | 24 +++++++++---------- 6 files changed, 41 insertions(+), 55 deletions(-) diff --git a/client/climisc.cpp b/client/climisc.cpp index 131377ef6f..bc7e79e60e 100644 --- a/client/climisc.cpp +++ b/client/climisc.cpp @@ -125,7 +125,7 @@ void client_remove_unit(struct unit *punit) } } - refresh_unit_mapcanvas(&old_unit, ptile, true, false); + refresh_unit_mapcanvas(&old_unit, ptile, true); flush_dirty_overview(); } @@ -161,7 +161,7 @@ void client_remove_city(struct city *pcity) } game_remove_city(&wld, pcity); city_report_dialog_update(); - refresh_city_mapcanvas(&old_city, ptile, true, false); + refresh_city_mapcanvas(&old_city, ptile, true); } /** diff --git a/client/control.cpp b/client/control.cpp index b73fd2ea6e..3d808919b0 100644 --- a/client/control.cpp +++ b/client/control.cpp @@ -432,7 +432,7 @@ static void current_focus_append(struct unit *punit) get_units_in_focus().push_back(punit); punit->client.focus_status = FOCUS_AVAIL; - refresh_unit_mapcanvas(punit, unit_tile(punit), true, false); + refresh_unit_mapcanvas(punit, unit_tile(punit), true); if (should_ask_server_for_actions(punit) && can_ask_server_for_actions()) { ask_server_for_actions(punit); @@ -500,7 +500,7 @@ void unit_focus_set(struct unit *punit) /* Redraw the old focus unit (to fix blinking or remove the selection * circle). */ for (const auto punit_old : get_units_in_focus()) { - refresh_unit_mapcanvas(punit_old, unit_tile(punit_old), true, false); + refresh_unit_mapcanvas(punit_old, unit_tile(punit_old), true); } get_units_in_focus().clear(); @@ -834,7 +834,7 @@ int blink_active_unit() /* We flush to screen directly here. This is most likely faster * since these drawing operations are all small but may be spread * out widely. */ - refresh_unit_mapcanvas(punit, unit_tile(punit), false, true); + refresh_unit_mapcanvas(punit, unit_tile(punit), false); } } @@ -2394,7 +2394,7 @@ void do_move_unit(struct unit *punit, struct unit *target_unit) /* We have to refresh the tile before moving. This will draw * the tile without the unit (because it was unlinked above). */ - refresh_unit_mapcanvas(punit, src_tile, true, false); + refresh_unit_mapcanvas(punit, src_tile, true); if (!gui_options.auto_center_on_automated && punit->ssa_controller != SSA_NONE) { @@ -2416,7 +2416,7 @@ void do_move_unit(struct unit *punit, struct unit *target_unit) // For find_visible_unit(), see above. punit_moving = nullptr; - refresh_unit_mapcanvas(punit, dst_tile, true, false); + refresh_unit_mapcanvas(punit, dst_tile, true); } /* With the "full" city bar we have to update the city bar when units move diff --git a/client/editor.cpp b/client/editor.cpp index bcf49dfc9c..fae1cb7ebe 100644 --- a/client/editor.cpp +++ b/client/editor.cpp @@ -745,7 +745,7 @@ static void editor_end_selection_rectangle(int canvas_x, int canvas_y) } if (ptile) { - refresh_tile_mapcanvas(ptile, true, true); + refresh_tile_mapcanvas(ptile, true); } return; diff --git a/client/mapview_common.cpp b/client/mapview_common.cpp index 9ceadfca1b..b4ff600882 100644 --- a/client/mapview_common.cpp +++ b/client/mapview_common.cpp @@ -97,30 +97,22 @@ void anim_delay(int milliseconds) /** Refreshes a single tile on the map canvas. */ -void refresh_tile_mapcanvas(const tile *ptile, bool full_refresh, - bool write_to_screen) +void refresh_tile_mapcanvas(const tile *ptile, bool full_refresh) { freeciv::map_updates_handler::invoke( qOverload(&freeciv::map_updates_handler::update), ptile, full_refresh); - if (write_to_screen) { - unqueue_mapview_updates(true); - flush_dirty_overview(); - } } /** Refreshes a single unit on the map canvas. */ void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, - bool full_refresh, bool write_to_screen) + bool full_refresh) { freeciv::map_updates_handler::invoke( qOverload(&freeciv::map_updates_handler::update), punit, full_refresh); - if (write_to_screen) { - unqueue_mapview_updates(true); - } } /** @@ -130,15 +122,11 @@ void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, also be refreshed. Otherwise only the base city sprite is refreshed. */ void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile, - bool full_refresh, bool write_to_screen) + bool full_refresh) { freeciv::map_updates_handler::invoke( qOverload(&freeciv::map_updates_handler::update), pcity, full_refresh); - if (write_to_screen) { - unqueue_mapview_updates(true); - flush_dirty_overview(); - } } /** @@ -1034,7 +1022,7 @@ void toggle_city_color(struct city *pcity) color_index = (color_index + 1) % NUM_CITY_COLORS; } - refresh_city_mapcanvas(pcity, pcity->tile, true, false); + refresh_city_mapcanvas(pcity, pcity->tile, true); } /** @@ -1052,7 +1040,7 @@ void toggle_unit_color(struct unit *punit) color_index = (color_index + 1) % NUM_CITY_COLORS; } - refresh_unit_mapcanvas(punit, unit_tile(punit), true, false); + refresh_unit_mapcanvas(punit, unit_tile(punit), true); } /** @@ -1614,10 +1602,10 @@ void decrease_unit_hp_smooth(struct unit *punit0, int hp0, if (fc_rand(diff0 + diff1) < diff0) { punit0->hp--; - refresh_unit_mapcanvas(punit0, unit_tile(punit0), false, false); + refresh_unit_mapcanvas(punit0, unit_tile(punit0), false); } else { punit1->hp--; - refresh_unit_mapcanvas(punit1, unit_tile(punit1), false, false); + refresh_unit_mapcanvas(punit1, unit_tile(punit1), false); } unqueue_mapview_updates(true); @@ -1626,8 +1614,7 @@ void decrease_unit_hp_smooth(struct unit *punit0, int hp0, if (num_tiles_explode_unit > 0 && tile_to_canvas_pos(&canvas_x, &canvas_y, unit_tile(losing_unit))) { - refresh_unit_mapcanvas(losing_unit, unit_tile(losing_unit), false, - false); + refresh_unit_mapcanvas(losing_unit, unit_tile(losing_unit), false); unqueue_mapview_updates(false); QPainter p(mapview.tmp_store); p.drawPixmap(canvas_x, canvas_y, *mapview.store, canvas_x, canvas_y, @@ -1658,8 +1645,8 @@ void decrease_unit_hp_smooth(struct unit *punit0, int hp0, } set_units_in_combat(nullptr, nullptr); - refresh_unit_mapcanvas(punit0, unit_tile(punit0), true, false); - refresh_unit_mapcanvas(punit1, unit_tile(punit1), true, false); + refresh_unit_mapcanvas(punit0, unit_tile(punit0), true); + refresh_unit_mapcanvas(punit1, unit_tile(punit1), true); flush_dirty_overview(); } @@ -2230,7 +2217,7 @@ void mapdeco_set_crosshair(const struct tile *ptile, bool crosshair) } if (!changed) { - refresh_tile_mapcanvas(ptile, false, false); + refresh_tile_mapcanvas(ptile, false); } } @@ -2252,7 +2239,7 @@ bool mapdeco_is_crosshair_set(const struct tile *ptile) void mapdeco_clear_crosshairs() { for (const auto *ptile : qAsConst(*mapdeco_crosshair_set)) { - refresh_tile_mapcanvas(ptile, false, false); + refresh_tile_mapcanvas(ptile, false); } mapdeco_crosshair_set->clear(); } @@ -2291,8 +2278,8 @@ void mapdeco_add_gotoline(const struct tile *ptile, enum direction8 dir, } if (changed) { - refresh_tile_mapcanvas(ptile, false, false); - refresh_tile_mapcanvas(ptile_dest, false, false); + refresh_tile_mapcanvas(ptile, false); + refresh_tile_mapcanvas(ptile_dest, false); } } @@ -2365,12 +2352,12 @@ void mapdeco_clear_gotoroutes() { gotohash::const_iterator i = mapdeco_gotoline->constBegin(); while (i != mapdeco_gotoline->constEnd()) { - refresh_tile_mapcanvas(i.key(), false, false); + refresh_tile_mapcanvas(i.key(), false); adjc_dir_iterate(&(wld.map), i.key(), ptile_dest, dir) { if (i.value()->line_count[dir] > 0 || i.value()->line_danger_count[dir] > 0) { - refresh_tile_mapcanvas(ptile_dest, false, false); + refresh_tile_mapcanvas(ptile_dest, false); } } adjc_dir_iterate_end; @@ -2690,7 +2677,7 @@ void link_mark_add_new(enum text_link_type type, int id) link_mark_list_append(link_marks, pmark); ptile = link_mark_tile(pmark); if (ptile && tile_visible_mapcanvas(ptile)) { - refresh_tile_mapcanvas(ptile, false, false); + refresh_tile_mapcanvas(ptile, false); } } @@ -2710,7 +2697,7 @@ void link_mark_restore(enum text_link_type type, int id) link_mark_list_append(link_marks, pmark); ptile = link_mark_tile(pmark); if (ptile && tile_visible_mapcanvas(ptile)) { - refresh_tile_mapcanvas(ptile, false, false); + refresh_tile_mapcanvas(ptile, false); } } diff --git a/client/mapview_common.h b/client/mapview_common.h index a10269d0ad..6fbaa710dd 100644 --- a/client/mapview_common.h +++ b/client/mapview_common.h @@ -220,12 +220,11 @@ extern bool can_slide; } \ gui_rect_iterate_end -void refresh_tile_mapcanvas(const tile *ptile, bool full_refresh, - bool write_to_screen); +void refresh_tile_mapcanvas(const tile *ptile, bool full_refresh); void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, - bool full_refresh, bool write_to_screen); + bool full_refresh); void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile, - bool full_refresh, bool write_to_screen); + bool full_refresh); void unqueue_mapview_updates(bool write_to_screen); void map_to_gui_vector(const struct tileset *t, float *gui_dx, float *gui_dy, diff --git a/client/packhand.cpp b/client/packhand.cpp index cb4ededa5e..a2e6f4badc 100644 --- a/client/packhand.cpp +++ b/client/packhand.cpp @@ -525,17 +525,17 @@ void handle_unit_combat_info(const struct packet_unit_combat_info *packet) punit1->hp = hp1; set_units_in_combat(nullptr, nullptr); - refresh_unit_mapcanvas(punit0, unit_tile(punit0), true, false); - refresh_unit_mapcanvas(punit1, unit_tile(punit1), true, false); + refresh_unit_mapcanvas(punit0, unit_tile(punit0), true); + refresh_unit_mapcanvas(punit1, unit_tile(punit1), true); } } if (packet->make_att_veteran && punit0) { punit0->veteran++; - refresh_unit_mapcanvas(punit0, unit_tile(punit0), true, false); + refresh_unit_mapcanvas(punit0, unit_tile(punit0), true); } if (packet->make_def_veteran && punit1) { punit1->veteran++; - refresh_unit_mapcanvas(punit1, unit_tile(punit1), true, false); + refresh_unit_mapcanvas(punit1, unit_tile(punit1), true); } } } @@ -965,7 +965,7 @@ static void city_packet_common(struct city *pcity, struct tile *pcenter, } if (can_client_change_view()) { - refresh_city_mapcanvas(pcity, pcenter, false, false); + refresh_city_mapcanvas(pcity, pcenter, false); } if (city_workers_display == pcity) { @@ -1594,7 +1594,7 @@ static bool handle_unit_packet_common(struct unit *packet_unit) * repaint being deferred until the unit is updated, so that what's * drawn reflects the new status (e.g., no city outline). */ if (unit_drawn_with_city_outline(punit, true)) { - refresh_unit_mapcanvas(punit, unit_tile(punit), true, false); + refresh_unit_mapcanvas(punit, unit_tile(punit), true); } ret = true; @@ -1774,7 +1774,7 @@ static bool handle_unit_packet_common(struct unit *packet_unit) if (ccity->client.occupied != new_occupied) { ccity->client.occupied = new_occupied; - refresh_city_mapcanvas(ccity, ccity->tile, false, false); + refresh_city_mapcanvas(ccity, ccity->tile, false); update_city_description(ccity); } } @@ -1791,7 +1791,7 @@ static bool handle_unit_packet_common(struct unit *packet_unit) // Unit moved into a city - obviously it's occupied. if (!ccity->client.occupied) { ccity->client.occupied = true; - refresh_city_mapcanvas(ccity, ccity->tile, false, false); + refresh_city_mapcanvas(ccity, ccity->tile, false); update_city_description(ccity); } } @@ -1933,7 +1933,7 @@ static bool handle_unit_packet_common(struct unit *packet_unit) } if (repaint_unit) { - refresh_unit_mapcanvas(punit, unit_tile(punit), true, false); + refresh_unit_mapcanvas(punit, unit_tile(punit), true); } if ((check_focus || get_num_units_in_focus() == 0) @@ -3123,7 +3123,7 @@ void handle_tile_info(const struct packet_tile_info *packet) if (can_client_change_view()) { // the tile itself (including the necessary parts of adjacent tiles) if (tile_changed || old_known != new_known) { - refresh_tile_mapcanvas(ptile, true, false); + refresh_tile_mapcanvas(ptile, true); } } @@ -5211,7 +5211,7 @@ void handle_edit_startpos(const struct packet_edit_startpos *packet) // Notify. if (changed && can_client_change_view()) { - refresh_tile_mapcanvas(ptile, true, false); + refresh_tile_mapcanvas(ptile, true); if (packet->removal) { editgui_notify_object_changed(OBJTYPE_STARTPOS, packet->id, true); } else { @@ -5245,7 +5245,7 @@ void handle_edit_startpos_full( // Handle. if (startpos_unpack(psp, packet) && can_client_change_view()) { // Notify. - refresh_tile_mapcanvas(ptile, true, false); + refresh_tile_mapcanvas(ptile, true); editgui_notify_object_changed(OBJTYPE_STARTPOS, startpos_number(psp), false); }