[Freeciv-Dev] (PR#8526) city_draw_iterate macro
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8526 >
This patch creates a city_draw_iterate macro used internally for city
drawing.
It's pretty straightforward. Although it only gives a small advantage
now, if we add more layers to the drawing it will become helpful.
jason
? core.16043
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.31
diff -u -r1.31 citydlg_common.c
--- client/citydlg_common.c 4 Apr 2004 14:49:09 -0000 1.31
+++ client/citydlg_common.c 16 Apr 2004 15:25:13 -0000
@@ -119,6 +119,27 @@
return is_valid_city_coords(*city_x, *city_y);
}
+#define city_draw_iterate(pcity, city_x, city_y, map_x, map_y, canvas_x,
canvas_y) \
+{ \
+ int city_x, city_y; \
+ \
+ /* We have to draw the tiles in a particular order, so its best \
+ * to avoid using any iterator macro. */ \
+ for (city_x = 0; city_x < CITY_MAP_SIZE; city_x++) { \
+ for (city_y = 0; city_y < CITY_MAP_SIZE; city_y++) { \
+ int map_x, map_y, canvas_x, canvas_y; \
+ \
+ if (is_valid_city_coords(city_x, city_y) \
+ && city_map_to_map(&map_x, &map_y, pcity, city_x, city_y) \
+ && tile_get_known(map_x, map_y) \
+ && city_to_canvas_pos(&canvas_x, &canvas_y, city_x, city_y)) { \
+
+#define city_draw_iterate_end \
+ } \
+ } \
+ } \
+}
+
/****************************************************************************
Draw the full city map onto the canvas store. Works for both isometric
and orthogonal views.
@@ -126,63 +147,46 @@
void city_dialog_redraw_map(struct city *pcity,
struct canvas *pcanvas)
{
- int city_x, city_y;
-
/* First make it all black. */
canvas_put_rectangle(pcanvas, COLOR_STD_BLACK, 0, 0,
get_citydlg_canvas_width(),
get_citydlg_canvas_height());
- /* We have to draw the tiles in a particular order, so its best
- to avoid using any iterator macro. */
- for (city_x = 0; city_x < CITY_MAP_SIZE; city_x++) {
- for (city_y = 0; city_y < CITY_MAP_SIZE; city_y++) {
- int map_x, map_y, canvas_x, canvas_y;
-
- if (is_valid_city_coords(city_x, city_y)
- && city_map_to_map(&map_x, &map_y, pcity, city_x, city_y)
- && tile_get_known(map_x, map_y)
- && city_to_canvas_pos(&canvas_x, &canvas_y, city_x, city_y)) {
- if (is_isometric) {
- put_one_tile_iso(pcanvas, map_x, map_y,
- canvas_x, canvas_y,
- 0, 0, 0,
- NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT,
- UNIT_TILE_HEIGHT,
- D_FULL, TRUE);
- } else {
- put_one_tile(pcanvas, map_x, map_y,
- canvas_x, canvas_y, TRUE);
- }
- }
+ city_draw_iterate(pcity, city_x, city_y,
+ map_x, map_y, canvas_x, canvas_y) {
+ if (is_isometric) {
+ put_one_tile_iso(pcanvas, map_x, map_y,
+ canvas_x, canvas_y,
+ 0, 0, 0,
+ NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT,
+ UNIT_TILE_HEIGHT,
+ D_FULL, TRUE);
+ } else {
+ put_one_tile(pcanvas, map_x, map_y,
+ canvas_x, canvas_y, TRUE);
}
- }
+ } city_draw_iterate_end;
/* We have to put the output afterwards or it will be covered
* in iso-view. */
- city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) {
- int canvas_x, canvas_y;
-
- if (tile_get_known(map_x, map_y)
- && city_to_canvas_pos(&canvas_x, &canvas_y, x, y)
- && pcity->city_map[x][y] == C_TILE_WORKER) {
- put_city_tile_output(pcity, x, y, pcanvas, canvas_x, canvas_y);
+ city_draw_iterate(pcity, city_x, city_y,
+ map_x, map_y, canvas_x, canvas_y) {
+ if (pcity->city_map[city_x][city_y] == C_TILE_WORKER) {
+ put_city_tile_output(pcity, city_x, city_y,
+ pcanvas, canvas_x, canvas_y);
}
- } city_map_checked_iterate_end;
+ } city_draw_iterate_end;
/* This sometimes will draw one of the lines on top of a city or
* unit pixmap (in iso-view). This should maybe be moved to
* put_one_tile to fix this, but maybe it wouldn't be a good idea because
* the lines would get obscured. */
- city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) {
- int canvas_x, canvas_y;
-
- if (tile_get_known(map_x, map_y)
- && city_to_canvas_pos(&canvas_x, &canvas_y, x, y)
- && pcity->city_map[x][y] == C_TILE_UNAVAILABLE) {
+ city_draw_iterate(pcity, city_x, city_y,
+ map_x, map_y, canvas_x, canvas_y) {
+ if (pcity->city_map[city_x][city_y] == C_TILE_UNAVAILABLE) {
put_red_frame_tile(pcanvas, canvas_x, canvas_y);
}
- } city_map_checked_iterate_end;
+ } city_draw_iterate_end;
}
/**************************************************************************
- [Freeciv-Dev] (PR#8526) city_draw_iterate macro,
Jason Short <=
|
|