Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor how map updates are propagated to widgets #1174

Merged
merged 10 commits into from
Aug 9, 2022
2 changes: 1 addition & 1 deletion client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ add_library(
helpdlg.cpp
hudwidget.cpp
icons.cpp
idlecallback.cpp
layer_background.cpp
layer_base_flags.cpp
layer_darkness.cpp
Expand All @@ -91,6 +90,7 @@ add_library(
mapctrl_common.cpp
mapview.cpp
mapview_common.cpp
map_updates_handler.cpp
menu.cpp
messageoptions.cpp
messagewin.cpp
Expand Down
4 changes: 2 additions & 2 deletions client/climisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

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

/**
Expand Down
10 changes: 5 additions & 5 deletions client/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

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

Expand Down Expand Up @@ -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) {
Expand All @@ -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
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
1 change: 0 additions & 1 deletion client/fc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ fc_client::~fc_client()
if (fc_shortcuts::sc()) {
delete fc_shortcuts::sc();
}
mrIdle::idlecb()->drop();
delete_cursors();
}

Expand Down
1 change: 0 additions & 1 deletion client/fc_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "tilespec.h"
// gui-qt
#include "chatline.h"
#include "idlecallback.h"
#include "menu.h"
#include "tradecalculation.h"

Expand Down
14 changes: 0 additions & 14 deletions client/gui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,6 @@ void real_focus_units_changed()
}
}

/**
Enqueue a callback to be called during an idle moment. The 'callback'
function should be called sometimes soon, and passed the 'data' pointer
as its data.
*/
void add_idle_callback(void(callback)(void *), void *data)
{
call_me_back *cb = new call_me_back; // removed in mr_idler:idling()

cb->callback = callback;
cb->data = data;
mrIdle::idlecb()->addCallback(cb);
}

/**
Shows/Hides titlebar
*/
Expand Down
81 changes: 0 additions & 81 deletions client/idlecallback.cpp

This file was deleted.

47 changes: 0 additions & 47 deletions client/idlecallback.h

This file was deleted.

122 changes: 122 additions & 0 deletions client/map_updates_handler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#include "map_updates_handler.h"
#include "city.h"
#include "options.h"
#include "tilespec.h"

FC_CPP_DECLARE_LISTENER(freeciv::map_updates_handler)

namespace freeciv {

/**
* @class map_updates_handler
* @brief Records regions of the map that should be updated
*
* This class records a list of all regions on the map that need an update,
* and the extent of the necessary update (as a combination of @ref
* update_type). It has nothing to do with tilesets and doesn't know about
* the map geometry, but some tilesets assumptions are hard-coded.
*/

/**
* Constructor
*/
map_updates_handler::map_updates_handler(QObject *parent) : QObject(parent)
{
map_updates_handler::listen();
}

/**
* Clears all pending updates.
*/
void map_updates_handler::clear()
{
m_full_update = false;
m_updates.clear();
}

/**
* Registers a city for update. If `full`, also update the city label.
* @see update_city_description
*/
void map_updates_handler::update(const city *city, bool full)
{
if (!m_full_update) {
const auto tile = city_tile(city);
if (full && (gui_options.draw_map_grid || gui_options.draw_borders)) {
m_updates[tile] |= update_type::city_map;
} else {
// Assumption: city sprites are as big as unit sprites
m_updates[tile] |= update_type::unit;
}
emit repaint_needed();
}
}

/**
* Registers a tile for update. If `full`, also update the neighboring area.
*/
void map_updates_handler::update(const tile *tile, bool full)
{
if (!m_full_update) {
if (full) {
m_updates[tile] |= update_type::tile_full;
} else {
m_updates[tile] |= update_type::tile_single;
}
emit repaint_needed();
}
}

/**
* Registers a unit for update.
*/
void map_updates_handler::update(const unit *unit, bool full)
{
if (!m_full_update) {
const auto tile = unit_tile(unit);
if (full && gui_options.draw_native) {
update_all();
} else if (full && unit_drawn_with_city_outline(unit, true)) {
m_updates[tile] |= update_type::city_map;
emit repaint_needed();
} else {
m_updates[tile] |= update_type::unit;
emit repaint_needed();
}
}
}

/**
* Requests an update of the whole (visible) map.
*/
void map_updates_handler::update_all()
{
m_updates.clear();
m_full_update = true;
emit repaint_needed();
}

/**
* Registers a city label for update.
* @see update(const city *, bool)
*/
void map_updates_handler::update_city_description(const city *city)
{
if (!m_full_update) {
m_updates[city_tile(city)] |= update_type::city_description;
emit repaint_needed();
}
}

/**
* Registers a tile label for update.
*/
void map_updates_handler::update_tile_label(const tile *tile)
{
if (!m_full_update) {
m_updates[tile] |= update_type::tile_label;
emit repaint_needed();
}
}

} // namespace freeciv
Loading