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

Preliminary cleanup of mapview_common #1169

Merged
merged 22 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/citydlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ void city_dialog::hideEvent(QHideEvent *event)
if (!dont_focus) {
unit_focus_update();
}
redraw_visible_map_now();
update_map_canvas_visible();
}
queen()->mapview_wdg->show_all_fcwidgets();
}
Expand All @@ -1531,7 +1531,7 @@ void city_dialog::showEvent(QShowEvent *event)
dont_focus = false;
if (pcity) {
unit_focus_set(nullptr);
redraw_visible_map_now();
update_map_canvas_visible();
}
}

Expand Down
3 changes: 2 additions & 1 deletion client/gui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
see https://www.gnu.org/licenses/.
**************************************************************************/

#include "mapview_common.h"
#ifdef AUDIO_SDL
#include <SDL2/SDL.h>
#endif // AUDIO_SDL
Expand Down Expand Up @@ -264,7 +265,7 @@ void gui_qt_apply_font(struct option *poption)
f.fromString(s);
s = option_name(poption);
fcFont::instance()->setFont(s, f);
update_city_descriptions();
update_map_canvas_visible();
queen()->chat->update_font();
QApplication::setFont(fcFont::instance()->getFont(fonts::default_font));
real_science_report_dialog_update(nullptr);
Expand Down
4 changes: 0 additions & 4 deletions client/include/mapview_g.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ void update_info_label(void);
void update_unit_info_label(struct unit_list *punitlist);
void update_mouse_cursor(enum cursor_type new_cursor_type);
void update_turn_done_button(bool do_restore);
void update_city_descriptions(void);
void update_minimap(void);

void dirty_rect(int canvas_x, int canvas_y, int pixel_width,
int pixel_height);
void dirty_all(void);
void flush_dirty(void);
void gui_flush(void);

void update_map_canvas_scrollbars(void);

void put_cross_overlay_tile(struct tile *ptile);

Expand Down
41 changes: 2 additions & 39 deletions client/mapctrl_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "governor.h"
#include "mapctrl_common.h"
#include "mapview.h"
#include "mapview_common.h"
#include "mapview_g.h"
#include "minimap_panel.h"
#include "options.h"
Expand Down Expand Up @@ -287,7 +288,7 @@ void adjust_workers_button_pressed(int canvas_x, int canvas_y)
struct tile *ptile = canvas_pos_to_tile(canvas_x, canvas_y);

if (nullptr != ptile && can_client_issue_orders()) {
struct city *pcity = find_city_near_tile(ptile);
struct city *pcity = find_city_or_settler_near_tile(ptile, nullptr);

if (pcity && !cma_is_city_under_agent(pcity, nullptr)) {
int city_x, city_y;
Expand Down Expand Up @@ -373,41 +374,3 @@ void update_line(int canvas_x, int canvas_y)
break;
};
}

/**
We sort according to the following logic:

- Transported units should immediately follow their transporter (note that
transporting may be recursive).
- Otherwise we sort by ID (which is what the list is originally sorted
by).
*/
static int unit_list_compare(const void *a, const void *b)
lmoureaux marked this conversation as resolved.
Show resolved Hide resolved
{
const struct unit *punit1 = *(struct unit **) a;
const struct unit *punit2 = *(struct unit **) b;

if (unit_transport_get(punit1) == unit_transport_get(punit2)) {
// For units with the same transporter or no transporter: sort by id.
// Perhaps we should sort by name instead?
return punit1->id - punit2->id;
} else if (unit_transport_get(punit1) == punit2) {
return 1;
} else if (unit_transport_get(punit2) == punit1) {
return -1;
} else {
/* If the transporters aren't the same, put in order by the
* transporters. */
const struct unit *ptrans1 = unit_transport_get(punit1);
const struct unit *ptrans2 = unit_transport_get(punit2);

if (!ptrans1) {
ptrans1 = punit1;
}
if (!ptrans2) {
ptrans2 = punit2;
}

return unit_list_compare(&ptrans1, &ptrans2);
}
}
62 changes: 8 additions & 54 deletions client/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@
static int mapview_frozen_level = 0;
extern void destroy_city_dialog();
extern QPixmap *canvas;
static QRegion dirty;

#define MAX_DIRTY_RECTS 20
static int num_dirty_rects = 0;
static QRect dirty_rects[MAX_DIRTY_RECTS];
info_tile *info_tile::m_instance = nullptr;
extern int last_center_enemy;
extern int last_center_capital;
Expand Down Expand Up @@ -480,18 +478,6 @@ void update_turn_done_button(bool do_restore)
// queen()->minimap_panel->turn_done()->blink();
}

/**
Flush the given part of the canvas buffer (if there is one) to the
screen.
*/
static void flush_mapcanvas(int canvas_x, int canvas_y, int pixel_width,
int pixel_height)
{
auto scale = queen()->mapview_wdg->scale();
queen()->mapview_wdg->repaint(canvas_x * scale, canvas_y * scale,
pixel_width * scale, pixel_height * scale);
}

/**
Mark the rectangular region as "dirty" so that we know to flush it
later.
Expand All @@ -502,13 +488,9 @@ void dirty_rect(int canvas_x, int canvas_y, int pixel_width,
if (mapview_is_frozen()) {
return;
}
if (num_dirty_rects < MAX_DIRTY_RECTS) {
dirty_rects[num_dirty_rects].setX(canvas_x);
dirty_rects[num_dirty_rects].setY(canvas_y);
dirty_rects[num_dirty_rects].setWidth(pixel_width);
dirty_rects[num_dirty_rects].setHeight(pixel_height);
num_dirty_rects++;
}
auto scale = queen()->mapview_wdg->scale();
dirty |= QRect(canvas_x * scale, canvas_y * scale, pixel_width * scale,
pixel_height * scale);
}

/**
Expand All @@ -519,52 +501,24 @@ void dirty_all(void)
if (mapview_is_frozen()) {
return;
}
num_dirty_rects = MAX_DIRTY_RECTS;
dirty |= QRect(QPoint(), queen()->mapview_wdg->size());
}

/**
Flush all regions that have been previously marked as dirty. See
dirty_rect and dirty_all. This function is generally called after we've
processed a batch of drawing operations.
*/
void flush_dirty(void)
void flush_dirty()
{
if (mapview_is_frozen()) {
return;
}
if (num_dirty_rects == MAX_DIRTY_RECTS) {
flush_mapcanvas(
0, 0, queen()->mapview_wdg->width() / queen()->mapview_wdg->scale(),
queen()->mapview_wdg->height() / queen()->mapview_wdg->scale());
} else {
int i;

for (i = 0; i < num_dirty_rects; i++) {
flush_mapcanvas(dirty_rects[i].x(), dirty_rects[i].y(),
dirty_rects[i].width(), dirty_rects[i].height());
}
}
num_dirty_rects = 0;
queen()->mapview_wdg->repaint(dirty);
dirty = QRegion();
}

/**
Do any necessary synchronization to make sure the screen is up-to-date.
The canvas should have already been flushed to screen via flush_dirty -
all this function does is make sure the hardware has caught up.
*/
void gui_flush(void) { queen()->mapview_wdg->update(); }

/**
Update (refresh) the locations of the mapview scrollbars (if it uses
them).
*/
void update_map_canvas_scrollbars(void) { queen()->mapview_wdg->update(); }

/**
Update (refresh) all city descriptions on the mapview.
*/
void update_city_descriptions(void) { update_map_canvas_visible(); }

/**
Put overlay tile to pixmap
*/
Expand Down
Loading