Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2002:
[Freeciv-Dev] [PATCH] extend IS_BORDER_MAP_POS use (PR#1276)
Home

[Freeciv-Dev] [PATCH] extend IS_BORDER_MAP_POS use (PR#1276)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] [PATCH] extend IS_BORDER_MAP_POS use (PR#1276)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Sat, 23 Feb 2002 15:57:53 -0800 (PST)

The attached patch is identical to the one just sent to freeciv-dev.

----------

I've changed IS_BORDER_MAP_POS to take a distance argument as well. This is similar to what Ross's changes do (it uses a more robust check for IS_BORDER than is currently used), except I've unified it into one macro call, rather than have a

#define IS_BORDER_MAP_POS(x, y) _IS_BORDER_MAP_POS(x, y, 1)

I've also added IS_BORDER checks to all of the iterator macros (why not?). I've taken the liberty of rewriting adjc_iterate in terms of square_iterate (which should give identical behavior, aside from the addition of the IS_BORDER check).

Since (just about) all of the iterators use a different internal notation, the changes may look a bit inconsistent.

In limited testing, this change caused about a 3% increase in server time efficiency (i.e. 3% decrease in running time [1]). This is less than I expected (normalize_map_pos accounts for 4.5% of server runtime according to the profile, and that doesn't include all of the function-call overhead which will also be included in the calling function's time) - which probably means there are a lot of normalize calls left.

jason
? crash
? diff
? jason-game.gz
? t
? test-alt.pl
? test.pl
? topology
? data/README-isotrident
? data/isoengels
? data/isoengels.tilespec
? data/isotrident
? data/isotrident.tilespec
? data/lexxy
? data/lexxy.tilespec
? data/macroisotrident
? data/macroisotrident.tilespec
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.121
diff -u -r1.121 map.h
--- common/map.h        2002/02/22 13:14:43     1.121
+++ common/map.h        2002/02/23 11:51:37
@@ -285,12 +285,13 @@
 #define regular_map_pos_is_normal(x, y) (TRUE)
 
 /*
- * A "border position" is any one that has adjacent positions that are
- * not normal/proper.
+ * A "border position" is any one that _may have_ positions within
+ * map distance dist that are non-normal.  To see its correctness,
+ * consider the case where dist is 1 or 0.
  */
-#define IS_BORDER_MAP_POS(x, y)              \
-  ((y) == 0 || (x) == 0 ||                   \
-   (y) == map.ysize-1 || (x) == map.xsize-1)
+#define IS_BORDER_MAP_POS(x, y, dist)                         \
+  ((x) < (dist) || (x) >= map.xsize - (dist)                  \
+   || (y) < (dist) || (y) >= map.ysize - (dist))
 
 bool normalize_map_pos(int *x, int *y);
 void nearest_real_pos(int *x, int *y);
@@ -378,6 +379,8 @@
   int MACRO_min_dx = -MACRO_max_dx - 1 + (map.xsize % 2);                     \
   bool MACRO_xcycle = TRUE;                                                   \
   bool MACRO_positive = FALSE;                                                \
+  bool MACRO_is_border = IS_BORDER_MAP_POS(ARG_start_x, ARG_start_y,          \
+                                           ARG_max_dist);                     \
   int MACRO_dxy = 0, MACRO_do_xy;                                             \
   CHECK_MAP_POS(ARG_start_x, ARG_start_y);                                    \
   while(MACRO_dxy <= (ARG_max_dist)) {                                        \
@@ -402,7 +405,7 @@
        if (MACRO_dx > MACRO_max_dx || MACRO_dx < MACRO_min_dx)               \
          continue;                                                           \
       }                                                                       \
-      if (!normalize_map_pos(&ARG_x_itr, &ARG_y_itr))                         \
+      if (MACRO_is_border && !normalize_map_pos(&ARG_x_itr, &ARG_y_itr))      \
        continue;
 
 #define iterate_outward_end                                                   \
@@ -428,11 +431,12 @@
                            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 (normalize_map_pos(&x_itr, &y_itr)) {
+      if (!_is_border || normalize_map_pos(&x_itr, &y_itr)) {                 \
 
 #define square_dxy_iterate_end                                                \
       }                                                                       \
@@ -473,23 +477,12 @@
 /* Iterate through all tiles adjacent to a tile */
 #define adjc_iterate(RI_center_x, RI_center_y, RI_x_itr, RI_y_itr)            \
 {                                                                             \
-  int RI_x_itr, RI_y_itr;                                                     \
-  int RI_x_itr1, RI_y_itr1;                                                   \
-  CHECK_MAP_POS(RI_center_x, RI_center_y);                                    \
-  for (RI_y_itr1 = RI_center_y - 1;                                           \
-       RI_y_itr1 <= RI_center_y + 1; RI_y_itr1++) {                           \
-    for (RI_x_itr1 = RI_center_x - 1;                                         \
-        RI_x_itr1 <= RI_center_x + 1; RI_x_itr1++) {                         \
-      RI_x_itr = RI_x_itr1;                                                   \
-      RI_y_itr = RI_y_itr1;                                                   \
-      if (!normalize_map_pos(&RI_x_itr, &RI_y_itr))                           \
-        continue;                                                             \
-      if (RI_x_itr == RI_center_x && RI_y_itr == RI_center_y)                 \
-        continue; 
+  square_iterate(RI_center_x, RI_center_y, 1, RI_x_itr, RI_y_itr) {           \
+    if (RI_x_itr == RI_center_x && RI_y_itr == RI_center_y)                   \
+      continue;
 
 #define adjc_iterate_end                                                      \
-    }                                                                         \
-  }                                                                           \
+  } square_iterate_end;                                                       \
 }
 
 /* Iterate through all tiles adjacent to a tile.  dir_itr is the
@@ -502,7 +495,7 @@
   int MACRO_center_x = (center_x);                                            \
   int MACRO_center_y = (center_y);                                            \
   CHECK_MAP_POS(MACRO_center_x, MACRO_center_y);                              \
-  MACRO_border = IS_BORDER_MAP_POS(MACRO_center_x, MACRO_center_y);           \
+  MACRO_border = IS_BORDER_MAP_POS(MACRO_center_x, MACRO_center_y, 1);        \
   for (dir_itr = 0; dir_itr < 8; dir_itr++) {                                 \
     DIRSTEP(x_itr, y_itr, dir_itr);                                           \
     x_itr += MACRO_center_x;                                                  \
@@ -579,12 +572,14 @@
 {                                                      \
   int IAC_i;                                           \
   int IAC_x, IAC_y;                                    \
+  bool _is_border = IS_BORDER_MAP_POS(x, y, 1);        \
   CHECK_MAP_POS(x, y);                                 \
   for (IAC_i = 0; IAC_i < 4; IAC_i++) {                \
     IAC_x = x + CAR_DIR_DX[IAC_i];                     \
     IAC_y = y + CAR_DIR_DY[IAC_i];                     \
                                                        \
-    if (normalize_map_pos(&IAC_x, &IAC_y)) {
+    if (!_is_border                                    \
+        || normalize_map_pos(&IAC_x, &IAC_y)) {
 
 #define cartesian_adjacent_iterate_end                 \
     }                                                  \

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] [PATCH] extend IS_BORDER_MAP_POS use (PR#1276), jdorje <=