Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2003:
[Freeciv-Dev] (PR#3451) rectangle_iterate
Home

[Freeciv-Dev] (PR#3451) rectangle_iterate

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#3451) rectangle_iterate
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 17 Feb 2003 00:11:17 -0800
Reply-to: rt@xxxxxxxxxxxxxx

The CHECK_MAP_POS in square_iterate caused an assertion in some code I 
recently added to mapview_common.  In this particular case, it is 
probably more appropriate to use a new macro rectangle_iterate rather 
than the original square_iterate.  No doubt this macro will be useful 
elsewhere as well.

The implementation is simple: I don't do an _is_border check nor use it 
as a wrapper for square_dxy_iterate (or better: replace square_dxy_iterate).

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.30
diff -u -r1.30 mapview_common.c
--- client/mapview_common.c     2003/02/17 02:11:25     1.30
+++ client/mapview_common.c     2003/02/17 08:05:02
@@ -48,7 +48,7 @@
        * the time).  Although it seems inefficient to redraw the
        * descriptions for so many tiles, remember that most of them don't
        * have cities on them. */
-      int iter, canvas_x, canvas_y;
+      int canvas_x, canvas_y;
       struct city *pcity;
 
       if (is_isometric) {
@@ -62,12 +62,12 @@
         *      1
         * Tile 1 is the one being updated; we redraw the city description
         * for tiles 2-8 (actually we end up drawing 1 as well). */
-       square_iterate(x - 1, y - 1, 1, city_x, city_y) {
+       rectangle_iterate(x - 2, y - 2, 3, 3, city_x, city_y) {
          if ((pcity = map_get_city(city_x, city_y))) {
            get_canvas_xy(city_x, city_y, &canvas_x, &canvas_y);
            show_city_desc(pcity, canvas_x, canvas_y);
          }
-       } square_iterate_end;
+       } rectangle_iterate_end;
       } else {
        /* We assume the city description will be held in the three tiles
         * right below the city.
@@ -75,15 +75,12 @@
         *        1
         * Tile 1 is the one being updated; we redraw the city description
         * for tiles 2, 3, and 4. */
-       for (iter = -1; iter <= 1; iter++) {
-         int city_x = x + iter, city_y = y - 1;
-
-         if (normalize_map_pos(&city_x, &city_y)
-             && (pcity = map_get_city(city_x, city_y))) {
+       rectangle_iterate(x - 1, y - 1, 3, 1, city_x, city_y) {
+         if ((pcity = map_get_city(city_x, city_y))) {
            get_canvas_xy(city_x, city_y, &canvas_x, &canvas_y);
            show_city_desc(pcity, canvas_x, canvas_y);
          }
-       }
+       } rectangle_iterate_end;
       }
     }
 
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.136
diff -u -r1.136 map.h
--- common/map.h        2003/02/17 02:11:26     1.136
+++ common/map.h        2003/02/17 08:05:03
@@ -401,6 +401,21 @@
   }                                                                           \
 }
 
+#define rectangle_iterate(map_x0, map_y0, map_width, map_height,            \
+                          x_itr, y_itr)                                     \
+{                                                                           \
+  int RI_dx_itr, RI_dy_itr;                                                 \
+  for (RI_dy_itr = 0; RI_dy_itr < (map_height); RI_dy_itr++) {              \
+    for (RI_dx_itr = 0; RI_dx_itr < (map_width); RI_dx_itr++) {             \
+      int x_itr = RI_dx_itr + (map_x0), y_itr = RI_dy_itr + (map_y0);       \
+      if (normalize_map_pos(&x_itr, &y_itr)) {
+
+#define rectangle_iterate_end                                               \
+      }                                                                     \
+    }                                                                       \
+  }                                                                         \
+}
+
 /* 
  * Iterate through all tiles in a square with given center and radius.
  * The position (x_itr, y_itr) that is returned will be normalized;

[Prev in Thread] Current Thread [Next in Thread]