Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9414) new iterator iterate_outward_dxy
Home

[Freeciv-Dev] (PR#9414) new iterator iterate_outward_dxy

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9414) new iterator iterate_outward_dxy
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 17 Jul 2004 19:10:53 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9414 >

This patch adds a new iterator iterate_outward_dxy.

It does exactly what you expect.  It is used by iterate_outward 
(naturally) and also by square_dxy_iterate (and thus by all of 
square_dxy_iterate's users).  This reduces code a bit and is also 
hex-friendly.  It changes the order of iteration of square_dxy_iterate 
but the order was never guaranteed by the interface (none of the users 
should care).

jason

Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.195
diff -u -r1.195 map.h
--- common/map.h        18 Jul 2004 01:42:02 -0000      1.195
+++ common/map.h        18 Jul 2004 01:57:55 -0000
@@ -415,30 +415,40 @@
 /* This iterates outwards from the starting point. Every tile within max_dist
  * will show up exactly once, in an outward (based on real map distance)
  * order.  The returned values are always real and are normalized.  The
- * starting position must be normal. */
-#define iterate_outward(start_x, start_y, max_dist, x_itr, y_itr)          \
+ * starting position must be normal.
+ *
+ * See also iterate_outward() */
+#define iterate_outward_dxy(start_x, start_y, max_dist, x_itr, y_itr,      \
+                           dx_itr, dy_itr)                                 \
 {                                                                          \
   int _start_x = (start_x), _start_y = (start_y), _max_dist = (max_dist);   \
   bool _is_border = IS_BORDER_MAP_POS(_start_x, _start_y, _max_dist);      \
-  int x_itr, y_itr, _dx_itr, _dy_itr, _index;                              \
+  int x_itr, y_itr, dx_itr, dy_itr, _index;                                \
                                                                            \
   CHECK_MAP_POS(_start_x, _start_y);                                       \
   for (_index = 0; _index < map.num_iterate_outwards_indices; _index++) {   \
     if (map.iterate_outwards_indices[_index].dist > _max_dist) {           \
       break;                                                               \
     }                                                                      \
-    _dx_itr = map.iterate_outwards_indices[_index].dx;                     \
-    _dy_itr = map.iterate_outwards_indices[_index].dy;                     \
-    x_itr = _dx_itr + _start_x;                                                
    \
-    y_itr = _dy_itr + _start_y;                                                
    \
+    dx_itr = map.iterate_outwards_indices[_index].dx;                      \
+    dy_itr = map.iterate_outwards_indices[_index].dy;                      \
+    x_itr = dx_itr + _start_x;                                             \
+    y_itr = dy_itr + _start_y;                                             \
     if (_is_border && !normalize_map_pos(&x_itr, &y_itr)) {                \
       continue;                                                                
    \
     }
 
-#define iterate_outward_end                                                \
+#define iterate_outward_dxy_end                                                
    \
   }                                                                         \
 }
 
+/* See iterate_outward_dxy() */
+#define iterate_outward(start_x, start_y, max_dist, x_itr, y_itr)          \
+  iterate_outward_dxy(start_x, start_y, max_dist, x_itr, y_itr,                
    \
+                     _dx_itr, _dy_itr)
+
+#define iterate_outward_end iterate_outward_dxy_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;
@@ -447,23 +457,12 @@
  * position. Note that when the square is larger than the map the
  * distance vector may not be the minimum distance vector.
  */
-#define square_dxy_iterate(center_x, center_y, radius, x_itr, y_itr,          \
-                           dx_itr, dy_itr)                                    \
-{                                                                             \
-  int dx_itr, dy_itr;                                                         \
-  bool _is_border = IS_BORDER_MAP_POS((center_x), (center_y), (radius));      \
-  CHECK_MAP_POS((center_x), (center_y));                                      \
-  for (dy_itr = -(radius); dy_itr <= (radius); dy_itr++) {                    \
-    for (dx_itr = -(radius); dx_itr <= (radius); dx_itr++) {                  \
-      int x_itr = dx_itr + (center_x), y_itr = dy_itr + (center_y);           \
-      if (_is_border && !normalize_map_pos(&x_itr, &y_itr)) {                 \
-        continue;                                                             \
-      }
+#define square_dxy_iterate(center_x, center_y, radius, x_itr, y_itr,        \
+                           dx_itr, dy_itr)                                  \
+  iterate_outward_dxy(center_x, center_y, radius, x_itr, y_itr,                
    \
+                     dx_itr, dy_itr)
 
-#define square_dxy_iterate_end                                                \
-    }                                                                         \
-  }                                                                           \
-}
+#define square_dxy_iterate_end iterate_outward_dxy_end
 
 /*
  * Iterate through all tiles in a square with given center and radius.

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9414) new iterator iterate_outward_dxy, Jason Short <=