Skip to content

Commit

Permalink
Remove the write_to_screen parameter of refresh* functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lmoureaux committed Jul 30, 2022
1 parent a4d0dd2 commit f08b919
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 55 deletions.
4 changes: 2 additions & 2 deletions client/climisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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();
}

Expand Down Expand Up @@ -157,7 +157,7 @@ void client_remove_city(struct city *pcity)
popdown_city_dialog(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);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions client/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ static void current_focus_append(struct unit *punit)
unit_list_append(current_focus, 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);
Expand Down Expand Up @@ -507,7 +507,7 @@ void unit_focus_set(struct unit *punit)
* circle). */
unit_list_iterate(current_focus, punit_old)
{
refresh_unit_mapcanvas(punit_old, unit_tile(punit_old), true, false);
refresh_unit_mapcanvas(punit_old, unit_tile(punit_old), true);
}
unit_list_iterate_end;
unit_list_clear(current_focus);
Expand Down Expand Up @@ -849,7 +849,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);
}
unit_list_iterate_end;
}
Expand Down Expand Up @@ -2438,7 +2438,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) {
Expand All @@ -2460,7 +2460,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
Expand Down
2 changes: 1 addition & 1 deletion client/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 18 additions & 31 deletions client/mapview_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const tile *, bool>(&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<const unit *, bool>(&freeciv::map_updates_handler::update),
punit, full_refresh);
if (write_to_screen) {
unqueue_mapview_updates(true);
}
}

/**
Expand All @@ -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<const city *, bool>(&freeciv::map_updates_handler::update),
pcity, full_refresh);
if (write_to_screen) {
unqueue_mapview_updates(true);
flush_dirty_overview();
}
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
7 changes: 3 additions & 4 deletions client/mapview_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions client/packhand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -968,7 +968,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) {
Expand Down Expand Up @@ -1597,7 +1597,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;
Expand Down Expand Up @@ -1777,7 +1777,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);
}
}
Expand All @@ -1794,7 +1794,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);
}
}
Expand Down Expand Up @@ -1936,7 +1936,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)
Expand Down Expand Up @@ -3126,7 +3126,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);
}
}

Expand Down Expand Up @@ -5214,7 +5214,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 {
Expand Down Expand Up @@ -5248,7 +5248,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);
}
Expand Down

0 comments on commit f08b919

Please sign in to comment.