[Freeciv-Dev] (PR#9162) new macro cardinal_adjc_dir_iterate
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#9162) new macro cardinal_adjc_dir_iterate |
From: |
"Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx> |
Date: |
Thu, 1 Jul 2004 11:40:16 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9162 >
This patch adds a new macro cardinal_adjc_dir_iterate, and removes the
CAR_DIR_D[XY] arrays.
The new method should work with hex topologies, is faster, and takes
less code.
jason
? common/st1D5ZmA
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.173
diff -u -r1.173 map.c
--- common/map.c 1 Jul 2004 18:15:52 -0000 1.173
+++ common/map.c 1 Jul 2004 18:35:59 -0000
@@ -54,10 +54,6 @@
const int DIR_DX[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int DIR_DY[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
-/* like DIR_DX[] and DIR_DY[], only cartesian */
-const int CAR_DIR_DX[4] = {1, 0, -1, 0};
-const int CAR_DIR_DY[4] = {0, 1, 0, -1};
-
/* Names of specials.
* (These must correspond to enum tile_special_type in terrain.h.)
*/
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.189
diff -u -r1.189 map.h
--- common/map.h 1 Jul 2004 18:15:52 -0000 1.189
+++ common/map.h 1 Jul 2004 18:35:59 -0000
@@ -557,6 +557,12 @@
#define adjc_dir_iterate_end adjc_dirlist_iterate_end
+#define cardinal_adjc_dir_iterate(center_x, center_y, x_itr, y_itr, dir_itr)\
+ adjc_dirlist_iterate(center_x, center_y, x_itr, y_itr, dir_itr, \
+ map.cardinal_dirs, map.num_cardinal_dirs)
+
+#define cardinal_adjc_dir_iterate_end adjc_dirlist_iterate_end
+
/* Iterate through all tiles adjacent to a tile using the given list of
* directions. dir_itr is the directional value, (center_x, center_y) is
* the center tile (which must be normalized), and (x_itr, y_itr) is the
@@ -624,10 +630,6 @@
extern const int DIR_DX[8];
extern const int DIR_DY[8];
-/* like DIR_DX[] and DIR_DY[], only cartesian */
-extern const int CAR_DIR_DX[4];
-extern const int CAR_DIR_DY[4];
-
#define cartesian_adjacent_iterate(center_x, center_y, x_itr, y_itr) \
adjc_dirlist_iterate(center_x, center_y, x_itr, y_itr, _dir_itr, \
map.cardinal_dirs, map.num_cardinal_dirs)
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.137
diff -u -r1.137 mapgen.c
--- server/mapgen.c 12 Jun 2004 17:42:28 -0000 1.137
+++ server/mapgen.c 1 Jul 2004 18:36:00 -0000
@@ -832,11 +832,8 @@
for (func_num = 0; func_num < NUM_TEST_FUNCTIONS; func_num++) {
int best_val = -1;
/* first get the tile values for the function */
- for (dir = 0; dir < 4; dir++) {
- int x1 = x + CAR_DIR_DX[dir];
- int y1 = y + CAR_DIR_DY[dir];
- if (normalize_map_pos(&x1, &y1)
- && rd_direction_is_valid[dir]) {
+ cardinal_adjc_dir_iterate(x, y, x1, y1, dir) {
+ if (rd_direction_is_valid[dir]) {
rd_comparison_val[dir] = (test_funcs[func_num].func) (x1, y1);
if (best_val == -1) {
best_val = rd_comparison_val[dir];
@@ -844,22 +841,19 @@
best_val = MIN(rd_comparison_val[dir], best_val);
}
}
- }
+ } cardinal_adjc_dir_iterate_end;
assert(best_val != -1);
/* should we abort? */
if (best_val > 0 && test_funcs[func_num].fatal) return FALSE;
/* mark the less attractive directions as invalid */
- for (dir = 0; dir < 4; dir++) {
- int x1 = x + CAR_DIR_DX[dir];
- int y1 = y + CAR_DIR_DY[dir];
- if (normalize_map_pos(&x1, &y1)
- && rd_direction_is_valid[dir]) {
+ cardinal_adjc_dir_iterate(x, y, x1, y1, dir) {
+ if (rd_direction_is_valid[dir]) {
if (rd_comparison_val[dir] != best_val)
rd_direction_is_valid[dir] = FALSE;
}
- }
+ } cardinal_adjc_dir_iterate_end;
}
/* Directions evaluated with all functions. Now choose the best
@@ -873,16 +867,13 @@
case 0:
return FALSE; /* river aborted */
case 1:
- for (dir = 0; dir < 4; dir++) {
- int x1 = x + CAR_DIR_DX[dir];
- int y1 = y + CAR_DIR_DY[dir];
- if (normalize_map_pos(&x1, &y1)
- && rd_direction_is_valid[dir]) {
+ cardinal_adjc_dir_iterate(x, y, x1, y1, dir) {
+ if (rd_direction_is_valid[dir]) {
river_blockmark(x, y);
x = x1;
y = y1;
}
- }
+ } cardinal_adjc_dir_iterate_end;
break;
default:
/* More than one possible direction; Let the random number
@@ -893,11 +884,8 @@
freelog(LOG_DEBUG, "mapgen.c: direction: %d", direction);
/* Find the direction that the random number generator selected. */
- for (dir = 0; dir < 4; dir++) {
- int x1 = x + CAR_DIR_DX[dir];
- int y1 = y + CAR_DIR_DY[dir];
- if (normalize_map_pos(&x1, &y1)
- && rd_direction_is_valid[dir]) {
+ cardinal_adjc_dir_iterate(x, y, x1, y1, dir) {
+ if (rd_direction_is_valid[dir]) {
if (direction > 0) direction--;
else {
river_blockmark(x, y);
@@ -906,7 +894,7 @@
break;
}
}
- }
+ } cardinal_adjc_dir_iterate_end;
break;
} /* end switch (rd_number_of_directions()) */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#9162) new macro cardinal_adjc_dir_iterate,
Jason Short <=
|
|