Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8773) rewrite city_map_iterate
Home

[Freeciv-Dev] (PR#8773) rewrite city_map_iterate

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8773) rewrite city_map_iterate
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 18 May 2004 18:30:27 -0700
Reply-to: rt@xxxxxxxxxxx

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

This patch rewrites city_map_iterate:

- It respects break (see PR#7075).
- It uses is_valid_city_coords rather than a hard-coded check (see 
PR#7350, PR#7481).

Those who would ask how much it slows down the code to use 
is_valid_city_coords here, should instead ask how much it will speed up 
the code to inline/macro-ise is_valid_city_coords.

jason

? eff
? flags
? data/flags
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.141
diff -u -r1.141 city.h
--- common/city.h       22 Apr 2004 22:58:28 -0000      1.141
+++ common/city.h       19 May 2004 01:25:43 -0000
@@ -84,15 +84,17 @@
 
 /* Iterate a city map */
 
-#define city_map_iterate(x, y)                     \
-{                                                  \
-  int x, y;                                        \
-  for (y = 0; y < CITY_MAP_SIZE; y++)              \
-    for (x = 0; x < CITY_MAP_SIZE; x++)            \
-      if (! ((x == 0 || x == (CITY_MAP_SIZE-1)) && \
-            (y == 0 || y == (CITY_MAP_SIZE-1))) )
-
-#define city_map_iterate_end                       \
+#define city_map_iterate(x, y)                                             \
+{                                                                          \
+  int _itr;                                                                \
+  for (_itr = 0; _itr < CITY_MAP_SIZE * CITY_MAP_SIZE; _itr++) {           \
+    const int x = _itr % CITY_MAP_SIZE, y = _itr / CITY_MAP_SIZE;          \
+                                                                           \
+    if (is_valid_city_coords(x, y)) {
+
+#define city_map_iterate_end                                               \
+    }                                                                      \
+  }                                                                        \
 }
 
 /* Iterate a city map, from the center (the city) outwards */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8773) rewrite city_map_iterate, Jason Short <=